diff --git a/esphome/components/dac7678/dac7678_output.cpp b/esphome/components/dac7678/dac7678_output.cpp index d1a076733aa..de61964a8ff 100644 --- a/esphome/components/dac7678/dac7678_output.cpp +++ b/esphome/components/dac7678/dac7678_output.cpp @@ -23,8 +23,7 @@ void DAC7678Output::setup() { // Reset device if (!this->write_byte_16(DAC7678_REG_SOFTWARE_RESET, 0x0000)) { - ESP_LOGE(TAG, "Reset failed"); - this->mark_failed(); + this->mark_failed(LOG_STR("Reset failed")); return; } else { ESP_LOGV(TAG, "Reset succeeded"); @@ -35,8 +34,7 @@ void DAC7678Output::setup() { // Set internal reference if (this->internal_reference_) { if (!this->write_byte_16(DAC7678_REG_INTERNAL_REF_0, 1 << 4)) { - ESP_LOGE(TAG, "Set internal reference failed"); - this->mark_failed(); + this->mark_failed(LOG_STR("Set internal reference failed")); return; } else { ESP_LOGV(TAG, "Internal reference enabled"); @@ -45,9 +43,7 @@ void DAC7678Output::setup() { } void DAC7678Output::dump_config() { - if (this->is_failed()) { - ESP_LOGE(TAG, "Setting up DAC7678 failed!"); - } else { + if (!this->is_failed()) { ESP_LOGCONFIG(TAG, "DAC7678 initialised"); } } diff --git a/esphome/components/dht12/dht12.cpp b/esphome/components/dht12/dht12.cpp index e099b65d5b7..353546dba3a 100644 --- a/esphome/components/dht12/dht12.cpp +++ b/esphome/components/dht12/dht12.cpp @@ -35,16 +35,13 @@ void DHT12Component::update() { void DHT12Component::setup() { uint8_t data[5]; if (!this->read_data_(data)) { - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } } void DHT12Component::dump_config() { ESP_LOGD(TAG, "DHT12:"); LOG_I2C_DEVICE(this); - if (this->is_failed()) { - ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); - } LOG_SENSOR(" ", "Temperature", this->temperature_sensor_); LOG_SENSOR(" ", "Humidity", this->humidity_sensor_); } diff --git a/esphome/components/dps310/dps310.cpp b/esphome/components/dps310/dps310.cpp index 080f101747f..6ab786e7c71 100644 --- a/esphome/components/dps310/dps310.cpp +++ b/esphome/components/dps310/dps310.cpp @@ -9,13 +9,17 @@ ESPHOME_LOG_TAG(TAG, "dps310"); static constexpr uint32_t READ_RETRY_TIMEOUT_ID = 0; void DPS310Component::setup() { + if (!this->setup_registers_()) + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); +} + +bool DPS310Component::setup_registers_() { uint8_t coef_data_raw[DPS310_NUM_COEF_REGS]; auto timer = DPS310_INIT_TIMEOUT; uint8_t reg = 0; // first, reset the sensor if (!this->write_byte(DPS310_REG_RESET, DPS310_CMD_RESET)) { - this->mark_failed(); - return; + return false; } delay(10); // wait for the sensor and its coefficients to be ready @@ -25,40 +29,32 @@ void DPS310Component::setup() { } if (!(reg & DPS310_BIT_SENSOR_RDY) || !(reg & DPS310_BIT_COEF_RDY)) { // the flags were not set in time - this->mark_failed(); - return; + return false; } // read device ID if (!this->read_byte(DPS310_REG_PROD_REV_ID, &this->prod_rev_id_)) { - this->mark_failed(); - return; + return false; } // read in coefficients used to calculate the compensated pressure and temperature values if (!this->read_bytes(DPS310_REG_COEF, coef_data_raw, DPS310_NUM_COEF_REGS)) { - this->mark_failed(); - return; + return false; } // read in coefficients source register, too -- we need this a few lines down if (!this->read_byte(DPS310_REG_TMP_COEF_SRC, ®)) { - this->mark_failed(); - return; + return false; } // set up operational stuff if (!this->write_byte(DPS310_REG_PRS_CFG, DPS310_VAL_PRS_CFG)) { - this->mark_failed(); - return; + return false; } if (!this->write_byte(DPS310_REG_TMP_CFG, DPS310_VAL_TMP_CFG | (reg & DPS310_BIT_TMP_COEF_SRC))) { - this->mark_failed(); - return; + return false; } if (!this->write_byte(DPS310_REG_CFG, DPS310_VAL_REG_CFG)) { - this->mark_failed(); - return; + return false; } if (!this->write_byte(DPS310_REG_MEAS_CFG, 0x07)) { // enable background mode - this->mark_failed(); - return; + return false; } this->c0_ = // we only ever use c0/2, so just divide by 2 here to save time later @@ -82,6 +78,7 @@ void DPS310Component::setup() { this->c20_ = int16_t(((uint16_t) coef_data_raw[12] << 8) | (uint16_t) coef_data_raw[13]); this->c21_ = int16_t(((uint16_t) coef_data_raw[14] << 8) | (uint16_t) coef_data_raw[15]); this->c30_ = int16_t(((uint16_t) coef_data_raw[16] << 8) | (uint16_t) coef_data_raw[17]); + return true; } void DPS310Component::dump_config() { @@ -91,9 +88,6 @@ void DPS310Component::dump_config() { " Revision ID: %u", this->prod_rev_id_ & 0x0F, (this->prod_rev_id_ >> 4) & 0x0F); LOG_I2C_DEVICE(this); - if (this->is_failed()) { - ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); - } LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "Temperature", this->temperature_sensor_); LOG_SENSOR(" ", "Pressure", this->pressure_sensor_); diff --git a/esphome/components/dps310/dps310.h b/esphome/components/dps310/dps310.h index 4dd23985d75..d761940ca99 100644 --- a/esphome/components/dps310/dps310.h +++ b/esphome/components/dps310/dps310.h @@ -45,6 +45,8 @@ class DPS310Component final : public PollingComponent, public i2c::I2CDevice { void set_pressure_sensor(sensor::Sensor *pressure_sensor) { pressure_sensor_ = pressure_sensor; } protected: + /// Configure the sensor; false on a failure. + bool setup_registers_(); void read_(); void read_pressure_(); void read_temperature_(); diff --git a/esphome/components/ds1307/ds1307.cpp b/esphome/components/ds1307/ds1307.cpp index 4ddef04f413..485e0f4b5c1 100644 --- a/esphome/components/ds1307/ds1307.cpp +++ b/esphome/components/ds1307/ds1307.cpp @@ -10,7 +10,7 @@ ESPHOME_LOG_TAG(TAG, "ds1307"); void DS1307Component::setup() { if (!this->read_rtc_()) { - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); } } @@ -19,9 +19,6 @@ void DS1307Component::update() { this->read_time(); } void DS1307Component::dump_config() { ESP_LOGCONFIG(TAG, "DS1307:"); LOG_I2C_DEVICE(this); - if (this->is_failed()) { - ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); - } RealTimeClock::dump_config(); } diff --git a/esphome/components/ds3231/ds3231.cpp b/esphome/components/ds3231/ds3231.cpp index 4f7396fcbdd..72cae0e3832 100644 --- a/esphome/components/ds3231/ds3231.cpp +++ b/esphome/components/ds3231/ds3231.cpp @@ -29,10 +29,6 @@ void DS3231Component::setup() { void DS3231Component::dump_config() { ESP_LOGCONFIG(TAG, "DS3231:"); LOG_I2C_DEVICE(this); - if (this->is_failed()) { - ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); - return; - } } bool DS3231Component::read_temperature(float &out) { diff --git a/esphome/components/emc2101/emc2101.cpp b/esphome/components/emc2101/emc2101.cpp index 6a21b4e7b8e..c6ae5169e4c 100644 --- a/esphome/components/emc2101/emc2101.cpp +++ b/esphome/components/emc2101/emc2101.cpp @@ -60,7 +60,7 @@ void Emc2101Component::setup() { uint8_t chip_id = reg(EMC2101_REGISTER_WHOAMI).get(); if ((chip_id != EMC2101_CHIP_ID) && (chip_id != EMC2101_ALT_CHIP_ID)) { ESP_LOGE(TAG, "Wrong chip ID %02X", chip_id); - this->mark_failed(); + this->mark_failed(LOG_STR("Wrong chip ID")); return; } @@ -90,9 +90,6 @@ void Emc2101Component::setup() { void Emc2101Component::dump_config() { ESP_LOGCONFIG(TAG, "Emc2101 component:"); LOG_I2C_DEVICE(this); - if (this->is_failed()) { - ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); - } ESP_LOGCONFIG(TAG, " Mode: %s", this->dac_mode_ ? LOG_STR_LITERAL("DAC") : LOG_STR_LITERAL("PWM")); if (this->dac_mode_) { ESP_LOGCONFIG(TAG, " DAC Conversion Rate: %X", this->dac_conversion_rate_); diff --git a/esphome/components/ens160_base/ens160_base.cpp b/esphome/components/ens160_base/ens160_base.cpp index b06182e59c0..b18a44f7523 100644 --- a/esphome/components/ens160_base/ens160_base.cpp +++ b/esphome/components/ens160_base/ens160_base.cpp @@ -62,20 +62,17 @@ void ENS160Component::setup() { // check part_id uint16_t part_id; if (!this->read_bytes(ENS160_REG_PART_ID, reinterpret_cast(&part_id), 2)) { - this->error_code_ = COMMUNICATION_FAILED; - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } if (part_id != ENS160_PART_ID) { - this->error_code_ = INVALID_ID; - this->mark_failed(); + this->mark_failed(LOG_STR("Sensor reported an invalid ID. Is this a ENS160?")); return; } // set mode to reset if (!this->write_byte(ENS160_REG_OPMODE, ENS160_OPMODE_RESET)) { - this->error_code_ = WRITE_FAILED; - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } delay(ENS160_BOOTING); @@ -83,51 +80,44 @@ void ENS160Component::setup() { // check status uint8_t status_value; if (!this->read_byte(ENS160_REG_DATA_STATUS, &status_value)) { - this->error_code_ = READ_FAILED; - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } this->validity_flag_ = static_cast((ENS160_DATA_STATUS_VALIDITY & status_value) >> 2); if (this->validity_flag_ == INVALID_OUTPUT) { - this->error_code_ = VALIDITY_INVALID; - this->mark_failed(); + this->mark_failed(LOG_STR("Invalid Device Status - No valid output")); return; } // set mode to idle if (!this->write_byte(ENS160_REG_OPMODE, ENS160_OPMODE_IDLE)) { - this->error_code_ = WRITE_FAILED; - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } delay(ENS160_BOOTING); // clear command if (!this->write_byte(ENS160_REG_COMMAND, ENS160_COMMAND_NOP)) { - this->error_code_ = WRITE_FAILED; - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } if (!this->write_byte(ENS160_REG_COMMAND, ENS160_COMMAND_CLRGPR)) { - this->error_code_ = WRITE_FAILED; - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } delay(ENS160_BOOTING); // read firmware version if (!this->write_byte(ENS160_REG_COMMAND, ENS160_COMMAND_GET_APPVER)) { - this->error_code_ = WRITE_FAILED; - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } delay(ENS160_BOOTING); uint8_t version_data[3]; if (!this->read_bytes(ENS160_REG_GPR_READ_4, version_data, 3)) { - this->error_code_ = READ_FAILED; - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } this->firmware_ver_major_ = version_data[0]; @@ -136,22 +126,19 @@ void ENS160Component::setup() { // set mode to standard if (!this->write_byte(ENS160_REG_OPMODE, ENS160_OPMODE_STD)) { - this->error_code_ = WRITE_FAILED; - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } // read opmode and check standard mode is achieved before finishing Setup uint8_t op_mode; if (!this->read_byte(ENS160_REG_OPMODE, &op_mode)) { - this->error_code_ = READ_FAILED; - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } if (op_mode != ENS160_OPMODE_STD) { - this->error_code_ = STD_OPMODE_FAILED; - this->mark_failed(); + this->mark_failed(LOG_STR("Device failed to achieve Standard Operating Mode")); return; } } @@ -291,29 +278,8 @@ void ENS160Component::send_env_data_() { void ENS160Component::dump_config() { ESP_LOGCONFIG(TAG, "ENS160:"); - - switch (this->error_code_) { - case COMMUNICATION_FAILED: - ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); - break; - case READ_FAILED: - ESP_LOGE(TAG, "Error reading from register"); - break; - case WRITE_FAILED: - ESP_LOGE(TAG, "Error writing to register"); - break; - case INVALID_ID: - ESP_LOGE(TAG, "Sensor reported an invalid ID. Is this a ENS160?"); - break; - case VALIDITY_INVALID: - ESP_LOGE(TAG, "Invalid Device Status - No valid output"); - break; - case STD_OPMODE_FAILED: - ESP_LOGE(TAG, "Device failed to achieve Standard Operating Mode"); - break; - case NONE: - ESP_LOGD(TAG, "Setup successful"); - break; + if (!this->is_failed()) { + ESP_LOGD(TAG, "Setup successful"); } ESP_LOGI(TAG, "Firmware Version: %d.%d.%d", this->firmware_ver_major_, this->firmware_ver_minor_, this->firmware_ver_build_); diff --git a/esphome/components/ens160_base/ens160_base.h b/esphome/components/ens160_base/ens160_base.h index f42272684ed..d844dccb02c 100644 --- a/esphome/components/ens160_base/ens160_base.h +++ b/esphome/components/ens160_base/ens160_base.h @@ -21,16 +21,6 @@ class ENS160Component : public PollingComponent, public sensor::Sensor { protected: void send_env_data_(); - enum ErrorCode { - NONE = 0, - COMMUNICATION_FAILED, - INVALID_ID, - VALIDITY_INVALID, - READ_FAILED, - WRITE_FAILED, - STD_OPMODE_FAILED, - } error_code_{NONE}; - enum ValidityFlag { NORMAL_OPERATION = 0, WARMING_UP, diff --git a/esphome/components/ens210/ens210.cpp b/esphome/components/ens210/ens210.cpp index 5815fc90382..2251e0a574b 100644 --- a/esphome/components/ens210/ens210.cpp +++ b/esphome/components/ens210/ens210.cpp @@ -55,8 +55,6 @@ static const LogString *ens210_status_to_human(int status) { return LOG_STR("Invalid data"); case ENS210Component::ENS210_STATUS_OK: return LOG_STR("Status OK"); - case ENS210Component::ENS210_WRONG_CHIP_ID: - return LOG_STR("ENS210 has wrong chip ID! Is it a ENS210?"); default: return LOG_STR("Unknown"); } @@ -93,8 +91,7 @@ void ENS210Component::setup() { // Reset if (!this->write_byte(ENS210_REGISTER_SYS_CTRL, 0x80)) { this->write_byte(ENS210_REGISTER_SYS_CTRL, 0x80); - this->error_code_ = ENS210_STATUS_I2C_ERROR; - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } // Wait to boot after reset @@ -103,24 +100,24 @@ void ENS210Component::setup() { if (!set_low_power_(false)) { // Try to go back to default mode (low power enabled) set_low_power_(true); - this->error_code_ = ENS210_STATUS_I2C_ERROR; - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } // Read the PART_ID if (!this->read_bytes(ENS210_REGISTER_PART_ID, data, 2)) { // Try to go back to default mode (low power enabled) set_low_power_(true); - this->error_code_ = ENS210_STATUS_I2C_ERROR; - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } // Pack bytes into partid part_id = data[1] * 256U + data[0] * 1U; // Check expected part id of the ENS210 if (part_id != ENS210_PART_ID) { - this->error_code_ = ENS210_WRONG_CHIP_ID; - this->mark_failed(); + // Try to go back to default mode (low power enabled) + set_low_power_(true); + this->mark_failed(LOG_STR("Wrong chip ID")); + return; } // Set default power mode (low power enabled) set_low_power_(true); @@ -129,9 +126,6 @@ void ENS210Component::setup() { void ENS210Component::dump_config() { ESP_LOGCONFIG(TAG, "ENS210:"); LOG_I2C_DEVICE(this); - if (this->is_failed()) { - ESP_LOGE(TAG, "%s", LOG_STR_ARG(ens210_status_to_human(this->error_code_))); - } LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "Temperature", this->temperature_sensor_); LOG_SENSOR(" ", "Humidity", this->humidity_sensor_); diff --git a/esphome/components/ens210/ens210.h b/esphome/components/ens210/ens210.h index fca20133b82..803d3b9cedf 100644 --- a/esphome/components/ens210/ens210.h +++ b/esphome/components/ens210/ens210.h @@ -22,8 +22,7 @@ class ENS210Component final : public PollingComponent, public i2c::I2CDevice { // not yet finished) ENS210_STATUS_CRC_ERROR, // The value was read, but the CRC over the payload (valid and data) does not match ENS210_STATUS_I2C_ERROR, // There was an I2C communication error - ENS210_WRONG_CHIP_ID // The read PART_ID is not the expected part id of the ENS210 - } error_code_{ENS210_STATUS_OK}; + }; protected: bool set_low_power_(bool enable); diff --git a/esphome/components/es7210/es7210.cpp b/esphome/components/es7210/es7210.cpp index fbabf7460f2..9eb24653dfc 100644 --- a/esphome/components/es7210/es7210.cpp +++ b/esphome/components/es7210/es7210.cpp @@ -13,7 +13,7 @@ static const size_t MCLK_DIV_FRE = 256; // Mark the component as failed; use only in setup #define ES7210_ERROR_FAILED(func) \ if (!(func)) { \ - this->mark_failed(); \ + this->mark_failed(LOG_STR("Failed to initialize")); \ return; \ } @@ -31,11 +31,6 @@ void ES7210::dump_config() { " Channel Gains: %.1f dB, %.1f dB, %.1f dB, %.1f dB", this->bits_per_sample_, this->sample_rate_, this->channel_gains_[0], this->channel_gains_[1], this->channel_gains_[2], this->channel_gains_[3]); - - if (this->is_failed()) { - ESP_LOGE(TAG, " Failed to initialize"); - return; - } } void ES7210::setup() { diff --git a/esphome/components/es7243e/es7243e.cpp b/esphome/components/es7243e/es7243e.cpp index 1bfa6933ddc..c43ed38cd57 100644 --- a/esphome/components/es7243e/es7243e.cpp +++ b/esphome/components/es7243e/es7243e.cpp @@ -13,7 +13,7 @@ ESPHOME_LOG_TAG(TAG, "es7243e"); // Mark the component as failed; use only in setup #define ES7243E_ERROR_FAILED(func) \ if (!(func)) { \ - this->mark_failed(); \ + this->mark_failed(LOG_STR("Failed to initialize")); \ return; \ } @@ -23,14 +23,7 @@ ESPHOME_LOG_TAG(TAG, "es7243e"); return false; \ } -void ES7243E::dump_config() { - ESP_LOGCONFIG(TAG, "ES7243E audio ADC:"); - - if (this->is_failed()) { - ESP_LOGE(TAG, " Failed to initialize"); - return; - } -} +void ES7243E::dump_config() { ESP_LOGCONFIG(TAG, "ES7243E audio ADC:"); } void ES7243E::setup() { ES7243E_ERROR_FAILED(this->write_byte(ES7243E_CLOCK_MGR_REG01, 0x3A)); diff --git a/esphome/components/es8156/es8156.cpp b/esphome/components/es8156/es8156.cpp index 467402e704c..4b854a1bc35 100644 --- a/esphome/components/es8156/es8156.cpp +++ b/esphome/components/es8156/es8156.cpp @@ -11,7 +11,7 @@ ESPHOME_LOG_TAG(TAG, "es8156"); // Mark the component as failed; use only in setup #define ES8156_ERROR_FAILED(func) \ if (!(func)) { \ - this->mark_failed(); \ + this->mark_failed(LOG_STR("Failed to initialize")); \ return; \ } @@ -74,14 +74,7 @@ void ES8156::setup() { ES8156_ERROR_FAILED(this->write_byte(ES8156_REG25_ANALOG_SYS5, 0x20)); } -void ES8156::dump_config() { - ESP_LOGCONFIG(TAG, "ES8156 Audio Codec:"); - - if (this->is_failed()) { - ESP_LOGCONFIG(TAG, " Failed to initialize"); - return; - } -} +void ES8156::dump_config() { ESP_LOGCONFIG(TAG, "ES8156 Audio Codec:"); } bool ES8156::set_volume(float volume) { volume = clamp(volume, 0.0f, 1.0f); diff --git a/esphome/components/es8311/es8311.cpp b/esphome/components/es8311/es8311.cpp index 96b644ee780..67229d908ec 100644 --- a/esphome/components/es8311/es8311.cpp +++ b/esphome/components/es8311/es8311.cpp @@ -11,7 +11,7 @@ ESPHOME_LOG_TAG(TAG, "es8311"); // Mark the component as failed; use only in setup #define ES8311_ERROR_FAILED(func) \ if (!(func)) { \ - this->mark_failed(); \ + this->mark_failed(LOG_STR("Failed to initialize")); \ return; \ } // Return false; use outside of setup @@ -56,11 +56,6 @@ void ES8311::dump_config() { " DAC Bits per Sample: %" PRIu8 "\n" " Sample Rate: %" PRIu32, YESNO(this->use_mclk_), YESNO(this->use_mic_), this->resolution_out_, this->sample_frequency_); - - if (this->is_failed()) { - ESP_LOGCONFIG(TAG, " Failed to initialize!"); - return; - } } bool ES8311::set_volume(float volume) { diff --git a/esphome/components/es8388/es8388.cpp b/esphome/components/es8388/es8388.cpp index 56ee1ac4a59..d7aedd9d9e5 100644 --- a/esphome/components/es8388/es8388.cpp +++ b/esphome/components/es8388/es8388.cpp @@ -11,7 +11,7 @@ ESPHOME_LOG_TAG(TAG, "es8388"); // Mark the component as failed; use only in setup #define ES8388_ERROR_FAILED(func) \ if (!(func)) { \ - this->mark_failed(); \ + this->mark_failed(LOG_STR("Failed to initialize")); \ return; \ } @@ -154,11 +154,6 @@ void ES8388::dump_config() { LOG_SELECT(" ", "DacOutputSelect", this->dac_output_select_); LOG_SELECT(" ", "ADCInputMicSelect", this->adc_input_mic_select_); #endif - - if (this->is_failed()) { - ESP_LOGCONFIG(TAG, " Failed to initialize"); - return; - } } bool ES8388::set_volume(float volume) { diff --git a/esphome/components/esp32_camera_web_server/camera_web_server.cpp b/esphome/components/esp32_camera_web_server/camera_web_server.cpp index 36c1cdfa45b..a248b901204 100644 --- a/esphome/components/esp32_camera_web_server/camera_web_server.cpp +++ b/esphome/components/esp32_camera_web_server/camera_web_server.cpp @@ -42,7 +42,7 @@ CameraWebServer::~CameraWebServer() {} void CameraWebServer::setup() { if (!camera::Camera::instance() || camera::Camera::instance()->is_failed()) { - this->mark_failed(); + this->mark_failed(LOG_STR("Camera not available")); return; } @@ -56,7 +56,7 @@ void CameraWebServer::setup() { config.lru_purge_enable = true; if (httpd_start(&this->httpd_, &config) != ESP_OK) { - mark_failed(); + this->mark_failed(LOG_STR("Failed to start the web server")); return; } @@ -97,10 +97,6 @@ void CameraWebServer::dump_config() { } else { ESP_LOGCONFIG(TAG, " Mode: snapshot"); } - - if (this->is_failed()) { - ESP_LOGE(TAG, " Setup Failed"); - } } float CameraWebServer::get_setup_priority() const { return setup_priority::LATE; } diff --git a/esphome/components/ezo/ezo.cpp b/esphome/components/ezo/ezo.cpp index d18e6e67cb1..c9a5087bf5c 100644 --- a/esphome/components/ezo/ezo.cpp +++ b/esphome/components/ezo/ezo.cpp @@ -13,9 +13,6 @@ static const char *const EZO_CALIBRATION_TYPE_STRINGS[] = {"LOW", "MID", "HIGH"} void EZOSensor::dump_config() { LOG_SENSOR("", "EZO", this); LOG_I2C_DEVICE(this); - if (this->is_failed()) { - ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); - } LOG_UPDATE_INTERVAL(this); } diff --git a/esphome/components/ezo_pmp/ezo_pmp.cpp b/esphome/components/ezo_pmp/ezo_pmp.cpp index 8db57670aea..393ba66fdf0 100644 --- a/esphome/components/ezo_pmp/ezo_pmp.cpp +++ b/esphome/components/ezo_pmp/ezo_pmp.cpp @@ -39,9 +39,6 @@ static const std::string DOSING_MODE_CONTINUOUS = "Continuous"; void EzoPMP::dump_config() { LOG_I2C_DEVICE(this); - if (this->is_failed()) { - ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); - } LOG_UPDATE_INTERVAL(this); } diff --git a/esphome/components/gdk101/gdk101.cpp b/esphome/components/gdk101/gdk101.cpp index 3c7e8d21613..a84d5ba06fb 100644 --- a/esphome/components/gdk101/gdk101.cpp +++ b/esphome/components/gdk101/gdk101.cpp @@ -82,9 +82,6 @@ bool GDK101Component::try_reset_() { void GDK101Component::dump_config() { ESP_LOGCONFIG(TAG, "GDK101:"); LOG_I2C_DEVICE(this); - if (this->is_failed()) { - ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); - } #ifdef USE_SENSOR LOG_SENSOR(" ", "Average Radaition Dose per 1 minute", this->rad_1m_sensor_); LOG_SENSOR(" ", "Average Radaition Dose per 10 minutes", this->rad_10m_sensor_); diff --git a/esphome/components/grove_gas_mc_v2/grove_gas_mc_v2.cpp b/esphome/components/grove_gas_mc_v2/grove_gas_mc_v2.cpp index b01dd119e63..1acf8076af4 100644 --- a/esphome/components/grove_gas_mc_v2/grove_gas_mc_v2.cpp +++ b/esphome/components/grove_gas_mc_v2/grove_gas_mc_v2.cpp @@ -23,7 +23,6 @@ bool GroveGasMultichannelV2Component::read_sensor_(uint8_t address, sensor::Sens uint32_t value = 0; if (!this->read_bytes(address, (uint8_t *) &value, 4)) { ESP_LOGW(TAG, "Reading Grove Gas Sensor data failed!"); - this->error_code_ = COMMUNICATION_FAILED; this->status_set_warning(); return false; } @@ -34,8 +33,7 @@ bool GroveGasMultichannelV2Component::read_sensor_(uint8_t address, sensor::Sens void GroveGasMultichannelV2Component::setup() { // Before reading sensor values, must preheat sensor if (!(this->write_bytes(GROVE_GAS_MC_V2_HEAT_ON, {}))) { - this->mark_failed(); - this->error_code_ = APP_START_FAILED; + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); } } @@ -61,24 +59,6 @@ void GroveGasMultichannelV2Component::dump_config() { LOG_SENSOR(" ", "Ethanol", this->ethanol_sensor_); LOG_SENSOR(" ", "Carbon Monoxide", this->carbon_monoxide_sensor_); LOG_SENSOR(" ", "TVOC", this->tvoc_sensor_); - - if (this->is_failed()) { - switch (this->error_code_) { - case COMMUNICATION_FAILED: - ESP_LOGW(TAG, ESP_LOG_MSG_COMM_FAIL); - break; - case APP_INVALID: - ESP_LOGW(TAG, "Sensor reported invalid APP installed"); - break; - case APP_START_FAILED: - ESP_LOGW(TAG, "Sensor reported APP start failed"); - break; - case UNKNOWN: - default: - ESP_LOGW(TAG, "Unknown setup error"); - break; - } - } } } // namespace esphome::grove_gas_mc_v2 diff --git a/esphome/components/grove_gas_mc_v2/grove_gas_mc_v2.h b/esphome/components/grove_gas_mc_v2/grove_gas_mc_v2.h index 545b6df97a9..8aafdea8e7d 100644 --- a/esphome/components/grove_gas_mc_v2/grove_gas_mc_v2.h +++ b/esphome/components/grove_gas_mc_v2/grove_gas_mc_v2.h @@ -22,13 +22,6 @@ class GroveGasMultichannelV2Component final : public PollingComponent, public i2 void dump_config() override; protected: - enum ErrorCode { - UNKNOWN, - COMMUNICATION_FAILED, - APP_INVALID, - APP_START_FAILED, - } error_code_{UNKNOWN}; - bool read_sensor_(uint8_t address, sensor::Sensor *sensor); }; diff --git a/esphome/components/hdc1080/hdc1080.cpp b/esphome/components/hdc1080/hdc1080.cpp index be0de1bae6e..c61feb52d57 100644 --- a/esphome/components/hdc1080/hdc1080.cpp +++ b/esphome/components/hdc1080/hdc1080.cpp @@ -24,9 +24,6 @@ void HDC1080Component::setup() { void HDC1080Component::dump_config() { ESP_LOGCONFIG(TAG, "HDC1080:"); LOG_I2C_DEVICE(this); - if (this->is_failed()) { - ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); - } LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "Temperature", this->temperature_); LOG_SENSOR(" ", "Humidity", this->humidity_); diff --git a/esphome/components/hdc2010/hdc2010.cpp b/esphome/components/hdc2010/hdc2010.cpp index 825d7d3da96..471afe515a1 100644 --- a/esphome/components/hdc2010/hdc2010.cpp +++ b/esphome/components/hdc2010/hdc2010.cpp @@ -42,9 +42,6 @@ void HDC2010Component::setup() { void HDC2010Component::dump_config() { ESP_LOGCONFIG(TAG, "HDC2010:"); LOG_I2C_DEVICE(this); - if (this->is_failed()) { - ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); - } LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "Temperature", this->temperature_sensor_); LOG_SENSOR(" ", "Humidity", this->humidity_sensor_); diff --git a/esphome/components/hdc2080/hdc2080.cpp b/esphome/components/hdc2080/hdc2080.cpp index 8210733b4cb..beb84f30746 100644 --- a/esphome/components/hdc2080/hdc2080.cpp +++ b/esphome/components/hdc2080/hdc2080.cpp @@ -33,9 +33,6 @@ void HDC2080Component::dump_config() { LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "Temperature", this->temperature_sensor_); LOG_SENSOR(" ", "Humidity", this->humidity_sensor_); - if (this->is_failed()) { - ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); - } } void HDC2080Component::update() { diff --git a/esphome/components/hmc5883l/hmc5883l.cpp b/esphome/components/hmc5883l/hmc5883l.cpp index c747e7968ed..d1abe8c1fdb 100644 --- a/esphome/components/hmc5883l/hmc5883l.cpp +++ b/esphome/components/hmc5883l/hmc5883l.cpp @@ -27,8 +27,7 @@ void HMC5883LComponent::setup() { if (!this->read_byte(HMC5883L_REGISTER_IDENTIFICATION_A, &id[0]) || !this->read_byte(HMC5883L_REGISTER_IDENTIFICATION_B, &id[1]) || !this->read_byte(HMC5883L_REGISTER_IDENTIFICATION_C, &id[2])) { - this->error_code_ = COMMUNICATION_FAILED; - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } @@ -37,8 +36,7 @@ void HMC5883LComponent::setup() { } if (id[0] != 0x48 || id[1] != 0x34 || id[2] != 0x33) { - this->error_code_ = ID_REGISTERS; - this->mark_failed(); + this->mark_failed(LOG_STR("The ID registers don't match - Is this really an HMC5883L?")); return; } @@ -47,16 +45,14 @@ void HMC5883LComponent::setup() { config_a |= this->datarate_ << 2; config_a |= 0b0 << 0; // Measurement Mode: Normal(high impedance on load) if (!this->write_byte(HMC5883L_REGISTER_CONFIG_A, config_a)) { - this->error_code_ = COMMUNICATION_FAILED; - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } uint8_t config_b = 0; config_b |= this->range_ << 5; if (!this->write_byte(HMC5883L_REGISTER_CONFIG_B, config_b)) { - this->error_code_ = COMMUNICATION_FAILED; - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } @@ -64,19 +60,13 @@ void HMC5883LComponent::setup() { // Continuous Measurement Mode mode |= 0b00; if (!this->write_byte(HMC5883L_REGISTER_MODE, mode)) { - this->error_code_ = COMMUNICATION_FAILED; - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } } void HMC5883LComponent::dump_config() { ESP_LOGCONFIG(TAG, "HMC5883L:"); LOG_I2C_DEVICE(this); - if (this->error_code_ == COMMUNICATION_FAILED) { - ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); - } else if (this->error_code_ == ID_REGISTERS) { - ESP_LOGE(TAG, "The ID registers don't match - Is this really an HMC5883L?"); - } LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "X Axis", this->x_sensor_); diff --git a/esphome/components/hmc5883l/hmc5883l.h b/esphome/components/hmc5883l/hmc5883l.h index d23eb1a0f4a..6e5303d8988 100644 --- a/esphome/components/hmc5883l/hmc5883l.h +++ b/esphome/components/hmc5883l/hmc5883l.h @@ -56,11 +56,6 @@ class HMC5883LComponent final : public PollingComponent, public i2c::I2CDevice { sensor::Sensor *y_sensor_{nullptr}; sensor::Sensor *z_sensor_{nullptr}; sensor::Sensor *heading_sensor_{nullptr}; - enum ErrorCode { - NONE = 0, - COMMUNICATION_FAILED, - ID_REGISTERS, - } error_code_{NONE}; HighFrequencyLoopRequester high_freq_; }; diff --git a/esphome/components/honeywell_hih_i2c/honeywell_hih.cpp b/esphome/components/honeywell_hih_i2c/honeywell_hih.cpp index 352d3f7f01f..91f3089c729 100644 --- a/esphome/components/honeywell_hih_i2c/honeywell_hih.cpp +++ b/esphome/components/honeywell_hih_i2c/honeywell_hih.cpp @@ -18,8 +18,7 @@ void HoneywellHIComponent::read_sensor_data_() { uint8_t data[4]; if (this->read(data, sizeof(data)) != i2c::ERROR_OK) { - ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } @@ -38,8 +37,7 @@ void HoneywellHIComponent::read_sensor_data_() { void HoneywellHIComponent::start_measurement_() { if (this->write(REQUEST_CMD, sizeof(REQUEST_CMD)) != i2c::ERROR_OK) { - ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } @@ -50,8 +48,7 @@ bool HoneywellHIComponent::is_measurement_ready_() { uint8_t data[1]; if (this->read(data, sizeof(data)) != i2c::ERROR_OK) { - ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return false; } @@ -60,9 +57,8 @@ bool HoneywellHIComponent::is_measurement_ready_() { } void HoneywellHIComponent::measurement_timeout_() { - ESP_LOGE(TAG, "Honeywell HIH Timeout!"); this->measurement_running_ = false; - this->mark_failed(); + this->mark_failed(LOG_STR("Measurement timeout")); } void HoneywellHIComponent::update() { @@ -84,9 +80,6 @@ void HoneywellHIComponent::loop() { void HoneywellHIComponent::dump_config() { ESP_LOGD(TAG, "Honeywell HIH:"); LOG_I2C_DEVICE(this); - if (this->is_failed()) { - ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); - } LOG_SENSOR(" ", "Temperature", this->temperature_sensor_); LOG_SENSOR(" ", "Humidity", this->humidity_sensor_); LOG_UPDATE_INTERVAL(this); diff --git a/esphome/components/htu21d/htu21d.cpp b/esphome/components/htu21d/htu21d.cpp index 468a7f8e6a2..4fe502f2a5c 100644 --- a/esphome/components/htu21d/htu21d.cpp +++ b/esphome/components/htu21d/htu21d.cpp @@ -18,7 +18,7 @@ static const uint8_t HTU21D_REG_HTRE_BIT = 0x02; /**< Control Register He void HTU21DComponent::setup() { if (!this->write_bytes(HTU21D_REGISTER_RESET, nullptr, 0)) { - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } @@ -28,9 +28,6 @@ void HTU21DComponent::setup() { void HTU21DComponent::dump_config() { ESP_LOGCONFIG(TAG, "HTU21D:"); LOG_I2C_DEVICE(this); - if (this->is_failed()) { - ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); - } LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "Temperature", this->temperature_); LOG_SENSOR(" ", "Humidity", this->humidity_); diff --git a/esphome/components/htu31d/htu31d.cpp b/esphome/components/htu31d/htu31d.cpp index 86c9876b2b6..5426ca50845 100644 --- a/esphome/components/htu31d/htu31d.cpp +++ b/esphome/components/htu31d/htu31d.cpp @@ -49,12 +49,12 @@ static const uint8_t HTU31D_DIAGNOSTICS = 0x08; */ void HTU31DComponent::setup() { if (!this->reset_()) { - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } if (this->read_serial_num_() == 0) { - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } } @@ -131,9 +131,6 @@ void HTU31DComponent::update() { void HTU31DComponent::dump_config() { ESP_LOGCONFIG(TAG, "HTU31D:"); LOG_I2C_DEVICE(this); - if (this->is_failed()) { - ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); - } LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "Temperature", this->temperature_); LOG_SENSOR(" ", "Humidity", this->humidity_); diff --git a/esphome/components/husb238/husb238.cpp b/esphome/components/husb238/husb238.cpp index 8ca841a7e43..d0f9973b2a4 100644 --- a/esphome/components/husb238/husb238.cpp +++ b/esphome/components/husb238/husb238.cpp @@ -39,9 +39,6 @@ void Husb238Component::dump_config() { ESP_LOGCONFIG(TAG, "HUSB238:"); LOG_I2C_DEVICE(this); LOG_UPDATE_INTERVAL(this); - if (this->is_failed()) { - ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); - } #ifdef USE_BINARY_SENSOR LOG_BINARY_SENSOR(" ", "PD Attached", this->attached_binary_sensor_); LOG_BINARY_SENSOR(" ", "CC Direction", this->cc_direction_binary_sensor_); diff --git a/esphome/components/hydreon_rgxx/hydreon_rgxx.cpp b/esphome/components/hydreon_rgxx/hydreon_rgxx.cpp index 36a7b1b3511..a2f8fc50862 100644 --- a/esphome/components/hydreon_rgxx/hydreon_rgxx.cpp +++ b/esphome/components/hydreon_rgxx/hydreon_rgxx.cpp @@ -15,9 +15,6 @@ static const char *const IGNORE_STRINGS[] = {HYDREON_RGXX_IGNORE_LIST(, HYDREON_ void HydreonRGxxComponent::dump_config() { ESP_LOGCONFIG(TAG, "hydreon_rgxx:"); - if (this->is_failed()) { - ESP_LOGE(TAG, "Connection with hydreon_rgxx failed!"); - } if (model_ == RG9) { ESP_LOGCONFIG(TAG, " Model: RG9\n" @@ -154,7 +151,7 @@ void HydreonRGxxComponent::schedule_reboot_() { sensor->publish_state(NAN); } } - this->mark_failed(); + this->mark_failed(LOG_STR("Sensor did not boot")); } }); } diff --git a/esphome/components/iaqcore/iaqcore.cpp b/esphome/components/iaqcore/iaqcore.cpp index 48935c24681..73b6252cece 100644 --- a/esphome/components/iaqcore/iaqcore.cpp +++ b/esphome/components/iaqcore/iaqcore.cpp @@ -27,8 +27,7 @@ struct SensorData { void IAQCore::setup() { if (this->write(nullptr, 0) != i2c::ERROR_OK) { - ESP_LOGD(TAG, ESP_LOG_MSG_COMM_FAIL); - this->mark_failed(); + this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); return; } } @@ -89,9 +88,6 @@ void IAQCore::dump_config() { ESP_LOGCONFIG(TAG, "AMS iAQ Core:"); LOG_I2C_DEVICE(this); LOG_UPDATE_INTERVAL(this); - if (this->is_failed()) { - ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); - } LOG_SENSOR(" ", "CO2", this->co2_); LOG_SENSOR(" ", "TVOC", this->tvoc_); } diff --git a/esphome/components/icm20689/icm20689.cpp b/esphome/components/icm20689/icm20689.cpp index 7331a3fe4f6..3bca35dc254 100644 --- a/esphome/components/icm20689/icm20689.cpp +++ b/esphome/components/icm20689/icm20689.cpp @@ -38,8 +38,7 @@ void ICM20689Component::setup() { this->spi_setup(); if (!this->spi_is_ready()) { - ESP_LOGE(TAG, "SPI device is not ready"); - this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); + this->mark_failed(LOG_STR("SPI device is not ready")); return; } @@ -61,7 +60,7 @@ void ICM20689Component::setup() { if (who_am_i != ICM20689_WHO_AM_I_VALUE) { ESP_LOGE(TAG, "Unexpected WHO_AM_I 0x%02X (expected 0x%02X) -- check wiring/CS", who_am_i, ICM20689_WHO_AM_I_VALUE); - this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); + this->mark_failed(LOG_STR("Wrong chip ID")); return; } @@ -77,10 +76,8 @@ void ICM20689Component::dump_config() { ESP_LOGCONFIG(TAG, "ICM20689 IMU:"); LOG_PIN(" CS Pin: ", this->cs_); - if (this->is_failed()) { - ESP_LOGE(TAG, " " ESP_LOG_MSG_COMM_FAIL); + if (this->is_failed()) return; - } ESP_LOGCONFIG(TAG, " Accel range: ±%dg", 2 << static_cast(this->accel_range_)); ESP_LOGCONFIG(TAG, " Gyro range: ±%d°/s", 250 << static_cast(this->gyro_range_)); diff --git a/esphome/components/ili9xxx/ili9xxx_display.cpp b/esphome/components/ili9xxx/ili9xxx_display.cpp index 870d4e7098d..d2e1bc127e5 100644 --- a/esphome/components/ili9xxx/ili9xxx_display.cpp +++ b/esphome/components/ili9xxx/ili9xxx_display.cpp @@ -70,7 +70,7 @@ void ILI9XXXDisplay::alloc_buffer_() { this->init_internal_(this->get_buffer_length_()); } if (this->buffer_ == nullptr) { - this->mark_failed(); + this->mark_failed(LOG_STR("Failed to allocate the display buffer")); } } @@ -122,9 +122,6 @@ void ILI9XXXDisplay::dump_config() { this->color_order_ == display::COLOR_ORDER_BGR ? LOG_STR_LITERAL("BGR") : LOG_STR_LITERAL("RGB"), YESNO(this->swap_xy_), YESNO(this->mirror_x_), YESNO(this->mirror_y_), YESNO(this->pre_invertcolors_)); - if (this->is_failed()) { - ESP_LOGCONFIG(TAG, " => Failed to init Memory: YES!"); - } LOG_UPDATE_INTERVAL(this); }