mirror of
https://github.com/esphome/esphome.git
synced 2024-11-14 11:08:10 +01:00
Check DHT sensor exists before publishing (#850)
Fixes https://github.com/esphome/issues/issues/841
This commit is contained in:
parent
74878276fc
commit
7c0d777173
1 changed files with 8 additions and 4 deletions
|
@ -47,7 +47,9 @@ void DHT::update() {
|
||||||
if (error) {
|
if (error) {
|
||||||
ESP_LOGD(TAG, "Got Temperature=%.1f°C Humidity=%.1f%%", temperature, humidity);
|
ESP_LOGD(TAG, "Got Temperature=%.1f°C Humidity=%.1f%%", temperature, humidity);
|
||||||
|
|
||||||
|
if (this->temperature_sensor_ != nullptr)
|
||||||
this->temperature_sensor_->publish_state(temperature);
|
this->temperature_sensor_->publish_state(temperature);
|
||||||
|
if (this->humidity_sensor_ != nullptr)
|
||||||
this->humidity_sensor_->publish_state(humidity);
|
this->humidity_sensor_->publish_state(humidity);
|
||||||
this->status_clear_warning();
|
this->status_clear_warning();
|
||||||
} else {
|
} else {
|
||||||
|
@ -56,7 +58,9 @@ void DHT::update() {
|
||||||
str = " and consider manually specifying the DHT model using the model option";
|
str = " and consider manually specifying the DHT model using the model option";
|
||||||
}
|
}
|
||||||
ESP_LOGW(TAG, "Invalid readings! Please check your wiring (pull-up resistor, pin number)%s.", str);
|
ESP_LOGW(TAG, "Invalid readings! Please check your wiring (pull-up resistor, pin number)%s.", str);
|
||||||
|
if (this->temperature_sensor_ != nullptr)
|
||||||
this->temperature_sensor_->publish_state(NAN);
|
this->temperature_sensor_->publish_state(NAN);
|
||||||
|
if (this->humidity_sensor_ != nullptr)
|
||||||
this->humidity_sensor_->publish_state(NAN);
|
this->humidity_sensor_->publish_state(NAN);
|
||||||
this->status_set_warning();
|
this->status_set_warning();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue