ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
sendspin_switch.cpp
Go to the documentation of this file.
1#include "sendspin_switch.h"
2
3#if defined(USE_ESP_IDF) && defined(USE_SENDSPIN_SWITCH)
4
5#include "esphome/core/log.h"
7
8namespace esphome::sendspin_ {
9
10ESPHOME_LOG_TAG(TAG, "sendspin.switch");
11
12// --- SendspinEnabledSwitch ---
13
15 // The hub waits for this request, so a restore mode without a state still has to answer.
16 this->control(this->get_initial_state_with_restore_mode().value_or(true));
17}
18
19void SendspinEnabledSwitch::dump_config() { LOG_SWITCH("", "Sendspin Enabled Switch", this); }
20
21// THREAD CONTEXT: Main loop
23 this->parent_->set_enabled(state);
24 this->publish_state(state);
25}
26
27// --- SendspinUnpairedAccessSwitch ---
28
30 // The hub holds the client's first start for this, so a restore mode without a state still has to answer.
31 this->control(this->get_initial_state_with_restore_mode().value_or(true));
32}
33
34void SendspinUnpairedAccessSwitch::dump_config() { LOG_SWITCH("", "Sendspin Unpaired Access Switch", this); }
35
36// THREAD CONTEXT: Main loop
38 const bool turning_off = !state && this->has_state() && this->state;
39 this->parent_->set_unpaired_access_enabled(state);
40 this->publish_state(state);
41 // Write the change to flash now: losing it in a power cut would reopen unpaired access.
42 if (turning_off) {
44 }
45}
46
47} // namespace esphome::sendspin_
48
49#endif
bool has_state() const
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
optional< bool > get_initial_state_with_restore_mode()
Returns the initial state of the switch, after applying restore mode rules.
Definition switch.cpp:42
void control(bool target_state)
Control this switch using a boolean state value.
Definition switch.cpp:12
bool state
Definition fan.h:2
ESPHOME_LOG_TAG(TAG, "sendspin.image")
ESPPreferences * global_preferences
bool sync()
Commit pending writes to flash.
Definition preferences.h:33