1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-03 20:02:22 +01:00

Add option to use MQTT abbreviations (#2641)

This commit is contained in:
Paul Monigatti
2021-10-31 15:34:08 +13:00
committed by GitHub
parent 7eee3cdc7f
commit 331a3ac387
14 changed files with 609 additions and 64 deletions

View File

@@ -1,6 +1,8 @@
#include "mqtt_binary_sensor.h"
#include "esphome/core/log.h"
#include "mqtt_const.h"
#ifdef USE_MQTT
#ifdef USE_BINARY_SENSOR
@@ -29,11 +31,11 @@ MQTTBinarySensorComponent::MQTTBinarySensorComponent(binary_sensor::BinarySensor
void MQTTBinarySensorComponent::send_discovery(JsonObject &root, mqtt::SendDiscoveryConfig &config) {
if (!this->binary_sensor_->get_device_class().empty())
root["device_class"] = this->binary_sensor_->get_device_class();
root[MQTT_DEVICE_CLASS] = this->binary_sensor_->get_device_class();
if (this->binary_sensor_->is_status_binary_sensor())
root["payload_on"] = mqtt::global_mqtt_client->get_availability().payload_available;
root[MQTT_PAYLOAD_ON] = mqtt::global_mqtt_client->get_availability().payload_available;
if (this->binary_sensor_->is_status_binary_sensor())
root["payload_off"] = mqtt::global_mqtt_client->get_availability().payload_not_available;
root[MQTT_PAYLOAD_OFF] = mqtt::global_mqtt_client->get_availability().payload_not_available;
config.command_topic = false;
}
bool MQTTBinarySensorComponent::send_initial_state() {