31 ESP_LOGW(TAG,
"'%s': Received unknown status payload: %s", LOG_STR_ARG(this->
log_name_()), payload.c_str());
46 root[MQTT_OPTIMISTIC] =
true;
52 char topic_buf[MQTT_DEFAULT_TOPIC_MAX_LEN];
53 const char *state_s =
state ?
"ON" :
"OFF";
void status_momentary_warning(uint32_t length=5000)
Set warning status flag and clear it after length ms.
void defer(const char *name, std::function< void()> &&f)
Defer a callback to the next loop() call with a const char* name.
static constexpr uint32_t SEND_DEFER_ID
const LogString * log_name_() const
Entity name for a "%s" log argument.
void subscribe(T &&topic, F &&callback, uint8_t qos=0)
Subscribe to a MQTT topic.
MQTTTopicSource command_topic_source_() const
The command topic as a subscription source. A lambda topic is read once and copied,...
bool publish(const std::string &topic, const std::string &payload)
Send a MQTT message.
StringRef get_state_topic_to_(std::span< char, MQTT_DEFAULT_TOPIC_MAX_LEN > buf) const
Get the MQTT state topic into a buffer (no heap allocation for non-lambda custom topics).
void send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) override
bool send_initial_state() override
MQTTSwitchComponent(switch_::Switch *a_switch)
bool publish_state(bool state)
switch_::Switch * switch_
void dump_config() override
Base class for all switches.
void toggle()
Toggle this switch.
void add_on_state_callback(F &&callback)
Set callback for state changes.
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 bool assumed_state()
Return whether this switch uses an assumed state - i.e.
ESPHOME_LOG_TAG(TAG, "alarm_control_panel")
MQTT_COMPONENT_TYPE(MQTTAlarmControlPanelComponent, "alarm_control_panel") const EntityBase *MQTTAlarmControlPanelComponent
ParseOnOffState parse_on_off(const char *str, const char *on, const char *off)
Parse a string that contains either on, off or toggle.
Simple Helper struct used for Home Assistant MQTT send_discovery().