8static const char *
const TAG =
"switch";
13 ESP_LOGV(TAG,
"'%s' Control: %s", this->
get_name().c_str(), ONOFF(target_state));
21 ESP_LOGD(TAG,
"'%s' Turning ON.", this->
get_name().c_str());
25 ESP_LOGD(TAG,
"'%s' Turning OFF.", this->
get_name().c_str());
29 ESP_LOGD(TAG,
"'%s' Toggling %s.", this->
get_name().c_str(), this->
state ?
"OFF" :
"ON");
38 if (!this->
rtc_.
load(&initial_state))
64 ESP_LOGD(TAG,
"'%s' >> %s", this->
name_.
c_str(), ONOFF(this->state));
66#if defined(USE_SWITCH) && defined(USE_CONTROLLER_REGISTRY)
81 const LogString *onoff = LOG_STR(
""), *inverted = onoff, *restore;
83 restore = LOG_STR(
"disabled");
93 "%s Restore Mode: %s%s %s",
94 prefix,
type, obj->
get_name().
c_str(), prefix, LOG_STR_ARG(inverted), LOG_STR_ARG(restore),
98 LOG_ENTITY_ICON(tag, prefix, *obj);
100 ESP_LOGCONFIG(tag,
"%s Assumed State: YES", prefix);
103 ESP_LOGCONFIG(tag,
"%s Inverted: YES", prefix);
105 LOG_ENTITY_DEVICE_CLASS(tag, prefix, *obj);
static void notify_switch_update(switch_::Switch *obj)
bool next(T value)
Feeds the next item in the series to the deduplicator and returns false if this is a duplicate.
const StringRef & get_name() const
ESPPreferenceObject make_entity_preference(uint32_t version=0)
Create a preference object for storing this entity's state/settings.
constexpr const char * c_str() const
value_type const & value() const
Base class for all switches.
void toggle()
Toggle this switch.
LazyCallbackManager< void(bool)> state_callback_
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_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_ON_MASK
constexpr int RESTORE_MODE_INVERTED_MASK
void log_switch(const char *tag, const char *prefix, const char *type, Switch *obj)
constexpr int RESTORE_MODE_PERSISTENT_MASK
constexpr int RESTORE_MODE_DISABLED_MASK