[shtcx] Shorten log messages (#9046)

This commit is contained in:
Keith Burzinski 2025-06-11 04:44:10 -05:00 committed by GitHub
parent 9d9d210176
commit 69f2c79ccb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -20,7 +20,7 @@ inline const char *to_string(SHTCXType type) {
case SHTCX_TYPE_SHTC1: case SHTCX_TYPE_SHTC1:
return "SHTC1"; return "SHTC1";
default: default:
return "[Unknown model]"; return "UNKNOWN";
} }
} }
@ -29,15 +29,9 @@ void SHTCXComponent::setup() {
this->wake_up(); this->wake_up();
this->soft_reset(); this->soft_reset();
if (!this->write_command(SHTCX_COMMAND_READ_ID_REGISTER)) {
ESP_LOGE(TAG, "Error requesting Device ID");
this->mark_failed();
return;
}
uint16_t device_id_register; uint16_t device_id_register;
if (!this->read_data(&device_id_register, 1)) { if (!this->write_command(SHTCX_COMMAND_READ_ID_REGISTER) || !this->read_data(&device_id_register, 1)) {
ESP_LOGE(TAG, "Error reading Device ID"); ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
this->mark_failed(); this->mark_failed();
return; return;
} }
@ -53,8 +47,8 @@ void SHTCXComponent::setup() {
} else { } else {
this->type_ = SHTCX_TYPE_UNKNOWN; this->type_ = SHTCX_TYPE_UNKNOWN;
} }
ESP_LOGCONFIG(TAG, " Device identified: %s (%04x)", to_string(this->type_), device_id_register);
} }
void SHTCXComponent::dump_config() { void SHTCXComponent::dump_config() {
ESP_LOGCONFIG(TAG, "SHTCx:"); ESP_LOGCONFIG(TAG, "SHTCx:");
ESP_LOGCONFIG(TAG, " Model: %s (%04x)", to_string(this->type_), this->sensor_id_); ESP_LOGCONFIG(TAG, " Model: %s (%04x)", to_string(this->type_), this->sensor_id_);
@ -67,17 +61,19 @@ void SHTCXComponent::dump_config() {
LOG_SENSOR(" ", "Temperature", this->temperature_sensor_); LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
LOG_SENSOR(" ", "Humidity", this->humidity_sensor_); LOG_SENSOR(" ", "Humidity", this->humidity_sensor_);
} }
float SHTCXComponent::get_setup_priority() const { return setup_priority::DATA; } float SHTCXComponent::get_setup_priority() const { return setup_priority::DATA; }
void SHTCXComponent::update() { void SHTCXComponent::update() {
if (this->status_has_warning()) { if (this->status_has_warning()) {
ESP_LOGW(TAG, "Retrying to reconnect the sensor."); ESP_LOGW(TAG, "Retrying communication");
this->soft_reset(); this->soft_reset();
} }
if (this->type_ != SHTCX_TYPE_SHTC1) { if (this->type_ != SHTCX_TYPE_SHTC1) {
this->wake_up(); this->wake_up();
} }
if (!this->write_command(SHTCX_COMMAND_POLLING_H)) { if (!this->write_command(SHTCX_COMMAND_POLLING_H)) {
ESP_LOGE(TAG, "sensor polling failed"); ESP_LOGE(TAG, "Polling failed");
if (this->temperature_sensor_ != nullptr) if (this->temperature_sensor_ != nullptr)
this->temperature_sensor_->publish_state(NAN); this->temperature_sensor_->publish_state(NAN);
if (this->humidity_sensor_ != nullptr) if (this->humidity_sensor_ != nullptr)
@ -91,13 +87,13 @@ void SHTCXComponent::update() {
float humidity = NAN; float humidity = NAN;
uint16_t raw_data[2]; uint16_t raw_data[2];
if (!this->read_data(raw_data, 2)) { if (!this->read_data(raw_data, 2)) {
ESP_LOGE(TAG, "sensor read failed"); ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
this->status_set_warning(); this->status_set_warning();
} else { } else {
temperature = 175.0f * float(raw_data[0]) / 65536.0f - 45.0f; temperature = 175.0f * float(raw_data[0]) / 65536.0f - 45.0f;
humidity = 100.0f * float(raw_data[1]) / 65536.0f; humidity = 100.0f * float(raw_data[1]) / 65536.0f;
ESP_LOGD(TAG, "Got temperature=%.2f°C humidity=%.2f%%", temperature, humidity); ESP_LOGD(TAG, "Temperature=%.2f°C Humidity=%.2f%%", temperature, humidity);
} }
if (this->temperature_sensor_ != nullptr) if (this->temperature_sensor_ != nullptr)
this->temperature_sensor_->publish_state(temperature); this->temperature_sensor_->publish_state(temperature);
@ -114,6 +110,7 @@ void SHTCXComponent::soft_reset() {
this->write_command(SHTCX_COMMAND_SOFT_RESET); this->write_command(SHTCX_COMMAND_SOFT_RESET);
delayMicroseconds(200); delayMicroseconds(200);
} }
void SHTCXComponent::sleep() { this->write_command(SHTCX_COMMAND_SLEEP); } void SHTCXComponent::sleep() { this->write_command(SHTCX_COMMAND_SLEEP); }
void SHTCXComponent::wake_up() { void SHTCXComponent::wake_up() {