[components] Let core report communication failures in dump_config (2/5) (#20871)

This commit is contained in:
J. Nick Koston
2026-10-16 08:39:20 -04:00
committed by GitHub
parent 126dc8b0b2
commit e95e56f100
35 changed files with 74 additions and 268 deletions
@@ -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");
}
}
+1 -4
View File
@@ -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_);
}
+15 -21
View File
@@ -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, &reg)) {
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_);
+2
View File
@@ -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_();
+1 -4
View File
@@ -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();
}
-4
View File
@@ -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) {
+1 -4
View File
@@ -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_);
+15 -49
View File
@@ -62,20 +62,17 @@ void ENS160Component::setup() {
// check part_id
uint16_t part_id;
if (!this->read_bytes(ENS160_REG_PART_ID, reinterpret_cast<uint8_t *>(&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<ValidityFlag>((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_);
@@ -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,
+7 -13
View File
@@ -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_);
+1 -2
View File
@@ -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);
+1 -6
View File
@@ -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() {
+2 -9
View File
@@ -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));
+2 -9
View File
@@ -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);
+1 -6
View File
@@ -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) {
+1 -6
View File
@@ -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) {
@@ -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; }
-3
View File
@@ -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);
}
-3
View File
@@ -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);
}
-3
View File
@@ -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_);
@@ -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
@@ -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);
};
-3
View File
@@ -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_);
-3
View File
@@ -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_);
-3
View File
@@ -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() {
+5 -15
View File
@@ -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_);
-5
View File
@@ -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_;
};
@@ -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);
+1 -4
View File
@@ -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_);
+2 -5
View File
@@ -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_);
-3
View File
@@ -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_);
@@ -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"));
}
});
}
+1 -5
View File
@@ -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_);
}
+3 -6
View File
@@ -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<uint8_t>(this->accel_range_));
ESP_LOGCONFIG(TAG, " Gyro range: ±%d°/s", 250 << static_cast<uint8_t>(this->gyro_range_));
@@ -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);
}