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))
Helper class to deduplicate items in a series of values.
Base class for all switches.
void toggle()
Toggle this switch.
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 add_on_state_callback(std::function< void(bool)> &&callback)
Set callback for state changes.
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)
CallbackManager< void(bool)> state_callback_
void set_inverted(bool inverted)
Set whether the state should be treated as inverted.
Deduplicator< bool > publish_dedup_
const int RESTORE_MODE_INVERTED_MASK
const int RESTORE_MODE_ON_MASK
const int RESTORE_MODE_DISABLED_MASK
void log_switch(const char *tag, const char *prefix, const char *type, Switch *obj)
const int RESTORE_MODE_PERSISTENT_MASK
@ SWITCH_RESTORE_DISABLED
@ SWITCH_RESTORE_INVERTED_DEFAULT_ON
@ SWITCH_RESTORE_INVERTED_DEFAULT_OFF
@ SWITCH_RESTORE_DEFAULT_OFF
@ SWITCH_RESTORE_DEFAULT_ON
Providing packet encoding functions for exchanging data with a remote host.