mirror of
https://github.com/esphome/esphome.git
synced 2024-12-23 16:47:57 +01:00
Add device_class support for MQTT integration (#1832)
This commit is contained in:
parent
d604321f37
commit
36861595f1
@ -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();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user