ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
demo_switch.h
Go to the documentation of this file.
1#pragma once
2
6
7namespace esphome::demo {
8
9class DemoSwitch : public switch_::Switch, public Component {
10 public:
11 void setup() override {
12 bool initial = random_float() < 0.5;
13 this->publish_state(initial);
14 }
15
16 protected:
17 void write_state(bool state) override { this->publish_state(state); }
18};
19
20} // namespace esphome::demo
void setup() override
Definition demo_switch.h:11
void write_state(bool state) override
Definition demo_switch.h:17
Base class for all switches.
Definition switch.h:38
bool state
The current reported state of the binary sensor.
Definition switch.h:55
void publish_state(bool state)
Publish a state to the front-end from the back-end.
Definition switch.cpp:56
float random_float()
Return a random float between 0 and 1.
Definition helpers.cpp:198