11 #define LOG_SWITCH(prefix, type, obj) \ 12 if ((obj) != nullptr) { \ 13 ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \ 14 if (!(obj)->get_icon().empty()) { \ 15 ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, (obj)->get_icon().c_str()); \ 17 if ((obj)->assumed_state()) { \ 18 ESP_LOGCONFIG(TAG, "%s Assumed State: YES", prefix); \ 20 if ((obj)->is_inverted()) { \ 21 ESP_LOGCONFIG(TAG, "%s Inverted: YES", prefix); \ 23 if (!(obj)->get_device_class().empty()) { \ 24 ESP_LOGCONFIG(TAG, "%s Device Class: '%s'", prefix, (obj)->get_device_class().c_str()); \ Base class for all switches.
CallbackManager< void(bool)> state_callback_
optional< std::string > device_class_
void set_device_class(const std::string &device_class)
Set the Home Assistant device class for this switch.
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()
void add_on_state_callback(std::function< void(bool)> &&callback)
Set callback for state changes.
void turn_on()
Turn this switch on.
void toggle()
Toggle this switch.
void set_inverted(bool inverted)
Set whether the state should be treated as inverted.
void publish_state(bool state)
Publish a state to the front-end from the back-end.
bool state
The current reported state of the binary sensor.
void turn_off()
Turn this switch off.