7 static const char *
const TAG =
"switch";
13 ESP_LOGD(TAG,
"'%s' Turning ON.", this->
get_name().c_str());
17 ESP_LOGD(TAG,
"'%s' Turning OFF.", this->
get_name().c_str());
21 ESP_LOGD(TAG,
"'%s' Toggling %s.", this->
get_name().c_str(), this->
state ?
"OFF" :
"ON");
27 if (!this->
rtc_.
load(&initial_state))
37 ESP_LOGD(TAG,
"'%s': Sending state %s", this->
name_.c_str(), ONOFF(this->state));
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.
bool next(T value)
Feeds the next item in the series to the deduplicator and returns whether this is a duplicate...
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.
const std::string & get_name() const
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.
ESPPreferences * global_preferences
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.
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
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.
uint32_t get_object_id_hash()
void turn_off()
Turn this switch off.