ESPHome 2025.5.0
Loading...
Searching...
No Matches
demo_switch.h
Go to the documentation of this file.
1#pragma once
2
6
7namespace esphome {
8namespace demo {
9
10class 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
void setup() override
Definition demo_switch.h:12
void write_state(bool state) override
Definition demo_switch.h:18
Base class for all switches.
Definition switch.h:39
bool state
The current reported state of the binary sensor.
Definition switch.h:53
void publish_state(bool state)
Publish a state to the front-end from the back-end.
Definition switch.cpp:47
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
float random_float()
Return a random float between 0 and 1.
Definition helpers.cpp:218