esphome/esphome/components/demo/demo_text_sensor.h
2021-07-29 11:50:55 +02:00

25 lines
556 B
C++

#pragma once
#include "esphome/core/component.h"
#include "esphome/core/helpers.h"
#include "esphome/components/text_sensor/text_sensor.h"
namespace esphome {
namespace demo {
class DemoTextSensor : public text_sensor::TextSensor, public PollingComponent {
public:
void update() override {
float val = random_float();
if (val < 0.33) {
this->publish_state("foo");
} else if (val < 0.66) {
this->publish_state("bar");
} else {
this->publish_state("foobar");
}
}
};
} // namespace demo
} // namespace esphome