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
1 changed files with 3 additions and 0 deletions

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; }
std::string MQTTSensorComponent::friendly_name() const { return this->sensor_->get_name(); }
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())
root["unit_of_measurement"] = this->sensor_->get_unit_of_measurement();