7#ifdef USE_BINARY_SENSOR
11static const char *
const TAG =
"mqtt.binary_sensor";
22 LOG_MQTT_COMPONENT(
true,
false);
25 : binary_sensor_(binary_sensor) {
27 this->set_custom_state_topic(mqtt::global_mqtt_client->get_availability().topic.c_str());
34 if (!device_class.empty()) {
35 root[MQTT_DEVICE_CLASS] = device_class;
55 char topic_buf[MQTT_DEFAULT_TOPIC_MAX_LEN];
56 const char *state_s =
state ?
"ON" :
"OFF";
StringRef get_device_class_ref() const
Get the device class as StringRef.
const StringRef & get_name() const
void add_on_state_callback(std::function< void(T)> &&callback)
virtual bool has_state() const
constexpr const char * c_str() const
Base class for all binary_sensor-type classes.
virtual bool is_status_binary_sensor() const
Return whether this binary sensor has outputted a state.
bool publish_state(bool state)
MQTTBinarySensorComponent(binary_sensor::BinarySensor *binary_sensor)
Construct a MQTTBinarySensorComponent.
void dump_config() override
void send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) override
bool send_initial_state() override
binary_sensor::BinarySensor * binary_sensor_
const Availability & get_availability()
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).
MQTT_COMPONENT_TYPE(MQTTAlarmControlPanelComponent, "alarm_control_panel") const EntityBase *MQTTAlarmControlPanelComponent
MQTTClientComponent * global_mqtt_client
std::string payload_not_available
std::string payload_available
Simple Helper struct used for Home Assistant MQTT send_discovery().
bool command_topic
If the command topic should be included. Default to true.