ESPHome  2024.3.1
demo_switch.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 
10 class DemoSwitch : public switch_::Switch, public Component {
11  public:
12  void setup() override {
13  bool initial = random_float() < 0.5;
14  this->publish_state(initial);
15  }
16 
17  protected:
18  void write_state(bool state) override { this->publish_state(state); }
19 };
20 
21 } // namespace demo
22 } // namespace esphome
Base class for all switches.
Definition: switch.h:39
void write_state(bool state) override
Definition: demo_switch.h:18
void setup() override
Definition: demo_switch.h:12
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
void publish_state(bool state)
Publish a state to the front-end from the back-end.
Definition: switch.cpp:47
bool state
The current reported state of the binary sensor.
Definition: switch.h:53
float random_float()
Return a random float between 0 and 1.
Definition: helpers.cpp:216