mirror of
https://github.com/esphome/esphome.git
synced 2026-08-31 10:06:03 +00:00
[sht4x] Restore original comments removed in refactor
This commit is contained in:
@@ -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<float>(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<float>(buffer[1]) / RAW_MAX;
|
||||
this->humidity_sensor_->publish_state(rh);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user