From 0302a14fa2525e3311506d6f2bbb79bf502e3a93 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 20 Mar 2026 14:10:40 -1000 Subject: [PATCH] [sht4x] Restore original comments removed in refactor --- esphome/components/sht4x/sht4x.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/esphome/components/sht4x/sht4x.cpp b/esphome/components/sht4x/sht4x.cpp index d9d6a71630..43c2436a56 100644 --- a/esphome/components/sht4x/sht4x.cpp +++ b/esphome/components/sht4x/sht4x.cpp @@ -79,7 +79,9 @@ void SHT4XComponent::dump_config() { } void SHT4XComponent::update() { + // Send command if (!this->write_command(MEASURECOMMANDS[this->precision_])) { + // Warning will be printed only if warning status is not set yet this->status_set_warning(LOG_STR("Failed to send measurement command")); return; } @@ -87,7 +89,9 @@ void SHT4XComponent::update() { this->set_timeout(10, [this]() { uint16_t buffer[2]; + // Read measurement if (!this->read_data(buffer, 2)) { + // Using ESP_LOGW to force the warning to be printed ESP_LOGW(TAG, "Sensor read failed"); this->status_set_warning(); return; @@ -95,12 +99,15 @@ void SHT4XComponent::update() { this->status_clear_warning(); + // Evaluate and publish measurements if (this->temp_sensor_ != nullptr) { + // Temp is contained in the first result word float temp = TEMPERATURE_OFFSET + TEMPERATURE_SPAN * static_cast(buffer[0]) / RAW_MAX; this->temp_sensor_->publish_state(temp); } if (this->humidity_sensor_ != nullptr) { + // Relative humidity is in the second result word float rh = HUMIDITY_OFFSET + HUMIDITY_SPAN * static_cast(buffer[1]) / RAW_MAX; this->humidity_sensor_->publish_state(rh); }