1
0
mirror of https://github.com/esphome/esphome.git synced 2024-10-06 10:50:58 +01:00

Add device_class support for MQTT integration (#1832)

This commit is contained in:
definitio 2021-07-01 16:36:01 +03:00 committed by GitHub
parent d604321f37
commit 36861595f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,6 +46,9 @@ void MQTTSensorComponent::set_expire_after(uint32_t expire_after) { this->expire
void MQTTSensorComponent::disable_expire_after() { this->expire_after_ = 0; } void MQTTSensorComponent::disable_expire_after() { this->expire_after_ = 0; }
std::string MQTTSensorComponent::friendly_name() const { return this->sensor_->get_name(); } std::string MQTTSensorComponent::friendly_name() const { return this->sensor_->get_name(); }
void MQTTSensorComponent::send_discovery(JsonObject &root, mqtt::SendDiscoveryConfig &config) { void MQTTSensorComponent::send_discovery(JsonObject &root, mqtt::SendDiscoveryConfig &config) {
if (!this->sensor_->get_device_class().empty())
root["device_class"] = this->sensor_->get_device_class();
if (!this->sensor_->get_unit_of_measurement().empty()) if (!this->sensor_->get_unit_of_measurement().empty())
root["unit_of_measurement"] = this->sensor_->get_unit_of_measurement(); root["unit_of_measurement"] = this->sensor_->get_unit_of_measurement();