10#define SUB_SWITCH(name) \
12 switch_::Switch *name##_switch_{nullptr}; \
15 void set_##name##_switch(switch_::Switch *s) { this->name##_switch_ = s; }
69 void control(
bool target_state);
121 void restore(
bool when_disabled);
157#define LOG_SWITCH(prefix, type, obj) log_switch((TAG), (prefix), LOG_STR_LITERAL(type), (obj))
158void log_switch(
const char *tag,
const char *prefix,
const char *
type, Switch *obj);
Helper class to deduplicate items in a series of values.
Calls the codegen-generated Fn(this, state) on a state write; the hub and any publish are baked into ...
void write_state(bool state) override
Base class for all switches.
void toggle()
Toggle this switch.
LazyCallbackManager< void(bool)> state_callback_
void add_on_state_callback(F &&callback)
Set callback for state changes.
optional< bool > get_initial_state()
Returns the initial state of the switch, as persisted previously, or empty if never persisted.
void turn_on()
Turn this switch on.
void turn_off()
Turn this switch off.
bool state
The current reported state of the binary sensor.
virtual void write_state(bool state)=0
Write the given state to hardware.
SwitchRestoreMode restore_mode
Indicates whether or not state is to be retrieved from flash and how.
void restore()
Drive the switch to the state its restore mode yields, through control(), so inversion and write_stat...
void publish_state(bool state)
Publish a state to the front-end from the back-end.
virtual bool assumed_state()
Return whether this switch uses an assumed state - i.e.
optional< bool > get_initial_state_with_restore_mode()
Returns the initial state of the switch, after applying restore mode rules.
void set_restore_mode(SwitchRestoreMode restore_mode)
void set_inverted(bool inverted)
Set whether the state should be treated as inverted.
Deduplicator< bool > publish_dedup_
void control(bool target_state)
Control this switch using a boolean state value.
constexpr int RESTORE_MODE_STORAGE_RTC_MASK
constexpr int RESTORE_MODE_ON_MASK
constexpr int RESTORE_MODE_STORAGE_MASK
constexpr int RESTORE_MODE_INVERTED_MASK
void log_switch(const char *tag, const char *prefix, const char *type, Switch *obj)
@ SWITCH_RESTORE_DISABLED
@ SWITCH_RESTORE_INVERTED_DEFAULT_ON
@ SWITCH_RESTORE_INVERTED_DEFAULT_OFF
@ SWITCH_RESTORE_DEFAULT_OFF
@ SWITCH_RESTORE_DEFAULT_ON
constexpr int RESTORE_MODE_STORAGE_FLASH_MASK
constexpr int RESTORE_MODE_PERSISTENT_MASK
constexpr int RESTORE_MODE_DISABLED_MASK