ESPHome  2022.6.3
demo_text_sensor.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/helpers.h"
6 
7 namespace esphome {
8 namespace demo {
9 
11  public:
12  void update() override {
13  float val = random_float();
14  if (val < 0.33) {
15  this->publish_state("foo");
16  } else if (val < 0.66) {
17  this->publish_state("bar");
18  } else {
19  this->publish_state("foobar");
20  }
21  }
22 };
23 
24 } // namespace demo
25 } // namespace esphome
This class simplifies creating components that periodically check a state.
Definition: component.h:266
void publish_state(const std::string &state)
Definition: text_sensor.cpp:12
Definition: a4988.cpp:4
uint32_t val
Definition: datatypes.h:85
float random_float()
Return a random float between 0 and 1.
Definition: helpers.cpp:83