Update esphome/components/mqtt/mqtt_sensor.cpp

This commit is contained in:
Jesse Hills 2024-11-18 09:13:30 +13:00 committed by GitHub
parent 9af492c219
commit cf8d931176
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -69,9 +69,9 @@ bool MQTTSensorComponent::send_initial_state() {
}
}
bool MQTTSensorComponent::publish_state(float value) {
int8_t accuracy = this->sensor_->get_accuracy_decimals();
if (std::isnan(value))
return this->publish(this->get_state_topic_(), "None");
int8_t accuracy = this->sensor_->get_accuracy_decimals();
return this->publish(this->get_state_topic_(), value_accuracy_to_string(value, accuracy));
}
std::string MQTTSensorComponent::unique_id() { return this->sensor_->unique_id(); }