131 #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_
optional< std::string > device_class_
void set_restore_mode(SwitchRestoreMode restore_mode)
void set_device_class(const std::string &device_class)
Set the Home Assistant device class for this switch.
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_
std::string get_device_class()
Get the device class for this switch.
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
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.