7#ifdef USE_BINARY_SENSOR
12static const char *
const TAG =
"mqtt.binary_sensor";
23 LOG_MQTT_COMPONENT(
true,
false)
26 : binary_sensor_(binary_sensor) {
28 this->set_custom_state_topic(mqtt::global_mqtt_client->get_availability().topic.c_str());
52 const char *state_s =
state ?
"ON" :
"OFF";
std::string get_device_class()
Get the device class, using the manual override if set.
const StringRef & get_name() const
constexpr const char * c_str() const
Base class for all binary_sensor-type classes.
virtual bool has_state() const
Return whether this binary sensor has outputted a state.
bool state
The current reported state of the binary sensor.
void add_on_state_callback(std::function< void(bool)> &&callback)
Add a callback to be notified of state changes.
virtual bool is_status_binary_sensor() const
bool publish_state(bool state)
MQTTBinarySensorComponent(binary_sensor::BinarySensor *binary_sensor)
Construct a MQTTBinarySensorComponent.
const EntityBase * get_entity() const override
void dump_config() override
void send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) override
bool send_initial_state() override
std::string component_type() const override
binary_sensor::BinarySensor * binary_sensor_
const Availability & get_availability()
bool publish(const std::string &topic, const std::string &payload)
Send a MQTT message.
std::string get_state_topic_() const
Get the MQTT topic that new states will be shared to.
constexpr const char *const MQTT_PAYLOAD_ON
constexpr const char *const MQTT_PAYLOAD_OFF
MQTTClientComponent * global_mqtt_client
constexpr const char *const MQTT_DEVICE_CLASS
Providing packet encoding functions for exchanging data with a remote host.
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.