mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-01 02:28:28 +02:00
Add option to use MQTT abbreviations (#2641)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#include "mqtt_sensor.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
#include "mqtt_const.h"
|
||||
|
||||
#ifdef USE_MQTT
|
||||
#ifdef USE_SENSOR
|
||||
|
||||
@@ -42,19 +44,19 @@ void MQTTSensorComponent::disable_expire_after() { this->expire_after_ = 0; }
|
||||
|
||||
void MQTTSensorComponent::send_discovery(JsonObject &root, mqtt::SendDiscoveryConfig &config) {
|
||||
if (!this->sensor_->get_device_class().empty())
|
||||
root["device_class"] = this->sensor_->get_device_class();
|
||||
root[MQTT_DEVICE_CLASS] = this->sensor_->get_device_class();
|
||||
|
||||
if (!this->sensor_->get_unit_of_measurement().empty())
|
||||
root["unit_of_measurement"] = this->sensor_->get_unit_of_measurement();
|
||||
root[MQTT_UNIT_OF_MEASUREMENT] = this->sensor_->get_unit_of_measurement();
|
||||
|
||||
if (this->get_expire_after() > 0)
|
||||
root["expire_after"] = this->get_expire_after() / 1000;
|
||||
root[MQTT_EXPIRE_AFTER] = this->get_expire_after() / 1000;
|
||||
|
||||
if (this->sensor_->get_force_update())
|
||||
root["force_update"] = true;
|
||||
root[MQTT_FORCE_UPDATE] = true;
|
||||
|
||||
if (this->sensor_->get_state_class() != STATE_CLASS_NONE)
|
||||
root["state_class"] = state_class_to_string(this->sensor_->get_state_class());
|
||||
root[MQTT_STATE_CLASS] = state_class_to_string(this->sensor_->get_state_class());
|
||||
|
||||
config.command_topic = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user