11 #define SUB_SWITCH(name) \ 13 switch_::Switch *name##_switch_{nullptr}; \ 16 void set_##name##_switch(switch_::Switch *s) { this->name##_switch_ = s; } 132 #define LOG_SWITCH(prefix, type, obj) log_switch((TAG), (prefix), LOG_STR_LITERAL(type), (obj))
Base class for all switches.
CallbackManager< void(bool)> state_callback_
void set_restore_mode(SwitchRestoreMode restore_mode)
void log_switch(const char *tag, const char *prefix, const char *type, Switch *obj)
virtual bool assumed_state()
Return whether this switch uses an assumed state - i.e.
virtual void write_state(bool state)=0
Write the given state to hardware.
Deduplicator< bool > publish_dedup_
optional< bool > get_initial_state()
Returns the initial state of the switch, as persisted previously, or empty if never persisted...
optional< bool > get_initial_state_with_restore_mode()
Returns the initial state of the switch, after applying restore mode rules.
void add_on_state_callback(std::function< void(bool)> &&callback)
Set callback for state changes.
const int RESTORE_MODE_ON_MASK
void turn_on()
Turn this switch on.
SwitchRestoreMode restore_mode
Indicates whether or not state is to be retrieved from flash and how.
void toggle()
Toggle this switch.
const int RESTORE_MODE_INVERTED_MASK
void set_inverted(bool inverted)
Set whether the state should be treated as inverted.
const int RESTORE_MODE_PERSISTENT_MASK
Implementation of SPI Controller mode.
void publish_state(bool state)
Publish a state to the front-end from the back-end.
const int RESTORE_MODE_DISABLED_MASK
bool state
The current reported state of the binary sensor.
void turn_off()
Turn this switch off.