mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 17:27:59 +01:00
MQTT handling of nan values to align with Hass
This commit is contained in:
parent
6ff866cf5b
commit
0ce94826e5
2 changed files with 6 additions and 4 deletions
|
@ -255,16 +255,16 @@ void LD2410Component::handle_periodic_data_(uint8_t *buffer, int len) {
|
|||
} else {
|
||||
for (auto *s : this->gate_move_sensors_) {
|
||||
if (s != nullptr && !std::isnan(s->get_state())) {
|
||||
s->publish_state(0);
|
||||
s->publish_state(NAN);
|
||||
}
|
||||
}
|
||||
for (auto *s : this->gate_still_sensors_) {
|
||||
if (s != nullptr && !std::isnan(s->get_state())) {
|
||||
s->publish_state(0);
|
||||
s->publish_state(NAN);
|
||||
}
|
||||
}
|
||||
if (this->light_sensor_ != nullptr && !std::isnan(this->light_sensor_->get_state())) {
|
||||
this->light_sensor_->publish_state(0);
|
||||
this->light_sensor_->publish_state(NAN);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -70,6 +70,8 @@ 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");
|
||||
return this->publish(this->get_state_topic_(), value_accuracy_to_string(value, accuracy));
|
||||
}
|
||||
std::string MQTTSensorComponent::unique_id() { return this->sensor_->unique_id(); }
|
||||
|
|
Loading…
Reference in a new issue