diff --git a/.github/actions/build-image/action.yaml b/.github/actions/build-image/action.yaml index 0e41314ce6..403b9d8c2a 100644 --- a/.github/actions/build-image/action.yaml +++ b/.github/actions/build-image/action.yaml @@ -47,7 +47,7 @@ runs: - name: Build and push to ghcr by digest id: build-ghcr - uses: docker/build-push-action@v6.17.0 + uses: docker/build-push-action@v6.18.0 env: DOCKER_BUILD_SUMMARY: false DOCKER_BUILD_RECORD_UPLOAD: false @@ -73,7 +73,7 @@ runs: - name: Build and push to dockerhub by digest id: build-dockerhub - uses: docker/build-push-action@v6.17.0 + uses: docker/build-push-action@v6.18.0 env: DOCKER_BUILD_SUMMARY: false DOCKER_BUILD_RECORD_UPLOAD: false diff --git a/CODEOWNERS b/CODEOWNERS index c7423e9eae..dade427a45 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -139,6 +139,7 @@ esphome/components/es7210/* @kahrendt esphome/components/es7243e/* @kbx81 esphome/components/es8156/* @kbx81 esphome/components/es8311/* @kahrendt @kroimon +esphome/components/es8388/* @P4uLT esphome/components/esp32/* @esphome/core esphome/components/esp32_ble/* @Rapsssito @jesserockz esphome/components/esp32_ble_client/* @jesserockz diff --git a/esphome/__main__.py b/esphome/__main__.py index 9f638456e6..adada75163 100644 --- a/esphome/__main__.py +++ b/esphome/__main__.py @@ -593,15 +593,20 @@ def command_update_all(args): middle_text = f" {middle_text} " width = len(click.unstyle(middle_text)) half_line = "=" * ((twidth - width) // 2) - click.echo(f"{half_line}{middle_text}{half_line}") + safe_print(f"{half_line}{middle_text}{half_line}") for f in files: - print(f"Updating {color(AnsiFore.CYAN, f)}") - print("-" * twidth) - print() - rc = run_external_process( - "esphome", "--dashboard", "run", f, "--no-logs", "--device", "OTA" - ) + safe_print(f"Updating {color(AnsiFore.CYAN, f)}") + safe_print("-" * twidth) + safe_print() + if CORE.dashboard: + rc = run_external_process( + "esphome", "--dashboard", "run", f, "--no-logs", "--device", "OTA" + ) + else: + rc = run_external_process( + "esphome", "run", f, "--no-logs", "--device", "OTA" + ) if rc == 0: print_bar(f"[{color(AnsiFore.BOLD_GREEN, 'SUCCESS')}] {f}") success[f] = True @@ -609,17 +614,17 @@ def command_update_all(args): print_bar(f"[{color(AnsiFore.BOLD_RED, 'ERROR')}] {f}") success[f] = False - print() - print() - print() + safe_print() + safe_print() + safe_print() print_bar(f"[{color(AnsiFore.BOLD_WHITE, 'SUMMARY')}]") failed = 0 for f in files: if success[f]: - print(f" - {f}: {color(AnsiFore.GREEN, 'SUCCESS')}") + safe_print(f" - {f}: {color(AnsiFore.GREEN, 'SUCCESS')}") else: - print(f" - {f}: {color(AnsiFore.BOLD_RED, 'FAILED')}") + safe_print(f" - {f}: {color(AnsiFore.BOLD_RED, 'FAILED')}") failed += 1 return failed diff --git a/esphome/components/a4988/a4988.cpp b/esphome/components/a4988/a4988.cpp index ae2df3233a..72b3835cfd 100644 --- a/esphome/components/a4988/a4988.cpp +++ b/esphome/components/a4988/a4988.cpp @@ -7,7 +7,7 @@ namespace a4988 { static const char *const TAG = "a4988.stepper"; void A4988::setup() { - ESP_LOGCONFIG(TAG, "Setting up A4988..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (this->sleep_pin_ != nullptr) { this->sleep_pin_->setup(); this->sleep_pin_->digital_write(false); diff --git a/esphome/components/absolute_humidity/absolute_humidity.cpp b/esphome/components/absolute_humidity/absolute_humidity.cpp index 13f30c996f..877e6dbe22 100644 --- a/esphome/components/absolute_humidity/absolute_humidity.cpp +++ b/esphome/components/absolute_humidity/absolute_humidity.cpp @@ -7,7 +7,7 @@ namespace absolute_humidity { static const char *const TAG = "absolute_humidity.sensor"; void AbsoluteHumidityComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up absolute humidity '%s'...", this->get_name().c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->get_name().c_str()); ESP_LOGD(TAG, " Added callback for temperature '%s'", this->temperature_sensor_->get_name().c_str()); this->temperature_sensor_->add_on_state_callback([this](float state) { this->temperature_callback_(state); }); diff --git a/esphome/components/adc/adc_sensor_esp32.cpp b/esphome/components/adc/adc_sensor_esp32.cpp index 0f1d802937..efd3bafb83 100644 --- a/esphome/components/adc/adc_sensor_esp32.cpp +++ b/esphome/components/adc/adc_sensor_esp32.cpp @@ -22,7 +22,7 @@ static const int ADC_MAX = (1 << SOC_ADC_RTC_MAX_BITWIDTH) - 1; static const int ADC_HALF = (1 << SOC_ADC_RTC_MAX_BITWIDTH) >> 1; void ADCSensor::setup() { - ESP_LOGCONFIG(TAG, "Setting up ADC '%s'...", this->get_name().c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'...", this->get_name().c_str()); if (this->channel1_ != ADC1_CHANNEL_MAX) { adc1_config_width(ADC_WIDTH_MAX_SOC_BITS); diff --git a/esphome/components/adc/adc_sensor_esp8266.cpp b/esphome/components/adc/adc_sensor_esp8266.cpp index 9a12009abc..14837562aa 100644 --- a/esphome/components/adc/adc_sensor_esp8266.cpp +++ b/esphome/components/adc/adc_sensor_esp8266.cpp @@ -17,7 +17,7 @@ namespace adc { static const char *const TAG = "adc.esp8266"; void ADCSensor::setup() { - ESP_LOGCONFIG(TAG, "Setting up ADC '%s'...", this->get_name().c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'...", this->get_name().c_str()); #ifndef USE_ADC_SENSOR_VCC this->pin_->setup(); #endif diff --git a/esphome/components/adc/adc_sensor_libretiny.cpp b/esphome/components/adc/adc_sensor_libretiny.cpp index 9e75ed414c..5676857dc9 100644 --- a/esphome/components/adc/adc_sensor_libretiny.cpp +++ b/esphome/components/adc/adc_sensor_libretiny.cpp @@ -9,7 +9,7 @@ namespace adc { static const char *const TAG = "adc.libretiny"; void ADCSensor::setup() { - ESP_LOGCONFIG(TAG, "Setting up ADC '%s'...", this->get_name().c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'...", this->get_name().c_str()); #ifndef USE_ADC_SENSOR_VCC this->pin_->setup(); #endif // !USE_ADC_SENSOR_VCC diff --git a/esphome/components/adc/adc_sensor_rp2040.cpp b/esphome/components/adc/adc_sensor_rp2040.cpp index f6cf1bac7a..8c6afb8186 100644 --- a/esphome/components/adc/adc_sensor_rp2040.cpp +++ b/esphome/components/adc/adc_sensor_rp2040.cpp @@ -14,7 +14,7 @@ namespace adc { static const char *const TAG = "adc.rp2040"; void ADCSensor::setup() { - ESP_LOGCONFIG(TAG, "Setting up ADC '%s'...", this->get_name().c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'...", this->get_name().c_str()); static bool initialized = false; if (!initialized) { adc_init(); diff --git a/esphome/components/adc128s102/adc128s102.cpp b/esphome/components/adc128s102/adc128s102.cpp index c27a354dd3..c8e8edb359 100644 --- a/esphome/components/adc128s102/adc128s102.cpp +++ b/esphome/components/adc128s102/adc128s102.cpp @@ -9,7 +9,7 @@ static const char *const TAG = "adc128s102"; float ADC128S102::get_setup_priority() const { return setup_priority::HARDWARE; } void ADC128S102::setup() { - ESP_LOGCONFIG(TAG, "Setting up adc128s102"); + ESP_LOGCONFIG(TAG, "Running setup"); this->spi_setup(); } diff --git a/esphome/components/ads1115/ads1115.cpp b/esphome/components/ads1115/ads1115.cpp index c05064383c..11a5663ed1 100644 --- a/esphome/components/ads1115/ads1115.cpp +++ b/esphome/components/ads1115/ads1115.cpp @@ -10,15 +10,13 @@ static const uint8_t ADS1115_REGISTER_CONVERSION = 0x00; static const uint8_t ADS1115_REGISTER_CONFIG = 0x01; void ADS1115Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up ADS1115..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint16_t value; if (!this->read_byte_16(ADS1115_REGISTER_CONVERSION, &value)) { this->mark_failed(); return; } - ESP_LOGCONFIG(TAG, "Configuring ADS1115..."); - uint16_t config = 0; // Clear single-shot bit // 0b0xxxxxxxxxxxxxxx @@ -68,10 +66,10 @@ void ADS1115Component::setup() { this->prev_config_ = config; } void ADS1115Component::dump_config() { - ESP_LOGCONFIG(TAG, "Setting up ADS1115..."); + ESP_LOGCONFIG(TAG, "ADS1115:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with ADS1115 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } } float ADS1115Component::request_measurement(ADS1115Multiplexer multiplexer, ADS1115Gain gain, diff --git a/esphome/components/ads1118/ads1118.cpp b/esphome/components/ads1118/ads1118.cpp index 7b9d0cc36b..976b599a6a 100644 --- a/esphome/components/ads1118/ads1118.cpp +++ b/esphome/components/ads1118/ads1118.cpp @@ -8,7 +8,7 @@ static const char *const TAG = "ads1118"; static const uint8_t ADS1118_DATA_RATE_860_SPS = 0b111; void ADS1118::setup() { - ESP_LOGCONFIG(TAG, "Setting up ads1118"); + ESP_LOGCONFIG(TAG, "Running setup"); this->spi_setup(); this->config_ = 0; diff --git a/esphome/components/ags10/ags10.cpp b/esphome/components/ags10/ags10.cpp index 422380da83..16228708ed 100644 --- a/esphome/components/ags10/ags10.cpp +++ b/esphome/components/ags10/ags10.cpp @@ -23,7 +23,7 @@ static const uint16_t ZP_CURRENT = 0x0000; static const uint16_t ZP_DEFAULT = 0xFFFF; void AGS10Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up ags10..."); + ESP_LOGCONFIG(TAG, "Running setup"); auto version = this->read_version_(); if (version) { @@ -65,7 +65,7 @@ void AGS10Component::dump_config() { case NONE: break; case COMMUNICATION_FAILED: - ESP_LOGE(TAG, "Communication with AGS10 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); break; case CRC_CHECK_FAILED: ESP_LOGE(TAG, "The crc check failed"); diff --git a/esphome/components/aht10/aht10.cpp b/esphome/components/aht10/aht10.cpp index 441c1ac9df..de7fd04be9 100644 --- a/esphome/components/aht10/aht10.cpp +++ b/esphome/components/aht10/aht10.cpp @@ -15,6 +15,7 @@ #include "aht10.h" #include "esphome/core/log.h" #include "esphome/core/hal.h" +#include "esphome/core/helpers.h" namespace esphome { namespace aht10 { @@ -34,57 +35,59 @@ static const uint8_t AHT10_INIT_ATTEMPTS = 10; static const uint8_t AHT10_STATUS_BUSY = 0x80; +static const float AHT10_DIVISOR = 1048576.0f; // 2^20, used for temperature and humidity calculations + void AHT10Component::setup() { + ESP_LOGCONFIG(TAG, "Running setup"); + if (this->write(AHT10_SOFTRESET_CMD, sizeof(AHT10_SOFTRESET_CMD)) != i2c::ERROR_OK) { - ESP_LOGE(TAG, "Reset AHT10 failed!"); + ESP_LOGE(TAG, "Reset failed"); } delay(AHT10_SOFTRESET_DELAY); i2c::ErrorCode error_code = i2c::ERROR_INVALID_ARGUMENT; switch (this->variant_) { case AHT10Variant::AHT20: - ESP_LOGCONFIG(TAG, "Setting up AHT20"); error_code = this->write(AHT20_INITIALIZE_CMD, sizeof(AHT20_INITIALIZE_CMD)); break; case AHT10Variant::AHT10: - ESP_LOGCONFIG(TAG, "Setting up AHT10"); error_code = this->write(AHT10_INITIALIZE_CMD, sizeof(AHT10_INITIALIZE_CMD)); break; } if (error_code != i2c::ERROR_OK) { - ESP_LOGE(TAG, "Communication with AHT10 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); this->mark_failed(); return; } + uint8_t cal_attempts = 0; uint8_t data = AHT10_STATUS_BUSY; - int cal_attempts = 0; while (data & AHT10_STATUS_BUSY) { delay(AHT10_DEFAULT_DELAY); if (this->read(&data, 1) != i2c::ERROR_OK) { - ESP_LOGE(TAG, "Communication with AHT10 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); this->mark_failed(); return; } ++cal_attempts; if (cal_attempts > AHT10_INIT_ATTEMPTS) { - ESP_LOGE(TAG, "AHT10 initialization timed out!"); + ESP_LOGE(TAG, "Initialization timed out"); this->mark_failed(); return; } } if ((data & 0x68) != 0x08) { // Bit[6:5] = 0b00, NORMAL mode and Bit[3] = 0b1, CALIBRATED - ESP_LOGE(TAG, "AHT10 initialization failed!"); + ESP_LOGE(TAG, "Initialization failed"); this->mark_failed(); return; } - ESP_LOGV(TAG, "AHT10 initialization"); + ESP_LOGV(TAG, "Initialization complete"); } void AHT10Component::restart_read_() { if (this->read_count_ == AHT10_ATTEMPTS) { this->read_count_ = 0; - this->status_set_error("Measurements reading timed-out!"); + this->status_set_error("Reading timed out"); return; } this->read_count_++; @@ -97,24 +100,24 @@ void AHT10Component::read_data_() { ESP_LOGD(TAG, "Read attempt %d at %ums", this->read_count_, (unsigned) (millis() - this->start_time_)); } if (this->read(data, 6) != i2c::ERROR_OK) { - this->status_set_warning("AHT10 read failed, retrying soon"); + this->status_set_warning("Read failed, will retry"); this->restart_read_(); return; } if ((data[0] & 0x80) == 0x80) { // Bit[7] = 0b1, device is busy - ESP_LOGD(TAG, "AHT10 is busy, waiting..."); + ESP_LOGD(TAG, "Device busy, will retry"); this->restart_read_(); return; } if (data[1] == 0x0 && data[2] == 0x0 && (data[3] >> 4) == 0x0) { - // Unrealistic humidity (0x0) + // Invalid humidity (0x0) if (this->humidity_sensor_ == nullptr) { - ESP_LOGV(TAG, "ATH10 Unrealistic humidity (0x0), but humidity is not required"); + ESP_LOGV(TAG, "Invalid humidity (reading not required)"); } else { - ESP_LOGD(TAG, "ATH10 Unrealistic humidity (0x0), retrying..."); + ESP_LOGD(TAG, "Invalid humidity, retrying..."); if (this->write(AHT10_MEASURE_CMD, sizeof(AHT10_MEASURE_CMD)) != i2c::ERROR_OK) { - this->status_set_warning("Communication with AHT10 failed!"); + this->status_set_warning(ESP_LOG_MSG_COMM_FAIL); } this->restart_read_(); return; @@ -123,22 +126,17 @@ void AHT10Component::read_data_() { if (this->read_count_ > 1) { ESP_LOGD(TAG, "Success at %ums", (unsigned) (millis() - this->start_time_)); } - uint32_t raw_temperature = ((data[3] & 0x0F) << 16) | (data[4] << 8) | data[5]; - uint32_t raw_humidity = ((data[1] << 16) | (data[2] << 8) | data[3]) >> 4; + uint32_t raw_temperature = encode_uint24(data[3] & 0xF, data[4], data[5]); + uint32_t raw_humidity = encode_uint24(data[1], data[2], data[3]) >> 4; if (this->temperature_sensor_ != nullptr) { - float temperature = ((200.0f * (float) raw_temperature) / 1048576.0f) - 50.0f; + float temperature = ((200.0f * static_cast(raw_temperature)) / AHT10_DIVISOR) - 50.0f; this->temperature_sensor_->publish_state(temperature); } if (this->humidity_sensor_ != nullptr) { - float humidity; - if (raw_humidity == 0) { // unrealistic value - humidity = NAN; - } else { - humidity = (float) raw_humidity * 100.0f / 1048576.0f; - } + float humidity = raw_humidity == 0 ? NAN : static_cast(raw_humidity) * 100.0f / AHT10_DIVISOR; if (std::isnan(humidity)) { - ESP_LOGW(TAG, "Invalid humidity! Sensor reported 0%% Hum"); + ESP_LOGW(TAG, "Invalid humidity reading (0%%), "); } this->humidity_sensor_->publish_state(humidity); } @@ -150,7 +148,7 @@ void AHT10Component::update() { return; this->start_time_ = millis(); if (this->write(AHT10_MEASURE_CMD, sizeof(AHT10_MEASURE_CMD)) != i2c::ERROR_OK) { - this->status_set_warning("Communication with AHT10 failed!"); + this->status_set_warning(ESP_LOG_MSG_COMM_FAIL); return; } this->restart_read_(); @@ -162,7 +160,7 @@ void AHT10Component::dump_config() { ESP_LOGCONFIG(TAG, "AHT10:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with AHT10 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/aic3204/aic3204.cpp b/esphome/components/aic3204/aic3204.cpp index 0560f2366b..a004fb42ce 100644 --- a/esphome/components/aic3204/aic3204.cpp +++ b/esphome/components/aic3204/aic3204.cpp @@ -17,7 +17,7 @@ static const char *const TAG = "aic3204"; } void AIC3204::setup() { - ESP_LOGCONFIG(TAG, "Setting up AIC3204..."); + ESP_LOGCONFIG(TAG, "Running setup"); // Set register page to 0 ERROR_CHECK(this->write_byte(AIC3204_PAGE_CTRL, 0x00), "Set page 0 failed"); @@ -113,7 +113,7 @@ void AIC3204::dump_config() { LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with AIC3204 failed"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } } diff --git a/esphome/components/am2315c/am2315c.cpp b/esphome/components/am2315c/am2315c.cpp index 90565de740..cea5263fd6 100644 --- a/esphome/components/am2315c/am2315c.cpp +++ b/esphome/components/am2315c/am2315c.cpp @@ -90,7 +90,7 @@ bool AM2315C::convert_(uint8_t *data, float &humidity, float &temperature) { } void AM2315C::setup() { - ESP_LOGCONFIG(TAG, "Setting up AM2315C..."); + ESP_LOGCONFIG(TAG, "Running setup"); // get status uint8_t status = 0; @@ -188,7 +188,7 @@ void AM2315C::dump_config() { ESP_LOGCONFIG(TAG, "AM2315C:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with AM2315C 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/am2320/am2320.cpp b/esphome/components/am2320/am2320.cpp index ec501f2d36..6400ecef4b 100644 --- a/esphome/components/am2320/am2320.cpp +++ b/esphome/components/am2320/am2320.cpp @@ -34,7 +34,7 @@ void AM2320Component::update() { this->status_clear_warning(); } void AM2320Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up AM2320..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t data[8]; data[0] = 0; data[1] = 4; @@ -47,7 +47,7 @@ void AM2320Component::dump_config() { ESP_LOGD(TAG, "AM2320:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with AM2320 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/apds9306/apds9306.cpp b/esphome/components/apds9306/apds9306.cpp index bbb3ba1910..b785f61c57 100644 --- a/esphome/components/apds9306/apds9306.cpp +++ b/esphome/components/apds9306/apds9306.cpp @@ -54,7 +54,7 @@ enum { // APDS9306 registers } void APDS9306::setup() { - ESP_LOGCONFIG(TAG, "Setting up APDS9306..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t id; if (!this->read_byte(APDS9306_PART_ID, &id)) { // Part ID register @@ -97,7 +97,7 @@ void APDS9306::dump_config() { if (this->is_failed()) { switch (this->error_code_) { case COMMUNICATION_FAILED: - ESP_LOGE(TAG, "Communication with APDS9306 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); break; case WRONG_ID: ESP_LOGE(TAG, "APDS9306 has invalid id!"); diff --git a/esphome/components/apds9960/apds9960.cpp b/esphome/components/apds9960/apds9960.cpp index d91378afee..4a6ce371e5 100644 --- a/esphome/components/apds9960/apds9960.cpp +++ b/esphome/components/apds9960/apds9960.cpp @@ -15,7 +15,7 @@ static const char *const TAG = "apds9960"; #define APDS9960_WRITE_BYTE(reg, value) APDS9960_ERROR_CHECK(this->write_byte(reg, value)); void APDS9960::setup() { - ESP_LOGCONFIG(TAG, "Setting up APDS9960..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t id; if (!this->read_byte(0x92, &id)) { // ID register this->error_code_ = COMMUNICATION_FAILED; @@ -141,7 +141,7 @@ void APDS9960::dump_config() { if (this->is_failed()) { switch (this->error_code_) { case COMMUNICATION_FAILED: - ESP_LOGE(TAG, "Communication with APDS9960 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); break; case WRONG_ID: ESP_LOGE(TAG, "APDS9960 has invalid id!"); diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index b4646a2d7d..ca615a6d98 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -135,31 +135,35 @@ void APIConnection::loop() { api_error_to_str(err), errno); return; } - ReadPacketBuffer buffer; - err = this->helper_->read_packet(&buffer); - if (err == APIError::WOULD_BLOCK) { - // pass - } else if (err != APIError::OK) { - on_fatal_error(); - if (err == APIError::SOCKET_READ_FAILED && errno == ECONNRESET) { - ESP_LOGW(TAG, "%s: Connection reset", this->client_combined_info_.c_str()); - } else if (err == APIError::CONNECTION_CLOSED) { - ESP_LOGW(TAG, "%s: Connection closed", this->client_combined_info_.c_str()); - } else { - ESP_LOGW(TAG, "%s: Reading failed: %s errno=%d", this->client_combined_info_.c_str(), api_error_to_str(err), - errno); - } - return; - } else { - this->last_traffic_ = App.get_loop_component_start_time(); - // read a packet - if (buffer.data_len > 0) { - this->read_message(buffer.data_len, buffer.type, &buffer.container[buffer.data_offset]); - } else { - this->read_message(0, buffer.type, nullptr); - } - if (this->remove_) + + // Check if socket has data ready before attempting to read + if (this->helper_->is_socket_ready()) { + ReadPacketBuffer buffer; + err = this->helper_->read_packet(&buffer); + if (err == APIError::WOULD_BLOCK) { + // pass + } else if (err != APIError::OK) { + on_fatal_error(); + if (err == APIError::SOCKET_READ_FAILED && errno == ECONNRESET) { + ESP_LOGW(TAG, "%s: Connection reset", this->client_combined_info_.c_str()); + } else if (err == APIError::CONNECTION_CLOSED) { + ESP_LOGW(TAG, "%s: Connection closed", this->client_combined_info_.c_str()); + } else { + ESP_LOGW(TAG, "%s: Reading failed: %s errno=%d", this->client_combined_info_.c_str(), api_error_to_str(err), + errno); + } return; + } else { + this->last_traffic_ = App.get_loop_component_start_time(); + // read a packet + if (buffer.data_len > 0) { + this->read_message(buffer.data_len, buffer.type, &buffer.container[buffer.data_offset]); + } else { + this->read_message(0, buffer.type, nullptr); + } + if (this->remove_) + return; + } } if (!this->deferred_message_queue_.empty() && this->helper_->can_write_without_blocking()) { diff --git a/esphome/components/api/api_frame_helper.cpp b/esphome/components/api/api_frame_helper.cpp index 19983e3456..19263f2f2c 100644 --- a/esphome/components/api/api_frame_helper.cpp +++ b/esphome/components/api/api_frame_helper.cpp @@ -831,12 +831,15 @@ APIError APIPlaintextFrameHelper::try_read_frame_(ParsedFrame *frame) { // read header while (!rx_header_parsed_) { - uint8_t data; - // Reading one byte at a time is fastest in practice for ESP32 when - // there is no data on the wire (which is the common case). - // This results in faster failure detection compared to - // attempting to read multiple bytes at once. - ssize_t received = this->socket_->read(&data, 1); + // Now that we know when the socket is ready, we can read up to 3 bytes + // into the rx_header_buf_ before we have to switch back to reading + // one byte at a time to ensure we don't read past the message and + // into the next one. + + // Read directly into rx_header_buf_ at the current position + // Try to get to at least 3 bytes total (indicator + 2 varint bytes), then read one byte at a time + ssize_t received = + this->socket_->read(&rx_header_buf_[rx_header_buf_pos_], rx_header_buf_pos_ < 3 ? 3 - rx_header_buf_pos_ : 1); if (received == -1) { if (errno == EWOULDBLOCK || errno == EAGAIN) { return APIError::WOULD_BLOCK; @@ -850,51 +853,46 @@ APIError APIPlaintextFrameHelper::try_read_frame_(ParsedFrame *frame) { return APIError::CONNECTION_CLOSED; } - // Successfully read a byte - - // Process byte according to current buffer position - if (rx_header_buf_pos_ == 0) { // Case 1: First byte (indicator byte) - if (data != 0x00) { + // If this was the first read, validate the indicator byte + if (rx_header_buf_pos_ == 0 && received > 0) { + if (rx_header_buf_[0] != 0x00) { state_ = State::FAILED; - HELPER_LOG("Bad indicator byte %u", data); + HELPER_LOG("Bad indicator byte %u", rx_header_buf_[0]); return APIError::BAD_INDICATOR; } - // We don't store the indicator byte, just increment position - rx_header_buf_pos_ = 1; // Set to 1 directly - continue; // Need more bytes before we can parse } - // Check buffer overflow before storing - if (rx_header_buf_pos_ == 5) { // Case 2: Buffer would overflow (5 bytes is max allowed) + rx_header_buf_pos_ += received; + + // Check for buffer overflow + if (rx_header_buf_pos_ >= sizeof(rx_header_buf_)) { state_ = State::FAILED; HELPER_LOG("Header buffer overflow"); return APIError::BAD_DATA_PACKET; } - // Store byte in buffer (adjust index to account for skipped indicator byte) - rx_header_buf_[rx_header_buf_pos_ - 1] = data; - - // Increment position after storing - rx_header_buf_pos_++; - - // Case 3: If we only have one varint byte, we need more - if (rx_header_buf_pos_ == 2) { // Have read indicator + 1 byte - continue; // Need more bytes before we can parse + // Need at least 3 bytes total (indicator + 2 varint bytes) before trying to parse + if (rx_header_buf_pos_ < 3) { + continue; } // At this point, we have at least 3 bytes total: - // - Validated indicator byte (0x00) but not stored + // - Validated indicator byte (0x00) stored at position 0 // - At least 2 bytes in the buffer for the varints // Buffer layout: - // First 1-3 bytes: Message size varint (variable length) + // [0]: indicator byte (0x00) + // [1-3]: Message size varint (variable length) // - 2 bytes would only allow up to 16383, which is less than noise's UINT16_MAX (65535) // - 3 bytes allows up to 2097151, ensuring we support at least as much as noise - // Remaining 1-2 bytes: Message type varint (variable length) + // [2-5]: Message type varint (variable length) // We now attempt to parse both varints. If either is incomplete, // we'll continue reading more bytes. + // Skip indicator byte at position 0 + uint8_t varint_pos = 1; uint32_t consumed = 0; - auto msg_size_varint = ProtoVarInt::parse(&rx_header_buf_[0], rx_header_buf_pos_ - 1, &consumed); + + auto msg_size_varint = ProtoVarInt::parse(&rx_header_buf_[varint_pos], rx_header_buf_pos_ - varint_pos, &consumed); if (!msg_size_varint.has_value()) { // not enough data there yet continue; @@ -908,7 +906,10 @@ APIError APIPlaintextFrameHelper::try_read_frame_(ParsedFrame *frame) { } rx_header_parsed_len_ = msg_size_varint->as_uint16(); - auto msg_type_varint = ProtoVarInt::parse(&rx_header_buf_[consumed], rx_header_buf_pos_ - 1 - consumed, &consumed); + // Move to next varint position + varint_pos += consumed; + + auto msg_type_varint = ProtoVarInt::parse(&rx_header_buf_[varint_pos], rx_header_buf_pos_ - varint_pos, &consumed); if (!msg_type_varint.has_value()) { // not enough data there yet continue; diff --git a/esphome/components/api/api_frame_helper.h b/esphome/components/api/api_frame_helper.h index bc25680a53..0799ae0f85 100644 --- a/esphome/components/api/api_frame_helper.h +++ b/esphome/components/api/api_frame_helper.h @@ -13,6 +13,7 @@ #include "api_noise_context.h" #include "esphome/components/socket/socket.h" +#include "esphome/core/application.h" namespace esphome { namespace api { @@ -90,6 +91,8 @@ class APIFrameHelper { virtual uint8_t frame_header_padding() = 0; // Get the frame footer size required by this protocol virtual uint8_t frame_footer_size() = 0; + // Check if socket has data ready to read + bool is_socket_ready() const { return socket_ != nullptr && socket_->ready(); } protected: // Struct for holding parsed frame data @@ -230,14 +233,14 @@ class APIPlaintextFrameHelper : public APIFrameHelper { protected: APIError try_read_frame_(ParsedFrame *frame); // Fixed-size header buffer for plaintext protocol: - // We only need space for the two varints since we validate the indicator byte separately. + // We now store the indicator byte + the two varints. // To match noise protocol's maximum message size (UINT16_MAX = 65535), we need: - // 3 bytes for message size varint (supports up to 2097151) + 2 bytes for message type varint + // 1 byte for indicator + 3 bytes for message size varint (supports up to 2097151) + 2 bytes for message type varint // // While varints could theoretically be up to 10 bytes each for 64-bit values, // attempting to process messages with headers that large would likely crash the // ESP32 due to memory constraints. - uint8_t rx_header_buf_[5]; // 5 bytes for varints (3 for size + 2 for type) + uint8_t rx_header_buf_[6]; // 1 byte indicator + 5 bytes for varints (3 for size + 2 for type) uint8_t rx_header_buf_pos_ = 0; bool rx_header_parsed_ = false; uint16_t rx_header_parsed_type_ = 0; diff --git a/esphome/components/api/api_server.cpp b/esphome/components/api/api_server.cpp index b987b44705..2d5c507b9d 100644 --- a/esphome/components/api/api_server.cpp +++ b/esphome/components/api/api_server.cpp @@ -27,7 +27,7 @@ APIServer *global_api_server = nullptr; // NOLINT(cppcoreguidelines-avoid-non-c APIServer::APIServer() { global_api_server = this; } void APIServer::setup() { - ESP_LOGCONFIG(TAG, "Setting up Home Assistant API server..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->setup_controller(); #ifdef USE_API_NOISE @@ -43,7 +43,7 @@ void APIServer::setup() { } #endif - this->socket_ = socket::socket_ip(SOCK_STREAM, 0); + this->socket_ = socket::socket_ip_loop_monitored(SOCK_STREAM, 0); // monitored for incoming connections if (this->socket_ == nullptr) { ESP_LOGW(TAG, "Could not create socket"); this->mark_failed(); @@ -112,18 +112,20 @@ void APIServer::setup() { } void APIServer::loop() { - // Accept new clients - while (true) { - struct sockaddr_storage source_addr; - socklen_t addr_len = sizeof(source_addr); - auto sock = this->socket_->accept((struct sockaddr *) &source_addr, &addr_len); - if (!sock) - break; - ESP_LOGD(TAG, "Accepted %s", sock->getpeername().c_str()); + // Accept new clients only if the socket has incoming connections + if (this->socket_->ready()) { + while (true) { + struct sockaddr_storage source_addr; + socklen_t addr_len = sizeof(source_addr); + auto sock = this->socket_->accept_loop_monitored((struct sockaddr *) &source_addr, &addr_len); + if (!sock) + break; + ESP_LOGD(TAG, "Accepted %s", sock->getpeername().c_str()); - auto *conn = new APIConnection(std::move(sock), this); - this->clients_.emplace_back(conn); - conn->start(); + auto *conn = new APIConnection(std::move(sock), this); + this->clients_.emplace_back(conn); + conn->start(); + } } // Process clients and remove disconnected ones in a single pass @@ -155,7 +157,7 @@ void APIServer::loop() { const uint32_t now = millis(); if (!this->is_connected()) { if (now - this->last_connected_ > this->reboot_timeout_) { - ESP_LOGE(TAG, "No client connected to API. Rebooting..."); + ESP_LOGE(TAG, "No client connected; rebooting"); App.reboot(); } this->status_set_warning(); diff --git a/esphome/components/as3935/as3935.cpp b/esphome/components/as3935/as3935.cpp index 29fc6ee685..adef45a395 100644 --- a/esphome/components/as3935/as3935.cpp +++ b/esphome/components/as3935/as3935.cpp @@ -7,7 +7,7 @@ namespace as3935 { static const char *const TAG = "as3935"; void AS3935Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up AS3935..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->irq_pin_->setup(); LOG_PIN(" IRQ Pin: ", this->irq_pin_); diff --git a/esphome/components/as5600/as5600.cpp b/esphome/components/as5600/as5600.cpp index 3fe7eab58d..5cfc7e1b9e 100644 --- a/esphome/components/as5600/as5600.cpp +++ b/esphome/components/as5600/as5600.cpp @@ -23,7 +23,7 @@ static const uint8_t REGISTER_AGC = 0x1A; // 8 bytes / R static const uint8_t REGISTER_MAGNITUDE = 0x1B; // 16 bytes / R void AS5600Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up AS5600..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (!this->read_byte(REGISTER_STATUS).has_value()) { this->mark_failed(); @@ -91,7 +91,7 @@ void AS5600Component::dump_config() { LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with AS5600 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); return; } diff --git a/esphome/components/as7341/as7341.cpp b/esphome/components/as7341/as7341.cpp index 129a3f9e37..b01bcf2eed 100644 --- a/esphome/components/as7341/as7341.cpp +++ b/esphome/components/as7341/as7341.cpp @@ -8,7 +8,7 @@ namespace as7341 { static const char *const TAG = "as7341"; void AS7341Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up AS7341..."); + ESP_LOGCONFIG(TAG, "Running setup"); LOG_I2C_DEVICE(this); // Verify device ID @@ -38,7 +38,7 @@ void AS7341Component::dump_config() { ESP_LOGCONFIG(TAG, "AS7341:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with AS7341 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); ESP_LOGCONFIG(TAG, " Gain: %u", get_gain()); diff --git a/esphome/components/at581x/at581x.cpp b/esphome/components/at581x/at581x.cpp index eef457f985..2171544be2 100644 --- a/esphome/components/at581x/at581x.cpp +++ b/esphome/components/at581x/at581x.cpp @@ -71,7 +71,7 @@ bool AT581XComponent::i2c_read_reg(uint8_t addr, uint8_t &data) { return this->read_register(addr, &data, 1) == esphome::i2c::NO_ERROR; } -void AT581XComponent::setup() { ESP_LOGCONFIG(TAG, "Setting up AT581X..."); } +void AT581XComponent::setup() { ESP_LOGCONFIG(TAG, "Running setup"); } void AT581XComponent::dump_config() { LOG_I2C_DEVICE(this); } #define ARRAY_SIZE(X) (sizeof(X) / sizeof((X)[0])) bool AT581XComponent::i2c_write_config() { diff --git a/esphome/components/atm90e26/atm90e26.cpp b/esphome/components/atm90e26/atm90e26.cpp index 6743f1a442..ce254f9532 100644 --- a/esphome/components/atm90e26/atm90e26.cpp +++ b/esphome/components/atm90e26/atm90e26.cpp @@ -41,7 +41,7 @@ void ATM90E26Component::update() { } void ATM90E26Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up ATM90E26 Component..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->spi_setup(); uint16_t mmode = 0x422; // default values for everything but L/N line current gains @@ -135,7 +135,7 @@ void ATM90E26Component::dump_config() { ESP_LOGCONFIG("", "ATM90E26:"); LOG_PIN(" CS Pin: ", this->cs_); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with ATM90E26 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "Voltage A", this->voltage_sensor_); diff --git a/esphome/components/atm90e32/atm90e32.cpp b/esphome/components/atm90e32/atm90e32.cpp index f4f177587c..545997eb14 100644 --- a/esphome/components/atm90e32/atm90e32.cpp +++ b/esphome/components/atm90e32/atm90e32.cpp @@ -108,7 +108,7 @@ void ATM90E32Component::update() { } void ATM90E32Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up ATM90E32 Component..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->spi_setup(); uint16_t mmode0 = 0x87; // 3P4W 50Hz @@ -217,7 +217,7 @@ void ATM90E32Component::dump_config() { ESP_LOGCONFIG("", "ATM90E32:"); LOG_PIN(" CS Pin: ", this->cs_); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with ATM90E32 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "Voltage A", this->phase_[PHASEA].voltage_sensor_); diff --git a/esphome/components/axs15231/touchscreen/axs15231_touchscreen.cpp b/esphome/components/axs15231/touchscreen/axs15231_touchscreen.cpp index c7646bcf2f..d4e5d7b9c6 100644 --- a/esphome/components/axs15231/touchscreen/axs15231_touchscreen.cpp +++ b/esphome/components/axs15231/touchscreen/axs15231_touchscreen.cpp @@ -17,7 +17,7 @@ constexpr static const uint8_t AXS_READ_TOUCHPAD[11] = {0xb5, 0xab, 0xa5, 0x5a, } void AXS15231Touchscreen::setup() { - ESP_LOGCONFIG(TAG, "Setting up AXS15231 Touchscreen..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (this->reset_pin_ != nullptr) { this->reset_pin_->setup(); this->reset_pin_->digital_write(false); diff --git a/esphome/components/beken_spi_led_strip/led_strip.cpp b/esphome/components/beken_spi_led_strip/led_strip.cpp index 04c8649b90..39bf831226 100644 --- a/esphome/components/beken_spi_led_strip/led_strip.cpp +++ b/esphome/components/beken_spi_led_strip/led_strip.cpp @@ -119,7 +119,7 @@ void spi_dma_tx_finish_callback(unsigned int param) { } void BekenSPILEDStripLightOutput::setup() { - ESP_LOGCONFIG(TAG, "Setting up Beken SPI LED Strip..."); + ESP_LOGCONFIG(TAG, "Running setup"); size_t buffer_size = this->get_buffer_size_(); size_t dma_buffer_size = (buffer_size * 8) + (2 * 64); diff --git a/esphome/components/bh1750/bh1750.cpp b/esphome/components/bh1750/bh1750.cpp index de6d811ed2..4b51794907 100644 --- a/esphome/components/bh1750/bh1750.cpp +++ b/esphome/components/bh1750/bh1750.cpp @@ -38,7 +38,7 @@ MTreg: */ void BH1750Sensor::setup() { - ESP_LOGCONFIG(TAG, "Setting up BH1750 '%s'...", this->name_.c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->name_.c_str()); uint8_t turn_on = BH1750_COMMAND_POWER_ON; if (this->write(&turn_on, 1) != i2c::ERROR_OK) { this->mark_failed(); @@ -118,7 +118,7 @@ void BH1750Sensor::dump_config() { LOG_SENSOR("", "BH1750", this); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with BH1750 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL_FOR, this->get_name().c_str()); } LOG_UPDATE_INTERVAL(this); diff --git a/esphome/components/bme280_base/bme280_base.cpp b/esphome/components/bme280_base/bme280_base.cpp index 76e20836c7..c73b48589d 100644 --- a/esphome/components/bme280_base/bme280_base.cpp +++ b/esphome/components/bme280_base/bme280_base.cpp @@ -88,7 +88,7 @@ const char *oversampling_to_str(BME280Oversampling oversampling) { // NOLINT } void BME280Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up BME280..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t chip_id = 0; // Mark as not failed before initializing. Some devices will turn off sensors to save on batteries @@ -182,7 +182,7 @@ void BME280Component::dump_config() { ESP_LOGCONFIG(TAG, "BME280:"); switch (this->error_code_) { case COMMUNICATION_FAILED: - ESP_LOGE(TAG, "Communication with BME280 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); break; case WRONG_CHIP_ID: ESP_LOGE(TAG, "BME280 has wrong chip ID! Is it a BME280?"); diff --git a/esphome/components/bme680/bme680.cpp b/esphome/components/bme680/bme680.cpp index 2b48f39e31..7e8f2f5a32 100644 --- a/esphome/components/bme680/bme680.cpp +++ b/esphome/components/bme680/bme680.cpp @@ -71,7 +71,7 @@ static const char *iir_filter_to_str(BME680IIRFilter filter) { } void BME680Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up BME680..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t chip_id; if (!this->read_byte(BME680_REGISTER_CHIPID, &chip_id) || chip_id != 0x61) { this->mark_failed(); @@ -215,7 +215,7 @@ void BME680Component::dump_config() { ESP_LOGCONFIG(TAG, "BME680:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with BME680 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } ESP_LOGCONFIG(TAG, " IIR Filter: %s", iir_filter_to_str(this->iir_filter_)); LOG_UPDATE_INTERVAL(this); @@ -307,7 +307,7 @@ void BME680Component::read_data_() { this->humidity_sensor_->publish_state(NAN); if (this->gas_resistance_sensor_ != nullptr) this->gas_resistance_sensor_->publish_state(NAN); - ESP_LOGW(TAG, "Communication with BME680 failed!"); + ESP_LOGW(TAG, ESP_LOG_MSG_COMM_FAIL); this->status_set_warning(); return; } diff --git a/esphome/components/bme680_bsec/bme680_bsec.cpp b/esphome/components/bme680_bsec/bme680_bsec.cpp index 17dae35b5c..92642173dc 100644 --- a/esphome/components/bme680_bsec/bme680_bsec.cpp +++ b/esphome/components/bme680_bsec/bme680_bsec.cpp @@ -15,7 +15,7 @@ std::vector uint8_t BME680BSECComponent::work_buffer_[BSEC_MAX_WORKBUFFER_SIZE] = {0}; void BME680BSECComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up BME680(%s) via BSEC...", this->device_id_.c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->device_id_.c_str()); uint8_t new_idx = BME680BSECComponent::instances.size(); BME680BSECComponent::instances.push_back(this); diff --git a/esphome/components/bme68x_bsec2/bme68x_bsec2.cpp b/esphome/components/bme68x_bsec2/bme68x_bsec2.cpp index 07ad1fde90..6b3663cdc8 100644 --- a/esphome/components/bme68x_bsec2/bme68x_bsec2.cpp +++ b/esphome/components/bme68x_bsec2/bme68x_bsec2.cpp @@ -21,7 +21,7 @@ static const char *const TAG = "bme68x_bsec2.sensor"; static const std::string IAQ_ACCURACY_STATES[4] = {"Stabilizing", "Uncertain", "Calibrating", "Calibrated"}; void BME68xBSEC2Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up BME68X via BSEC2..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->bsec_status_ = bsec_init_m(&this->bsec_instance_); if (this->bsec_status_ != BSEC_OK) { diff --git a/esphome/components/bmi160/bmi160.cpp b/esphome/components/bmi160/bmi160.cpp index 69b4694345..67106cc20c 100644 --- a/esphome/components/bmi160/bmi160.cpp +++ b/esphome/components/bmi160/bmi160.cpp @@ -119,7 +119,7 @@ const float GRAVITY_EARTH = 9.80665f; void BMI160Component::internal_setup_(int stage) { switch (stage) { case 0: - ESP_LOGCONFIG(TAG, "Setting up BMI160..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t chipid; if (!this->read_byte(BMI160_REGISTER_CHIPID, &chipid) || (chipid != 0b11010001)) { this->mark_failed(); @@ -189,7 +189,7 @@ void BMI160Component::dump_config() { ESP_LOGCONFIG(TAG, "BMI160:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with BMI160 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "Acceleration X", this->accel_x_sensor_); diff --git a/esphome/components/bmp085/bmp085.cpp b/esphome/components/bmp085/bmp085.cpp index caf2264390..7f00a915f1 100644 --- a/esphome/components/bmp085/bmp085.cpp +++ b/esphome/components/bmp085/bmp085.cpp @@ -20,7 +20,7 @@ void BMP085Component::update() { this->set_timeout("temperature", 5, [this]() { this->read_temperature_(); }); } void BMP085Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up BMP085..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t data[22]; if (!this->read_bytes(BMP085_REGISTER_AC1_H, data, 22)) { this->mark_failed(); diff --git a/esphome/components/bmp280_base/bmp280_base.cpp b/esphome/components/bmp280_base/bmp280_base.cpp index f94456f6e6..665707e26c 100644 --- a/esphome/components/bmp280_base/bmp280_base.cpp +++ b/esphome/components/bmp280_base/bmp280_base.cpp @@ -57,7 +57,7 @@ static const char *iir_filter_to_str(BMP280IIRFilter filter) { } void BMP280Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up BMP280..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t chip_id = 0; // Read the chip id twice, to work around a bug where the first read is 0. @@ -132,7 +132,7 @@ void BMP280Component::dump_config() { ESP_LOGCONFIG(TAG, "BMP280:"); switch (this->error_code_) { case COMMUNICATION_FAILED: - ESP_LOGE(TAG, "Communication with BMP280 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); break; case WRONG_CHIP_ID: ESP_LOGE(TAG, "BMP280 has wrong chip ID! Is it a BME280?"); diff --git a/esphome/components/bmp3xx_base/bmp3xx_base.cpp b/esphome/components/bmp3xx_base/bmp3xx_base.cpp index 75b6812f81..d35c5fd331 100644 --- a/esphome/components/bmp3xx_base/bmp3xx_base.cpp +++ b/esphome/components/bmp3xx_base/bmp3xx_base.cpp @@ -70,7 +70,7 @@ static const LogString *iir_filter_to_str(IIRFilter filter) { void BMP3XXComponent::setup() { this->error_code_ = NONE; - ESP_LOGCONFIG(TAG, "Setting up BMP3XX..."); + ESP_LOGCONFIG(TAG, "Running setup"); // Call the Device base class "initialise" function if (!reset()) { ESP_LOGE(TAG, "Failed to reset BMP3XX..."); @@ -154,7 +154,7 @@ void BMP3XXComponent::dump_config() { case NONE: break; case ERROR_COMMUNICATION_FAILED: - ESP_LOGE(TAG, "Communication with BMP3XX failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); break; case ERROR_WRONG_CHIP_ID: ESP_LOGE( diff --git a/esphome/components/bmp581/bmp581.cpp b/esphome/components/bmp581/bmp581.cpp index 0308da0bcb..30d5b95a46 100644 --- a/esphome/components/bmp581/bmp581.cpp +++ b/esphome/components/bmp581/bmp581.cpp @@ -122,7 +122,7 @@ void BMP581Component::setup() { */ this->error_code_ = NONE; - ESP_LOGCONFIG(TAG, "Setting up BMP581..."); + ESP_LOGCONFIG(TAG, "Running setup"); //////////////////// // 1) Soft reboot // diff --git a/esphome/components/bp1658cj/bp1658cj.cpp b/esphome/components/bp1658cj/bp1658cj.cpp index 4b74cc85f5..3a679bd79b 100644 --- a/esphome/components/bp1658cj/bp1658cj.cpp +++ b/esphome/components/bp1658cj/bp1658cj.cpp @@ -15,7 +15,7 @@ static const uint8_t BP1658CJ_ADDR_START_5CH = 0x30; static const uint8_t BP1658CJ_DELAY = 2; void BP1658CJ::setup() { - ESP_LOGCONFIG(TAG, "Setting up BP1658CJ Output Component..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->data_pin_->setup(); this->data_pin_->digital_write(false); this->clock_pin_->setup(); diff --git a/esphome/components/bp5758d/bp5758d.cpp b/esphome/components/bp5758d/bp5758d.cpp index 87c4165275..797ddd919e 100644 --- a/esphome/components/bp5758d/bp5758d.cpp +++ b/esphome/components/bp5758d/bp5758d.cpp @@ -20,7 +20,7 @@ static const uint8_t BP5758D_ALL_DATA_CHANNEL_ENABLEMENT = 0b00011111; static const uint8_t BP5758D_DELAY = 2; void BP5758D::setup() { - ESP_LOGCONFIG(TAG, "Setting up BP5758D Output Component..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->data_pin_->setup(); this->data_pin_->digital_write(false); delayMicroseconds(BP5758D_DELAY); diff --git a/esphome/components/canbus/canbus.cpp b/esphome/components/canbus/canbus.cpp index 3b86f209cd..d08558037e 100644 --- a/esphome/components/canbus/canbus.cpp +++ b/esphome/components/canbus/canbus.cpp @@ -7,7 +7,7 @@ namespace canbus { static const char *const TAG = "canbus"; void Canbus::setup() { - ESP_LOGCONFIG(TAG, "Setting up Canbus..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (!this->setup_internal()) { ESP_LOGE(TAG, "setup error!"); this->mark_failed(); diff --git a/esphome/components/cap1188/cap1188.cpp b/esphome/components/cap1188/cap1188.cpp index 10d8325537..2fdcca94c1 100644 --- a/esphome/components/cap1188/cap1188.cpp +++ b/esphome/components/cap1188/cap1188.cpp @@ -8,7 +8,7 @@ namespace cap1188 { static const char *const TAG = "cap1188"; void CAP1188Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up CAP1188..."); + ESP_LOGCONFIG(TAG, "Running setup"); // Reset device using the reset pin if (this->reset_pin_ != nullptr) { diff --git a/esphome/components/captive_portal/captive_portal.cpp b/esphome/components/captive_portal/captive_portal.cpp index d1960e9a93..31e6c51f0f 100644 --- a/esphome/components/captive_portal/captive_portal.cpp +++ b/esphome/components/captive_portal/captive_portal.cpp @@ -29,7 +29,7 @@ void CaptivePortal::handle_config(AsyncWebServerRequest *request) { void CaptivePortal::handle_wifisave(AsyncWebServerRequest *request) { std::string ssid = request->arg("ssid").c_str(); std::string psk = request->arg("psk").c_str(); - ESP_LOGI(TAG, "Captive Portal Requested WiFi Settings Change:"); + ESP_LOGI(TAG, "Requested WiFi Settings Change:"); ESP_LOGI(TAG, " SSID='%s'", ssid.c_str()); ESP_LOGI(TAG, " Password=" LOG_SECRET("'%s'"), psk.c_str()); wifi::global_wifi_component->save_wifi_sta(ssid, psk); diff --git a/esphome/components/ccs811/ccs811.cpp b/esphome/components/ccs811/ccs811.cpp index f1dadf673a..700e1b4df0 100644 --- a/esphome/components/ccs811/ccs811.cpp +++ b/esphome/components/ccs811/ccs811.cpp @@ -163,7 +163,7 @@ void CCS811Component::dump_config() { if (this->is_failed()) { switch (this->error_code_) { case COMMUNICATION_FAILED: - ESP_LOGW(TAG, "Communication failed! Is the sensor connected?"); + ESP_LOGW(TAG, ESP_LOG_MSG_COMM_FAIL); break; case INVALID_ID: ESP_LOGW(TAG, "Sensor reported an invalid ID. Is this a CCS811?"); diff --git a/esphome/components/cd74hc4067/cd74hc4067.cpp b/esphome/components/cd74hc4067/cd74hc4067.cpp index f7629df3ca..3c7b9038d7 100644 --- a/esphome/components/cd74hc4067/cd74hc4067.cpp +++ b/esphome/components/cd74hc4067/cd74hc4067.cpp @@ -10,7 +10,7 @@ static const char *const TAG = "cd74hc4067"; float CD74HC4067Component::get_setup_priority() const { return setup_priority::DATA; } void CD74HC4067Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up CD74HC4067..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->pin_s0_->setup(); this->pin_s1_->setup(); diff --git a/esphome/components/ch422g/ch422g.cpp b/esphome/components/ch422g/ch422g.cpp index 0db179d99e..325c56e470 100644 --- a/esphome/components/ch422g/ch422g.cpp +++ b/esphome/components/ch422g/ch422g.cpp @@ -14,7 +14,7 @@ static const uint8_t CH422G_REG_OUT_UPPER = 0x23; // write reg for output bit static const char *const TAG = "ch422g"; void CH422GComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up CH422G..."); + ESP_LOGCONFIG(TAG, "Running setup"); // set outputs before mode this->write_outputs_(); // Set mode and check for errors @@ -37,7 +37,7 @@ void CH422GComponent::dump_config() { ESP_LOGCONFIG(TAG, "CH422G:"); LOG_I2C_DEVICE(this) if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with CH422G failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } } diff --git a/esphome/components/chsc6x/chsc6x_touchscreen.cpp b/esphome/components/chsc6x/chsc6x_touchscreen.cpp index 5ad4329718..7755b1d229 100644 --- a/esphome/components/chsc6x/chsc6x_touchscreen.cpp +++ b/esphome/components/chsc6x/chsc6x_touchscreen.cpp @@ -4,7 +4,7 @@ namespace esphome { namespace chsc6x { void CHSC6XTouchscreen::setup() { - ESP_LOGCONFIG(TAG, "Setting up CHSC6X Touchscreen..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (this->interrupt_pin_ != nullptr) { this->interrupt_pin_->setup(); this->attach_interrupt_(this->interrupt_pin_, gpio::INTERRUPT_FALLING_EDGE); diff --git a/esphome/components/cm1106/cm1106.cpp b/esphome/components/cm1106/cm1106.cpp index b7b0fe0063..aa19c0664e 100644 --- a/esphome/components/cm1106/cm1106.cpp +++ b/esphome/components/cm1106/cm1106.cpp @@ -20,10 +20,10 @@ uint8_t cm1106_checksum(const uint8_t *response, size_t len) { } void CM1106Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up CM1106..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t response[8] = {0}; if (!this->cm1106_write_command_(C_M1106_CMD_GET_CO2, sizeof(C_M1106_CMD_GET_CO2), response, sizeof(response))) { - ESP_LOGE(TAG, "Communication with CM1106 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); this->mark_failed(); return; } @@ -104,7 +104,7 @@ void CM1106Component::dump_config() { LOG_SENSOR(" ", "CO2", this->co2_sensor_); this->check_uart_settings(9600); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with CM1106 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } } diff --git a/esphome/components/cs5460a/cs5460a.cpp b/esphome/components/cs5460a/cs5460a.cpp index 0d347ae0c1..4e045c17be 100644 --- a/esphome/components/cs5460a/cs5460a.cpp +++ b/esphome/components/cs5460a/cs5460a.cpp @@ -52,7 +52,7 @@ bool CS5460AComponent::softreset_() { } void CS5460AComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up CS5460A..."); + ESP_LOGCONFIG(TAG, "Running setup"); float current_full_scale = (pga_gain_ == CS5460A_PGA_GAIN_10X) ? 0.25 : 0.10; float voltage_full_scale = 0.25; diff --git a/esphome/components/cse7761/cse7761.cpp b/esphome/components/cse7761/cse7761.cpp index 337996f6ef..6c3d457f26 100644 --- a/esphome/components/cse7761/cse7761.cpp +++ b/esphome/components/cse7761/cse7761.cpp @@ -42,7 +42,7 @@ static const uint8_t CSE7761_CMD_ENABLE_WRITE = 0xE5; // Enable write operation enum CSE7761 { RMS_IAC, RMS_IBC, RMS_UC, POWER_PAC, POWER_PBC, POWER_SC, ENERGY_AC, ENERGY_BC }; void CSE7761Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up CSE7761..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->write_(CSE7761_SPECIAL_COMMAND, CSE7761_CMD_RESET); uint16_t syscon = this->read_(0x00, 2); // Default 0x0A04 if ((0x0A04 == syscon) && this->chip_init_()) { @@ -57,7 +57,7 @@ void CSE7761Component::setup() { void CSE7761Component::dump_config() { ESP_LOGCONFIG(TAG, "CSE7761:"); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with CSE7761 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); this->check_uart_settings(38400, 1, uart::UART_CONFIG_PARITY_EVEN, 8); diff --git a/esphome/components/cst226/touchscreen/cst226_touchscreen.cpp b/esphome/components/cst226/touchscreen/cst226_touchscreen.cpp index fa8cd9b057..c444dd7485 100644 --- a/esphome/components/cst226/touchscreen/cst226_touchscreen.cpp +++ b/esphome/components/cst226/touchscreen/cst226_touchscreen.cpp @@ -6,7 +6,7 @@ namespace cst226 { static const char *const TAG = "cst226.touchscreen"; void CST226Touchscreen::setup() { - ESP_LOGCONFIG(TAG, "Setting up CST226 Touchscreen..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (this->reset_pin_ != nullptr) { this->reset_pin_->setup(); this->reset_pin_->digital_write(true); diff --git a/esphome/components/cst816/touchscreen/cst816_touchscreen.cpp b/esphome/components/cst816/touchscreen/cst816_touchscreen.cpp index 607f209c4a..e76e40dba7 100644 --- a/esphome/components/cst816/touchscreen/cst816_touchscreen.cpp +++ b/esphome/components/cst816/touchscreen/cst816_touchscreen.cpp @@ -38,7 +38,7 @@ void CST816Touchscreen::continue_setup_() { } void CST816Touchscreen::setup() { - ESP_LOGCONFIG(TAG, "Setting up CST816 Touchscreen..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (this->reset_pin_ != nullptr) { this->reset_pin_->setup(); this->reset_pin_->digital_write(true); diff --git a/esphome/components/dac7678/dac7678_output.cpp b/esphome/components/dac7678/dac7678_output.cpp index b6de615b30..31d153beb9 100644 --- a/esphome/components/dac7678/dac7678_output.cpp +++ b/esphome/components/dac7678/dac7678_output.cpp @@ -20,7 +20,7 @@ static const uint8_t DAC7678_REG_INTERNAL_REF_0 = 0x80; static const uint8_t DAC7678_REG_INTERNAL_REF_1 = 0x90; void DAC7678Output::setup() { - ESP_LOGCONFIG(TAG, "Setting up DAC7678OutputComponent..."); + ESP_LOGCONFIG(TAG, "Running setup"); ESP_LOGV(TAG, "Resetting device..."); diff --git a/esphome/components/dallas_temp/dallas_temp.cpp b/esphome/components/dallas_temp/dallas_temp.cpp index 46db22d97f..3796a888fd 100644 --- a/esphome/components/dallas_temp/dallas_temp.cpp +++ b/esphome/components/dallas_temp/dallas_temp.cpp @@ -70,7 +70,7 @@ bool DallasTemperatureSensor::read_scratch_pad_() { } void DallasTemperatureSensor::setup() { - ESP_LOGCONFIG(TAG, "setting up Dallas temperature sensor..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (!this->check_address_()) return; if (!this->read_scratch_pad_()) @@ -80,7 +80,7 @@ void DallasTemperatureSensor::setup() { if ((this->address_ & 0xff) == DALLAS_MODEL_DS18S20) { // DS18S20 doesn't support resolution. - ESP_LOGW(TAG, "DS18S20 doesn't support setting resolution."); + ESP_LOGW(TAG, "DS18S20 doesn't support setting resolution"); return; } @@ -125,7 +125,6 @@ bool DallasTemperatureSensor::check_scratch_pad_() { crc8(this->scratch_pad_, 8)); #endif if (!chksum_validity) { - ESP_LOGW(TAG, "'%s' - Scratch pad checksum invalid!", this->get_name().c_str()); this->status_set_warning("scratch pad checksum invalid"); ESP_LOGD(TAG, "Scratch pad: %02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X (%02X)", this->scratch_pad_[0], this->scratch_pad_[1], this->scratch_pad_[2], this->scratch_pad_[3], this->scratch_pad_[4], diff --git a/esphome/components/deep_sleep/deep_sleep_component.cpp b/esphome/components/deep_sleep/deep_sleep_component.cpp index 1e7637f3e5..b53dabc92f 100644 --- a/esphome/components/deep_sleep/deep_sleep_component.cpp +++ b/esphome/components/deep_sleep/deep_sleep_component.cpp @@ -10,20 +10,20 @@ static const char *const TAG = "deep_sleep"; bool global_has_deep_sleep = false; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) void DeepSleepComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up Deep Sleep..."); + ESP_LOGCONFIG(TAG, "Running setup"); global_has_deep_sleep = true; const optional run_duration = get_run_duration_(); if (run_duration.has_value()) { - ESP_LOGI(TAG, "Scheduling Deep Sleep to start in %" PRIu32 " ms", *run_duration); + ESP_LOGI(TAG, "Scheduling in %" PRIu32 " ms", *run_duration); this->set_timeout(*run_duration, [this]() { this->begin_sleep(); }); } else { - ESP_LOGD(TAG, "Not scheduling Deep Sleep, as no run duration is configured."); + ESP_LOGD(TAG, "Not scheduling; no run duration configured"); } } void DeepSleepComponent::dump_config() { - ESP_LOGCONFIG(TAG, "Setting up Deep Sleep..."); + ESP_LOGCONFIG(TAG, "Deep sleep:"); if (this->sleep_duration_.has_value()) { uint32_t duration = *this->sleep_duration_ / 1000; ESP_LOGCONFIG(TAG, " Sleep Duration: %" PRIu32 " ms", duration); @@ -57,7 +57,7 @@ void DeepSleepComponent::begin_sleep(bool manual) { return; } - ESP_LOGI(TAG, "Beginning Deep Sleep"); + ESP_LOGI(TAG, "Beginning sleep"); if (this->sleep_duration_.has_value()) { ESP_LOGI(TAG, "Sleeping for %" PRId64 "us", *this->sleep_duration_); } diff --git a/esphome/components/deep_sleep/deep_sleep_esp32.cpp b/esphome/components/deep_sleep/deep_sleep_esp32.cpp index 4582d695f6..3c5d3382ce 100644 --- a/esphome/components/deep_sleep/deep_sleep_esp32.cpp +++ b/esphome/components/deep_sleep/deep_sleep_esp32.cpp @@ -59,7 +59,7 @@ bool DeepSleepComponent::prepare_to_sleep_() { // Defer deep sleep until inactive if (!this->next_enter_deep_sleep_) { this->status_set_warning(); - ESP_LOGW(TAG, "Waiting wakeup pin state change to enter deep sleep..."); + ESP_LOGW(TAG, "Waiting for wakeup pin state change"); } this->next_enter_deep_sleep_ = true; return false; diff --git a/esphome/components/demo/__init__.py b/esphome/components/demo/__init__.py index 96ffb58b82..0a56073284 100644 --- a/esphome/components/demo/__init__.py +++ b/esphome/components/demo/__init__.py @@ -1,14 +1,22 @@ import esphome.codegen as cg from esphome.components import ( + alarm_control_panel, binary_sensor, + button, climate, cover, + datetime, + event, fan, light, + lock, number, + select, sensor, switch, + text, text_sensor, + valve, ) import esphome.config_validation as cv from esphome.const import ( @@ -20,7 +28,9 @@ from esphome.const import ( CONF_INVERTED, CONF_MAX_VALUE, CONF_MIN_VALUE, + CONF_MODE, CONF_NAME, + CONF_OPTIONS, CONF_OUTPUT_ID, CONF_SENSORS, CONF_STATE_CLASS, @@ -31,9 +41,11 @@ from esphome.const import ( CONF_UNIT_OF_MEASUREMENT, DEVICE_CLASS_ENERGY, DEVICE_CLASS_HUMIDITY, + DEVICE_CLASS_IDENTIFY, DEVICE_CLASS_MOISTURE, DEVICE_CLASS_MOTION, DEVICE_CLASS_TEMPERATURE, + DEVICE_CLASS_UPDATE, ICON_BLUETOOTH, ICON_BLUR, ICON_THERMOMETER, @@ -45,38 +57,68 @@ from esphome.const import ( ) AUTO_LOAD = [ + "alarm_control_panel", "binary_sensor", + "button", "climate", "cover", + "datetime", + "event", "fan", "light", + "lock", "number", + "select", "sensor", "switch", + "text", "text_sensor", + "valve", ] demo_ns = cg.esphome_ns.namespace("demo") +DemoAlarmControlPanel = demo_ns.class_( + "DemoAlarmControlPanel", alarm_control_panel.AlarmControlPanel, cg.Component +) +DemoAlarmControlPanelType = demo_ns.enum("DemoAlarmControlPanelType", is_class=True) DemoBinarySensor = demo_ns.class_( "DemoBinarySensor", binary_sensor.BinarySensor, cg.PollingComponent ) +DemoButton = demo_ns.class_("DemoButton", button.Button) DemoClimate = demo_ns.class_("DemoClimate", climate.Climate, cg.Component) DemoClimateType = demo_ns.enum("DemoClimateType", is_class=True) DemoCover = demo_ns.class_("DemoCover", cover.Cover, cg.Component) DemoCoverType = demo_ns.enum("DemoCoverType", is_class=True) +DemoDate = demo_ns.class_("DemoDate", datetime.DateEntity, cg.Component) +DemoDateTime = demo_ns.class_("DemoDateTime", datetime.DateTimeEntity, cg.Component) +DemoTime = demo_ns.class_("DemoTime", datetime.TimeEntity, cg.Component) +DemoEvent = demo_ns.class_("DemoEvent", event.Event, cg.Component) DemoFan = demo_ns.class_("DemoFan", fan.Fan, cg.Component) DemoFanType = demo_ns.enum("DemoFanType", is_class=True) DemoLight = demo_ns.class_("DemoLight", light.LightOutput, cg.Component) DemoLightType = demo_ns.enum("DemoLightType", is_class=True) +DemoLock = demo_ns.class_("DemoLock", lock.Lock, cg.Component) +DemoLockType = demo_ns.enum("DemoLockType", is_class=True) DemoNumber = demo_ns.class_("DemoNumber", number.Number, cg.Component) DemoNumberType = demo_ns.enum("DemoNumberType", is_class=True) +DemoSelect = demo_ns.class_("DemoSelect", select.Select, cg.Component) +DemoSelectType = demo_ns.enum("DemoSelectType", is_class=True) DemoSensor = demo_ns.class_("DemoSensor", sensor.Sensor, cg.PollingComponent) DemoSwitch = demo_ns.class_("DemoSwitch", switch.Switch, cg.Component) +DemoText = demo_ns.class_("DemoText", text.Text, cg.Component) +DemoTextType = demo_ns.enum("DemoTextType", is_class=True) DemoTextSensor = demo_ns.class_( "DemoTextSensor", text_sensor.TextSensor, cg.PollingComponent ) +DemoValve = demo_ns.class_("DemoValve", valve.Valve) +DemoValveType = demo_ns.enum("DemoValveType", is_class=True) +ALARM_CONTROL_PANEL_TYPES = { + 1: DemoAlarmControlPanelType.TYPE_1, + 2: DemoAlarmControlPanelType.TYPE_2, + 3: DemoAlarmControlPanelType.TYPE_3, +} CLIMATE_TYPES = { 1: DemoClimateType.TYPE_1, 2: DemoClimateType.TYPE_2, @@ -103,21 +145,67 @@ LIGHT_TYPES = { 6: DemoLightType.TYPE_6, 7: DemoLightType.TYPE_7, } +LOCK_TYPES = { + 1: DemoLockType.TYPE_1, + 2: DemoLockType.TYPE_2, +} NUMBER_TYPES = { 1: DemoNumberType.TYPE_1, 2: DemoNumberType.TYPE_2, 3: DemoNumberType.TYPE_3, } +TEXT_TYPES = { + 1: DemoTextType.TYPE_1, + 2: DemoTextType.TYPE_2, +} +VALVE_TYPES = { + 1: DemoValveType.TYPE_1, + 2: DemoValveType.TYPE_2, +} +CONF_ALARM_CONTROL_PANELS = "alarm_control_panels" +CONF_BUTTONS = "buttons" CONF_CLIMATES = "climates" CONF_COVERS = "covers" +CONF_DATETIMES = "datetimes" CONF_FANS = "fans" CONF_LIGHTS = "lights" +CONF_LOCKS = "locks" CONF_NUMBERS = "numbers" +CONF_SELECTS = "selects" +CONF_TEXTS = "texts" +CONF_VALVES = "valves" CONFIG_SCHEMA = cv.Schema( { + cv.Optional( + CONF_ALARM_CONTROL_PANELS, + default=[ + { + CONF_NAME: "Demo Alarm Control Panel", + CONF_TYPE: 1, + }, + { + CONF_NAME: "Demo Alarm Control Panel Code", + CONF_TYPE: 2, + }, + { + CONF_NAME: "Demo Alarm Control Panel Code to Arm", + CONF_TYPE: 3, + }, + ], + ): [ + alarm_control_panel.alarm_control_panel_schema( + DemoAlarmControlPanel + ).extend( + { + cv.Required(CONF_TYPE): cv.enum( + ALARM_CONTROL_PANEL_TYPES, int=True + ), + } + ) + ], cv.Optional( CONF_BINARY_SENSORS, default=[ @@ -135,6 +223,21 @@ CONFIG_SCHEMA = cv.Schema( cv.polling_component_schema("60s") ) ], + cv.Optional( + CONF_BUTTONS, + default=[ + { + CONF_NAME: "Demo Update Button", + CONF_DEVICE_CLASS: DEVICE_CLASS_UPDATE, + }, + { + CONF_NAME: "Demo Button Identify", + CONF_DEVICE_CLASS: DEVICE_CLASS_IDENTIFY, + }, + ], + ): [ + button.button_schema(DemoButton), + ], cv.Optional( CONF_CLIMATES, default=[ @@ -191,6 +294,20 @@ CONFIG_SCHEMA = cv.Schema( } ) ], + cv.Optional( + CONF_DATETIMES, + default=[ + {CONF_NAME: "Demo DateTime", CONF_TYPE: "DATETIME"}, + {CONF_NAME: "Demo Date", CONF_TYPE: "DATE"}, + {CONF_NAME: "Demo Time", CONF_TYPE: "TIME"}, + ], + ): [ + cv.Any( + datetime.date_schema(DemoDate), + datetime.datetime_schema(DemoDateTime), + datetime.time_schema(DemoTime), + ) + ], cv.Optional( CONF_FANS, default=[ @@ -262,6 +379,19 @@ CONFIG_SCHEMA = cv.Schema( } ) ], + cv.Optional( + CONF_LOCKS, + default=[ + {CONF_NAME: "Demo Lock", CONF_TYPE: 1}, + {CONF_NAME: "Demo Lock and Open", CONF_TYPE: 2}, + ], + ): [ + lock.lock_schema(DemoLock).extend( + { + cv.Required(CONF_TYPE): cv.enum(LOCK_TYPES, int=True), + } + ) + ], cv.Optional( CONF_NUMBERS, default=[ @@ -299,6 +429,25 @@ CONFIG_SCHEMA = cv.Schema( } ) ], + cv.Optional( + CONF_SELECTS, + default=[ + { + CONF_NAME: "Demo Select 1", + CONF_OPTIONS: ["Option 1", "Option 2", "Option 3"], + }, + { + CONF_NAME: "Demo Select 2", + CONF_OPTIONS: ["Option A", "Option B", "Option C"], + }, + ], + ): [ + select.select_schema(DemoSelect).extend( + { + cv.Required(CONF_OPTIONS): cv.ensure_list(cv.string_strict), + } + ) + ], cv.Optional( CONF_SENSORS, default=[ @@ -355,6 +504,19 @@ CONFIG_SCHEMA = cv.Schema( }, ], ): [switch.switch_schema(DemoSwitch).extend(cv.COMPONENT_SCHEMA)], + cv.Optional( + CONF_TEXTS, + default=[ + {CONF_NAME: "Demo Text 1", CONF_MODE: "TEXT", CONF_TYPE: 1}, + {CONF_NAME: "Demo Text 2", CONF_MODE: "PASSWORD", CONF_TYPE: 2}, + ], + ): [ + text.text_schema(DemoText).extend( + { + cv.Required(CONF_TYPE): cv.enum(TEXT_TYPES, int=True), + } + ) + ], cv.Optional( CONF_TEXT_SENSORS, default=[ @@ -371,15 +533,36 @@ CONFIG_SCHEMA = cv.Schema( cv.polling_component_schema("60s") ) ], + cv.Optional( + CONF_VALVES, + default=[ + {CONF_NAME: "Demo Valve 1", CONF_TYPE: 1}, + {CONF_NAME: "Demo Valve 2", CONF_TYPE: 2}, + ], + ): [ + valve.valve_schema(DemoValve).extend( + { + cv.Required(CONF_TYPE): cv.enum(VALVE_TYPES, int=True), + } + ) + ], } ) async def to_code(config): + for conf in config[CONF_ALARM_CONTROL_PANELS]: + var = await alarm_control_panel.new_alarm_control_panel(conf) + cg.add(var.set_type(conf[CONF_TYPE])) + await cg.register_component(var, conf) + for conf in config[CONF_BINARY_SENSORS]: var = await binary_sensor.new_binary_sensor(conf) await cg.register_component(var, conf) + for conf in config[CONF_BUTTONS]: + await button.new_button(conf) + for conf in config[CONF_CLIMATES]: var = await climate.new_climate(conf) await cg.register_component(var, conf) @@ -390,6 +573,10 @@ async def to_code(config): await cg.register_component(var, conf) cg.add(var.set_type(conf[CONF_TYPE])) + for conf in config[CONF_DATETIMES]: + var = await datetime.new_datetime(conf) + await cg.register_component(var, conf) + for conf in config[CONF_FANS]: var = await fan.new_fan(conf) await cg.register_component(var, conf) @@ -400,6 +587,11 @@ async def to_code(config): await cg.register_component(var, conf) cg.add(var.set_type(conf[CONF_TYPE])) + for conf in config[CONF_LOCKS]: + var = await lock.new_lock(conf) + if conf[CONF_TYPE] == 2: + cg.add(var.traits.set_supports_open(True)) + for conf in config[CONF_NUMBERS]: var = await number.new_number( conf, @@ -410,6 +602,10 @@ async def to_code(config): await cg.register_component(var, conf) cg.add(var.set_type(conf[CONF_TYPE])) + for conf in config[CONF_SELECTS]: + var = await select.new_select(conf, options=conf[CONF_OPTIONS]) + await cg.register_component(var, conf) + for conf in config[CONF_SENSORS]: var = await sensor.new_sensor(conf) await cg.register_component(var, conf) @@ -418,6 +614,16 @@ async def to_code(config): var = await switch.new_switch(conf) await cg.register_component(var, conf) + for conf in config[CONF_TEXTS]: + var = await text.new_text(conf) + await cg.register_component(var, conf) + if conf[CONF_TYPE] == 2: + cg.add(var.traits.set_mode(text.TextMode.TEXT_MODE_PASSWORD)) + for conf in config[CONF_TEXT_SENSORS]: var = await text_sensor.new_text_sensor(conf) await cg.register_component(var, conf) + + for conf in config[CONF_VALVES]: + var = await valve.new_valve(conf) + cg.add(var.set_type(conf[CONF_TYPE])) diff --git a/esphome/components/demo/demo_alarm_control_panel.h b/esphome/components/demo/demo_alarm_control_panel.h new file mode 100644 index 0000000000..9902d27882 --- /dev/null +++ b/esphome/components/demo/demo_alarm_control_panel.h @@ -0,0 +1,65 @@ +#pragma once + +#include "esphome/components/alarm_control_panel/alarm_control_panel.h" +#include "esphome/core/component.h" + +namespace esphome { +namespace demo { + +using namespace alarm_control_panel; + +enum class DemoAlarmControlPanelType { + TYPE_1, + TYPE_2, + TYPE_3, +}; + +class DemoAlarmControlPanel : public AlarmControlPanel, public Component { + public: + void setup() override {} + + uint32_t get_supported_features() const override { return ACP_FEAT_ARM_AWAY | ACP_FEAT_TRIGGER; } + + bool get_requires_code() const override { return this->type_ != DemoAlarmControlPanelType::TYPE_1; } + + bool get_requires_code_to_arm() const override { return this->type_ == DemoAlarmControlPanelType::TYPE_3; } + + void set_type(DemoAlarmControlPanelType type) { this->type_ = type; } + + protected: + void control(const AlarmControlPanelCall &call) override { + auto state = call.get_state().value_or(ACP_STATE_DISARMED); + switch (state) { + case ACP_STATE_ARMED_AWAY: + if (this->get_requires_code_to_arm() && call.get_code().has_value()) { + if (call.get_code().value() != "1234") { + this->status_momentary_error("Invalid code", 5000); + return; + } + } + this->publish_state(ACP_STATE_ARMED_AWAY); + break; + case ACP_STATE_DISARMED: + if (this->get_requires_code() && call.get_code().has_value()) { + if (call.get_code().value() != "1234") { + this->status_momentary_error("Invalid code", 5000); + return; + } + } + this->publish_state(ACP_STATE_DISARMED); + return; + case ACP_STATE_TRIGGERED: + this->publish_state(ACP_STATE_TRIGGERED); + return; + case ACP_STATE_PENDING: + this->publish_state(ACP_STATE_PENDING); + return; + default: + break; + } + } + DemoAlarmControlPanelType type_{}; +}; + +} // namespace demo +} // namespace esphome diff --git a/esphome/components/demo/demo_button.h b/esphome/components/demo/demo_button.h new file mode 100644 index 0000000000..be80d26a8a --- /dev/null +++ b/esphome/components/demo/demo_button.h @@ -0,0 +1,15 @@ +#pragma once + +#include "esphome/components/button/button.h" +#include "esphome/core/log.h" + +namespace esphome { +namespace demo { + +class DemoButton : public button::Button { + protected: + void press_action() override {} +}; + +} // namespace demo +} // namespace esphome diff --git a/esphome/components/demo/demo_date.h b/esphome/components/demo/demo_date.h new file mode 100644 index 0000000000..e09ab5f887 --- /dev/null +++ b/esphome/components/demo/demo_date.h @@ -0,0 +1,34 @@ +#pragma once + +#include "esphome/core/defines.h" + +#ifdef USE_DATETIME_DATE + +#include "esphome/components/datetime/date_entity.h" +#include "esphome/core/component.h" + +namespace esphome { +namespace demo { + +class DemoDate : public datetime::DateEntity, public Component { + public: + void setup() override { + this->year_ = 2038; + this->month_ = 01; + this->day_ = 19; + this->publish_state(); + } + + protected: + void control(const datetime::DateCall &call) override { + this->year_ = call.get_year().value_or(this->year_); + this->month_ = call.get_month().value_or(this->month_); + this->day_ = call.get_day().value_or(this->day_); + this->publish_state(); + } +}; + +} // namespace demo +} // namespace esphome + +#endif diff --git a/esphome/components/demo/demo_datetime.h b/esphome/components/demo/demo_datetime.h new file mode 100644 index 0000000000..5ebcc3e64e --- /dev/null +++ b/esphome/components/demo/demo_datetime.h @@ -0,0 +1,40 @@ +#pragma once + +#include "esphome/core/defines.h" + +#ifdef USE_DATETIME_DATETIME + +#include "esphome/components/datetime/datetime_entity.h" +#include "esphome/core/component.h" + +namespace esphome { +namespace demo { + +class DemoDateTime : public datetime::DateTimeEntity, public Component { + public: + void setup() override { + this->year_ = 2038; + this->month_ = 01; + this->day_ = 19; + this->hour_ = 3; + this->minute_ = 14; + this->second_ = 8; + this->publish_state(); + } + + protected: + void control(const datetime::DateTimeCall &call) override { + this->year_ = call.get_year().value_or(this->year_); + this->month_ = call.get_month().value_or(this->month_); + this->day_ = call.get_day().value_or(this->day_); + this->hour_ = call.get_hour().value_or(this->hour_); + this->minute_ = call.get_minute().value_or(this->minute_); + this->second_ = call.get_second().value_or(this->second_); + this->publish_state(); + } +}; + +} // namespace demo +} // namespace esphome + +#endif diff --git a/esphome/components/demo/demo_lock.h b/esphome/components/demo/demo_lock.h new file mode 100644 index 0000000000..94d0f70a14 --- /dev/null +++ b/esphome/components/demo/demo_lock.h @@ -0,0 +1,17 @@ +#pragma once + +#include "esphome/components/lock/lock.h" + +namespace esphome { +namespace demo { + +class DemoLock : public lock::Lock { + protected: + void control(const lock::LockCall &call) override { + auto state = *call.get_state(); + this->publish_state(state); + } +}; + +} // namespace demo +} // namespace esphome diff --git a/esphome/components/demo/demo_select.h b/esphome/components/demo/demo_select.h new file mode 100644 index 0000000000..1951a684a2 --- /dev/null +++ b/esphome/components/demo/demo_select.h @@ -0,0 +1,15 @@ +#pragma once + +#include "esphome/components/select/select.h" +#include "esphome/core/component.h" + +namespace esphome { +namespace demo { + +class DemoSelect : public select::Select, public Component { + protected: + void control(const std::string &value) override { this->publish_state(value); } +}; + +} // namespace demo +} // namespace esphome diff --git a/esphome/components/demo/demo_text.h b/esphome/components/demo/demo_text.h new file mode 100644 index 0000000000..a753175062 --- /dev/null +++ b/esphome/components/demo/demo_text.h @@ -0,0 +1,18 @@ +#pragma once + +#include "esphome/components/text/text.h" +#include "esphome/core/component.h" + +namespace esphome { +namespace demo { + +class DemoText : public text::Text, public Component { + public: + void setup() override { this->publish_state("I am a text entity"); } + + protected: + void control(const std::string &value) override { this->publish_state(value); } +}; + +} // namespace demo +} // namespace esphome diff --git a/esphome/components/demo/demo_time.h b/esphome/components/demo/demo_time.h new file mode 100644 index 0000000000..42788504bb --- /dev/null +++ b/esphome/components/demo/demo_time.h @@ -0,0 +1,34 @@ +#pragma once + +#include "esphome/core/defines.h" + +#ifdef USE_DATETIME_TIME + +#include "esphome/components/datetime/time_entity.h" +#include "esphome/core/component.h" + +namespace esphome { +namespace demo { + +class DemoTime : public datetime::TimeEntity, public Component { + public: + void setup() override { + this->hour_ = 3; + this->minute_ = 14; + this->second_ = 8; + this->publish_state(); + } + + protected: + void control(const datetime::TimeCall &call) override { + this->hour_ = call.get_hour().value_or(this->hour_); + this->minute_ = call.get_minute().value_or(this->minute_); + this->second_ = call.get_second().value_or(this->second_); + this->publish_state(); + } +}; + +} // namespace demo +} // namespace esphome + +#endif diff --git a/esphome/components/demo/demo_valve.h b/esphome/components/demo/demo_valve.h new file mode 100644 index 0000000000..55d457f176 --- /dev/null +++ b/esphome/components/demo/demo_valve.h @@ -0,0 +1,54 @@ +#pragma once + +#include "esphome/components/valve/valve.h" + +namespace esphome { +namespace demo { + +enum class DemoValveType { + TYPE_1, + TYPE_2, +}; + +class DemoValve : public valve::Valve { + public: + valve::ValveTraits get_traits() override { + valve::ValveTraits traits; + if (this->type_ == DemoValveType::TYPE_2) { + traits.set_supports_position(true); + traits.set_supports_toggle(true); + traits.set_supports_stop(true); + } + return traits; + } + + void set_type(DemoValveType type) { this->type_ = type; } + + protected: + void control(const valve::ValveCall &call) override { + if (call.get_position().has_value()) { + this->position = *call.get_position(); + this->publish_state(); + return; + } else if (call.get_toggle().has_value()) { + if (call.get_toggle().value()) { + if (this->position == valve::VALVE_OPEN) { + this->position = valve::VALVE_CLOSED; + this->publish_state(); + } else { + this->position = valve::VALVE_OPEN; + this->publish_state(); + } + } + return; + } else if (call.get_stop()) { + this->current_operation = valve::VALVE_OPERATION_IDLE; + this->publish_state(); // Keep the current position + return; + } + } + DemoValveType type_{}; +}; + +} // namespace demo +} // namespace esphome diff --git a/esphome/components/dht/dht.cpp b/esphome/components/dht/dht.cpp index f2a33a26ac..27234ed4d1 100644 --- a/esphome/components/dht/dht.cpp +++ b/esphome/components/dht/dht.cpp @@ -8,25 +8,19 @@ namespace dht { static const char *const TAG = "dht"; void DHT::setup() { - ESP_LOGCONFIG(TAG, "Setting up DHT..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->pin_->digital_write(true); this->pin_->setup(); this->pin_->digital_write(true); } + void DHT::dump_config() { ESP_LOGCONFIG(TAG, "DHT:"); LOG_PIN(" Pin: ", this->pin_); - if (this->is_auto_detect_) { - ESP_LOGCONFIG(TAG, " Auto-detected model: %s", this->model_ == DHT_MODEL_DHT11 ? "DHT11" : "DHT22"); - } else if (this->model_ == DHT_MODEL_DHT11) { - ESP_LOGCONFIG(TAG, " Model: DHT11"); - } else { - ESP_LOGCONFIG(TAG, " Model: DHT22 (or equivalent)"); - } - ESP_LOGCONFIG(TAG, " Internal Pull-up: %s", ONOFF(this->pin_->get_flags() & gpio::FLAG_PULLUP)); - + ESP_LOGCONFIG(TAG, " %sModel: %s", this->is_auto_detect_ ? "Auto-detected " : "", + this->model_ == DHT_MODEL_DHT11 ? "DHT11" : "DHT22 or equivalent"); + ESP_LOGCONFIG(TAG, " Internal pull-up: %s", ONOFF(this->pin_->get_flags() & gpio::FLAG_PULLUP)); LOG_UPDATE_INTERVAL(this); - LOG_SENSOR(" ", "Temperature", this->temperature_sensor_); LOG_SENSOR(" ", "Humidity", this->humidity_sensor_); } @@ -46,7 +40,7 @@ void DHT::update() { } if (success) { - ESP_LOGD(TAG, "Got Temperature=%.1f°C Humidity=%.1f%%", temperature, humidity); + ESP_LOGD(TAG, "Temperature %.1f°C Humidity %.1f%%", temperature, humidity); if (this->temperature_sensor_ != nullptr) this->temperature_sensor_->publish_state(temperature); @@ -54,11 +48,8 @@ void DHT::update() { this->humidity_sensor_->publish_state(humidity); this->status_clear_warning(); } else { - const char *str = ""; - if (this->is_auto_detect_) { - str = " and consider manually specifying the DHT model using the model option"; - } - ESP_LOGW(TAG, "Invalid readings! Please check your wiring (pull-up resistor, pin number)%s.", str); + ESP_LOGW(TAG, "Invalid readings! Check pin number and pull-up resistor%s.", + this->is_auto_detect_ ? " and try manually specifying the model" : ""); if (this->temperature_sensor_ != nullptr) this->temperature_sensor_->publish_state(NAN); if (this->humidity_sensor_ != nullptr) @@ -68,10 +59,12 @@ void DHT::update() { } float DHT::get_setup_priority() const { return setup_priority::DATA; } + void DHT::set_dht_model(DHTModel model) { this->model_ = model; this->is_auto_detect_ = model == DHT_MODEL_AUTO_DETECT; } + bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool report_errors) { *humidity = NAN; *temperature = NAN; @@ -121,9 +114,9 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r while (!this->pin_->digital_read()) { if (micros() - start_time > 90) { if (i < 0) { - error_code = 1; + error_code = 1; // line didn't clear } else { - error_code = 2; + error_code = 2; // rising edge for bit i timeout } break; } @@ -139,9 +132,9 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r end_time = micros(); if (end_time - start_time > 90) { if (i < 0) { - error_code = 3; + error_code = 3; // requesting data failed } else { - error_code = 4; + error_code = 4; // falling edge for bit i timeout } break; } @@ -166,22 +159,9 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r if (!report_errors && error_code != 0) return false; - switch (error_code) { - case 1: - ESP_LOGW(TAG, "Waiting for DHT communication to clear failed!"); - return false; - case 2: - ESP_LOGW(TAG, "Rising edge for bit %d failed!", i); - return false; - case 3: - ESP_LOGW(TAG, "Requesting data from DHT failed!"); - return false; - case 4: - ESP_LOGW(TAG, "Falling edge for bit %d failed!", i); - return false; - case 0: - default: - break; + if (error_code) { + ESP_LOGW(TAG, ESP_LOG_MSG_COMM_FAIL); + return false; } ESP_LOGVV(TAG, @@ -206,15 +186,15 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r if (checksum_a == data[4]) { // Data format: 8bit integral RH data + 8bit decimal RH data + 8bit integral T data + 8bit decimal T data + 8bit // check sum - some models always have 0 in the decimal part - const uint16_t raw_temperature = uint16_t(data[2]) * 10 + (data[3] & 0x7F); - *temperature = raw_temperature / 10.0f; + const uint16_t raw_temperature = static_cast(data[2]) * 10 + (data[3] & 0x7F); + *temperature = static_cast(raw_temperature) / 10.0f; if ((data[3] & 0x80) != 0) { // negative *temperature *= -1; } - const uint16_t raw_humidity = uint16_t(data[0]) * 10 + data[1]; - *humidity = raw_humidity / 10.0f; + const uint16_t raw_humidity = static_cast(data[0]) * 10 + data[1]; + *humidity = static_cast(raw_humidity) / 10.0f; } else { // For compatibility with DHT11 models which might only use 2 bytes checksums, only use the data from these two // bytes @@ -222,8 +202,8 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r *humidity = data[0]; } } else { - uint16_t raw_humidity = (uint16_t(data[0] & 0xFF) << 8) | (data[1] & 0xFF); - uint16_t raw_temperature = (uint16_t(data[2] & 0xFF) << 8) | (data[3] & 0xFF); + uint16_t raw_humidity = encode_uint16(data[0], data[1]); + uint16_t raw_temperature = encode_uint16(data[2], data[3]); if (raw_temperature & 0x8000) { if (!(raw_temperature & 0x4000)) @@ -234,24 +214,23 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r if (raw_temperature == 1 && raw_humidity == 10) { if (report_errors) { - ESP_LOGW(TAG, "Invalid temperature+humidity! Sensor reported 1°C and 1%% Hum"); + ESP_LOGW(TAG, "Invalid data"); } return false; } - *humidity = raw_humidity * 0.1f; - if (*humidity > 100) + *humidity = static_cast(raw_humidity) * 0.1f; + if (*humidity > 100.0f) *humidity = NAN; - *temperature = int16_t(raw_temperature) * 0.1f; + *temperature = static_cast(raw_temperature) * 0.1f; } if (*temperature == 0.0f && (*humidity == 1.0f || *humidity == 2.0f)) { if (report_errors) { - ESP_LOGW(TAG, "DHT reports invalid data. Is the update interval too high or the sensor damaged?"); + ESP_LOGW(TAG, "Invalid data"); } return false; } - return true; } diff --git a/esphome/components/dht12/dht12.cpp b/esphome/components/dht12/dht12.cpp index a5e1886918..54a6688b0b 100644 --- a/esphome/components/dht12/dht12.cpp +++ b/esphome/components/dht12/dht12.cpp @@ -34,7 +34,7 @@ void DHT12Component::update() { this->status_clear_warning(); } void DHT12Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up DHT12..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t data[5]; if (!this->read_data_(data)) { this->mark_failed(); @@ -45,7 +45,7 @@ void DHT12Component::dump_config() { ESP_LOGD(TAG, "DHT12:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with DHT12 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 22fb52967f..b1287b6f2d 100644 --- a/esphome/components/dps310/dps310.cpp +++ b/esphome/components/dps310/dps310.cpp @@ -12,7 +12,7 @@ void DPS310Component::setup() { auto timer = DPS310_INIT_TIMEOUT; uint8_t reg = 0; - ESP_LOGCONFIG(TAG, "Setting up DPS310..."); + ESP_LOGCONFIG(TAG, "Running setup"); // first, reset the sensor if (!this->write_byte(DPS310_REG_RESET, DPS310_CMD_RESET)) { this->mark_failed(); @@ -91,7 +91,7 @@ void DPS310Component::dump_config() { ESP_LOGCONFIG(TAG, " Revision ID: %u", (this->prod_rev_id_ >> 4) & 0x0F); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with DPS310 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "Temperature", this->temperature_sensor_); diff --git a/esphome/components/ds1307/ds1307.cpp b/esphome/components/ds1307/ds1307.cpp index 9df8a1d373..db0180e6f1 100644 --- a/esphome/components/ds1307/ds1307.cpp +++ b/esphome/components/ds1307/ds1307.cpp @@ -10,7 +10,7 @@ namespace ds1307 { static const char *const TAG = "ds1307"; void DS1307Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up DS1307..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (!this->read_rtc_()) { this->mark_failed(); } @@ -22,7 +22,7 @@ void DS1307Component::dump_config() { ESP_LOGCONFIG(TAG, "DS1307:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with DS1307 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } ESP_LOGCONFIG(TAG, " Timezone: '%s'", this->timezone_.c_str()); } diff --git a/esphome/components/duty_cycle/duty_cycle_sensor.cpp b/esphome/components/duty_cycle/duty_cycle_sensor.cpp index 9a881c81f0..6c24fc7a8b 100644 --- a/esphome/components/duty_cycle/duty_cycle_sensor.cpp +++ b/esphome/components/duty_cycle/duty_cycle_sensor.cpp @@ -8,7 +8,7 @@ namespace duty_cycle { static const char *const TAG = "duty_cycle"; void DutyCycleSensor::setup() { - ESP_LOGCONFIG(TAG, "Setting up Duty Cycle Sensor '%s'...", this->get_name().c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->get_name().c_str()); this->pin_->setup(); this->store_.pin = this->pin_->to_isr(); this->store_.last_level = this->pin_->digital_read(); diff --git a/esphome/components/ee895/ee895.cpp b/esphome/components/ee895/ee895.cpp index a7186ffbbc..4ce29bcfab 100644 --- a/esphome/components/ee895/ee895.cpp +++ b/esphome/components/ee895/ee895.cpp @@ -16,7 +16,7 @@ static const uint16_t PRESSURE_ADDRESS = 0x04B0; void EE895Component::setup() { uint16_t crc16_check = 0; - ESP_LOGCONFIG(TAG, "Setting up EE895..."); + ESP_LOGCONFIG(TAG, "Running setup"); write_command_(SERIAL_NUMBER, 8); uint8_t serial_number[20]; this->read(serial_number, 20); @@ -35,7 +35,7 @@ void EE895Component::dump_config() { LOG_I2C_DEVICE(this); switch (this->error_code_) { case COMMUNICATION_FAILED: - ESP_LOGE(TAG, "Communication with EE895 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); break; case CRC_CHECK_FAILED: ESP_LOGE(TAG, "The crc check failed"); diff --git a/esphome/components/ektf2232/touchscreen/ektf2232.cpp b/esphome/components/ektf2232/touchscreen/ektf2232.cpp index 603b554273..666e56e2a7 100644 --- a/esphome/components/ektf2232/touchscreen/ektf2232.cpp +++ b/esphome/components/ektf2232/touchscreen/ektf2232.cpp @@ -16,7 +16,7 @@ static const uint8_t GET_Y_RES[4] = {0x53, 0x63, 0x00, 0x00}; static const uint8_t GET_POWER_STATE_CMD[4] = {0x53, 0x50, 0x00, 0x01}; void EKTF2232Touchscreen::setup() { - ESP_LOGCONFIG(TAG, "Setting up EKT2232 Touchscreen..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->interrupt_pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP); this->interrupt_pin_->setup(); diff --git a/esphome/components/emc2101/emc2101.cpp b/esphome/components/emc2101/emc2101.cpp index 2f45b2e27a..6918c6d391 100644 --- a/esphome/components/emc2101/emc2101.cpp +++ b/esphome/components/emc2101/emc2101.cpp @@ -57,7 +57,7 @@ static const uint8_t EMC2101_POLARITY_BIT = 1 << 4; float Emc2101Component::get_setup_priority() const { return setup_priority::HARDWARE; } void Emc2101Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up Emc2101 sensor..."); + ESP_LOGCONFIG(TAG, "Running setup"); // make sure we're talking to the right chip uint8_t chip_id = reg(EMC2101_REGISTER_WHOAMI).get(); @@ -94,7 +94,7 @@ void Emc2101Component::dump_config() { ESP_LOGCONFIG(TAG, "Emc2101 component:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with EMC2101 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } ESP_LOGCONFIG(TAG, " Mode: %s", this->dac_mode_ ? "DAC" : "PWM"); if (this->dac_mode_) { @@ -110,7 +110,7 @@ void Emc2101Component::set_duty_cycle(float value) { uint8_t duty_cycle = remap(value, 0.0f, 1.0f, (uint8_t) 0, this->max_output_value_); ESP_LOGD(TAG, "Setting duty fan setting to %02X", duty_cycle); if (!this->write_byte(EMC2101_REGISTER_FAN_SETTING, duty_cycle)) { - ESP_LOGE(TAG, "Communication with EMC2101 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); this->status_set_warning(); return; } @@ -119,7 +119,7 @@ void Emc2101Component::set_duty_cycle(float value) { float Emc2101Component::get_duty_cycle() { uint8_t duty_cycle; if (!this->read_byte(EMC2101_REGISTER_FAN_SETTING, &duty_cycle)) { - ESP_LOGE(TAG, "Communication with EMC2101 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); this->status_set_warning(); return NAN; } @@ -129,7 +129,7 @@ float Emc2101Component::get_duty_cycle() { float Emc2101Component::get_internal_temperature() { uint8_t temperature; if (!this->read_byte(EMC2101_REGISTER_INTERNAL_TEMP, &temperature)) { - ESP_LOGE(TAG, "Communication with EMC2101 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); this->status_set_warning(); return NAN; } @@ -141,7 +141,7 @@ float Emc2101Component::get_external_temperature() { uint8_t lsb, msb; if (!this->read_byte(EMC2101_REGISTER_EXTERNAL_TEMP_MSB, &msb) || !this->read_byte(EMC2101_REGISTER_EXTERNAL_TEMP_LSB, &lsb)) { - ESP_LOGE(TAG, "Communication with EMC2101 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); this->status_set_warning(); return NAN; } @@ -155,7 +155,7 @@ float Emc2101Component::get_speed() { // Read **LSB** first to match 'Data Read Interlock' behavior from 6.1 of datasheet uint8_t lsb, msb; if (!this->read_byte(EMC2101_REGISTER_TACH_LSB, &lsb) || !this->read_byte(EMC2101_REGISTER_TACH_MSB, &msb)) { - ESP_LOGE(TAG, "Communication with EMC2101 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); this->status_set_warning(); return NAN; } diff --git a/esphome/components/ens160_base/ens160_base.cpp b/esphome/components/ens160_base/ens160_base.cpp index 852328d4bb..7e5b8528b7 100644 --- a/esphome/components/ens160_base/ens160_base.cpp +++ b/esphome/components/ens160_base/ens160_base.cpp @@ -49,7 +49,7 @@ static const uint8_t ENS160_DATA_STATUS_NEWGPR = 0x01; static const uint8_t ENS160_DATA_AQI = 0x07; void ENS160Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up ENS160..."); + ESP_LOGCONFIG(TAG, "Running setup"); // check part_id uint16_t part_id; @@ -279,7 +279,7 @@ void ENS160Component::dump_config() { switch (this->error_code_) { case COMMUNICATION_FAILED: - ESP_LOGE(TAG, "Communication failed! Is the sensor connected?"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); break; case READ_FAILED: ESP_LOGE(TAG, "Error reading from register"); diff --git a/esphome/components/ens210/ens210.cpp b/esphome/components/ens210/ens210.cpp index 86890c05e8..b296e9dd42 100644 --- a/esphome/components/ens210/ens210.cpp +++ b/esphome/components/ens210/ens210.cpp @@ -87,7 +87,7 @@ static uint32_t crc7(uint32_t value) { } void ENS210Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up ENS210..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t data[2]; uint16_t part_id = 0; // Reset @@ -163,7 +163,7 @@ void ENS210Component::update() { // Read T_VAL and H_VAL if (!this->read_bytes(ENS210_REGISTER_T_VAL, data, 6)) { - ESP_LOGE(TAG, "Communication with ENS210 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); this->status_set_warning(); return; } diff --git a/esphome/components/es7210/es7210.cpp b/esphome/components/es7210/es7210.cpp index 9a99e60995..f494bf32f0 100644 --- a/esphome/components/es7210/es7210.cpp +++ b/esphome/components/es7210/es7210.cpp @@ -36,7 +36,7 @@ void ES7210::dump_config() { } void ES7210::setup() { - ESP_LOGCONFIG(TAG, "Setting up ES7210..."); + ESP_LOGCONFIG(TAG, "Running setup"); // Software reset ES7210_ERROR_FAILED(this->write_byte(ES7210_RESET_REG00, 0xff)); diff --git a/esphome/components/es7243e/es7243e.cpp b/esphome/components/es7243e/es7243e.cpp index ce65ce973e..d5115cb880 100644 --- a/esphome/components/es7243e/es7243e.cpp +++ b/esphome/components/es7243e/es7243e.cpp @@ -34,7 +34,7 @@ void ES7243E::dump_config() { } void ES7243E::setup() { - ESP_LOGCONFIG(TAG, "Setting up ES7243E..."); + ESP_LOGCONFIG(TAG, "Running setup"); ES7243E_ERROR_FAILED(this->write_byte(ES7243E_CLOCK_MGR_REG01, 0x3A)); ES7243E_ERROR_FAILED(this->write_byte(ES7243E_RESET_REG00, 0x80)); diff --git a/esphome/components/es8156/es8156.cpp b/esphome/components/es8156/es8156.cpp index 62d35aa2d2..c8330b4f84 100644 --- a/esphome/components/es8156/es8156.cpp +++ b/esphome/components/es8156/es8156.cpp @@ -17,7 +17,7 @@ static const char *const TAG = "es8156"; } void ES8156::setup() { - ESP_LOGCONFIG(TAG, "Setting up ES8156..."); + ESP_LOGCONFIG(TAG, "Running setup"); ES8156_ERROR_FAILED(this->write_byte(ES8156_REG02_SCLK_MODE, 0x04)); ES8156_ERROR_FAILED(this->write_byte(ES8156_REG20_ANALOG_SYS1, 0x2A)); diff --git a/esphome/components/es8311/es8311.cpp b/esphome/components/es8311/es8311.cpp index 1cb1fbbe08..47bd82adb1 100644 --- a/esphome/components/es8311/es8311.cpp +++ b/esphome/components/es8311/es8311.cpp @@ -22,7 +22,7 @@ static const char *const TAG = "es8311"; } void ES8311::setup() { - ESP_LOGCONFIG(TAG, "Setting up ES8311..."); + ESP_LOGCONFIG(TAG, "Running setup"); // Reset ES8311_ERROR_FAILED(this->write_byte(ES8311_REG00_RESET, 0x1F)); diff --git a/esphome/components/es8388/__init__.py b/esphome/components/es8388/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/esphome/components/es8388/audio_dac.py b/esphome/components/es8388/audio_dac.py new file mode 100644 index 0000000000..77e07b2e01 --- /dev/null +++ b/esphome/components/es8388/audio_dac.py @@ -0,0 +1,26 @@ +import esphome.codegen as cg +from esphome.components import i2c +from esphome.components.audio_dac import AudioDac +import esphome.config_validation as cv +from esphome.const import CONF_ID + +CODEOWNERS = ["@P4uLT"] +CONF_ES8388_ID = "es8388_id" + +es8388_ns = cg.esphome_ns.namespace("es8388") + +ES8388 = es8388_ns.class_("ES8388", AudioDac, cg.Component, i2c.I2CDevice) + +DEPENDENCIES = ["i2c"] + +CONFIG_SCHEMA = ( + cv.Schema({cv.GenerateID(): cv.declare_id(ES8388)}) + .extend(cv.COMPONENT_SCHEMA) + .extend(i2c.i2c_device_schema(0x10)) +) + + +async def to_code(config): + var = cg.new_Pvariable(config[CONF_ID]) + await cg.register_component(var, config) + await i2c.register_i2c_device(var, config) diff --git a/esphome/components/es8388/es8388.cpp b/esphome/components/es8388/es8388.cpp new file mode 100644 index 0000000000..87cf9a47ee --- /dev/null +++ b/esphome/components/es8388/es8388.cpp @@ -0,0 +1,289 @@ +#include "es8388.h" + +#include +#include "esphome/core/hal.h" +#include "esphome/core/log.h" + +namespace esphome { +namespace es8388 { + +static const char *const TAG = "es8388"; + +// Mark the component as failed; use only in setup +#define ES8388_ERROR_FAILED(func) \ + if (!(func)) { \ + this->mark_failed(); \ + return; \ + } + +// Return false; use outside of setup +#define ES8388_ERROR_CHECK(func) \ + if (!(func)) { \ + return false; \ + } + +void ES8388::setup() { + ESP_LOGCONFIG(TAG, "Running setup"); + + // mute DAC + this->set_mute_state_(true); + + // I2S worker mode + ES8388_ERROR_FAILED(this->write_byte(ES8388_MASTERMODE, 0x00)); + + /* Chip Control and Power Management */ + ES8388_ERROR_FAILED(this->write_byte(ES8388_CONTROL2, 0x50)); + // normal all and power up all + ES8388_ERROR_FAILED(this->write_byte(ES8388_CHIPPOWER, 0x00)); + + // vmidsel/500k + // EnRef=0,Play&Record Mode,(0x17-both of mic&play) + ES8388_ERROR_FAILED(this->write_byte(ES8388_CONTROL1, 0x12)); + + // i2s 16 bits + ES8388_ERROR_FAILED(this->write_byte(ES8388_DACCONTROL1, 0x18)); + // sample freq 256 + // DACFsMode,SINGLE SPEED; DACFsRatio,256 + ES8388_ERROR_FAILED(this->write_byte(ES8388_DACCONTROL2, 0x02)); + // 0x00 audio on LIN1&RIN1, 0x09 LIN2&RIN2 + ES8388_ERROR_FAILED(this->write_byte(ES8388_DACCONTROL16, 0x00)); + // only left DAC to left mixer enable 0db + ES8388_ERROR_FAILED(this->write_byte(ES8388_DACCONTROL17, 0x90)); + // only right DAC to right mixer enable 0db + ES8388_ERROR_FAILED(this->write_byte(ES8388_DACCONTROL20, 0x90)); + // set internal ADC and DAC use the same LRCK clock, ADC LRCK as internal LRCK + ES8388_ERROR_FAILED(this->write_byte(ES8388_DACCONTROL21, 0x80)); + // vroi=0 - 1.5k VREF to analog output resistance (default) + ES8388_ERROR_FAILED(this->write_byte(ES8388_DACCONTROL23, 0x00)); + + // power down adc and line in + ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCPOWER, 0xFF)); + + //@nightdav + ES8388_ERROR_FAILED( + this->write_byte(ES8388_ADCCONTROL1, 0x00)); // +21dB : recommended value for ALC & voice recording + + // set to Mono Right + ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCCONTROL3, 0x02)); + + // I2S 16 Bits length and I2S serial audio data format + ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCCONTROL4, 0x0d)); + // ADCFsMode,singel SPEED,RATIO=256 + ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCCONTROL5, 0x02)); + + // ADC Volume + ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCCONTROL8, 0x00)); + ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCCONTROL9, 0x00)); + + //@nightDav + // ALC Config (as recommended by ES8388 user guide for voice recording) + + // Reg 0x12 = 0xe2 (ALC enable, PGA Max. Gain=23.5dB, Min. Gain=0dB) + ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCCONTROL10, 0xe2)); + + // Reg 0x13 = 0xa0 (ALC Target=-1.5dB, ALC Hold time =0 mS) + ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCCONTROL11, 0xa0)); + // Reg 0x14 = 0x12(Decay time =820uS , Attack time = 416 uS) + ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCCONTROL12, 0x12)); + + // Reg 0x15 = 0x06(ALC mode) + ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCCONTROL13, 0x06)); + + // Reg 0x16 = 0xc3(nose gate = -40.5dB, NGG = 0x01(mute ADC)) + ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCCONTROL14, 0xc3)); + + // Power on ADC + ES8388_ERROR_FAILED(this->write_byte(ES8388_DACCONTROL21, 0x80)); + + // Start state machine + ES8388_ERROR_FAILED(this->write_byte(ES8388_CHIPPOWER, 0xF0)); + delay(1); + ES8388_ERROR_FAILED(this->write_byte(ES8388_CHIPPOWER, 0x00)); + + // DAC volume max + // Set initial volume + // this->set_volume(0.75); // 0.75 = 0xBF = 0dB + + this->set_mute_state_(false); + + // unmute ADC with fade in + ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCCONTROL7, 0x60)); + // unmute DAC with fade in + ES8388_ERROR_FAILED(this->write_byte(ES8388_DACCONTROL3, 0x20)); + + // Power on ADC, Enable LIN&RIN, Power off MICBIAS, set int1lp to low power mode + ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCPOWER, 0x09)); + +#ifdef USE_SELECT + if (this->dac_output_select_ != nullptr) { + auto dac_power = this->get_dac_power(); + if (dac_power.has_value()) { + auto dac_power_str = this->dac_output_select_->at(dac_power.value()); + if (dac_power_str.has_value()) { + this->dac_output_select_->publish_state(dac_power_str.value()); + } else { + ESP_LOGW(TAG, "Unknown DAC output power value: %d", dac_power.value()); + } + } + } + if (this->adc_input_mic_select_ != nullptr) { + auto mic_input = this->get_mic_input(); + if (mic_input.has_value()) { + auto mic_input_str = this->adc_input_mic_select_->at(mic_input.value()); + if (mic_input_str.has_value()) { + this->adc_input_mic_select_->publish_state(mic_input_str.value()); + } else { + ESP_LOGW(TAG, "Unknown ADC input mic value: %d", mic_input.value()); + } + } + } +#endif +} + +void ES8388::dump_config() { + ESP_LOGCONFIG(TAG, "ES8388 Audio Codec:"); + LOG_I2C_DEVICE(this); +#ifdef USE_SELECT + 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) { + volume = clamp(volume, 0.0f, 1.0f); + uint8_t value = remap(volume, 0.0f, 1.0f, -96, 0); + ESP_LOGD(TAG, "Setting ES8388_DACCONTROL4 / ES8388_DACCONTROL5 to 0x%02X (volume: %f)", value, volume); + ES8388_ERROR_CHECK(this->write_byte(ES8388_DACCONTROL4, value)); + ES8388_ERROR_CHECK(this->write_byte(ES8388_DACCONTROL5, value)); + + return true; +} + +float ES8388::volume() { + uint8_t value; + ES8388_ERROR_CHECK(this->read_byte(ES8388_DACCONTROL4, &value)); + return remap(value, -96, 0, 0.0f, 1.0f); +} + +bool ES8388::set_mute_state_(bool mute_state) { + uint8_t value = 0; + + this->is_muted_ = mute_state; + + ES8388_ERROR_CHECK(this->read_byte(ES8388_DACCONTROL3, &value)); + ESP_LOGV(TAG, "Read ES8388_DACCONTROL3: 0x%02X", value); + + if (mute_state) { + value = 0x3C; + } + + ESP_LOGV(TAG, "Setting ES8388_DACCONTROL3 to 0x%02X (muted: %s)", value, YESNO(mute_state)); + return this->write_byte(ES8388_DACCONTROL3, value); +} + +// Set dac power output +bool ES8388::set_dac_output(DacOutputLine line) { + uint8_t reg_out1 = 0; + uint8_t reg_out2 = 0; + uint8_t dac_power = 0; + + // 0x00: -30dB , 0x1E: 0dB + switch (line) { + case DAC_OUTPUT_LINE1: + reg_out1 = 0x1E; + dac_power = ES8388_DAC_OUTPUT_LOUT1_ROUT1; + break; + case DAC_OUTPUT_LINE2: + reg_out2 = 0x1E; + dac_power = ES8388_DAC_OUTPUT_LOUT2_ROUT2; + break; + case DAC_OUTPUT_BOTH: + reg_out1 = 0x1E; + reg_out2 = 0x1E; + dac_power = ES8388_DAC_OUTPUT_BOTH; + break; + default: + ESP_LOGE(TAG, "Unknown DAC output line: %d", line); + return false; + }; + + ESP_LOGV(TAG, "Setting ES8388_DACPOWER to 0x%02X", dac_power); + ESP_LOGV(TAG, "Setting ES8388_DACCONTROL24 / ES8388_DACCONTROL25 to 0x%02X", reg_out1); + ESP_LOGV(TAG, "Setting ES8388_DACCONTROL26 / ES8388_DACCONTROL27 to 0x%02X", reg_out2); + + ES8388_ERROR_CHECK(this->write_byte(ES8388_DACCONTROL24, reg_out1)); // LOUT1VOL + ES8388_ERROR_CHECK(this->write_byte(ES8388_DACCONTROL25, reg_out1)); // ROUT1VOL + ES8388_ERROR_CHECK(this->write_byte(ES8388_DACCONTROL26, reg_out2)); // LOUT2VOL + ES8388_ERROR_CHECK(this->write_byte(ES8388_DACCONTROL27, reg_out2)); // ROUT1VOL + + return this->write_byte(ES8388_DACPOWER, dac_power); +} + +optional ES8388::get_dac_power() { + uint8_t dac_power; + if (!this->read_byte(ES8388_DACPOWER, &dac_power)) { + this->status_momentary_warning("Failed to read ES8388_DACPOWER"); + return {}; + } + switch (dac_power) { + case ES8388_DAC_OUTPUT_LOUT1_ROUT1: + return DAC_OUTPUT_LINE1; + case ES8388_DAC_OUTPUT_LOUT2_ROUT2: + return DAC_OUTPUT_LINE2; + case ES8388_DAC_OUTPUT_BOTH: + return DAC_OUTPUT_BOTH; + default: + return {}; + } +} + +// Set ADC input MIC +bool ES8388::set_adc_input_mic(AdcInputMicLine line) { + uint8_t mic_input = 0; + + switch (line) { + case ADC_INPUT_MIC_LINE1: + mic_input = ES8388_ADC_INPUT_LINPUT1_RINPUT1; + break; + case ADC_INPUT_MIC_LINE2: + mic_input = ES8388_ADC_INPUT_LINPUT2_RINPUT2; + break; + case ADC_INPUT_MIC_DIFFERENCE: + mic_input = ES8388_ADC_INPUT_DIFFERENCE; + break; + default: + ESP_LOGE(TAG, "Unknown ADC input mic line: %d", line); + return false; + } + + ESP_LOGV(TAG, "Setting ES8388_ADCCONTROL2 to 0x%02X", mic_input); + ES8388_ERROR_CHECK(this->write_byte(ES8388_ADCCONTROL2, mic_input)); + + return true; +} + +optional ES8388::get_mic_input() { + uint8_t mic_input; + if (!this->read_byte(ES8388_ADCCONTROL2, &mic_input)) { + this->status_momentary_warning("Failed to read ES8388_ADCCONTROL2"); + return {}; + } + switch (mic_input) { + case ES8388_ADC_INPUT_LINPUT1_RINPUT1: + return ADC_INPUT_MIC_LINE1; + case ES8388_ADC_INPUT_LINPUT2_RINPUT2: + return ADC_INPUT_MIC_LINE2; + case ES8388_ADC_INPUT_DIFFERENCE: + return ADC_INPUT_MIC_DIFFERENCE; + default: + return {}; + }; +} + +} // namespace es8388 +} // namespace esphome diff --git a/esphome/components/es8388/es8388.h b/esphome/components/es8388/es8388.h new file mode 100644 index 0000000000..45944f68bd --- /dev/null +++ b/esphome/components/es8388/es8388.h @@ -0,0 +1,81 @@ +#pragma once + +#include + +#include "esphome/components/audio_dac/audio_dac.h" +#include "esphome/components/i2c/i2c.h" +#include "esphome/core/component.h" +#ifdef USE_SELECT +#include "esphome/components/select/select.h" +#endif + +#include "es8388_const.h" + +namespace esphome { +namespace es8388 { + +enum DacOutputLine : uint8_t { + DAC_OUTPUT_LINE1, + DAC_OUTPUT_LINE2, + DAC_OUTPUT_BOTH, +}; + +enum AdcInputMicLine : uint8_t { + ADC_INPUT_MIC_LINE1, + ADC_INPUT_MIC_LINE2, + ADC_INPUT_MIC_DIFFERENCE, +}; + +class ES8388 : public audio_dac::AudioDac, public Component, public i2c::I2CDevice { +#ifdef USE_SELECT + SUB_SELECT(dac_output) + SUB_SELECT(adc_input_mic) +#endif + + public: + ///////////////////////// + // Component overrides // + ///////////////////////// + + void setup() override; + float get_setup_priority() const override { return setup_priority::DATA; } + void dump_config() override; + + //////////////////////// + // AudioDac overrides // + //////////////////////// + + /// @brief Writes the volume out to the DAC + /// @param volume floating point between 0.0 and 1.0 + /// @return True if successful and false otherwise + bool set_volume(float volume) override; + + /// @brief Gets the current volume out from the DAC + /// @return floating point between 0.0 and 1.0 + float volume() override; + + /// @brief Disables mute for audio out + /// @return True if successful and false otherwise + bool set_mute_off() override { return this->set_mute_state_(false); } + + /// @brief Enables mute for audio out + /// @return True if successful and false otherwise + bool set_mute_on() override { return this->set_mute_state_(true); } + + bool is_muted() override { return this->is_muted_; } + + optional get_dac_power(); + optional get_mic_input(); + + bool set_dac_output(DacOutputLine line); + bool set_adc_input_mic(AdcInputMicLine line); + + protected: + /// @brief Mutes or unmutes the DAC audio out + /// @param mute_state True to mute, false to unmute + /// @return True if successful and false otherwise + bool set_mute_state_(bool mute_state); +}; + +} // namespace es8388 +} // namespace esphome diff --git a/esphome/components/es8388/es8388_const.h b/esphome/components/es8388/es8388_const.h new file mode 100644 index 0000000000..2a51f078bc --- /dev/null +++ b/esphome/components/es8388/es8388_const.h @@ -0,0 +1,83 @@ +#pragma once +#include + +namespace esphome { +namespace es8388 { + +/* ES8388 register */ +static const uint8_t ES8388_CONTROL1 = 0x00; +static const uint8_t ES8388_CONTROL2 = 0x01; + +static const uint8_t ES8388_CHIPPOWER = 0x02; + +static const uint8_t ES8388_ADCPOWER = 0x03; +static const uint8_t ES8388_DACPOWER = 0x04; + +static const uint8_t ES8388_CHIPLOPOW1 = 0x05; +static const uint8_t ES8388_CHIPLOPOW2 = 0x06; + +static const uint8_t ES8388_ANAVOLMANAG = 0x07; + +static const uint8_t ES8388_MASTERMODE = 0x08; + +/* ADC */ +static const uint8_t ES8388_ADCCONTROL1 = 0x09; +static const uint8_t ES8388_ADCCONTROL2 = 0x0a; +static const uint8_t ES8388_ADCCONTROL3 = 0x0b; +static const uint8_t ES8388_ADCCONTROL4 = 0x0c; +static const uint8_t ES8388_ADCCONTROL5 = 0x0d; +static const uint8_t ES8388_ADCCONTROL6 = 0x0e; +static const uint8_t ES8388_ADCCONTROL7 = 0x0f; +static const uint8_t ES8388_ADCCONTROL8 = 0x10; +static const uint8_t ES8388_ADCCONTROL9 = 0x11; +static const uint8_t ES8388_ADCCONTROL10 = 0x12; +static const uint8_t ES8388_ADCCONTROL11 = 0x13; +static const uint8_t ES8388_ADCCONTROL12 = 0x14; +static const uint8_t ES8388_ADCCONTROL13 = 0x15; +static const uint8_t ES8388_ADCCONTROL14 = 0x16; +/* DAC */ +static const uint8_t ES8388_DACCONTROL1 = 0x17; +static const uint8_t ES8388_DACCONTROL2 = 0x18; +static const uint8_t ES8388_DACCONTROL3 = 0x19; +static const uint8_t ES8388_DACCONTROL4 = 0x1a; +static const uint8_t ES8388_DACCONTROL5 = 0x1b; +static const uint8_t ES8388_DACCONTROL6 = 0x1c; +static const uint8_t ES8388_DACCONTROL7 = 0x1d; +static const uint8_t ES8388_DACCONTROL8 = 0x1e; +static const uint8_t ES8388_DACCONTROL9 = 0x1f; +static const uint8_t ES8388_DACCONTROL10 = 0x20; +static const uint8_t ES8388_DACCONTROL11 = 0x21; +static const uint8_t ES8388_DACCONTROL12 = 0x22; +static const uint8_t ES8388_DACCONTROL13 = 0x23; +static const uint8_t ES8388_DACCONTROL14 = 0x24; +static const uint8_t ES8388_DACCONTROL15 = 0x25; +static const uint8_t ES8388_DACCONTROL16 = 0x26; +static const uint8_t ES8388_DACCONTROL17 = 0x27; +static const uint8_t ES8388_DACCONTROL18 = 0x28; +static const uint8_t ES8388_DACCONTROL19 = 0x29; +static const uint8_t ES8388_DACCONTROL20 = 0x2a; +static const uint8_t ES8388_DACCONTROL21 = 0x2b; +static const uint8_t ES8388_DACCONTROL22 = 0x2c; +static const uint8_t ES8388_DACCONTROL23 = 0x2d; +static const uint8_t ES8388_DACCONTROL24 = 0x2e; +static const uint8_t ES8388_DACCONTROL25 = 0x2f; +static const uint8_t ES8388_DACCONTROL26 = 0x30; +static const uint8_t ES8388_DACCONTROL27 = 0x31; +static const uint8_t ES8388_DACCONTROL28 = 0x32; +static const uint8_t ES8388_DACCONTROL29 = 0x33; +static const uint8_t ES8388_DACCONTROL30 = 0x34; + +static const uint8_t ES8388_DAC_OUTPUT_NONE = 0xC0; // ALL DAC DOWN + +static const uint8_t ES8388_DAC_OUTPUT_LOUT1_ROUT1 = 0x30; +static const uint8_t ES8388_DAC_OUTPUT_LOUT2_ROUT2 = 0x0C; +static const uint8_t ES8388_DAC_OUTPUT_BOTH = 0x3C; + +static const uint8_t ES8388_ADC_INPUT_LINPUT1_RINPUT1 = 0x00; +static const uint8_t ES8388_ADC_INPUT_MIC1 = 0x05; +static const uint8_t ES8388_ADC_INPUT_MIC2 = 0x06; +static const uint8_t ES8388_ADC_INPUT_LINPUT2_RINPUT2 = 0x50; +static const uint8_t ES8388_ADC_INPUT_DIFFERENCE = 0xf0; + +} // namespace es8388 +} // namespace esphome diff --git a/esphome/components/es8388/select/__init__.py b/esphome/components/es8388/select/__init__.py new file mode 100644 index 0000000000..068d9f9fb8 --- /dev/null +++ b/esphome/components/es8388/select/__init__.py @@ -0,0 +1,47 @@ +import esphome.codegen as cg +from esphome.components import select +import esphome.config_validation as cv +from esphome.const import ENTITY_CATEGORY_CONFIG, ICON_CHIP # noqa: F401 + +from ..audio_dac import CONF_ES8388_ID, ES8388, es8388_ns + +CONF_DAC_OUTPUT = "dac_output" +CONF_ADC_INPUT_MIC = "adc_input_mic" + +DacOutputSelect = es8388_ns.class_("DacOutputSelect", select.Select) +ADCInputMicSelect = es8388_ns.class_("ADCInputMicSelect", select.Select) + +CONFIG_SCHEMA = cv.All( + { + cv.GenerateID(CONF_ES8388_ID): cv.use_id(ES8388), + cv.Optional(CONF_DAC_OUTPUT): select.select_schema( + DacOutputSelect, + entity_category=ENTITY_CATEGORY_CONFIG, + icon=ICON_CHIP, + ), + cv.Optional(CONF_ADC_INPUT_MIC): select.select_schema( + ADCInputMicSelect, + entity_category=ENTITY_CATEGORY_CONFIG, + icon=ICON_CHIP, + ), + } +) + + +async def to_code(config): + parent = await cg.get_variable(config[CONF_ES8388_ID]) + if dac_output_config := config.get(CONF_DAC_OUTPUT): + s = await select.new_select( + dac_output_config, + options=["LINE1", "LINE2", "BOTH"], + ) + await cg.register_parented(s, parent) + cg.add(parent.set_dac_output_select(s)) + + if adc_input_mic_config := config.get(CONF_ADC_INPUT_MIC): + s = await select.new_select( + adc_input_mic_config, + options=["LINE1", "LINE2", "DIFFERENCE"], + ) + await cg.register_parented(s, parent) + cg.add(parent.set_adc_input_mic_select(s)) diff --git a/esphome/components/es8388/select/adc_input_mic_select.cpp b/esphome/components/es8388/select/adc_input_mic_select.cpp new file mode 100644 index 0000000000..5fab5b8a92 --- /dev/null +++ b/esphome/components/es8388/select/adc_input_mic_select.cpp @@ -0,0 +1,12 @@ +#include "adc_input_mic_select.h" + +namespace esphome { +namespace es8388 { + +void ADCInputMicSelect::control(const std::string &value) { + this->publish_state(value); + this->parent_->set_adc_input_mic(static_cast(this->index_of(value).value())); +} + +} // namespace es8388 +} // namespace esphome diff --git a/esphome/components/es8388/select/adc_input_mic_select.h b/esphome/components/es8388/select/adc_input_mic_select.h new file mode 100644 index 0000000000..8d035525ef --- /dev/null +++ b/esphome/components/es8388/select/adc_input_mic_select.h @@ -0,0 +1,15 @@ +#pragma once + +#include "esphome/components/es8388/es8388.h" +#include "esphome/components/select/select.h" + +namespace esphome { +namespace es8388 { + +class ADCInputMicSelect : public select::Select, public Parented { + protected: + void control(const std::string &value) override; +}; + +} // namespace es8388 +} // namespace esphome diff --git a/esphome/components/es8388/select/dac_output_select.cpp b/esphome/components/es8388/select/dac_output_select.cpp new file mode 100644 index 0000000000..268b5f290c --- /dev/null +++ b/esphome/components/es8388/select/dac_output_select.cpp @@ -0,0 +1,12 @@ +#include "dac_output_select.h" + +namespace esphome { +namespace es8388 { + +void DacOutputSelect::control(const std::string &value) { + this->publish_state(value); + this->parent_->set_dac_output(static_cast(this->index_of(value).value())); +} + +} // namespace es8388 +} // namespace esphome diff --git a/esphome/components/es8388/select/dac_output_select.h b/esphome/components/es8388/select/dac_output_select.h new file mode 100644 index 0000000000..fccae9fc19 --- /dev/null +++ b/esphome/components/es8388/select/dac_output_select.h @@ -0,0 +1,15 @@ +#pragma once + +#include "esphome/components/es8388/es8388.h" +#include "esphome/components/select/select.h" + +namespace esphome { +namespace es8388 { + +class DacOutputSelect : public select::Select, public Parented { + protected: + void control(const std::string &value) override; +}; + +} // namespace es8388 +} // namespace esphome diff --git a/esphome/components/esp32/boards.py b/esphome/components/esp32/boards.py index e7cdac0d8e..68fee48830 100644 --- a/esphome/components/esp32/boards.py +++ b/esphome/components/esp32/boards.py @@ -2,7 +2,6 @@ from .const import ( VARIANT_ESP32, VARIANT_ESP32C2, VARIANT_ESP32C3, - VARIANT_ESP32C5, VARIANT_ESP32C6, VARIANT_ESP32H2, VARIANT_ESP32P4, @@ -1340,17 +1339,7 @@ ESP32_BOARD_PINS = { } """ -BOARDS generated with: - -git clone https://github.com/platformio/platform-espressif32 -for x in platform-espressif32/boards/*.json; do - mcu=$(jq -r .build.mcu <"$x"); - name=$(jq -r .name <"$x"); - fname=$(basename "$x") - board="${fname%.*}" - variant=$(echo "$mcu" | tr '[:lower:]' '[:upper:]') - echo " \"$board\": {\"name\": \"$name\", \"variant\": VARIANT_${variant},}," -done | sort +BOARDS generated with script/generate-esp32-boards.py """ BOARDS = { @@ -1362,6 +1351,10 @@ BOARDS = { "name": "Adafruit pyCamera S3", "variant": VARIANT_ESP32S3, }, + "adafruit_feather_esp32_v2": { + "name": "Adafruit Feather ESP32 V2", + "variant": VARIANT_ESP32, + }, "adafruit_feather_esp32c6": { "name": "Adafruit Feather ESP32-C6", "variant": VARIANT_ESP32C6, @@ -1394,10 +1387,6 @@ BOARDS = { "name": "Adafruit Feather ESP32-S3 TFT", "variant": VARIANT_ESP32S3, }, - "adafruit_feather_esp32_v2": { - "name": "Adafruit Feather ESP32 V2", - "variant": VARIANT_ESP32, - }, "adafruit_funhouse_esp32s2": { "name": "Adafruit FunHouse", "variant": VARIANT_ESP32S2, @@ -1422,14 +1411,14 @@ BOARDS = { "name": "Adafruit Metro ESP32-S3", "variant": VARIANT_ESP32S3, }, - "adafruit_qtpy_esp32c3": { - "name": "Adafruit QT Py ESP32-C3", - "variant": VARIANT_ESP32C3, - }, "adafruit_qtpy_esp32": { "name": "Adafruit QT Py ESP32", "variant": VARIANT_ESP32, }, + "adafruit_qtpy_esp32c3": { + "name": "Adafruit QT Py ESP32-C3", + "variant": VARIANT_ESP32C3, + }, "adafruit_qtpy_esp32s2": { "name": "Adafruit QT Py ESP32-S2", "variant": VARIANT_ESP32S2, @@ -1478,14 +1467,14 @@ BOARDS = { "name": "Smart Bee Data Logger", "variant": VARIANT_ESP32S3, }, - "bee_motion_mini": { - "name": "Smart Bee Motion Mini", - "variant": VARIANT_ESP32C3, - }, "bee_motion": { "name": "Smart Bee Motion", "variant": VARIANT_ESP32S2, }, + "bee_motion_mini": { + "name": "Smart Bee Motion Mini", + "variant": VARIANT_ESP32C3, + }, "bee_motion_s3": { "name": "Smart Bee Motion S3", "variant": VARIANT_ESP32S3, @@ -1518,6 +1507,10 @@ BOARDS = { "name": "D-duino-32", "variant": VARIANT_ESP32, }, + "deneyapkart": { + "name": "Deneyap Kart", + "variant": VARIANT_ESP32, + }, "deneyapkart1A": { "name": "Deneyap Kart 1A", "variant": VARIANT_ESP32, @@ -1530,10 +1523,6 @@ BOARDS = { "name": "Deneyap Kart G", "variant": VARIANT_ESP32C3, }, - "deneyapkart": { - "name": "Deneyap Kart", - "variant": VARIANT_ESP32, - }, "deneyapmini": { "name": "Deneyap Mini", "variant": VARIANT_ESP32S2, @@ -1574,8 +1563,8 @@ BOARDS = { "name": "Seeed Studio Edgebox-ESP-100", "variant": VARIANT_ESP32S3, }, - "esp320": { - "name": "Electronic SweetPeas ESP320", + "esp-wrover-kit": { + "name": "Espressif ESP-WROVER-KIT", "variant": VARIANT_ESP32, }, "esp32-c2-devkitm-1": { @@ -1594,10 +1583,6 @@ BOARDS = { "name": "Ai-Thinker ESP-C3-M1-I-Kit", "variant": VARIANT_ESP32C3, }, - "esp32-c5-devkitc-1": { - "name": "Espressif ESP32-C5-DevKitC-1", - "variant": VARIANT_ESP32C5, - }, "esp32-c6-devkitc-1": { "name": "Espressif ESP32-C6-DevKitC-1", "variant": VARIANT_ESP32C6, @@ -1606,26 +1591,10 @@ BOARDS = { "name": "Espressif ESP32-C6-DevKitM-1", "variant": VARIANT_ESP32C6, }, - "esp32cam": { - "name": "AI Thinker ESP32-CAM", - "variant": VARIANT_ESP32, - }, "esp32-devkitlipo": { "name": "OLIMEX ESP32-DevKit-LiPo", "variant": VARIANT_ESP32, }, - "esp32dev": { - "name": "Espressif ESP32 Dev Module", - "variant": VARIANT_ESP32, - }, - "esp32doit-devkit-v1": { - "name": "DOIT ESP32 DEVKIT V1", - "variant": VARIANT_ESP32, - }, - "esp32doit-espduino": { - "name": "DOIT ESPduino32", - "variant": VARIANT_ESP32, - }, "esp32-evb": { "name": "OLIMEX ESP32-EVB", "variant": VARIANT_ESP32, @@ -1650,14 +1619,14 @@ BOARDS = { "name": "Espressif ESP32-PICO-DevKitM-2", "variant": VARIANT_ESP32, }, - "esp32-poe-iso": { - "name": "OLIMEX ESP32-PoE-ISO", - "variant": VARIANT_ESP32, - }, "esp32-poe": { "name": "OLIMEX ESP32-PoE", "variant": VARIANT_ESP32, }, + "esp32-poe-iso": { + "name": "OLIMEX ESP32-PoE-ISO", + "variant": VARIANT_ESP32, + }, "esp32-pro": { "name": "OLIMEX ESP32-PRO", "variant": VARIANT_ESP32, @@ -1674,14 +1643,6 @@ BOARDS = { "name": "Espressif ESP32-S2-Saola-1", "variant": VARIANT_ESP32S2, }, - "esp32s3box": { - "name": "Espressif ESP32-S3-Box", - "variant": VARIANT_ESP32S3, - }, - "esp32s3camlcd": { - "name": "ESP32S3 CAM LCD", - "variant": VARIANT_ESP32S3, - }, "esp32-s3-devkitc-1": { "name": "Espressif ESP32-S3-DevKitC-1-N8 (8 MB QD, No PSRAM)", "variant": VARIANT_ESP32S3, @@ -1690,18 +1651,50 @@ BOARDS = { "name": "Espressif ESP32-S3-DevKitM-1", "variant": VARIANT_ESP32S3, }, + "esp32-solo1": { + "name": "Espressif Generic ESP32-solo1 4M Flash", + "variant": VARIANT_ESP32, + }, + "esp320": { + "name": "Electronic SweetPeas ESP320", + "variant": VARIANT_ESP32, + }, + "esp32cam": { + "name": "AI Thinker ESP32-CAM", + "variant": VARIANT_ESP32, + }, + "esp32dev": { + "name": "Espressif ESP32 Dev Module", + "variant": VARIANT_ESP32, + }, + "esp32doit-devkit-v1": { + "name": "DOIT ESP32 DEVKIT V1", + "variant": VARIANT_ESP32, + }, + "esp32doit-espduino": { + "name": "DOIT ESPduino32", + "variant": VARIANT_ESP32, + }, + "esp32s3_120_16_8-qio_opi": { + "name": "ESP32-S3 16MB QIO, 8MB OPI PSRAM", + "variant": VARIANT_ESP32S3, + }, "esp32s3_powerfeather": { "name": "ESP32-S3 PowerFeather", "variant": VARIANT_ESP32S3, }, + "esp32s3box": { + "name": "Espressif ESP32-S3-Box", + "variant": VARIANT_ESP32S3, + }, + "esp32s3camlcd": { + "name": "ESP32S3 CAM LCD", + "variant": VARIANT_ESP32S3, + }, "esp32s3usbotg": { "name": "Espressif ESP32-S3-USB-OTG", "variant": VARIANT_ESP32S3, }, - "esp32-solo1": { - "name": "Espressif Generic ESP32-solo1 4M Flash", - "variant": VARIANT_ESP32, - }, "esp32thing": { "name": "SparkFun ESP32 Thing", "variant": VARIANT_ESP32, @@ -1726,10 +1719,6 @@ BOARDS = { "name": "ESPino32", "variant": VARIANT_ESP32, }, - "esp-wrover-kit": { - "name": "Espressif ESP-WROVER-KIT", - "variant": VARIANT_ESP32, - }, "etboard": { "name": "ETBoard", "variant": VARIANT_ESP32, @@ -1758,6 +1747,14 @@ BOARDS = { "name": "Franzininho WiFi MSC", "variant": VARIANT_ESP32S2, }, + "freenove_esp32_s3_wroom": { + "name": "Freenove ESP32-S3 WROOM N8R8 (8MB Flash / 8MB PSRAM)", + "variant": VARIANT_ESP32S3, + }, + "freenove_esp32_wrover": { + "name": "Freenove ESP32-Wrover", + "variant": VARIANT_ESP32, + }, "frogboard": { "name": "Frog Board ESP32", "variant": VARIANT_ESP32, @@ -1774,6 +1771,10 @@ BOARDS = { "name": "Heltec WiFi Kit 32 (V3)", "variant": VARIANT_ESP32S3, }, + "heltec_wifi_kit_32_v2": { + "name": "Heltec WiFi Kit 32 (V2)", + "variant": VARIANT_ESP32, + }, "heltec_wifi_lora_32": { "name": "Heltec WiFi LoRa 32", "variant": VARIANT_ESP32, @@ -1786,14 +1787,14 @@ BOARDS = { "name": "Heltec WiFi LoRa 32 (V3)", "variant": VARIANT_ESP32S3, }, - "heltec_wireless_stick_lite": { - "name": "Heltec Wireless Stick Lite", - "variant": VARIANT_ESP32, - }, "heltec_wireless_stick": { "name": "Heltec Wireless Stick", "variant": VARIANT_ESP32, }, + "heltec_wireless_stick_lite": { + "name": "Heltec Wireless Stick Lite", + "variant": VARIANT_ESP32, + }, "honeylemon": { "name": "HONEYLemon", "variant": VARIANT_ESP32, @@ -1806,6 +1807,14 @@ BOARDS = { "name": "Hornbill ESP32 Minima", "variant": VARIANT_ESP32, }, + "huidu_hd_wf2": { + "name": "Huidu HD-WF2", + "variant": VARIANT_ESP32S3, + }, + "huidu_hd_wf4": { + "name": "Huidu HD-WF4", + "variant": VARIANT_ESP32S3, + }, "imbrios-logsens-v1p1": { "name": "Imbrios LogSens V1P1", "variant": VARIANT_ESP32, @@ -1838,6 +1847,10 @@ BOARDS = { "name": "ArtronShop IOXESP32PS", "variant": VARIANT_ESP32, }, + "jczn_2432s028r": { + "name": "ESP32-2432S028R CYD", + "variant": VARIANT_ESP32, + }, "kb32-ft": { "name": "MakerAsia KB32-FT", "variant": VARIANT_ESP32, @@ -1862,6 +1875,10 @@ BOARDS = { "name": "LilyGo T-Display-S3", "variant": VARIANT_ESP32S3, }, + "lilygo-t3-s3": { + "name": "LilyGo T3-S3", + "variant": VARIANT_ESP32S3, + }, "lionbit": { "name": "Lion:Bit Dev Board", "variant": VARIANT_ESP32, @@ -1870,14 +1887,14 @@ BOARDS = { "name": "Lion:Bit S3 STEM Dev Board", "variant": VARIANT_ESP32S3, }, - "lolin32_lite": { - "name": "WEMOS LOLIN32 Lite", - "variant": VARIANT_ESP32, - }, "lolin32": { "name": "WEMOS LOLIN32", "variant": VARIANT_ESP32, }, + "lolin32_lite": { + "name": "WEMOS LOLIN32 Lite", + "variant": VARIANT_ESP32, + }, "lolin_c3_mini": { "name": "WEMOS LOLIN C3 Mini", "variant": VARIANT_ESP32C3, @@ -1898,26 +1915,30 @@ BOARDS = { "name": "WEMOS LOLIN S2 PICO", "variant": VARIANT_ESP32S2, }, + "lolin_s3": { + "name": "WEMOS LOLIN S3", + "variant": VARIANT_ESP32S3, + }, "lolin_s3_mini": { "name": "WEMOS LOLIN S3 Mini", "variant": VARIANT_ESP32S3, }, - "lolin_s3": { - "name": "WEMOS LOLIN S3", + "lolin_s3_mini_pro": { + "name": "WEMOS LOLIN S3 Mini Pro", "variant": VARIANT_ESP32S3, }, "lolin_s3_pro": { "name": "WEMOS LOLIN S3 PRO", "variant": VARIANT_ESP32S3, }, - "lopy4": { - "name": "Pycom LoPy4", - "variant": VARIANT_ESP32, - }, "lopy": { "name": "Pycom LoPy", "variant": VARIANT_ESP32, }, + "lopy4": { + "name": "Pycom LoPy4", + "variant": VARIANT_ESP32, + }, "m5stack-atom": { "name": "M5Stack-ATOM", "variant": VARIANT_ESP32, @@ -1926,16 +1947,16 @@ BOARDS = { "name": "M5Stack AtomS3", "variant": VARIANT_ESP32S3, }, - "m5stack-core2": { - "name": "M5Stack Core2", + "m5stack-core-esp32": { + "name": "M5Stack Core ESP32", "variant": VARIANT_ESP32, }, "m5stack-core-esp32-16M": { "name": "M5Stack Core ESP32 16M", "variant": VARIANT_ESP32, }, - "m5stack-core-esp32": { - "name": "M5Stack Core ESP32", + "m5stack-core2": { + "name": "M5Stack Core2", "variant": VARIANT_ESP32, }, "m5stack-coreink": { @@ -1954,10 +1975,6 @@ BOARDS = { "name": "M5Stack GREY ESP32", "variant": VARIANT_ESP32, }, - "m5stack_paper": { - "name": "M5Stack Paper", - "variant": VARIANT_ESP32, - }, "m5stack-stamps3": { "name": "M5Stack StampS3", "variant": VARIANT_ESP32S3, @@ -1970,6 +1987,10 @@ BOARDS = { "name": "M5Stack Timer CAM", "variant": VARIANT_ESP32, }, + "m5stack_paper": { + "name": "M5Stack Paper", + "variant": VARIANT_ESP32, + }, "m5stamp-pico": { "name": "M5Stamp-Pico", "variant": VARIANT_ESP32, @@ -2038,14 +2059,14 @@ BOARDS = { "name": "Node32s", "variant": VARIANT_ESP32, }, - "nodemcu-32s2": { - "name": "Ai-Thinker NodeMCU-32S2 (ESP-12K)", - "variant": VARIANT_ESP32S2, - }, "nodemcu-32s": { "name": "NodeMCU-32S", "variant": VARIANT_ESP32, }, + "nodemcu-32s2": { + "name": "Ai-Thinker NodeMCU-32S2 (ESP-12K)", + "variant": VARIANT_ESP32S2, + }, "nscreen-32": { "name": "YeaCreate NSCREEN-32", "variant": VARIANT_ESP32, @@ -2094,10 +2115,22 @@ BOARDS = { "name": "RoboHeart Hercules", "variant": VARIANT_ESP32, }, + "rymcu-esp32-s3-devkitc-1": { + "name": "RYMCU ESP32-S3-DevKitC-1-N8R2 (8 MB QD, 2 MB PSRAM)", + "variant": VARIANT_ESP32S3, + }, + "s_odi_ultra": { + "name": "S.ODI Ultra v1", + "variant": VARIANT_ESP32, + }, "seeed_xiao_esp32c3": { "name": "Seeed Studio XIAO ESP32C3", "variant": VARIANT_ESP32C3, }, + "seeed_xiao_esp32c6": { + "name": "Seeed Studio XIAO ESP32C6", + "variant": VARIANT_ESP32C6, + }, "seeed_xiao_esp32s3": { "name": "Seeed Studio XIAO ESP32S3", "variant": VARIANT_ESP32S3, @@ -2114,34 +2147,38 @@ BOARDS = { "name": "SG-O AirMon", "variant": VARIANT_ESP32, }, - "s_odi_ultra": { - "name": "S.ODI Ultra v1", + "sparkfun_esp32_iot_redboard": { + "name": "SparkFun ESP32 IoT RedBoard", "variant": VARIANT_ESP32, }, "sparkfun_esp32c6_thing_plus": { "name": "Sparkfun ESP32-C6 Thing Plus", "variant": VARIANT_ESP32C6, }, - "sparkfun_esp32_iot_redboard": { - "name": "SparkFun ESP32 IoT RedBoard", - "variant": VARIANT_ESP32, - }, "sparkfun_esp32micromod": { "name": "SparkFun ESP32 MicroMod", "variant": VARIANT_ESP32, }, - "sparkfun_esp32s2_thing_plus_c": { - "name": "SparkFun ESP32 Thing Plus C", - "variant": VARIANT_ESP32, - }, "sparkfun_esp32s2_thing_plus": { "name": "SparkFun ESP32-S2 Thing Plus", "variant": VARIANT_ESP32S2, }, + "sparkfun_esp32s2_thing_plus_c": { + "name": "SparkFun ESP32 Thing Plus C", + "variant": VARIANT_ESP32, + }, + "sparkfun_esp32s3_thing_plus": { + "name": "SPARKFUN_ESP32S3_THING_PLUS", + "variant": VARIANT_ESP32S3, + }, "sparkfun_lora_gateway_1-channel": { "name": "SparkFun LoRa Gateway 1-Channel", "variant": VARIANT_ESP32, }, + "sparkfun_qwiic_pocket_esp32c6": { + "name": "SparkFun ESP32-C6 Qwiic Pocket", + "variant": VARIANT_ESP32C6, + }, "tamc_termod_s3": { "name": "TAMC Termod S3", "variant": VARIANT_ESP32S3, @@ -2150,6 +2187,10 @@ BOARDS = { "name": "Unexpected Maker TinyPICO", "variant": VARIANT_ESP32, }, + "trueverit-iot-driver": { + "name": "Trueverit ESP32 Universal IoT Driver", + "variant": VARIANT_ESP32, + }, "trueverit-iot-driver-mk2": { "name": "Trueverit ESP32 Universal IoT Driver MK II", "variant": VARIANT_ESP32, @@ -2158,32 +2199,16 @@ BOARDS = { "name": "Trueverit ESP32 Universal IoT Driver MK III", "variant": VARIANT_ESP32, }, - "trueverit-iot-driver": { - "name": "Trueverit ESP32 Universal IoT Driver", - "variant": VARIANT_ESP32, - }, "ttgo-lora32-v1": { "name": "TTGO LoRa32-OLED V1", "variant": VARIANT_ESP32, }, - "ttgo-lora32-v21": { - "name": "TTGO LoRa32-OLED v2.1.6", - "variant": VARIANT_ESP32, - }, "ttgo-lora32-v2": { "name": "TTGO LoRa32-OLED V2", "variant": VARIANT_ESP32, }, - "ttgo-t1": { - "name": "TTGO T1", - "variant": VARIANT_ESP32, - }, - "ttgo-t7-v13-mini32": { - "name": "TTGO T7 V1.3 Mini32", - "variant": VARIANT_ESP32, - }, - "ttgo-t7-v14-mini32": { - "name": "TTGO T7 V1.4 Mini32", + "ttgo-lora32-v21": { + "name": "TTGO LoRa32-OLED v2.1.6", "variant": VARIANT_ESP32, }, "ttgo-t-beam": { @@ -2198,6 +2223,18 @@ BOARDS = { "name": "TTGO T-Watch", "variant": VARIANT_ESP32, }, + "ttgo-t1": { + "name": "TTGO T1", + "variant": VARIANT_ESP32, + }, + "ttgo-t7-v13-mini32": { + "name": "TTGO T7 V1.3 Mini32", + "variant": VARIANT_ESP32, + }, + "ttgo-t7-v14-mini32": { + "name": "TTGO T7 V1.4 Mini32", + "variant": VARIANT_ESP32, + }, "turta_iot_node": { "name": "Turta IoT Node", "variant": VARIANT_ESP32, @@ -2270,9 +2307,17 @@ BOARDS = { "name": "SQFMI Watchy v2.0", "variant": VARIANT_ESP32, }, - "wemosbat": { - "name": "WeMos WiFi and Bluetooth Battery", - "variant": VARIANT_ESP32, + "waveshare_esp32_s3_zero": { + "name": "Waveshare ESP32-S3-Zero", + "variant": VARIANT_ESP32S3, + }, + "waveshare_esp32s3_touch_lcd_128": { + "name": "Waveshare ESP32-S3-Touch-LCD-1.28 (16 MB QD, 2MB PSRAM)", + "variant": VARIANT_ESP32S3, + }, + "weactstudio_esp32c3coreboard": { + "name": "WeAct Studio ESP32C3CoreBoard", + "variant": VARIANT_ESP32C3, }, "wemos_d1_mini32": { "name": "WEMOS D1 MINI ESP32", @@ -2282,6 +2327,10 @@ BOARDS = { "name": "WEMOS D1 R32", "variant": VARIANT_ESP32, }, + "wemosbat": { + "name": "WeMos WiFi and Bluetooth Battery", + "variant": VARIANT_ESP32, + }, "wesp32": { "name": "Silicognition wESP32", "variant": VARIANT_ESP32, @@ -2290,14 +2339,14 @@ BOARDS = { "name": "Widora AIR", "variant": VARIANT_ESP32, }, - "wifiduino32c3": { - "name": "Blinker WiFiduinoV2 (ESP32-C3)", - "variant": VARIANT_ESP32C3, - }, "wifiduino32": { "name": "Blinker WiFiduino32", "variant": VARIANT_ESP32, }, + "wifiduino32c3": { + "name": "Blinker WiFiduinoV2 (ESP32-C3)", + "variant": VARIANT_ESP32C3, + }, "wifiduino32s3": { "name": "Blinker WiFiduino32S3", "variant": VARIANT_ESP32S3, @@ -2306,12 +2355,32 @@ BOARDS = { "name": "Pycom WiPy3", "variant": VARIANT_ESP32, }, + "ws_esp32_s3_matrix": { + "name": "Waveshare ESP32-S3-Matrix", + "variant": VARIANT_ESP32S3, + }, "wt32-eth01": { "name": "Wireless-Tag WT32-ETH01 Ethernet Module", "variant": VARIANT_ESP32, }, + "wt32-sc01-plus": { + "name": "wt32-sc01-plus", + "variant": VARIANT_ESP32S3, + }, "xinabox_cw02": { "name": "XinaBox CW02", "variant": VARIANT_ESP32, }, + "yb_esp32s3_amp_v2": { + "name": "YelloByte YB-ESP32-S3-AMP (Rev.2)", + "variant": VARIANT_ESP32S3, + }, + "yb_esp32s3_amp_v3": { + "name": "YelloByte YB-ESP32-S3-AMP (Rev.3)", + "variant": VARIANT_ESP32S3, + }, + "yb_esp32s3_eth": { + "name": "YelloByte YB-ESP32-S3-ETH", + "variant": VARIANT_ESP32S3, + }, } diff --git a/esphome/components/esp32_ble/ble.cpp b/esphome/components/esp32_ble/ble.cpp index fc1303673f..9d9a264154 100644 --- a/esphome/components/esp32_ble/ble.cpp +++ b/esphome/components/esp32_ble/ble.cpp @@ -28,7 +28,7 @@ static RAMAllocator EVENT_ALLOCATOR( // NOLINT(cppcoreguidelines-avoi void ESP32BLE::setup() { global_ble = this; - ESP_LOGCONFIG(TAG, "Setting up BLE..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (!ble_pre_setup_()) { ESP_LOGE(TAG, "BLE could not be prepared for configuration"); diff --git a/esphome/components/esp32_dac/esp32_dac.cpp b/esphome/components/esp32_dac/esp32_dac.cpp index 6f1577b8b1..46e3553559 100644 --- a/esphome/components/esp32_dac/esp32_dac.cpp +++ b/esphome/components/esp32_dac/esp32_dac.cpp @@ -20,7 +20,7 @@ static constexpr uint8_t DAC0_PIN = 25; static const char *const TAG = "esp32_dac"; void ESP32DAC::setup() { - ESP_LOGCONFIG(TAG, "Setting up ESP32 DAC Output..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->pin_->setup(); this->turn_off(); diff --git a/esphome/components/esp32_rmt_led_strip/led_strip.cpp b/esphome/components/esp32_rmt_led_strip/led_strip.cpp index 355f60ef05..9b15e1898e 100644 --- a/esphome/components/esp32_rmt_led_strip/led_strip.cpp +++ b/esphome/components/esp32_rmt_led_strip/led_strip.cpp @@ -22,7 +22,7 @@ static const uint8_t RMT_CLK_DIV = 2; #endif void ESP32RMTLEDStripLightOutput::setup() { - ESP_LOGCONFIG(TAG, "Setting up ESP32 LED Strip..."); + ESP_LOGCONFIG(TAG, "Running setup"); size_t buffer_size = this->get_buffer_size_(); diff --git a/esphome/components/esp32_touch/esp32_touch.cpp b/esphome/components/esp32_touch/esp32_touch.cpp index 1dcb39e5de..b6fd2dda96 100644 --- a/esphome/components/esp32_touch/esp32_touch.cpp +++ b/esphome/components/esp32_touch/esp32_touch.cpp @@ -13,7 +13,7 @@ namespace esp32_touch { static const char *const TAG = "esp32_touch"; void ESP32TouchComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up ESP32 Touch Hub..."); + ESP_LOGCONFIG(TAG, "Running setup"); touch_pad_init(); // set up and enable/start filtering based on ESP32 variant #if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) diff --git a/esphome/components/esp8266_pwm/esp8266_pwm.cpp b/esphome/components/esp8266_pwm/esp8266_pwm.cpp index 8b3d8613b0..fcf66ee1a5 100644 --- a/esphome/components/esp8266_pwm/esp8266_pwm.cpp +++ b/esphome/components/esp8266_pwm/esp8266_pwm.cpp @@ -14,7 +14,7 @@ namespace esp8266_pwm { static const char *const TAG = "esp8266_pwm"; void ESP8266PWM::setup() { - ESP_LOGCONFIG(TAG, "Setting up ESP8266 PWM Output..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->pin_->setup(); this->turn_off(); } diff --git a/esphome/components/esphome/ota/ota_esphome.cpp b/esphome/components/esphome/ota/ota_esphome.cpp index 6067da15cb..6f128e548b 100644 --- a/esphome/components/esphome/ota/ota_esphome.cpp +++ b/esphome/components/esphome/ota/ota_esphome.cpp @@ -26,7 +26,7 @@ void ESPHomeOTAComponent::setup() { ota::register_ota_platform(this); #endif - server_ = socket::socket_ip(SOCK_STREAM, 0); + server_ = socket::socket_ip_loop_monitored(SOCK_STREAM, 0); // monitored for incoming connections if (server_ == nullptr) { ESP_LOGW(TAG, "Could not create socket"); this->mark_failed(); @@ -100,9 +100,12 @@ void ESPHomeOTAComponent::handle_() { #endif if (client_ == nullptr) { - struct sockaddr_storage source_addr; - socklen_t addr_len = sizeof(source_addr); - client_ = server_->accept((struct sockaddr *) &source_addr, &addr_len); + // Check if the server socket is ready before accepting + if (this->server_->ready()) { + struct sockaddr_storage source_addr; + socklen_t addr_len = sizeof(source_addr); + client_ = server_->accept((struct sockaddr *) &source_addr, &addr_len); + } } if (client_ == nullptr) return; diff --git a/esphome/components/ethernet/ethernet_component.cpp b/esphome/components/ethernet/ethernet_component.cpp index 79ef0715d8..c76c5523b2 100644 --- a/esphome/components/ethernet/ethernet_component.cpp +++ b/esphome/components/ethernet/ethernet_component.cpp @@ -38,7 +38,7 @@ EthernetComponent *global_eth_component; // NOLINT(cppcoreguidelines-avoid-non- EthernetComponent::EthernetComponent() { global_eth_component = this; } void EthernetComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up Ethernet..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (esp_reset_reason() != ESP_RST_DEEPSLEEP) { // Delay here to allow power to stabilise before Ethernet is initialized. delay(300); // NOLINT diff --git a/esphome/components/ezo/ezo.cpp b/esphome/components/ezo/ezo.cpp index 10f3d530ce..2e92c58e29 100644 --- a/esphome/components/ezo/ezo.cpp +++ b/esphome/components/ezo/ezo.cpp @@ -15,7 +15,7 @@ void EZOSensor::dump_config() { LOG_SENSOR("", "EZO", this); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with EZO circuit 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 6e5779a12e..9ec41cce30 100644 --- a/esphome/components/ezo_pmp/ezo_pmp.cpp +++ b/esphome/components/ezo_pmp/ezo_pmp.cpp @@ -41,7 +41,7 @@ static const std::string DOSING_MODE_CONTINUOUS = "Continuous"; void EzoPMP::dump_config() { LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with EZO-PMP circuit failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); } diff --git a/esphome/components/factory_reset/button/factory_reset_button.cpp b/esphome/components/factory_reset/button/factory_reset_button.cpp index 9354a3363e..a6e7b41e82 100644 --- a/esphome/components/factory_reset/button/factory_reset_button.cpp +++ b/esphome/components/factory_reset/button/factory_reset_button.cpp @@ -10,7 +10,7 @@ static const char *const TAG = "factory_reset.button"; void FactoryResetButton::dump_config() { LOG_BUTTON("", "Factory Reset Button", this); } void FactoryResetButton::press_action() { - ESP_LOGI(TAG, "Resetting to factory defaults..."); + ESP_LOGI(TAG, "Resetting..."); // Let MQTT settle a bit delay(100); // NOLINT global_preferences->reset(); diff --git a/esphome/components/factory_reset/switch/factory_reset_switch.cpp b/esphome/components/factory_reset/switch/factory_reset_switch.cpp index 7bc8676736..116d696aa7 100644 --- a/esphome/components/factory_reset/switch/factory_reset_switch.cpp +++ b/esphome/components/factory_reset/switch/factory_reset_switch.cpp @@ -14,7 +14,7 @@ void FactoryResetSwitch::write_state(bool state) { this->publish_state(false); if (state) { - ESP_LOGI(TAG, "Resetting to factory defaults..."); + ESP_LOGI(TAG, "Resetting..."); // Let MQTT settle a bit delay(100); // NOLINT global_preferences->reset(); diff --git a/esphome/components/fastled_base/fastled_light.cpp b/esphome/components/fastled_base/fastled_light.cpp index 3ecdee61b1..5d5b65cb7e 100644 --- a/esphome/components/fastled_base/fastled_light.cpp +++ b/esphome/components/fastled_base/fastled_light.cpp @@ -9,7 +9,7 @@ namespace fastled_base { static const char *const TAG = "fastled"; void FastLEDLightOutput::setup() { - ESP_LOGCONFIG(TAG, "Setting up FastLED light..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->controller_->init(); this->controller_->setLeds(this->leds_, this->num_leds_); this->effect_data_ = new uint8_t[this->num_leds_]; // NOLINT diff --git a/esphome/components/fingerprint_grow/fingerprint_grow.cpp b/esphome/components/fingerprint_grow/fingerprint_grow.cpp index 0dfea49b8b..57b12ef228 100644 --- a/esphome/components/fingerprint_grow/fingerprint_grow.cpp +++ b/esphome/components/fingerprint_grow/fingerprint_grow.cpp @@ -57,7 +57,7 @@ void FingerprintGrowComponent::update() { } void FingerprintGrowComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up Grow Fingerprint Reader..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->has_sensing_pin_ = (this->sensing_pin_ != nullptr); this->has_power_pin_ = (this->sensor_power_pin_ != nullptr); diff --git a/esphome/components/fs3000/fs3000.cpp b/esphome/components/fs3000/fs3000.cpp index fb729ed0a0..c99772a23d 100644 --- a/esphome/components/fs3000/fs3000.cpp +++ b/esphome/components/fs3000/fs3000.cpp @@ -7,7 +7,7 @@ namespace fs3000 { static const char *const TAG = "fs3000"; void FS3000Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up FS3000..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (model_ == FIVE) { // datasheet gives 9 points to interpolate from for the 1005 model diff --git a/esphome/components/ft5x06/touchscreen/ft5x06_touchscreen.cpp b/esphome/components/ft5x06/touchscreen/ft5x06_touchscreen.cpp index bd603fdc10..3e12d06647 100644 --- a/esphome/components/ft5x06/touchscreen/ft5x06_touchscreen.cpp +++ b/esphome/components/ft5x06/touchscreen/ft5x06_touchscreen.cpp @@ -8,7 +8,7 @@ namespace ft5x06 { static const char *const TAG = "ft5x06.touchscreen"; void FT5x06Touchscreen::setup() { - ESP_LOGCONFIG(TAG, "Setting up FT5x06 Touchscreen..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (this->interrupt_pin_ != nullptr) { this->interrupt_pin_->setup(); this->interrupt_pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP); diff --git a/esphome/components/ft63x6/ft63x6.cpp b/esphome/components/ft63x6/ft63x6.cpp index 8bc66822eb..cd5a646d2e 100644 --- a/esphome/components/ft63x6/ft63x6.cpp +++ b/esphome/components/ft63x6/ft63x6.cpp @@ -28,7 +28,7 @@ static const uint8_t FT63X6_ADDR_CHIP_ID = 0xA3; static const char *const TAG = "FT63X6"; void FT63X6Touchscreen::setup() { - ESP_LOGCONFIG(TAG, "Setting up FT63X6 Touchscreen..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (this->interrupt_pin_ != nullptr) { this->interrupt_pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP); this->interrupt_pin_->setup(); diff --git a/esphome/components/gcja5/gcja5.cpp b/esphome/components/gcja5/gcja5.cpp index 64b237515b..29b0b910a7 100644 --- a/esphome/components/gcja5/gcja5.cpp +++ b/esphome/components/gcja5/gcja5.cpp @@ -14,8 +14,6 @@ namespace gcja5 { static const char *const TAG = "gcja5"; -void GCJA5Component::setup() { ESP_LOGCONFIG(TAG, "Setting up gcja5..."); } - void GCJA5Component::loop() { const uint32_t now = App.get_loop_component_start_time(); if (now - this->last_transmission_ >= 500) { diff --git a/esphome/components/gcja5/gcja5.h b/esphome/components/gcja5/gcja5.h index 7593c90323..844da33a54 100644 --- a/esphome/components/gcja5/gcja5.h +++ b/esphome/components/gcja5/gcja5.h @@ -9,7 +9,6 @@ namespace gcja5 { class GCJA5Component : public Component, public uart::UARTDevice { public: - void setup() override; void dump_config() override; void loop() override; float get_setup_priority() const override { return setup_priority::DATA; } diff --git a/esphome/components/gdk101/gdk101.cpp b/esphome/components/gdk101/gdk101.cpp index 93f3c20fa8..e8401aa09b 100644 --- a/esphome/components/gdk101/gdk101.cpp +++ b/esphome/components/gdk101/gdk101.cpp @@ -34,7 +34,7 @@ void GDK101Component::update() { void GDK101Component::setup() { uint8_t data[2]; - ESP_LOGCONFIG(TAG, "Setting up GDK101..."); + ESP_LOGCONFIG(TAG, "Running setup"); // first, reset the sensor if (!this->reset_sensor_(data)) { this->status_set_error("Reset failed!"); @@ -60,7 +60,7 @@ void GDK101Component::dump_config() { ESP_LOGCONFIG(TAG, "GDK101:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with GDK101 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } #ifdef USE_SENSOR LOG_SENSOR(" ", "Firmware Version", this->fw_version_sensor_); diff --git a/esphome/components/gpio/one_wire/gpio_one_wire.cpp b/esphome/components/gpio/one_wire/gpio_one_wire.cpp index 8a56595efb..7022c5fc31 100644 --- a/esphome/components/gpio/one_wire/gpio_one_wire.cpp +++ b/esphome/components/gpio/one_wire/gpio_one_wire.cpp @@ -8,7 +8,7 @@ namespace gpio { static const char *const TAG = "gpio.one_wire"; void GPIOOneWireBus::setup() { - ESP_LOGCONFIG(TAG, "Setting up 1-wire bus..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->t_pin_->setup(); this->t_pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP); // clear bus with 480µs high, otherwise initial reset in search might fail diff --git a/esphome/components/gpio/output/gpio_binary_output.cpp b/esphome/components/gpio/output/gpio_binary_output.cpp index a7dd9ab188..13538b6f2b 100644 --- a/esphome/components/gpio/output/gpio_binary_output.cpp +++ b/esphome/components/gpio/output/gpio_binary_output.cpp @@ -7,7 +7,7 @@ namespace gpio { static const char *const TAG = "gpio.output"; void GPIOBinaryOutput::dump_config() { - ESP_LOGCONFIG(TAG, "GPIO Binary Output:"); + ESP_LOGCONFIG(TAG, "Binary Output:"); LOG_PIN(" Pin: ", this->pin_); LOG_BINARY_OUTPUT(this); } diff --git a/esphome/components/gpio/switch/gpio_switch.cpp b/esphome/components/gpio/switch/gpio_switch.cpp index 5033315b5e..6f901d602d 100644 --- a/esphome/components/gpio/switch/gpio_switch.cpp +++ b/esphome/components/gpio/switch/gpio_switch.cpp @@ -8,7 +8,7 @@ static const char *const TAG = "switch.gpio"; float GPIOSwitch::get_setup_priority() const { return setup_priority::HARDWARE; } void GPIOSwitch::setup() { - ESP_LOGCONFIG(TAG, "Setting up GPIO Switch '%s'...", this->name_.c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->name_.c_str()); bool initial_state = this->get_initial_state_with_restore_mode().value_or(false); 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 ed40ba42a5..361f3e04fd 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 @@ -33,8 +33,7 @@ bool GroveGasMultichannelV2Component::read_sensor_(uint8_t address, sensor::Sens } void GroveGasMultichannelV2Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up Grove Multichannel Gas Sensor V2..."); - + ESP_LOGCONFIG(TAG, "Running setup"); // Before reading sensor values, must preheat sensor if (!(this->write_bytes(GROVE_GAS_MC_V2_HEAT_ON, {}))) { this->mark_failed(); @@ -68,17 +67,17 @@ void GroveGasMultichannelV2Component::dump_config() { if (this->is_failed()) { switch (this->error_code_) { case COMMUNICATION_FAILED: - ESP_LOGW(TAG, "Communication failed! Is the sensor connected?"); + ESP_LOGW(TAG, ESP_LOG_MSG_COMM_FAIL); break; case APP_INVALID: - ESP_LOGW(TAG, "Sensor reported invalid APP installed."); + ESP_LOGW(TAG, "Sensor reported invalid APP installed"); break; case APP_START_FAILED: - ESP_LOGW(TAG, "Sensor reported APP start failed."); + ESP_LOGW(TAG, "Sensor reported APP start failed"); break; case UNKNOWN: default: - ESP_LOGW(TAG, "Unknown setup error!"); + ESP_LOGW(TAG, "Unknown setup error"); break; } } diff --git a/esphome/components/grove_tb6612fng/grove_tb6612fng.cpp b/esphome/components/grove_tb6612fng/grove_tb6612fng.cpp index 621b7968a4..0dfb8478e7 100644 --- a/esphome/components/grove_tb6612fng/grove_tb6612fng.cpp +++ b/esphome/components/grove_tb6612fng/grove_tb6612fng.cpp @@ -24,7 +24,7 @@ void GroveMotorDriveTB6612FNG::dump_config() { } void GroveMotorDriveTB6612FNG::setup() { - ESP_LOGCONFIG(TAG, "Setting up Grove Motor Drive TB6612FNG ..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (!this->standby()) { this->mark_failed(); return; diff --git a/esphome/components/gt911/touchscreen/gt911_touchscreen.cpp b/esphome/components/gt911/touchscreen/gt911_touchscreen.cpp index 674ef51d64..1cead70181 100644 --- a/esphome/components/gt911/touchscreen/gt911_touchscreen.cpp +++ b/esphome/components/gt911/touchscreen/gt911_touchscreen.cpp @@ -25,7 +25,7 @@ static const size_t MAX_BUTTONS = 4; // max number of buttons scanned void GT911Touchscreen::setup() { i2c::ErrorCode err; - ESP_LOGCONFIG(TAG, "Setting up GT911 Touchscreen..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (this->reset_pin_ != nullptr) { this->reset_pin_->setup(); this->reset_pin_->digital_write(false); diff --git a/esphome/components/hbridge/switch/hbridge_switch.cpp b/esphome/components/hbridge/switch/hbridge_switch.cpp index c0949be947..2a1afa48c5 100644 --- a/esphome/components/hbridge/switch/hbridge_switch.cpp +++ b/esphome/components/hbridge/switch/hbridge_switch.cpp @@ -10,7 +10,7 @@ static const char *const TAG = "switch.hbridge"; float HBridgeSwitch::get_setup_priority() const { return setup_priority::HARDWARE; } void HBridgeSwitch::setup() { - ESP_LOGCONFIG(TAG, "Setting up H-Bridge Switch '%s'...", this->name_.c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->name_.c_str()); optional initial_state = this->get_initial_state_with_restore_mode(); diff --git a/esphome/components/hdc1080/hdc1080.cpp b/esphome/components/hdc1080/hdc1080.cpp index 7186578a22..956d01ed82 100644 --- a/esphome/components/hdc1080/hdc1080.cpp +++ b/esphome/components/hdc1080/hdc1080.cpp @@ -13,7 +13,7 @@ static const uint8_t HDC1080_CMD_TEMPERATURE = 0x00; static const uint8_t HDC1080_CMD_HUMIDITY = 0x01; void HDC1080Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up HDC1080..."); + ESP_LOGCONFIG(TAG, "Running setup"); const uint8_t data[2] = { 0b00000000, // resolution 14bit for both humidity and temperature @@ -31,7 +31,7 @@ void HDC1080Component::dump_config() { ESP_LOGCONFIG(TAG, "HDC1080:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with HDC1080 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "Temperature", this->temperature_); diff --git a/esphome/components/hlw8012/hlw8012.cpp b/esphome/components/hlw8012/hlw8012.cpp index 1efc57ab66..1044a528a0 100644 --- a/esphome/components/hlw8012/hlw8012.cpp +++ b/esphome/components/hlw8012/hlw8012.cpp @@ -11,7 +11,7 @@ static const uint32_t HLW8012_CLOCK_FREQUENCY = 3579000; void HLW8012Component::setup() { float reference_voltage = 0; - ESP_LOGCONFIG(TAG, "Setting up HLW8012..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->sel_pin_->setup(); this->sel_pin_->digital_write(this->current_mode_); this->cf_store_.pulse_counter_setup(this->cf_pin_); diff --git a/esphome/components/hm3301/hm3301.cpp b/esphome/components/hm3301/hm3301.cpp index 379c4dbc5a..b165e361ff 100644 --- a/esphome/components/hm3301/hm3301.cpp +++ b/esphome/components/hm3301/hm3301.cpp @@ -11,7 +11,7 @@ static const uint8_t PM_2_5_VALUE_INDEX = 6; static const uint8_t PM_10_0_VALUE_INDEX = 7; void HM3301Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up HM3301..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (i2c::ERROR_OK != this->write(&SELECT_COMM_CMD, 1)) { error_code_ = ERROR_COMM; this->mark_failed(); @@ -23,7 +23,7 @@ void HM3301Component::dump_config() { ESP_LOGCONFIG(TAG, "HM3301:"); LOG_I2C_DEVICE(this); if (error_code_ == ERROR_COMM) { - ESP_LOGE(TAG, "Communication with HM3301 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_SENSOR(" ", "PM1.0", this->pm_1_0_sensor_); diff --git a/esphome/components/hmc5883l/hmc5883l.cpp b/esphome/components/hmc5883l/hmc5883l.cpp index 24f4b3f8f1..fe90b25af2 100644 --- a/esphome/components/hmc5883l/hmc5883l.cpp +++ b/esphome/components/hmc5883l/hmc5883l.cpp @@ -22,7 +22,7 @@ static const uint8_t HMC5883L_REGISTER_IDENTIFICATION_B = 0x0B; static const uint8_t HMC5883L_REGISTER_IDENTIFICATION_C = 0x0C; void HMC5883LComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up HMC5583L..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t id[3]; if (!this->read_byte(HMC5883L_REGISTER_IDENTIFICATION_A, &id[0]) || !this->read_byte(HMC5883L_REGISTER_IDENTIFICATION_B, &id[1]) || @@ -73,7 +73,7 @@ void HMC5883LComponent::dump_config() { ESP_LOGCONFIG(TAG, "HMC5883L:"); LOG_I2C_DEVICE(this); if (this->error_code_ == COMMUNICATION_FAILED) { - ESP_LOGE(TAG, "Communication with HMC5883L 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?"); } diff --git a/esphome/components/honeywell_hih_i2c/honeywell_hih.cpp b/esphome/components/honeywell_hih_i2c/honeywell_hih.cpp index 64d5ddb541..5f2b009972 100644 --- a/esphome/components/honeywell_hih_i2c/honeywell_hih.cpp +++ b/esphome/components/honeywell_hih_i2c/honeywell_hih.cpp @@ -17,7 +17,7 @@ void HoneywellHIComponent::read_sensor_data_() { uint8_t data[4]; if (this->read(data, sizeof(data)) != i2c::ERROR_OK) { - ESP_LOGE(TAG, "Communication with Honeywell HIH failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); this->mark_failed(); return; } @@ -37,7 +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, "Communication with Honeywell HIH failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); this->mark_failed(); return; } @@ -49,7 +49,7 @@ bool HoneywellHIComponent::is_measurement_ready_() { uint8_t data[1]; if (this->read(data, sizeof(data)) != i2c::ERROR_OK) { - ESP_LOGE(TAG, "Communication with Honeywell HIH failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); this->mark_failed(); return false; } @@ -84,7 +84,7 @@ void HoneywellHIComponent::dump_config() { ESP_LOGD(TAG, "Honeywell HIH:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with Honeywell HIH 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/honeywellabp2_i2c/honeywellabp2.cpp b/esphome/components/honeywellabp2_i2c/honeywellabp2.cpp index d111723669..598f69d226 100644 --- a/esphome/components/honeywellabp2_i2c/honeywellabp2.cpp +++ b/esphome/components/honeywellabp2_i2c/honeywellabp2.cpp @@ -14,7 +14,7 @@ static const char *const TAG = "honeywellabp2"; void HONEYWELLABP2Sensor::read_sensor_data() { if (this->read(raw_data_, 7) != i2c::ERROR_OK) { - ESP_LOGE(TAG, "Communication with ABP2 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); this->status_set_warning("couldn't read sensor data"); return; } @@ -30,7 +30,7 @@ void HONEYWELLABP2Sensor::read_sensor_data() { void HONEYWELLABP2Sensor::start_measurement() { if (this->write(i2c_cmd_, 3) != i2c::ERROR_OK) { - ESP_LOGE(TAG, "Communication with ABP2 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); this->status_set_warning("couldn't start measurement"); return; } @@ -39,7 +39,7 @@ void HONEYWELLABP2Sensor::start_measurement() { bool HONEYWELLABP2Sensor::is_measurement_ready() { if (this->read(raw_data_, 1) != i2c::ERROR_OK) { - ESP_LOGE(TAG, "Communication with ABP2 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); this->status_set_warning("couldn't check measurement"); return false; } diff --git a/esphome/components/hte501/hte501.cpp b/esphome/components/hte501/hte501.cpp index 68edd07a22..e40d53b52d 100644 --- a/esphome/components/hte501/hte501.cpp +++ b/esphome/components/hte501/hte501.cpp @@ -7,7 +7,7 @@ namespace hte501 { static const char *const TAG = "hte501"; void HTE501Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up HTE501..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t address[] = {0x70, 0x29}; this->write(address, 2, false); uint8_t identification[9]; @@ -25,7 +25,7 @@ void HTE501Component::dump_config() { LOG_I2C_DEVICE(this); switch (this->error_code_) { case COMMUNICATION_FAILED: - ESP_LOGE(TAG, "Communication with HTE501 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); break; case CRC_CHECK_FAILED: ESP_LOGE(TAG, "The crc check failed"); diff --git a/esphome/components/http_request/__init__.py b/esphome/components/http_request/__init__.py index 9aa0c42fa2..878f362f28 100644 --- a/esphome/components/http_request/__init__.py +++ b/esphome/components/http_request/__init__.py @@ -10,6 +10,7 @@ from esphome.const import ( CONF_TIMEOUT, CONF_TRIGGER_ID, CONF_URL, + CONF_WATCHDOG_TIMEOUT, PLATFORM_HOST, __version__, ) @@ -43,7 +44,6 @@ CONF_USERAGENT = "useragent" CONF_VERIFY_SSL = "verify_ssl" CONF_FOLLOW_REDIRECTS = "follow_redirects" CONF_REDIRECT_LIMIT = "redirect_limit" -CONF_WATCHDOG_TIMEOUT = "watchdog_timeout" CONF_BUFFER_SIZE_RX = "buffer_size_rx" CONF_BUFFER_SIZE_TX = "buffer_size_tx" CONF_CA_CERTIFICATE_PATH = "ca_certificate_path" diff --git a/esphome/components/htu21d/htu21d.cpp b/esphome/components/htu21d/htu21d.cpp index 411d1e1d6a..b5d6ad45d5 100644 --- a/esphome/components/htu21d/htu21d.cpp +++ b/esphome/components/htu21d/htu21d.cpp @@ -18,7 +18,7 @@ static const uint8_t HTU21D_READHEATER_REG_CMD = 0x11; /**< Read Heater Control static const uint8_t HTU21D_REG_HTRE_BIT = 0x02; /**< Control Register Heater Bit */ void HTU21DComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up HTU21D..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (!this->write_bytes(HTU21D_REGISTER_RESET, nullptr, 0)) { this->mark_failed(); @@ -32,7 +32,7 @@ void HTU21DComponent::dump_config() { ESP_LOGCONFIG(TAG, "HTU21D:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with HTU21D failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "Temperature", this->temperature_); diff --git a/esphome/components/htu31d/htu31d.cpp b/esphome/components/htu31d/htu31d.cpp index bf4689d837..284548ed96 100644 --- a/esphome/components/htu31d/htu31d.cpp +++ b/esphome/components/htu31d/htu31d.cpp @@ -75,7 +75,7 @@ uint8_t compute_crc(uint32_t value) { * I2C. */ void HTU31DComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up esphome/components/htu31d HTU31D..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (!this->reset_()) { this->mark_failed(); @@ -161,7 +161,7 @@ void HTU31DComponent::dump_config() { ESP_LOGCONFIG(TAG, "HTU31D:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with HTU31D failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "Temperature", this->temperature_); diff --git a/esphome/components/hx711/hx711.cpp b/esphome/components/hx711/hx711.cpp index 9643d0c411..d9b82fd7cd 100644 --- a/esphome/components/hx711/hx711.cpp +++ b/esphome/components/hx711/hx711.cpp @@ -8,7 +8,7 @@ namespace hx711 { static const char *const TAG = "hx711"; void HX711Sensor::setup() { - ESP_LOGCONFIG(TAG, "Setting up HX711 '%s'...", this->name_.c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->name_.c_str()); this->sck_pin_->setup(); this->dout_pin_->setup(); this->sck_pin_->digital_write(false); diff --git a/esphome/components/hydreon_rgxx/hydreon_rgxx.cpp b/esphome/components/hydreon_rgxx/hydreon_rgxx.cpp index 92d7774193..86cf19eb24 100644 --- a/esphome/components/hydreon_rgxx/hydreon_rgxx.cpp +++ b/esphome/components/hydreon_rgxx/hydreon_rgxx.cpp @@ -39,7 +39,7 @@ void HydreonRGxxComponent::dump_config() { } void HydreonRGxxComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up hydreon_rgxx..."); + ESP_LOGCONFIG(TAG, "Running setup"); while (this->available() != 0) { this->read(); } diff --git a/esphome/components/hyt271/hyt271.cpp b/esphome/components/hyt271/hyt271.cpp index 3b81294cfc..f187e054a8 100644 --- a/esphome/components/hyt271/hyt271.cpp +++ b/esphome/components/hyt271/hyt271.cpp @@ -21,14 +21,14 @@ void HYT271Component::update() { if (this->write(&raw_data[0], 0) != i2c::ERROR_OK) { this->status_set_warning(); - ESP_LOGE(TAG, "Communication with HYT271 failed! => Ask new values"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); return; } this->set_timeout("wait_convert", 50, [this]() { uint8_t raw_data[4]; if (this->read(raw_data, 4) != i2c::ERROR_OK) { this->status_set_warning(); - ESP_LOGE(TAG, "Communication with HYT271 failed! => Read values"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); return; } uint16_t raw_temperature = ((raw_data[2] << 8) | raw_data[3]) >> 2; diff --git a/esphome/components/i2c/i2c_bus_arduino.cpp b/esphome/components/i2c/i2c_bus_arduino.cpp index cd1b2aacc7..9a5f1233b1 100644 --- a/esphome/components/i2c/i2c_bus_arduino.cpp +++ b/esphome/components/i2c/i2c_bus_arduino.cpp @@ -13,6 +13,7 @@ namespace i2c { static const char *const TAG = "i2c.arduino"; void ArduinoI2CBus::setup() { + ESP_LOGCONFIG(TAG, "Running setup"); recover_(); #if defined(USE_ESP32) @@ -93,13 +94,13 @@ void ArduinoI2CBus::dump_config() { break; } if (this->scan_) { - ESP_LOGI(TAG, "Results from i2c bus scan:"); + ESP_LOGI(TAG, "Results from bus scan:"); if (scan_results_.empty()) { - ESP_LOGI(TAG, "Found no i2c devices!"); + ESP_LOGI(TAG, "Found no devices"); } else { for (const auto &s : scan_results_) { if (s.second) { - ESP_LOGI(TAG, "Found i2c device at address 0x%02X", s.first); + ESP_LOGI(TAG, "Found device at address 0x%02X", s.first); } else { ESP_LOGE(TAG, "Unknown error at address 0x%02X", s.first); } @@ -215,7 +216,7 @@ ErrorCode ArduinoI2CBus::writev(uint8_t address, WriteBuffer *buffers, size_t cn /// https://www.nxp.com/docs/en/user-guide/UM10204.pdf /// https://www.analog.com/media/en/technical-documentation/application-notes/54305147357414AN686_0.pdf void ArduinoI2CBus::recover_() { - ESP_LOGI(TAG, "Performing I2C bus recovery"); + ESP_LOGI(TAG, "Performing bus recovery"); // For the upcoming operations, target for a 100kHz toggle frequency. // This is the maximum frequency for I2C running in standard-mode. @@ -231,7 +232,7 @@ void ArduinoI2CBus::recover_() { // line. In that case, the I2C bus cannot be recovered. delayMicroseconds(half_period_usec); if (digitalRead(scl_pin_) == LOW) { // NOLINT - ESP_LOGE(TAG, "Recovery failed: SCL is held LOW on the I2C bus"); + ESP_LOGE(TAG, "Recovery failed: SCL is held LOW on the bus"); recovery_result_ = RECOVERY_FAILED_SCL_LOW; return; } diff --git a/esphome/components/i2c/i2c_bus_esp_idf.cpp b/esphome/components/i2c/i2c_bus_esp_idf.cpp index c14300f725..c99870191e 100644 --- a/esphome/components/i2c/i2c_bus_esp_idf.cpp +++ b/esphome/components/i2c/i2c_bus_esp_idf.cpp @@ -18,7 +18,7 @@ namespace i2c { static const char *const TAG = "i2c.idf"; void IDFI2CBus::setup() { - ESP_LOGCONFIG(TAG, "Setting up I2C bus..."); + ESP_LOGCONFIG(TAG, "Running setup"); static i2c_port_t next_port = I2C_NUM_0; port_ = next_port; #if SOC_HP_I2C_NUM > 1 @@ -28,7 +28,7 @@ void IDFI2CBus::setup() { #endif if (port_ == I2C_NUM_MAX) { - ESP_LOGE(TAG, "Too many I2C buses configured. Max %u supported.", SOC_HP_I2C_NUM); + ESP_LOGE(TAG, "No more than %u buses supported", SOC_HP_I2C_NUM); this->mark_failed(); return; } @@ -99,13 +99,13 @@ void IDFI2CBus::dump_config() { break; } if (this->scan_) { - ESP_LOGI(TAG, "Results from i2c bus scan:"); + ESP_LOGI(TAG, "Results from bus scan:"); if (scan_results_.empty()) { - ESP_LOGI(TAG, "Found no i2c devices!"); + ESP_LOGI(TAG, "Found no devices"); } else { for (const auto &s : scan_results_) { if (s.second) { - ESP_LOGI(TAG, "Found i2c device at address 0x%02X", s.first); + ESP_LOGI(TAG, "Found device at address 0x%02X", s.first); } else { ESP_LOGE(TAG, "Unknown error at address 0x%02X", s.first); } @@ -257,7 +257,7 @@ ErrorCode IDFI2CBus::writev(uint8_t address, WriteBuffer *buffers, size_t cnt, b /// https://www.nxp.com/docs/en/user-guide/UM10204.pdf /// https://www.analog.com/media/en/technical-documentation/application-notes/54305147357414AN686_0.pdf void IDFI2CBus::recover_() { - ESP_LOGI(TAG, "Performing I2C bus recovery"); + ESP_LOGI(TAG, "Performing bus recovery"); const gpio_num_t scl_pin = static_cast(scl_pin_); const gpio_num_t sda_pin = static_cast(sda_pin_); @@ -294,7 +294,7 @@ void IDFI2CBus::recover_() { // with the SCL line. In that case, the I2C bus cannot be recovered. delayMicroseconds(half_period_usec); if (gpio_get_level(scl_pin) == 0) { - ESP_LOGE(TAG, "Recovery failed: SCL is held LOW on the I2C bus"); + ESP_LOGE(TAG, "Recovery failed: SCL is held LOW on the bus"); recovery_result_ = RECOVERY_FAILED_SCL_LOW; return; } diff --git a/esphome/components/i2s_audio/i2s_audio.cpp b/esphome/components/i2s_audio/i2s_audio.cpp index ad73b383fe..2de3f1d9f8 100644 --- a/esphome/components/i2s_audio/i2s_audio.cpp +++ b/esphome/components/i2s_audio/i2s_audio.cpp @@ -14,18 +14,17 @@ static const uint8_t I2S_NUM_MAX = SOC_I2S_NUM; // because IDF 5+ took this awa #endif void I2SAudioComponent::setup() { - static i2s_port_t next_port_num = I2S_NUM_0; + ESP_LOGCONFIG(TAG, "Running setup"); + static i2s_port_t next_port_num = I2S_NUM_0; if (next_port_num >= I2S_NUM_MAX) { - ESP_LOGE(TAG, "Too many I2S Audio components!"); + ESP_LOGE(TAG, "Too many I2S Audio components"); this->mark_failed(); return; } this->port_ = next_port_num; next_port_num = (i2s_port_t) (next_port_num + 1); - - ESP_LOGCONFIG(TAG, "Setting up I2S Audio..."); } } // namespace i2s_audio diff --git a/esphome/components/i2s_audio/media_player/__init__.py b/esphome/components/i2s_audio/media_player/__init__.py index 51001e9444..f7ef134803 100644 --- a/esphome/components/i2s_audio/media_player/__init__.py +++ b/esphome/components/i2s_audio/media_player/__init__.py @@ -116,5 +116,5 @@ async def to_code(config): cg.add_library("WiFiClientSecure", None) cg.add_library("HTTPClient", None) - cg.add_library("esphome/ESP32-audioI2S", "2.0.7") + cg.add_library("esphome/ESP32-audioI2S", "2.2.0") cg.add_build_flag("-DAUDIO_NO_SD_FS") diff --git a/esphome/components/i2s_audio/media_player/i2s_audio_media_player.cpp b/esphome/components/i2s_audio/media_player/i2s_audio_media_player.cpp index 34ed5b02a0..db6c3ae228 100644 --- a/esphome/components/i2s_audio/media_player/i2s_audio_media_player.cpp +++ b/esphome/components/i2s_audio/media_player/i2s_audio_media_player.cpp @@ -120,7 +120,7 @@ void I2SAudioMediaPlayer::set_volume_(float volume, bool publish) { } void I2SAudioMediaPlayer::setup() { - ESP_LOGCONFIG(TAG, "Setting up Audio..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->state = media_player::MEDIA_PLAYER_STATE_IDLE; } diff --git a/esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp b/esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp index 2ff1daa197..1ce98d51d3 100644 --- a/esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp +++ b/esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp @@ -30,17 +30,17 @@ static const int32_t DC_OFFSET_MOVING_AVERAGE_COEFFICIENT_DENOMINATOR = 1000; static const char *const TAG = "i2s_audio.microphone"; enum MicrophoneEventGroupBits : uint32_t { - COMMAND_STOP = (1 << 0), // stops the microphone task - TASK_STARTING = (1 << 10), - TASK_RUNNING = (1 << 11), - TASK_STOPPING = (1 << 12), - TASK_STOPPED = (1 << 13), + COMMAND_STOP = (1 << 0), // stops the microphone task, set and cleared by ``loop`` + + TASK_STARTING = (1 << 10), // set by mic task, cleared by ``loop`` + TASK_RUNNING = (1 << 11), // set by mic task, cleared by ``loop`` + TASK_STOPPED = (1 << 13), // set by mic task, cleared by ``loop`` ALL_BITS = 0x00FFFFFF, // All valid FreeRTOS event group bits }; void I2SAudioMicrophone::setup() { - ESP_LOGCONFIG(TAG, "Setting up I2S Audio Microphone..."); + ESP_LOGCONFIG(TAG, "Running setup"); #ifdef USE_I2S_LEGACY #if SOC_I2S_SUPPORTS_ADC if (this->adc_) { @@ -151,24 +151,21 @@ bool I2SAudioMicrophone::start_driver_() { config.mode = (i2s_mode_t) (config.mode | I2S_MODE_ADC_BUILT_IN); err = i2s_driver_install(this->parent_->get_port(), &config, 0, nullptr); if (err != ESP_OK) { - ESP_LOGW(TAG, "Error installing I2S driver: %s", esp_err_to_name(err)); - this->status_set_error(); + ESP_LOGE(TAG, "Error installing I2S driver: %s", esp_err_to_name(err)); return false; } err = i2s_set_adc_mode(ADC_UNIT_1, this->adc_channel_); if (err != ESP_OK) { - ESP_LOGW(TAG, "Error setting ADC mode: %s", esp_err_to_name(err)); - this->status_set_error(); - return false; - } - err = i2s_adc_enable(this->parent_->get_port()); - if (err != ESP_OK) { - ESP_LOGW(TAG, "Error enabling ADC: %s", esp_err_to_name(err)); - this->status_set_error(); + ESP_LOGE(TAG, "Error setting ADC mode: %s", esp_err_to_name(err)); return false; } + err = i2s_adc_enable(this->parent_->get_port()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Error enabling ADC: %s", esp_err_to_name(err)); + return false; + } } else #endif { @@ -177,8 +174,7 @@ bool I2SAudioMicrophone::start_driver_() { err = i2s_driver_install(this->parent_->get_port(), &config, 0, nullptr); if (err != ESP_OK) { - ESP_LOGW(TAG, "Error installing I2S driver: %s", esp_err_to_name(err)); - this->status_set_error(); + ESP_LOGE(TAG, "Error installing I2S driver: %s", esp_err_to_name(err)); return false; } @@ -187,8 +183,7 @@ bool I2SAudioMicrophone::start_driver_() { err = i2s_set_pin(this->parent_->get_port(), &pin_config); if (err != ESP_OK) { - ESP_LOGW(TAG, "Error setting I2S pin: %s", esp_err_to_name(err)); - this->status_set_error(); + ESP_LOGE(TAG, "Error setting I2S pin: %s", esp_err_to_name(err)); return false; } } @@ -203,8 +198,7 @@ bool I2SAudioMicrophone::start_driver_() { /* Allocate a new RX channel and get the handle of this channel */ err = i2s_new_channel(&chan_cfg, NULL, &this->rx_handle_); if (err != ESP_OK) { - ESP_LOGW(TAG, "Error creating new I2S channel: %s", esp_err_to_name(err)); - this->status_set_error(); + ESP_LOGE(TAG, "Error creating new I2S channel: %s", esp_err_to_name(err)); return false; } @@ -276,22 +270,20 @@ bool I2SAudioMicrophone::start_driver_() { err = i2s_channel_init_std_mode(this->rx_handle_, &std_cfg); } if (err != ESP_OK) { - ESP_LOGW(TAG, "Error initializing I2S channel: %s", esp_err_to_name(err)); - this->status_set_error(); + ESP_LOGE(TAG, "Error initializing I2S channel: %s", esp_err_to_name(err)); return false; } /* Before reading data, start the RX channel first */ i2s_channel_enable(this->rx_handle_); if (err != ESP_OK) { - ESP_LOGW(TAG, "Error enabling I2S Microphone: %s", esp_err_to_name(err)); - this->status_set_error(); + ESP_LOGE(TAG, "Error enabling I2S Microphone: %s", esp_err_to_name(err)); return false; } #endif - this->status_clear_error(); this->configure_stream_settings_(); // redetermine the settings in case some settings were changed after compilation + return true; } @@ -303,71 +295,55 @@ void I2SAudioMicrophone::stop() { } void I2SAudioMicrophone::stop_driver_() { + // There is no harm continuing to unload the driver if an error is ever returned by the various functions. This + // ensures that we stop/unload the driver when it only partially starts. + esp_err_t err; #ifdef USE_I2S_LEGACY #if SOC_I2S_SUPPORTS_ADC if (this->adc_) { err = i2s_adc_disable(this->parent_->get_port()); if (err != ESP_OK) { - ESP_LOGW(TAG, "Error disabling ADC: %s", esp_err_to_name(err)); - this->status_set_error(); - return; + ESP_LOGW(TAG, "Error disabling ADC - it may not have started: %s", esp_err_to_name(err)); } } #endif err = i2s_stop(this->parent_->get_port()); if (err != ESP_OK) { - ESP_LOGW(TAG, "Error stopping I2S microphone: %s", esp_err_to_name(err)); - this->status_set_error(); - return; + ESP_LOGW(TAG, "Error stopping I2S microphone - it may not have started: %s", esp_err_to_name(err)); } err = i2s_driver_uninstall(this->parent_->get_port()); if (err != ESP_OK) { - ESP_LOGW(TAG, "Error uninstalling I2S driver: %s", esp_err_to_name(err)); - this->status_set_error(); - return; + ESP_LOGW(TAG, "Error uninstalling I2S driver - it may not have started: %s", esp_err_to_name(err)); } #else /* Have to stop the channel before deleting it */ err = i2s_channel_disable(this->rx_handle_); if (err != ESP_OK) { - ESP_LOGW(TAG, "Error stopping I2S microphone: %s", esp_err_to_name(err)); - this->status_set_error(); - return; + ESP_LOGW(TAG, "Error stopping I2S microphone - it may not have started: %s", esp_err_to_name(err)); } /* If the handle is not needed any more, delete it to release the channel resources */ err = i2s_del_channel(this->rx_handle_); if (err != ESP_OK) { - ESP_LOGW(TAG, "Error deleting I2S channel: %s", esp_err_to_name(err)); - this->status_set_error(); - return; + ESP_LOGW(TAG, "Error deleting I2S channel - it may not have started: %s", esp_err_to_name(err)); } #endif this->parent_->unlock(); - this->status_clear_error(); } void I2SAudioMicrophone::mic_task(void *params) { I2SAudioMicrophone *this_microphone = (I2SAudioMicrophone *) params; - xEventGroupSetBits(this_microphone->event_group_, MicrophoneEventGroupBits::TASK_STARTING); - uint8_t start_counter = 0; - bool started = this_microphone->start_driver_(); - while (!started && start_counter < 10) { - // Attempt to load the driver again in 100 ms. Doesn't slow down main loop since its in a task. - vTaskDelay(pdMS_TO_TICKS(100)); - ++start_counter; - started = this_microphone->start_driver_(); - } + { // Ensures the samples vector is freed when the task stops - if (started) { - xEventGroupSetBits(this_microphone->event_group_, MicrophoneEventGroupBits::TASK_RUNNING); const size_t bytes_to_read = this_microphone->audio_stream_info_.ms_to_bytes(READ_DURATION_MS); std::vector samples; samples.reserve(bytes_to_read); - while (!(xEventGroupGetBits(this_microphone->event_group_) & COMMAND_STOP)) { + xEventGroupSetBits(this_microphone->event_group_, MicrophoneEventGroupBits::TASK_RUNNING); + + while (!(xEventGroupGetBits(this_microphone->event_group_) & MicrophoneEventGroupBits::COMMAND_STOP)) { if (this_microphone->data_callbacks_.size() > 0) { samples.resize(bytes_to_read); size_t bytes_read = this_microphone->read_(samples.data(), bytes_to_read, 2 * pdMS_TO_TICKS(READ_DURATION_MS)); @@ -382,9 +358,6 @@ void I2SAudioMicrophone::mic_task(void *params) { } } - xEventGroupSetBits(this_microphone->event_group_, MicrophoneEventGroupBits::TASK_STOPPING); - this_microphone->stop_driver_(); - xEventGroupSetBits(this_microphone->event_group_, MicrophoneEventGroupBits::TASK_STOPPED); while (true) { // Continuously delay until the loop method deletes the task @@ -425,7 +398,10 @@ size_t I2SAudioMicrophone::read_(uint8_t *buf, size_t len, TickType_t ticks_to_w #endif if ((err != ESP_OK) && ((err != ESP_ERR_TIMEOUT) || (ticks_to_wait != 0))) { // Ignore ESP_ERR_TIMEOUT if ticks_to_wait = 0, as it will read the data on the next call - ESP_LOGW(TAG, "Error reading from I2S microphone: %s", esp_err_to_name(err)); + if (!this->status_has_warning()) { + // Avoid spamming the logs with the error message if its repeated + ESP_LOGW(TAG, "Error reading from I2S microphone: %s", esp_err_to_name(err)); + } this->status_set_warning(); return 0; } @@ -452,7 +428,7 @@ void I2SAudioMicrophone::loop() { uint32_t event_group_bits = xEventGroupGetBits(this->event_group_); if (event_group_bits & MicrophoneEventGroupBits::TASK_STARTING) { - ESP_LOGD(TAG, "Task has started, attempting to setup I2S audio driver"); + ESP_LOGD(TAG, "Task started, attempting to allocate buffer"); xEventGroupClearBits(this->event_group_, MicrophoneEventGroupBits::TASK_STARTING); } @@ -463,23 +439,25 @@ void I2SAudioMicrophone::loop() { this->state_ = microphone::STATE_RUNNING; } - if (event_group_bits & MicrophoneEventGroupBits::TASK_STOPPING) { - ESP_LOGD(TAG, "Task is stopping, attempting to unload the I2S audio driver"); - xEventGroupClearBits(this->event_group_, MicrophoneEventGroupBits::TASK_STOPPING); - } - if ((event_group_bits & MicrophoneEventGroupBits::TASK_STOPPED)) { - ESP_LOGD(TAG, "Task is finished, freeing resources"); + ESP_LOGD(TAG, "Task finished, freeing resources and uninstalling I2S driver"); + vTaskDelete(this->task_handle_); this->task_handle_ = nullptr; + this->stop_driver_(); xEventGroupClearBits(this->event_group_, ALL_BITS); + this->status_clear_error(); + this->state_ = microphone::STATE_STOPPED; } + // Start the microphone if any semaphores are taken if ((uxSemaphoreGetCount(this->active_listeners_semaphore_) < MAX_LISTENERS) && (this->state_ == microphone::STATE_STOPPED)) { this->state_ = microphone::STATE_STARTING; } + + // Stop the microphone if all semaphores are returned if ((uxSemaphoreGetCount(this->active_listeners_semaphore_) == MAX_LISTENERS) && (this->state_ == microphone::STATE_RUNNING)) { this->state_ = microphone::STATE_STOPPING; @@ -487,14 +465,26 @@ void I2SAudioMicrophone::loop() { switch (this->state_) { case microphone::STATE_STARTING: - if ((this->task_handle_ == nullptr) && !this->status_has_error()) { + if (this->status_has_error()) { + break; + } + + if (!this->start_driver_()) { + this->status_momentary_error("I2S driver failed to start, unloading it and attempting again in 1 second", 1000); + this->stop_driver_(); // Stop/frees whatever possibly started + break; + } + + if (this->task_handle_ == nullptr) { xTaskCreate(I2SAudioMicrophone::mic_task, "mic_task", TASK_STACK_SIZE, (void *) this, TASK_PRIORITY, &this->task_handle_); if (this->task_handle_ == nullptr) { this->status_momentary_error("Task failed to start, attempting again in 1 second", 1000); + this->stop_driver_(); // Stops the driver to return the lock; will be reloaded in next attempt } } + break; case microphone::STATE_RUNNING: break; diff --git a/esphome/components/i2s_audio/microphone/i2s_audio_microphone.h b/esphome/components/i2s_audio/microphone/i2s_audio_microphone.h index 39249e879b..c35f88f8ee 100644 --- a/esphome/components/i2s_audio/microphone/i2s_audio_microphone.h +++ b/esphome/components/i2s_audio/microphone/i2s_audio_microphone.h @@ -43,7 +43,11 @@ class I2SAudioMicrophone : public I2SAudioIn, public microphone::Microphone, pub #endif protected: + /// @brief Starts the I2S driver. Updates the ``audio_stream_info_`` member variable with the current setttings. + /// @return True if succesful, false otherwise bool start_driver_(); + + /// @brief Stops the I2S driver. void stop_driver_(); /// @brief Attempts to correct a microphone DC offset; e.g., a microphones silent level is offset from 0. Applies a diff --git a/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp b/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp index d85409f1a8..f4c761ecc0 100644 --- a/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp +++ b/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp @@ -99,7 +99,7 @@ static const std::vector Q15_VOLUME_SCALING_FACTORS = { 19508, 20665, 21891, 23189, 24565, 26022, 27566, 29201, 30933, 32767}; void I2SAudioSpeaker::setup() { - ESP_LOGCONFIG(TAG, "Setting up I2S Audio Speaker..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->event_group_ = xEventGroupCreate(); diff --git a/esphome/components/iaqcore/iaqcore.cpp b/esphome/components/iaqcore/iaqcore.cpp index 810e8da0b2..27ae776287 100644 --- a/esphome/components/iaqcore/iaqcore.cpp +++ b/esphome/components/iaqcore/iaqcore.cpp @@ -26,7 +26,7 @@ struct SensorData { void IAQCore::setup() { if (this->write(nullptr, 0) != i2c::ERROR_OK) { - ESP_LOGD(TAG, "Communication failed!"); + ESP_LOGD(TAG, ESP_LOG_MSG_COMM_FAIL); this->mark_failed(); return; } @@ -89,7 +89,7 @@ void IAQCore::dump_config() { LOG_I2C_DEVICE(this); LOG_UPDATE_INTERVAL(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with AMS iAQ Core failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_SENSOR(" ", "CO2", this->co2_); LOG_SENSOR(" ", "TVOC", this->tvoc_); diff --git a/esphome/components/ina219/ina219.cpp b/esphome/components/ina219/ina219.cpp index 2fb3bea356..8d5271fa84 100644 --- a/esphome/components/ina219/ina219.cpp +++ b/esphome/components/ina219/ina219.cpp @@ -34,7 +34,7 @@ static const uint8_t INA219_REGISTER_CURRENT = 0x04; static const uint8_t INA219_REGISTER_CALIBRATION = 0x05; void INA219Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up INA219..."); + ESP_LOGCONFIG(TAG, "Running setup"); // Config Register // 0bx000000000000000 << 15 RESET Bit (1 -> trigger reset) if (!this->write_byte_16(INA219_REGISTER_CONFIG, 0x8000)) { @@ -134,7 +134,7 @@ void INA219Component::dump_config() { LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with INA219 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); return; } LOG_UPDATE_INTERVAL(this); diff --git a/esphome/components/ina226/ina226.cpp b/esphome/components/ina226/ina226.cpp index 7a57c118af..f25e11e2e1 100644 --- a/esphome/components/ina226/ina226.cpp +++ b/esphome/components/ina226/ina226.cpp @@ -37,7 +37,7 @@ static const uint16_t INA226_ADC_TIMES[] = {140, 204, 332, 588, 1100, 2116, 4156 static const uint16_t INA226_ADC_AVG_SAMPLES[] = {1, 4, 16, 64, 128, 256, 512, 1024}; void INA226Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up INA226..."); + ESP_LOGCONFIG(TAG, "Running setup"); ConfigurationRegister config; @@ -88,7 +88,7 @@ void INA226Component::dump_config() { LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with INA226 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); return; } LOG_UPDATE_INTERVAL(this); diff --git a/esphome/components/ina260/ina260.cpp b/esphome/components/ina260/ina260.cpp index 2f220e6a11..2b6208f60f 100644 --- a/esphome/components/ina260/ina260.cpp +++ b/esphome/components/ina260/ina260.cpp @@ -35,7 +35,7 @@ static const uint8_t INA260_REGISTER_MANUFACTURE_ID = 0xFE; static const uint8_t INA260_REGISTER_DEVICE_ID = 0xFF; void INA260Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up INA260..."); + ESP_LOGCONFIG(TAG, "Running setup"); // Reset device on setup if (!this->write_byte_16(INA260_REGISTER_CONFIG, 0x8000)) { diff --git a/esphome/components/ina2xx_base/ina2xx_base.cpp b/esphome/components/ina2xx_base/ina2xx_base.cpp index 924bf91e5e..82fd1e4d4d 100644 --- a/esphome/components/ina2xx_base/ina2xx_base.cpp +++ b/esphome/components/ina2xx_base/ina2xx_base.cpp @@ -50,7 +50,7 @@ static bool check_model_and_device_match(INAModel model, uint16_t dev_id) { } void INA2XX::setup() { - ESP_LOGCONFIG(TAG, "Setting up INA2xx..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (!this->reset_config_()) { ESP_LOGE(TAG, "Reset failed, check connection"); @@ -203,7 +203,7 @@ void INA2XX::dump_config() { this->dev_id_); } if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with INA2xx failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); ESP_LOGCONFIG(TAG, " Shunt resistance = %f Ohm", this->shunt_resistance_ohm_); diff --git a/esphome/components/ina3221/ina3221.cpp b/esphome/components/ina3221/ina3221.cpp index 3f8e2d06df..35e79462ab 100644 --- a/esphome/components/ina3221/ina3221.cpp +++ b/esphome/components/ina3221/ina3221.cpp @@ -22,7 +22,7 @@ static const uint8_t INA3221_REGISTER_CHANNEL3_BUS_VOLTAGE = 0x06; // A0 = SCL -> 0x43 void INA3221Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up INA3221..."); + ESP_LOGCONFIG(TAG, "Running setup"); // Config Register // 0bx000000000000000 << 15 RESET Bit (1 -> trigger reset) if (!this->write_byte_16(INA3221_REGISTER_CONFIG, 0x8000)) { @@ -60,7 +60,7 @@ void INA3221Component::dump_config() { ESP_LOGCONFIG(TAG, "INA3221:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with INA3221 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); diff --git a/esphome/components/inkplate6/display.py b/esphome/components/inkplate6/display.py index 56d20508ec..492cdf9340 100644 --- a/esphome/components/inkplate6/display.py +++ b/esphome/components/inkplate6/display.py @@ -6,9 +6,12 @@ from esphome.const import ( CONF_FULL_UPDATE_EVERY, CONF_ID, CONF_LAMBDA, + CONF_MIRROR_X, + CONF_MIRROR_Y, CONF_MODEL, CONF_OE_PIN, CONF_PAGES, + CONF_TRANSFORM, CONF_WAKEUP_PIN, ) @@ -36,7 +39,6 @@ CONF_SPH_PIN = "sph_pin" CONF_SPV_PIN = "spv_pin" CONF_VCOM_PIN = "vcom_pin" - inkplate6_ns = cg.esphome_ns.namespace("inkplate6") Inkplate6 = inkplate6_ns.class_( "Inkplate6", @@ -62,6 +64,12 @@ CONFIG_SCHEMA = cv.All( { cv.GenerateID(): cv.declare_id(Inkplate6), cv.Optional(CONF_GREYSCALE, default=False): cv.boolean, + cv.Optional(CONF_TRANSFORM): cv.Schema( + { + cv.Optional(CONF_MIRROR_X, default=False): cv.boolean, + cv.Optional(CONF_MIRROR_Y, default=False): cv.boolean, + } + ), cv.Optional(CONF_PARTIAL_UPDATING, default=True): cv.boolean, cv.Optional(CONF_FULL_UPDATE_EVERY, default=10): cv.uint32_t, cv.Optional(CONF_MODEL, default="inkplate_6"): cv.enum( @@ -126,6 +134,9 @@ async def to_code(config): cg.add(var.set_writer(lambda_)) cg.add(var.set_greyscale(config[CONF_GREYSCALE])) + if transform := config.get(CONF_TRANSFORM): + cg.add(var.set_mirror_x(transform[CONF_MIRROR_X])) + cg.add(var.set_mirror_y(transform[CONF_MIRROR_Y])) cg.add(var.set_partial_updating(config[CONF_PARTIAL_UPDATING])) cg.add(var.set_full_update_every(config[CONF_FULL_UPDATE_EVERY])) diff --git a/esphome/components/inkplate6/inkplate.cpp b/esphome/components/inkplate6/inkplate.cpp index f4d0fedf83..8c853b75c2 100644 --- a/esphome/components/inkplate6/inkplate.cpp +++ b/esphome/components/inkplate6/inkplate.cpp @@ -1,7 +1,7 @@ #include "inkplate.h" -#include "esphome/core/log.h" #include "esphome/core/application.h" #include "esphome/core/helpers.h" +#include "esphome/core/log.h" #ifdef USE_ESP32_FRAMEWORK_ARDUINO @@ -156,6 +156,12 @@ void HOT Inkplate6::draw_absolute_pixel_internal(int x, int y, Color color) { if (x >= this->get_width_internal() || y >= this->get_height_internal() || x < 0 || y < 0) return; + if (this->mirror_y_) + y = this->get_height_internal() - y - 1; + + if (this->mirror_x_) + x = this->get_width_internal() - x - 1; + if (this->greyscale_) { int x1 = x / 2; int x_sub = x % 2; diff --git a/esphome/components/inkplate6/inkplate.h b/esphome/components/inkplate6/inkplate.h index ca2ad46f1e..1680b84b7f 100644 --- a/esphome/components/inkplate6/inkplate.h +++ b/esphome/components/inkplate6/inkplate.h @@ -1,9 +1,9 @@ #pragma once +#include "esphome/components/display/display_buffer.h" +#include "esphome/components/i2c/i2c.h" #include "esphome/core/component.h" #include "esphome/core/hal.h" -#include "esphome/components/i2c/i2c.h" -#include "esphome/components/display/display_buffer.h" #ifdef USE_ESP32_FRAMEWORK_ARDUINO @@ -92,6 +92,9 @@ class Inkplate6 : public display::DisplayBuffer, public i2c::I2CDevice { if (this->is_ready()) this->initialize_(); } + void set_mirror_y(bool mirror_y) { this->mirror_y_ = mirror_y; } + void set_mirror_x(bool mirror_x) { this->mirror_x_ = mirror_x; } + void set_partial_updating(bool partial_updating) { this->partial_updating_ = partial_updating; } void set_full_update_every(uint32_t full_update_every) { this->full_update_every_ = full_update_every; } @@ -221,6 +224,8 @@ class Inkplate6 : public display::DisplayBuffer, public i2c::I2CDevice { bool block_partial_{true}; bool greyscale_; + bool mirror_y_{false}; + bool mirror_x_{false}; bool partial_updating_; InkplateModel model_; diff --git a/esphome/components/internal_temperature/internal_temperature.cpp b/esphome/components/internal_temperature/internal_temperature.cpp index d3ff7433b6..f503927d8e 100644 --- a/esphome/components/internal_temperature/internal_temperature.cpp +++ b/esphome/components/internal_temperature/internal_temperature.cpp @@ -66,7 +66,7 @@ void InternalTemperatureSensor::update() { esp_err_t result = temperature_sensor_get_celsius(tsensNew, &temperature); success = (result == ESP_OK); if (!success) { - ESP_LOGE(TAG, "Failed to get temperature: %d", result); + ESP_LOGE(TAG, "Reading failed (%d)", result); } #endif // ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) #endif // USE_ESP32_VARIANT @@ -103,20 +103,20 @@ void InternalTemperatureSensor::setup() { (defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S2) || \ defined(USE_ESP32_VARIANT_ESP32S3) || defined(USE_ESP32_VARIANT_ESP32H2) || defined(USE_ESP32_VARIANT_ESP32C2) || \ defined(USE_ESP32_VARIANT_ESP32P4)) - ESP_LOGCONFIG(TAG, "Setting up temperature sensor..."); + ESP_LOGCONFIG(TAG, "Running setup"); temperature_sensor_config_t tsens_config = TEMPERATURE_SENSOR_CONFIG_DEFAULT(-10, 80); esp_err_t result = temperature_sensor_install(&tsens_config, &tsensNew); if (result != ESP_OK) { - ESP_LOGE(TAG, "Failed to install temperature sensor: %d", result); + ESP_LOGE(TAG, "Install failed (%d)", result); this->mark_failed(); return; } result = temperature_sensor_enable(tsensNew); if (result != ESP_OK) { - ESP_LOGE(TAG, "Failed to enable temperature sensor: %d", result); + ESP_LOGE(TAG, "Enabling failed (%d)", result); this->mark_failed(); return; } diff --git a/esphome/components/json/json_util.cpp b/esphome/components/json/json_util.cpp index d50b2b483c..6c66476dc1 100644 --- a/esphome/components/json/json_util.cpp +++ b/esphome/components/json/json_util.cpp @@ -20,8 +20,7 @@ std::string build_json(const json_build_t &f) { ESP_LOGV(TAG, "Attempting to allocate %zu bytes for JSON serialization", request_size); DynamicJsonDocument json_document(request_size); if (json_document.capacity() == 0) { - ESP_LOGE(TAG, - "Could not allocate memory for JSON document! Requested %zu bytes, largest free heap block: %zu bytes", + ESP_LOGE(TAG, "Could not allocate memory for document! Requested %zu bytes, largest free heap block: %zu bytes", request_size, free_heap); return "{}"; } @@ -29,7 +28,7 @@ std::string build_json(const json_build_t &f) { f(root); if (json_document.overflowed()) { if (request_size == free_heap) { - ESP_LOGE(TAG, "Could not allocate memory for JSON document! Overflowed largest free heap block: %zu bytes", + ESP_LOGE(TAG, "Could not allocate memory for document! Overflowed largest free heap block: %zu bytes", free_heap); return "{}"; } @@ -54,7 +53,7 @@ bool parse_json(const std::string &data, const json_parse_t &f) { while (true) { DynamicJsonDocument json_document(request_size); if (json_document.capacity() == 0) { - ESP_LOGE(TAG, "Could not allocate memory for JSON document! Requested %zu bytes, free heap: %zu", request_size, + ESP_LOGE(TAG, "Could not allocate memory for document! Requested %zu bytes, free heap: %zu", request_size, free_heap); return false; } @@ -74,7 +73,7 @@ bool parse_json(const std::string &data, const json_parse_t &f) { request_size *= 2; continue; } else { - ESP_LOGE(TAG, "JSON parse error: %s", err.c_str()); + ESP_LOGE(TAG, "Parse error: %s", err.c_str()); return false; } }; diff --git a/esphome/components/kamstrup_kmp/kamstrup_kmp.cpp b/esphome/components/kamstrup_kmp/kamstrup_kmp.cpp index b870d1b56d..c058c7b3aa 100644 --- a/esphome/components/kamstrup_kmp/kamstrup_kmp.cpp +++ b/esphome/components/kamstrup_kmp/kamstrup_kmp.cpp @@ -10,7 +10,7 @@ static const char *const TAG = "kamstrup_kmp"; void KamstrupKMPComponent::dump_config() { ESP_LOGCONFIG(TAG, "kamstrup_kmp:"); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with Kamstrup meter failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); diff --git a/esphome/components/kmeteriso/kmeteriso.cpp b/esphome/components/kmeteriso/kmeteriso.cpp index 0276ab3f67..4856ee0e8f 100644 --- a/esphome/components/kmeteriso/kmeteriso.cpp +++ b/esphome/components/kmeteriso/kmeteriso.cpp @@ -13,7 +13,7 @@ static const uint8_t KMETER_INTERNAL_TEMP_VAL_REG = 0x10; static const uint8_t KMETER_FIRMWARE_VERSION_REG = 0xFE; void KMeterISOComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up KMeterISO..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->error_code_ = NONE; // Mark as not failed before initializing. Some devices will turn off sensors to save on batteries diff --git a/esphome/components/lcd_gpio/gpio_lcd_display.cpp b/esphome/components/lcd_gpio/gpio_lcd_display.cpp index a738893816..1b1b07c464 100644 --- a/esphome/components/lcd_gpio/gpio_lcd_display.cpp +++ b/esphome/components/lcd_gpio/gpio_lcd_display.cpp @@ -7,7 +7,7 @@ namespace lcd_gpio { static const char *const TAG = "lcd_gpio"; void GPIOLCDDisplay::setup() { - ESP_LOGCONFIG(TAG, "Setting up GPIO LCD Display..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->rs_pin_->setup(); // OUTPUT this->rs_pin_->digital_write(false); if (this->rw_pin_ != nullptr) { diff --git a/esphome/components/lcd_pcf8574/pcf8574_display.cpp b/esphome/components/lcd_pcf8574/pcf8574_display.cpp index 5b00b08aff..90ba3ba876 100644 --- a/esphome/components/lcd_pcf8574/pcf8574_display.cpp +++ b/esphome/components/lcd_pcf8574/pcf8574_display.cpp @@ -11,7 +11,7 @@ static const uint8_t LCD_DISPLAY_BACKLIGHT_ON = 0x08; static const uint8_t LCD_DISPLAY_BACKLIGHT_OFF = 0x00; void PCF8574LCDDisplay::setup() { - ESP_LOGCONFIG(TAG, "Setting up PCF8574 LCD Display..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->backlight_value_ = LCD_DISPLAY_BACKLIGHT_ON; if (!this->write_bytes(this->backlight_value_, nullptr, 0)) { this->mark_failed(); @@ -26,7 +26,7 @@ void PCF8574LCDDisplay::dump_config() { LOG_I2C_DEVICE(this); LOG_UPDATE_INTERVAL(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with LCD Display failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } } void PCF8574LCDDisplay::write_n_bits(uint8_t value, uint8_t n) { diff --git a/esphome/components/ld2410/ld2410.cpp b/esphome/components/ld2410/ld2410.cpp index c3b57815d6..20411be078 100644 --- a/esphome/components/ld2410/ld2410.cpp +++ b/esphome/components/ld2410/ld2410.cpp @@ -78,11 +78,8 @@ void LD2410Component::dump_config() { } void LD2410Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up LD2410..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->read_all_info(); - ESP_LOGCONFIG(TAG, "Mac Address : %s", const_cast(this->mac_.c_str())); - ESP_LOGCONFIG(TAG, "Firmware Version : %s", const_cast(this->version_.c_str())); - ESP_LOGCONFIG(TAG, "LD2410 setup complete."); } void LD2410Component::read_all_info() { diff --git a/esphome/components/ld2420/ld2420.cpp b/esphome/components/ld2420/ld2420.cpp index 9d628cc14f..f94a5d7781 100644 --- a/esphome/components/ld2420/ld2420.cpp +++ b/esphome/components/ld2420/ld2420.cpp @@ -111,7 +111,7 @@ int LD2420Component::get_firmware_int_(const char *version_string) { } void LD2420Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up LD2420..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (this->set_config_mode(true) == LD2420_ERROR_TIMEOUT) { ESP_LOGE(TAG, "LD2420 module has failed to respond, check baud rate and serial connections."); this->mark_failed(); diff --git a/esphome/components/ld2450/ld2450.cpp b/esphome/components/ld2450/ld2450.cpp index 3db065ba1a..59aeb5ccb4 100644 --- a/esphome/components/ld2450/ld2450.cpp +++ b/esphome/components/ld2450/ld2450.cpp @@ -109,7 +109,7 @@ static inline std::string format_version(uint8_t *buffer) { LD2450Component::LD2450Component() {} void LD2450Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up HLK-LD2450..."); + ESP_LOGCONFIG(TAG, "Running setup"); #ifdef USE_NUMBER if (this->presence_timeout_number_ != nullptr) { this->pref_ = global_preferences->make_preference(this->presence_timeout_number_->get_object_id_hash()); diff --git a/esphome/components/ledc/ledc_output.cpp b/esphome/components/ledc/ledc_output.cpp index 4ced4b8f76..567fa5ac07 100644 --- a/esphome/components/ledc/ledc_output.cpp +++ b/esphome/components/ledc/ledc_output.cpp @@ -46,11 +46,13 @@ inline ledc_mode_t get_speed_mode(uint8_t) { return LEDC_LOW_SPEED_MODE; } #endif #endif -float ledc_max_frequency_for_bit_depth(uint8_t bit_depth) { return CLOCK_FREQUENCY / float(1 << bit_depth); } +float ledc_max_frequency_for_bit_depth(uint8_t bit_depth) { + return static_cast(CLOCK_FREQUENCY) / static_cast(1 << bit_depth); +} float ledc_min_frequency_for_bit_depth(uint8_t bit_depth, bool low_frequency) { const float max_div_num = ((1 << MAX_RES_BITS) - 1) / (low_frequency ? 32.0f : 256.0f); - return CLOCK_FREQUENCY / (max_div_num * float(1 << bit_depth)); + return static_cast(CLOCK_FREQUENCY) / (max_div_num * static_cast(1 << bit_depth)); } optional ledc_bit_depth_for_frequency(float frequency) { @@ -100,13 +102,13 @@ esp_err_t configure_timer_frequency(ledc_mode_t speed_mode, ledc_timer_t timer_n #ifdef USE_ESP_IDF constexpr int ledc_angle_to_htop(float angle, uint8_t bit_depth) { - return static_cast(angle * ((1U << bit_depth) - 1) / 360.); + return static_cast(angle * ((1U << bit_depth) - 1) / 360.0f); } #endif // USE_ESP_IDF void LEDCOutput::write_state(float state) { - if (!initialized_) { - ESP_LOGW(TAG, "LEDC output hasn't been initialized yet!"); + if (!this->initialized_) { + ESP_LOGW(TAG, "Not yet initialized"); return; } @@ -122,8 +124,8 @@ void LEDCOutput::write_state(float state) { ledcWrite(this->channel_, duty); #endif #ifdef USE_ESP_IDF - auto speed_mode = get_speed_mode(channel_); - auto chan_num = static_cast(channel_ % 8); + auto speed_mode = get_speed_mode(this->channel_); + auto chan_num = static_cast(this->channel_ % 8); int hpoint = ledc_angle_to_htop(this->phase_angle_, this->bit_depth_); if (duty == max_duty) { ledc_stop(speed_mode, chan_num, 1); @@ -145,9 +147,9 @@ void LEDCOutput::setup() { ledcAttachPin(this->pin_->get_pin(), this->channel_); #endif #ifdef USE_ESP_IDF - auto speed_mode = get_speed_mode(channel_); - auto timer_num = static_cast((channel_ % 8) / 2); - auto chan_num = static_cast(channel_ % 8); + auto speed_mode = get_speed_mode(this->channel_); + auto timer_num = static_cast((this->channel_ % 8) / 2); + auto chan_num = static_cast(this->channel_ % 8); esp_err_t timer_init_result = configure_timer_frequency(speed_mode, timer_num, chan_num, this->channel_, this->bit_depth_, this->frequency_); @@ -163,23 +165,23 @@ void LEDCOutput::setup() { ESP_LOGV(TAG, "Angle of %.1f° results in hpoint %u", this->phase_angle_, hpoint); ledc_channel_config_t chan_conf{}; - chan_conf.gpio_num = pin_->get_pin(); + chan_conf.gpio_num = this->pin_->get_pin(); chan_conf.speed_mode = speed_mode; chan_conf.channel = chan_num; chan_conf.intr_type = LEDC_INTR_DISABLE; chan_conf.timer_sel = timer_num; - chan_conf.duty = inverted_ == pin_->is_inverted() ? 0 : (1U << bit_depth_); + chan_conf.duty = this->inverted_ == this->pin_->is_inverted() ? 0 : (1U << this->bit_depth_); chan_conf.hpoint = hpoint; ledc_channel_config(&chan_conf); - initialized_ = true; + this->initialized_ = true; this->status_clear_error(); #endif } void LEDCOutput::dump_config() { - ESP_LOGCONFIG(TAG, "LEDC Output:"); + ESP_LOGCONFIG(TAG, "Output:"); LOG_PIN(" Pin ", this->pin_); - ESP_LOGCONFIG(TAG, " LEDC Channel: %u", this->channel_); + ESP_LOGCONFIG(TAG, " Channel: %u", this->channel_); ESP_LOGCONFIG(TAG, " PWM Frequency: %.1f Hz", this->frequency_); ESP_LOGCONFIG(TAG, " Phase angle: %.1f°", this->phase_angle_); ESP_LOGCONFIG(TAG, " Bit depth: %u", this->bit_depth_); @@ -211,11 +213,11 @@ void LEDCOutput::update_frequency(float frequency) { // Configure LEDC channel, frequency and bit depth with fallback int attempt_count_max = SETUP_ATTEMPT_COUNT_MAX; while (attempt_count_max > 0 && configured_frequency == 0) { - ESP_LOGV(TAG, "Trying initialize channel %u with frequency %.1f and bit depth of %u...", this->channel_, + ESP_LOGV(TAG, "Initializing channel %u with frequency %.1f and bit depth of %u...", this->channel_, this->frequency_, this->bit_depth_); configured_frequency = ledcSetup(this->channel_, frequency, this->bit_depth_); if (configured_frequency != 0) { - initialized_ = true; + this->initialized_ = true; this->status_clear_error(); ESP_LOGV(TAG, "Configured frequency: %u with bit depth: %u", configured_frequency, this->bit_depth_); } else { @@ -236,14 +238,14 @@ void LEDCOutput::update_frequency(float frequency) { #endif // USE_ARDUINO #ifdef USE_ESP_IDF - if (!initialized_) { - ESP_LOGW(TAG, "LEDC output hasn't been initialized yet!"); + if (!this->initialized_) { + ESP_LOGW(TAG, "Not yet initialized"); return; } - auto speed_mode = get_speed_mode(channel_); - auto timer_num = static_cast((channel_ % 8) / 2); - auto chan_num = static_cast(channel_ % 8); + auto speed_mode = get_speed_mode(this->channel_); + auto timer_num = static_cast((this->channel_ % 8) / 2); + auto chan_num = static_cast(this->channel_ % 8); esp_err_t timer_init_result = configure_timer_frequency(speed_mode, timer_num, chan_num, this->channel_, this->bit_depth_, this->frequency_); diff --git a/esphome/components/light/light_state.cpp b/esphome/components/light/light_state.cpp index 16b78a17bd..0f8de7fac5 100644 --- a/esphome/components/light/light_state.cpp +++ b/esphome/components/light/light_state.cpp @@ -18,7 +18,7 @@ LightCall LightState::toggle() { return this->make_call().set_state(!this->remot LightCall LightState::make_call() { return LightCall(this); } void LightState::setup() { - ESP_LOGCONFIG(TAG, "Setting up light '%s'...", this->get_name().c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->get_name().c_str()); this->output_->setup_state(this); for (auto *effect : this->effects_) { diff --git a/esphome/components/lightwaverf/lightwaverf.cpp b/esphome/components/lightwaverf/lightwaverf.cpp index 89cbdae6e1..626e5747b7 100644 --- a/esphome/components/lightwaverf/lightwaverf.cpp +++ b/esphome/components/lightwaverf/lightwaverf.cpp @@ -14,7 +14,7 @@ static const bool DEFAULT_INVERT = false; static const uint32_t DEFAULT_TICK = 330; void LightWaveRF::setup() { - ESP_LOGCONFIG(TAG, "Setting up Lightwave RF..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->lwtx_.lwtx_setup(pin_tx_, DEFAULT_REPEAT, DEFAULT_INVERT, DEFAULT_TICK); this->lwrx_.lwrx_setup(pin_rx_); diff --git a/esphome/components/lilygo_t5_47/touchscreen/lilygo_t5_47_touchscreen.cpp b/esphome/components/lilygo_t5_47/touchscreen/lilygo_t5_47_touchscreen.cpp index 58f2a42812..c472a9f669 100644 --- a/esphome/components/lilygo_t5_47/touchscreen/lilygo_t5_47_touchscreen.cpp +++ b/esphome/components/lilygo_t5_47/touchscreen/lilygo_t5_47_touchscreen.cpp @@ -24,7 +24,7 @@ static const uint8_t READ_TOUCH[1] = {0x07}; } void LilygoT547Touchscreen::setup() { - ESP_LOGCONFIG(TAG, "Setting up Lilygo T5 4.7 Touchscreen..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->interrupt_pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP); this->interrupt_pin_->setup(); diff --git a/esphome/components/ltr390/ltr390.cpp b/esphome/components/ltr390/ltr390.cpp index 84b2eba2de..6e31fcdc42 100644 --- a/esphome/components/ltr390/ltr390.cpp +++ b/esphome/components/ltr390/ltr390.cpp @@ -148,7 +148,7 @@ void LTR390Component::read_mode_(int mode_index) { } void LTR390Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up ltr390..."); + ESP_LOGCONFIG(TAG, "Running setup"); // reset std::bitset<8> ctrl = this->reg(LTR390_MAIN_CTRL).get(); diff --git a/esphome/components/ltr501/ltr501.cpp b/esphome/components/ltr501/ltr501.cpp index b30e520f2b..9fbc3f3b13 100644 --- a/esphome/components/ltr501/ltr501.cpp +++ b/esphome/components/ltr501/ltr501.cpp @@ -74,7 +74,7 @@ static float get_ps_gain_coeff(PsGain501 gain) { } void LTRAlsPs501Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up LTR-501/301/558"); + ESP_LOGCONFIG(TAG, "Running setup"); // As per datasheet we need to wait at least 100ms after power on to get ALS chip responsive this->set_timeout(100, [this]() { this->state_ = State::DELAYED_SETUP; }); } @@ -113,7 +113,7 @@ void LTRAlsPs501Component::dump_config() { LOG_SENSOR(" ", "Actual gain", this->actual_gain_sensor_); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with I2C LTR-501/301/558 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } } diff --git a/esphome/components/ltr_als_ps/ltr_als_ps.cpp b/esphome/components/ltr_als_ps/ltr_als_ps.cpp index ae299c9b66..402fd1318b 100644 --- a/esphome/components/ltr_als_ps/ltr_als_ps.cpp +++ b/esphome/components/ltr_als_ps/ltr_als_ps.cpp @@ -63,7 +63,7 @@ static float get_ps_gain_coeff(PsGain gain) { } void LTRAlsPsComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up LTR-303/329/55x/659"); + ESP_LOGCONFIG(TAG, "Running setup"); // As per datasheet we need to wait at least 100ms after power on to get ALS chip responsive this->set_timeout(100, [this]() { this->state_ = State::DELAYED_SETUP; }); } @@ -105,7 +105,7 @@ void LTRAlsPsComponent::dump_config() { LOG_UPDATE_INTERVAL(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with I2C LTR-303/329/55x/659 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } } diff --git a/esphome/components/m5stack_8angle/m5stack_8angle.cpp b/esphome/components/m5stack_8angle/m5stack_8angle.cpp index 6a584eddbc..f08bb1214c 100644 --- a/esphome/components/m5stack_8angle/m5stack_8angle.cpp +++ b/esphome/components/m5stack_8angle/m5stack_8angle.cpp @@ -8,7 +8,7 @@ namespace m5stack_8angle { static const char *const TAG = "m5stack_8angle"; void M5Stack8AngleComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up M5STACK_8ANGLE..."); + ESP_LOGCONFIG(TAG, "Running setup"); i2c::ErrorCode err; err = this->read(nullptr, 0); diff --git a/esphome/components/max17043/max17043.cpp b/esphome/components/max17043/max17043.cpp index 4a83320455..dc61babc7e 100644 --- a/esphome/components/max17043/max17043.cpp +++ b/esphome/components/max17043/max17043.cpp @@ -41,7 +41,7 @@ void MAX17043Component::update() { } void MAX17043Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up MAX17043..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint16_t config_reg; if (this->write(&MAX17043_CONFIG, 1) != i2c::ERROR_OK) { @@ -76,7 +76,7 @@ void MAX17043Component::dump_config() { ESP_LOGCONFIG(TAG, "MAX17043:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with MAX17043 failed"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "Battery Voltage", this->voltage_sensor_); diff --git a/esphome/components/max31855/max31855.cpp b/esphome/components/max31855/max31855.cpp index 445e086ef6..e4ca94c5a5 100644 --- a/esphome/components/max31855/max31855.cpp +++ b/esphome/components/max31855/max31855.cpp @@ -19,7 +19,7 @@ void MAX31855Sensor::update() { } void MAX31855Sensor::setup() { - ESP_LOGCONFIG(TAG, "Setting up MAX31855Sensor '%s'...", this->name_.c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->name_.c_str()); this->spi_setup(); } void MAX31855Sensor::dump_config() { diff --git a/esphome/components/max31856/max31856.cpp b/esphome/components/max31856/max31856.cpp index 6a4d34b430..2eb4a7538e 100644 --- a/esphome/components/max31856/max31856.cpp +++ b/esphome/components/max31856/max31856.cpp @@ -11,7 +11,7 @@ static const char *const TAG = "max31856"; // Based on Adafruit's library: https://github.com/adafruit/Adafruit_MAX31856 void MAX31856Sensor::setup() { - ESP_LOGCONFIG(TAG, "Setting up MAX31856Sensor '%s'...", this->name_.c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->name_.c_str()); this->spi_setup(); // assert on any fault @@ -23,8 +23,6 @@ void MAX31856Sensor::setup() { this->set_thermocouple_type_(); this->set_noise_filter_(); - - ESP_LOGCONFIG(TAG, "Completed setting up MAX31856Sensor '%s'...", this->name_.c_str()); } void MAX31856Sensor::dump_config() { diff --git a/esphome/components/max31865/max31865.cpp b/esphome/components/max31865/max31865.cpp index 4749874ac7..ac41130a8e 100644 --- a/esphome/components/max31865/max31865.cpp +++ b/esphome/components/max31865/max31865.cpp @@ -65,7 +65,7 @@ void MAX31865Sensor::update() { } void MAX31865Sensor::setup() { - ESP_LOGCONFIG(TAG, "Setting up MAX31865Sensor '%s'...", this->name_.c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->name_.c_str()); this->spi_setup(); // Build base configuration diff --git a/esphome/components/max44009/max44009.cpp b/esphome/components/max44009/max44009.cpp index 6f12fb6583..6d1ce351d4 100644 --- a/esphome/components/max44009/max44009.cpp +++ b/esphome/components/max44009/max44009.cpp @@ -21,7 +21,7 @@ static const uint8_t MAX44009_ERROR_HIGH_BYTE = -30; static const uint8_t MAX44009_ERROR_LOW_BYTE = -31; void MAX44009Sensor::setup() { - ESP_LOGCONFIG(TAG, "Setting up MAX44009..."); + ESP_LOGCONFIG(TAG, "Running setup"); bool state_ok = false; if (this->mode_ == MAX44009Mode::MAX44009_MODE_LOW_POWER) { state_ok = this->set_low_power_mode(); @@ -48,7 +48,7 @@ void MAX44009Sensor::dump_config() { ESP_LOGCONFIG(TAG, "MAX44009:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with MAX44009 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } } diff --git a/esphome/components/max6675/max6675.cpp b/esphome/components/max6675/max6675.cpp index 1ec1d5ee53..a2881911f2 100644 --- a/esphome/components/max6675/max6675.cpp +++ b/esphome/components/max6675/max6675.cpp @@ -18,7 +18,7 @@ void MAX6675Sensor::update() { } void MAX6675Sensor::setup() { - ESP_LOGCONFIG(TAG, "Setting up MAX6675Sensor '%s'...", this->name_.c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->name_.c_str()); this->spi_setup(); } void MAX6675Sensor::dump_config() { diff --git a/esphome/components/max6956/max6956.cpp b/esphome/components/max6956/max6956.cpp index c2d9ba0175..3da4dcc43d 100644 --- a/esphome/components/max6956/max6956.cpp +++ b/esphome/components/max6956/max6956.cpp @@ -20,7 +20,7 @@ const uint8_t MASK_CURRENT_PIN = 0x0F; * MAX6956 * **************************************/ void MAX6956::setup() { - ESP_LOGCONFIG(TAG, "Setting up MAX6956..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t configuration; if (!this->read_reg_(MAX6956_CONFIGURATION, &configuration)) { this->mark_failed(); diff --git a/esphome/components/max7219/max7219.cpp b/esphome/components/max7219/max7219.cpp index d3cf6f5c48..64be13d621 100644 --- a/esphome/components/max7219/max7219.cpp +++ b/esphome/components/max7219/max7219.cpp @@ -116,7 +116,7 @@ const uint8_t MAX7219_ASCII_TO_RAW[95] PROGMEM = { float MAX7219Component::get_setup_priority() const { return setup_priority::PROCESSOR; } void MAX7219Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up MAX7219..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->spi_setup(); this->buffer_ = new uint8_t[this->num_chips_ * 8]; // NOLINT for (uint8_t i = 0; i < this->num_chips_ * 8; i++) diff --git a/esphome/components/max7219digit/max7219digit.cpp b/esphome/components/max7219digit/max7219digit.cpp index 154accd66f..a6c06b5213 100644 --- a/esphome/components/max7219digit/max7219digit.cpp +++ b/esphome/components/max7219digit/max7219digit.cpp @@ -26,7 +26,7 @@ constexpr uint8_t MAX7219_DISPLAY_TEST = 0x01; float MAX7219Component::get_setup_priority() const { return setup_priority::PROCESSOR; } void MAX7219Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up MAX7219_DIGITS..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->spi_setup(); this->stepsleft_ = 0; for (int chip_line = 0; chip_line < this->num_chip_lines_; chip_line++) { diff --git a/esphome/components/max9611/max9611.cpp b/esphome/components/max9611/max9611.cpp index 70a94c4ad9..ca081b9f16 100644 --- a/esphome/components/max9611/max9611.cpp +++ b/esphome/components/max9611/max9611.cpp @@ -29,8 +29,9 @@ static const uint8_t SETUP_DELAY = 4; // Wait 2 integration periods. static const float VOUT_LSB = 14.0 / 1000.0; // 14mV/LSB static const float TEMP_LSB = 0.48; // 0.48C/LSB static const float MICRO_VOLTS_PER_VOLT = 1000000.0; + void MAX9611Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up max9611..."); + ESP_LOGCONFIG(TAG, "Running setup"); // Perform dummy-read uint8_t value; this->read(&value, 1); diff --git a/esphome/components/mcp23008/mcp23008.cpp b/esphome/components/mcp23008/mcp23008.cpp index 24b9a63f48..b93bec9e79 100644 --- a/esphome/components/mcp23008/mcp23008.cpp +++ b/esphome/components/mcp23008/mcp23008.cpp @@ -7,7 +7,7 @@ namespace mcp23008 { static const char *const TAG = "mcp23008"; void MCP23008::setup() { - ESP_LOGCONFIG(TAG, "Setting up MCP23008..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t iocon; if (!this->read_reg(mcp23x08_base::MCP23X08_IOCON, &iocon)) { this->mark_failed(); diff --git a/esphome/components/mcp23016/mcp23016.cpp b/esphome/components/mcp23016/mcp23016.cpp index 70df0dfb7b..17647e9915 100644 --- a/esphome/components/mcp23016/mcp23016.cpp +++ b/esphome/components/mcp23016/mcp23016.cpp @@ -8,7 +8,7 @@ namespace mcp23016 { static const char *const TAG = "mcp23016"; void MCP23016::setup() { - ESP_LOGCONFIG(TAG, "Setting up MCP23016..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t iocon; if (!this->read_reg_(MCP23016_IOCON0, &iocon)) { this->mark_failed(); diff --git a/esphome/components/mcp23017/mcp23017.cpp b/esphome/components/mcp23017/mcp23017.cpp index b82e750eaf..5c0c2c4703 100644 --- a/esphome/components/mcp23017/mcp23017.cpp +++ b/esphome/components/mcp23017/mcp23017.cpp @@ -7,7 +7,7 @@ namespace mcp23017 { static const char *const TAG = "mcp23017"; void MCP23017::setup() { - ESP_LOGCONFIG(TAG, "Setting up MCP23017..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t iocon; if (!this->read_reg(mcp23x17_base::MCP23X17_IOCONA, &iocon)) { this->mark_failed(); diff --git a/esphome/components/mcp23s08/mcp23s08.cpp b/esphome/components/mcp23s08/mcp23s08.cpp index 2f885743de..671506c79d 100644 --- a/esphome/components/mcp23s08/mcp23s08.cpp +++ b/esphome/components/mcp23s08/mcp23s08.cpp @@ -13,7 +13,7 @@ void MCP23S08::set_device_address(uint8_t device_addr) { } void MCP23S08::setup() { - ESP_LOGCONFIG(TAG, "Setting up MCP23S08..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->spi_setup(); this->enable(); diff --git a/esphome/components/mcp23s17/mcp23s17.cpp b/esphome/components/mcp23s17/mcp23s17.cpp index ca4c28e0b4..1b922a8130 100644 --- a/esphome/components/mcp23s17/mcp23s17.cpp +++ b/esphome/components/mcp23s17/mcp23s17.cpp @@ -13,7 +13,7 @@ void MCP23S17::set_device_address(uint8_t device_addr) { } void MCP23S17::setup() { - ESP_LOGCONFIG(TAG, "Setting up MCP23S17..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->spi_setup(); this->enable(); diff --git a/esphome/components/mcp3008/mcp3008.cpp b/esphome/components/mcp3008/mcp3008.cpp index aed48456b2..fb9bda35d0 100644 --- a/esphome/components/mcp3008/mcp3008.cpp +++ b/esphome/components/mcp3008/mcp3008.cpp @@ -11,7 +11,7 @@ static const char *const TAG = "mcp3008"; float MCP3008::get_setup_priority() const { return setup_priority::HARDWARE; } void MCP3008::setup() { - ESP_LOGCONFIG(TAG, "Setting up mcp3008"); + ESP_LOGCONFIG(TAG, "Running setup"); this->spi_setup(); } diff --git a/esphome/components/mcp3204/mcp3204.cpp b/esphome/components/mcp3204/mcp3204.cpp index 283df4ccdc..1f956612d7 100644 --- a/esphome/components/mcp3204/mcp3204.cpp +++ b/esphome/components/mcp3204/mcp3204.cpp @@ -9,7 +9,7 @@ static const char *const TAG = "mcp3204"; float MCP3204::get_setup_priority() const { return setup_priority::HARDWARE; } void MCP3204::setup() { - ESP_LOGCONFIG(TAG, "Setting up mcp3204"); + ESP_LOGCONFIG(TAG, "Running setup"); this->spi_setup(); } diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index 5393241281..88e7475a76 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -10,7 +10,7 @@ static const char *const TAG = "mcp4461"; constexpr uint8_t EEPROM_WRITE_TIMEOUT_MS = 10; void Mcp4461Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up mcp4461 using address (0x%02X)...", this->address_); + ESP_LOGCONFIG(TAG, "Running setup for address 0x%02X", this->address_); auto err = this->write(nullptr, 0); if (err != i2c::ERROR_OK) { this->error_code_ = MCP4461_STATUS_I2C_ERROR; diff --git a/esphome/components/mcp4725/mcp4725.cpp b/esphome/components/mcp4725/mcp4725.cpp index 2cb19282b6..8b2f8524d8 100644 --- a/esphome/components/mcp4725/mcp4725.cpp +++ b/esphome/components/mcp4725/mcp4725.cpp @@ -7,7 +7,7 @@ namespace mcp4725 { static const char *const TAG = "mcp4725"; void MCP4725::setup() { - ESP_LOGCONFIG(TAG, "Setting up MCP4725 (0x%02X)...", this->address_); + ESP_LOGCONFIG(TAG, "Running setup for address 0x%02X", this->address_); auto err = this->write(nullptr, 0); if (err != i2c::ERROR_OK) { this->error_code_ = COMMUNICATION_FAILED; @@ -20,7 +20,7 @@ void MCP4725::dump_config() { LOG_I2C_DEVICE(this); if (this->error_code_ == COMMUNICATION_FAILED) { - ESP_LOGE(TAG, "Communication with MCP4725 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } } diff --git a/esphome/components/mcp4728/mcp4728.cpp b/esphome/components/mcp4728/mcp4728.cpp index 1a8568a21c..7b2b43d4d8 100644 --- a/esphome/components/mcp4728/mcp4728.cpp +++ b/esphome/components/mcp4728/mcp4728.cpp @@ -9,7 +9,7 @@ namespace mcp4728 { static const char *const TAG = "mcp4728"; void MCP4728Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up MCP4728 (0x%02X)...", this->address_); + ESP_LOGCONFIG(TAG, "Running setup for address 0x%02X", this->address_); auto err = this->write(nullptr, 0); if (err != i2c::ERROR_OK) { this->mark_failed(); @@ -21,7 +21,7 @@ void MCP4728Component::dump_config() { ESP_LOGCONFIG(TAG, "MCP4728:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with MCP4728 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } } diff --git a/esphome/components/mcp9600/mcp9600.cpp b/esphome/components/mcp9600/mcp9600.cpp index b56c838f78..16c19326f2 100644 --- a/esphome/components/mcp9600/mcp9600.cpp +++ b/esphome/components/mcp9600/mcp9600.cpp @@ -28,7 +28,7 @@ static const uint8_t MCP9600_REGISTER_ALERT4_LIMIT = 0x13; static const uint8_t MCP9600_REGISTER_DEVICE_ID = 0x20; void MCP9600Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up MCP9600..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint16_t dev_id = 0; this->read_byte_16(MCP9600_REGISTER_DEVICE_ID, &dev_id); diff --git a/esphome/components/mcp9808/mcp9808.cpp b/esphome/components/mcp9808/mcp9808.cpp index 626fcd540d..02ddc1aceb 100644 --- a/esphome/components/mcp9808/mcp9808.cpp +++ b/esphome/components/mcp9808/mcp9808.cpp @@ -18,18 +18,18 @@ static const uint8_t MCP9808_AMBIENT_TEMP_NEGATIVE = 0x10; static const char *const TAG = "mcp9808"; void MCP9808Sensor::setup() { - ESP_LOGCONFIG(TAG, "Setting up %s...", this->name_.c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->name_.c_str()); uint16_t manu = 0; if (!this->read_byte_16(MCP9808_REG_MANUF_ID, &manu) || manu != MCP9808_MANUF_ID) { this->mark_failed(); - ESP_LOGE(TAG, "%s manufacuturer id failed, device returned %X", this->name_.c_str(), manu); + ESP_LOGE(TAG, "Incorrect manufacturer ID (%X) for '%s'", manu, this->name_.c_str()); return; } uint16_t dev_id = 0; if (!this->read_byte_16(MCP9808_REG_DEVICE_ID, &dev_id) || dev_id != MCP9808_DEV_ID) { this->mark_failed(); - ESP_LOGE(TAG, "%s device id failed, device returned %X", this->name_.c_str(), dev_id); + ESP_LOGE(TAG, "Incorrect device ID (%X) for '%s'", dev_id, this->name_.c_str()); return; } } @@ -37,7 +37,7 @@ void MCP9808Sensor::dump_config() { ESP_LOGCONFIG(TAG, "%s:", this->name_.c_str()); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with %s failed!", this->name_.c_str()); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL_FOR, this->name_.c_str()); } LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "Temperature", this); diff --git a/esphome/components/mdns/mdns_esp32.cpp b/esphome/components/mdns/mdns_esp32.cpp index fed18d3630..ffd86afec1 100644 --- a/esphome/components/mdns/mdns_esp32.cpp +++ b/esphome/components/mdns/mdns_esp32.cpp @@ -17,7 +17,7 @@ void MDNSComponent::setup() { esp_err_t err = mdns_init(); if (err != ESP_OK) { - ESP_LOGW(TAG, "mDNS init failed: %s", esp_err_to_name(err)); + ESP_LOGW(TAG, "Init failed: %s", esp_err_to_name(err)); this->mark_failed(); return; } @@ -45,7 +45,7 @@ void MDNSComponent::setup() { } if (err != ESP_OK) { - ESP_LOGW(TAG, "Failed to register mDNS service %s: %s", service.service_type.c_str(), esp_err_to_name(err)); + ESP_LOGW(TAG, "Failed to register service %s: %s", service.service_type.c_str(), esp_err_to_name(err)); } } } diff --git a/esphome/components/micro_wake_word/micro_wake_word.cpp b/esphome/components/micro_wake_word/micro_wake_word.cpp index a44348fdc9..201d956a37 100644 --- a/esphome/components/micro_wake_word/micro_wake_word.cpp +++ b/esphome/components/micro_wake_word/micro_wake_word.cpp @@ -72,7 +72,7 @@ void MicroWakeWord::dump_config() { } void MicroWakeWord::setup() { - ESP_LOGCONFIG(TAG, "Setting up microWakeWord..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->frontend_config_.window.size_ms = FEATURE_DURATION_MS; this->frontend_config_.window.step_size_ms = this->features_step_size_; diff --git a/esphome/components/mics_4514/mics_4514.cpp b/esphome/components/mics_4514/mics_4514.cpp index ed2fc6c826..5fab97d57a 100644 --- a/esphome/components/mics_4514/mics_4514.cpp +++ b/esphome/components/mics_4514/mics_4514.cpp @@ -12,7 +12,7 @@ static const uint8_t SENSOR_REGISTER = 0x04; static const uint8_t POWER_MODE_REGISTER = 0x0a; void MICS4514Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up MICS 4514..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t power_mode; this->read_register(POWER_MODE_REGISTER, &power_mode, 1); if (power_mode == 0x00) { diff --git a/esphome/components/mipi_spi/mipi_spi.cpp b/esphome/components/mipi_spi/mipi_spi.cpp index 2d393ac349..043346411e 100644 --- a/esphome/components/mipi_spi/mipi_spi.cpp +++ b/esphome/components/mipi_spi/mipi_spi.cpp @@ -5,7 +5,7 @@ namespace esphome { namespace mipi_spi { void MipiSpi::setup() { - ESP_LOGCONFIG(TAG, "Setting up MIPI SPI"); + ESP_LOGCONFIG(TAG, "Running setup"); this->spi_setup(); if (this->dc_pin_ != nullptr) { this->dc_pin_->setup(); diff --git a/esphome/components/mlx90393/sensor_mlx90393.cpp b/esphome/components/mlx90393/sensor_mlx90393.cpp index 46fe68fab0..96749cd378 100644 --- a/esphome/components/mlx90393/sensor_mlx90393.cpp +++ b/esphome/components/mlx90393/sensor_mlx90393.cpp @@ -103,7 +103,7 @@ bool MLX90393Cls::apply_all_settings_() { } void MLX90393Cls::setup() { - ESP_LOGCONFIG(TAG, "Setting up MLX90393..."); + ESP_LOGCONFIG(TAG, "Running setup"); // note the two arguments A0 and A1 which are used to construct an i2c address // we can hard-code these because we never actually use the constructed address // see the transceive function above, which uses the address from I2CComponent @@ -122,7 +122,7 @@ void MLX90393Cls::dump_config() { LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with MLX90393 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); return; } LOG_UPDATE_INTERVAL(this); diff --git a/esphome/components/mlx90614/mlx90614.cpp b/esphome/components/mlx90614/mlx90614.cpp index f681f3cc7e..97888b59bd 100644 --- a/esphome/components/mlx90614/mlx90614.cpp +++ b/esphome/components/mlx90614/mlx90614.cpp @@ -27,9 +27,9 @@ static const uint8_t MLX90614_ID4 = 0x3F; static const char *const TAG = "mlx90614"; void MLX90614Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up MLX90614..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (!this->write_emissivity_()) { - ESP_LOGE(TAG, "Communication with MLX90614 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); this->mark_failed(); return; } @@ -79,7 +79,7 @@ void MLX90614Component::dump_config() { ESP_LOGCONFIG(TAG, "MLX90614:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with MLX90614 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "Ambient", this->ambient_sensor_); diff --git a/esphome/components/mmc5603/mmc5603.cpp b/esphome/components/mmc5603/mmc5603.cpp index 6fbf4810f2..86b1b23c15 100644 --- a/esphome/components/mmc5603/mmc5603.cpp +++ b/esphome/components/mmc5603/mmc5603.cpp @@ -31,7 +31,7 @@ static const uint8_t MMC56X3_CTRL2_REG = 0x1D; static const uint8_t MMC5603_ODR_REG = 0x1A; void MMC5603Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up MMC5603..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t id = 0; if (!this->read_byte(MMC56X3_PRODUCT_ID, &id)) { this->error_code_ = COMMUNICATION_FAILED; @@ -79,7 +79,7 @@ void MMC5603Component::dump_config() { ESP_LOGCONFIG(TAG, "MMC5603:"); LOG_I2C_DEVICE(this); if (this->error_code_ == COMMUNICATION_FAILED) { - ESP_LOGE(TAG, "Communication with MMC5603 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 MMC5603?"); } diff --git a/esphome/components/mmc5983/mmc5983.cpp b/esphome/components/mmc5983/mmc5983.cpp index 5b045ae38b..d5394da618 100644 --- a/esphome/components/mmc5983/mmc5983.cpp +++ b/esphome/components/mmc5983/mmc5983.cpp @@ -67,7 +67,7 @@ void MMC5983Component::update() { } void MMC5983Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up MMC5983..."); + ESP_LOGCONFIG(TAG, "Running setup"); // Verify product id. const uint8_t mmc5983_product_id = 0x30; diff --git a/esphome/components/modbus/modbus.cpp b/esphome/components/modbus/modbus.cpp index 80c2ffe3d6..cd5fc55689 100644 --- a/esphome/components/modbus/modbus.cpp +++ b/esphome/components/modbus/modbus.cpp @@ -90,7 +90,7 @@ bool Modbus::parse_modbus_byte_(uint8_t byte) { } else { // data starts at 2 and length is 4 for read registers commands - if (this->role == ModbusRole::SERVER && (function_code == 0x3 || function_code == 0x4)) { + if (this->role == ModbusRole::SERVER && (function_code == 0x1 || function_code == 0x3 || function_code == 0x4)) { data_offset = 2; data_len = 4; } diff --git a/esphome/components/mpl3115a2/mpl3115a2.cpp b/esphome/components/mpl3115a2/mpl3115a2.cpp index f1e553e107..d415b77294 100644 --- a/esphome/components/mpl3115a2/mpl3115a2.cpp +++ b/esphome/components/mpl3115a2/mpl3115a2.cpp @@ -8,7 +8,7 @@ namespace mpl3115a2 { static const char *const TAG = "mpl3115a2"; void MPL3115A2Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up MPL3115A2..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t whoami = 0xFF; if (!this->read_byte(MPL3115A2_WHOAMI, &whoami, false)) { @@ -37,7 +37,7 @@ void MPL3115A2Component::dump_config() { if (this->is_failed()) { switch (this->error_code_) { case COMMUNICATION_FAILED: - ESP_LOGE(TAG, "Communication with MPL3115A2 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); break; case WRONG_ID: ESP_LOGE(TAG, "MPL3115A2 has invalid id"); diff --git a/esphome/components/mpr121/mpr121.cpp b/esphome/components/mpr121/mpr121.cpp index de364c59ff..39c45d7a89 100644 --- a/esphome/components/mpr121/mpr121.cpp +++ b/esphome/components/mpr121/mpr121.cpp @@ -11,7 +11,7 @@ namespace mpr121 { static const char *const TAG = "mpr121"; void MPR121Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up MPR121..."); + ESP_LOGCONFIG(TAG, "Running setup"); // soft reset device this->write_byte(MPR121_SOFTRESET, 0x63); delay(100); // NOLINT @@ -72,7 +72,7 @@ void MPR121Component::dump_config() { LOG_I2C_DEVICE(this); switch (this->error_code_) { case COMMUNICATION_FAILED: - ESP_LOGE(TAG, "Communication with MPR121 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); break; case WRONG_CHIP_STATE: ESP_LOGE(TAG, "MPR121 has wrong default value for CONFIG2?"); diff --git a/esphome/components/mpu6050/mpu6050.cpp b/esphome/components/mpu6050/mpu6050.cpp index 64fcd3a2a8..127d84e816 100644 --- a/esphome/components/mpu6050/mpu6050.cpp +++ b/esphome/components/mpu6050/mpu6050.cpp @@ -21,7 +21,7 @@ const uint8_t MPU6050_BIT_TEMPERATURE_DISABLED = 3; const float GRAVITY_EARTH = 9.80665f; void MPU6050Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up MPU6050..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t who_am_i; if (!this->read_byte(MPU6050_REGISTER_WHO_AM_I, &who_am_i) || (who_am_i != 0x68 && who_am_i != 0x70 && who_am_i != 0x98)) { @@ -86,7 +86,7 @@ void MPU6050Component::dump_config() { ESP_LOGCONFIG(TAG, "MPU6050:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with MPU6050 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "Acceleration X", this->accel_x_sensor_); diff --git a/esphome/components/mpu6886/mpu6886.cpp b/esphome/components/mpu6886/mpu6886.cpp index c296653e6b..8f3adeed8d 100644 --- a/esphome/components/mpu6886/mpu6886.cpp +++ b/esphome/components/mpu6886/mpu6886.cpp @@ -26,7 +26,7 @@ const float TEMPERATURE_SENSITIVITY = 326.8; const float TEMPERATURE_OFFSET = 25.0; void MPU6886Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up MPU6886..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t who_am_i; if (!this->read_byte(MPU6886_REGISTER_WHO_AM_I, &who_am_i) || who_am_i != MPU6886_WHO_AM_I_IDENTIFIER) { this->mark_failed(); @@ -91,7 +91,7 @@ void MPU6886Component::dump_config() { ESP_LOGCONFIG(TAG, "MPU6886:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with MPU6886 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "Acceleration X", this->accel_x_sensor_); diff --git a/esphome/components/mqtt/mqtt_client.cpp b/esphome/components/mqtt/mqtt_client.cpp index e3722099a7..f95096106f 100644 --- a/esphome/components/mqtt/mqtt_client.cpp +++ b/esphome/components/mqtt/mqtt_client.cpp @@ -34,7 +34,7 @@ MQTTClientComponent::MQTTClientComponent() { // Connection void MQTTClientComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up MQTT..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->mqtt_backend_.set_on_message( [this](const char *topic, const char *payload, size_t len, size_t index, size_t total) { if (index == 0) diff --git a/esphome/components/ms5611/ms5611.cpp b/esphome/components/ms5611/ms5611.cpp index 4b34e1d71a..7a820f3b5a 100644 --- a/esphome/components/ms5611/ms5611.cpp +++ b/esphome/components/ms5611/ms5611.cpp @@ -15,7 +15,7 @@ static const uint8_t MS5611_CMD_CONV_D2 = 0x50; static const uint8_t MS5611_CMD_READ_PROM = 0xA2; void MS5611Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up MS5611..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (!this->write_bytes(MS5611_CMD_RESET, nullptr, 0)) { this->mark_failed(); return; @@ -32,7 +32,7 @@ void MS5611Component::dump_config() { ESP_LOGCONFIG(TAG, "MS5611:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with MS5611 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "Temperature", this->temperature_sensor_); diff --git a/esphome/components/ms8607/ms8607.cpp b/esphome/components/ms8607/ms8607.cpp index 4ad6ac336d..b985623b24 100644 --- a/esphome/components/ms8607/ms8607.cpp +++ b/esphome/components/ms8607/ms8607.cpp @@ -67,7 +67,7 @@ static uint8_t crc4(uint16_t *buffer, size_t length); static uint8_t hsensor_crc_check(uint16_t value); void MS8607Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up MS8607..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->error_code_ = ErrorCode::NONE; this->setup_status_ = SetupStatus::NEEDS_RESET; @@ -140,7 +140,7 @@ void MS8607Component::dump_config() { // LOG_I2C_DEVICE doesn't work for humidity, the `address_` is protected. Log using get_address() ESP_LOGCONFIG(TAG, " Address: 0x%02X", this->humidity_device_->get_address()); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with MS8607 failed."); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); switch (this->error_code_) { case ErrorCode::PT_RESET_FAILED: ESP_LOGE(TAG, "Temperature/Pressure RESET failed"); diff --git a/esphome/components/msa3xx/msa3xx.cpp b/esphome/components/msa3xx/msa3xx.cpp index 8ecb319955..75aa139e88 100644 --- a/esphome/components/msa3xx/msa3xx.cpp +++ b/esphome/components/msa3xx/msa3xx.cpp @@ -118,7 +118,7 @@ const char *orientation_xy_to_string(OrientationXY orientation) { const char *orientation_z_to_string(bool orientation) { return orientation ? "Downwards looking" : "Upwards looking"; } void MSA3xxComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up MSA3xx..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t part_id{0xff}; if (!this->read_byte(static_cast(RegisterMap::PART_ID), &part_id) || (part_id != MSA_3XX_PART_ID)) { @@ -159,7 +159,7 @@ void MSA3xxComponent::dump_config() { ESP_LOGCONFIG(TAG, "MSA3xx:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with MSA3xx failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } ESP_LOGCONFIG(TAG, " Model: %s", model_to_string(this->model_)); ESP_LOGCONFIG(TAG, " Power Mode: %s", power_mode_to_string(this->power_mode_)); diff --git a/esphome/components/my9231/my9231.cpp b/esphome/components/my9231/my9231.cpp index c511591856..5edaa83c38 100644 --- a/esphome/components/my9231/my9231.cpp +++ b/esphome/components/my9231/my9231.cpp @@ -28,7 +28,7 @@ static const uint8_t MY9231_CMD_SCATTER_APDM = 0x0 << 0; static const uint8_t MY9231_CMD_SCATTER_PWM = 0x1 << 0; void MY9231OutputComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up MY9231OutputComponent..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->pin_di_->setup(); this->pin_di_->digital_write(false); this->pin_dcki_->setup(); diff --git a/esphome/components/nau7802/nau7802.cpp b/esphome/components/nau7802/nau7802.cpp index d7149e5697..fa4c4b64a1 100644 --- a/esphome/components/nau7802/nau7802.cpp +++ b/esphome/components/nau7802/nau7802.cpp @@ -52,8 +52,8 @@ static const uint8_t POWER_PGA_CAP_EN = 0x80; static const uint8_t DEVICE_REV = 0x1F; void NAU7802Sensor::setup() { + ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->name_.c_str()); i2c::I2CRegister pu_ctrl = this->reg(PU_CTRL_REG); - ESP_LOGCONFIG(TAG, "Setting up NAU7802 '%s'...", this->name_.c_str()); uint8_t rev; if (this->read_register(DEVICE_REV | READ_BIT, &rev, 1)) { @@ -127,7 +127,7 @@ void NAU7802Sensor::dump_config() { LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with NAU7802 failed earlier, during setup"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL_FOR, this->get_name().c_str()); return; } // Note these may differ from the values on the device if calbration has been run diff --git a/esphome/components/npi19/npi19.cpp b/esphome/components/npi19/npi19.cpp index ca1fc39943..3da5a9dbf8 100644 --- a/esphome/components/npi19/npi19.cpp +++ b/esphome/components/npi19/npi19.cpp @@ -11,18 +11,16 @@ static const char *const TAG = "npi19"; static const uint8_t READ_COMMAND = 0xAC; void NPI19Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up NPI19..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint16_t raw_temperature(0); uint16_t raw_pressure(0); i2c::ErrorCode err = this->read_(raw_temperature, raw_pressure); if (err != i2c::ERROR_OK) { - ESP_LOGCONFIG(TAG, " I2C Communication Failed..."); + ESP_LOGCONFIG(TAG, ESP_LOG_MSG_COMM_FAIL); this->mark_failed(); return; } - - ESP_LOGCONFIG(TAG, " Success..."); } void NPI19Component::dump_config() { @@ -90,7 +88,7 @@ void NPI19Component::update() { i2c::ErrorCode err = this->read_(raw_temperature, raw_pressure); if (err != i2c::ERROR_OK) { - ESP_LOGW(TAG, "I2C Communication Failed"); + ESP_LOGW(TAG, ESP_LOG_MSG_COMM_FAIL); this->status_set_warning(); return; } diff --git a/esphome/components/online_image/__init__.py b/esphome/components/online_image/__init__.py index 55b9037176..7ef80ff92f 100644 --- a/esphome/components/online_image/__init__.py +++ b/esphome/components/online_image/__init__.py @@ -213,7 +213,7 @@ async def to_code(config): for conf in config.get(CONF_ON_DOWNLOAD_FINISHED, []): trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var) - await automation.build_automation(trigger, [], conf) + await automation.build_automation(trigger, [(bool, "cached")], conf) for conf in config.get(CONF_ON_ERROR, []): trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var) diff --git a/esphome/components/online_image/online_image.cpp b/esphome/components/online_image/online_image.cpp index cb4a3be9e8..5c0ffc1cb2 100644 --- a/esphome/components/online_image/online_image.cpp +++ b/esphome/components/online_image/online_image.cpp @@ -3,6 +3,10 @@ #include "esphome/core/log.h" static const char *const TAG = "online_image"; +static const char *const ETAG_HEADER_NAME = "etag"; +static const char *const IF_NONE_MATCH_HEADER_NAME = "if-none-match"; +static const char *const LAST_MODIFIED_HEADER_NAME = "last-modified"; +static const char *const IF_MODIFIED_SINCE_HEADER_NAME = "if-modified-since"; #include "image_decoder.h" @@ -60,6 +64,8 @@ void OnlineImage::release() { this->height_ = 0; this->buffer_width_ = 0; this->buffer_height_ = 0; + this->last_modified_ = ""; + this->etag_ = ""; this->end_connection_(); } } @@ -127,9 +133,17 @@ void OnlineImage::update() { } accept_header.value = accept_mime_type + ",*/*;q=0.8"; + if (!this->etag_.empty()) { + headers.push_back(http_request::Header{IF_NONE_MATCH_HEADER_NAME, this->etag_}); + } + + if (!this->last_modified_.empty()) { + headers.push_back(http_request::Header{IF_MODIFIED_SINCE_HEADER_NAME, this->last_modified_}); + } + headers.push_back(accept_header); - this->downloader_ = this->parent_->get(this->url_, headers); + this->downloader_ = this->parent_->get(this->url_, headers, {ETAG_HEADER_NAME, LAST_MODIFIED_HEADER_NAME}); if (this->downloader_ == nullptr) { ESP_LOGE(TAG, "Download failed."); @@ -141,7 +155,9 @@ void OnlineImage::update() { int http_code = this->downloader_->status_code; if (http_code == HTTP_CODE_NOT_MODIFIED) { // Image hasn't changed on server. Skip download. + ESP_LOGI(TAG, "Server returned HTTP 304 (Not Modified). Download skipped."); this->end_connection_(); + this->download_finished_callback_.call(true); return; } if (http_code != HTTP_CODE_OK) { @@ -201,8 +217,10 @@ void OnlineImage::loop() { ESP_LOGD(TAG, "Image fully downloaded, read %zu bytes, width/height = %d/%d", this->downloader_->get_bytes_read(), this->width_, this->height_); ESP_LOGD(TAG, "Total time: %lds", ::time(nullptr) - this->start_time_); + this->etag_ = this->downloader_->get_response_header(ETAG_HEADER_NAME); + this->last_modified_ = this->downloader_->get_response_header(LAST_MODIFIED_HEADER_NAME); + this->download_finished_callback_.call(false); this->end_connection_(); - this->download_finished_callback_.call(); return; } if (this->downloader_ == nullptr) { @@ -325,7 +343,7 @@ bool OnlineImage::validate_url_(const std::string &url) { return true; } -void OnlineImage::add_on_finished_callback(std::function &&callback) { +void OnlineImage::add_on_finished_callback(std::function &&callback) { this->download_finished_callback_.add(std::move(callback)); } diff --git a/esphome/components/online_image/online_image.h b/esphome/components/online_image/online_image.h index 2d10e528b1..920aee2796 100644 --- a/esphome/components/online_image/online_image.h +++ b/esphome/components/online_image/online_image.h @@ -63,6 +63,8 @@ class OnlineImage : public PollingComponent, if (this->validate_url_(url)) { this->url_ = url; } + this->etag_ = ""; + this->last_modified_ = ""; } /** @@ -86,7 +88,7 @@ class OnlineImage : public PollingComponent, */ size_t resize_download_buffer(size_t size) { return this->download_buffer_.resize(size); } - void add_on_finished_callback(std::function &&callback); + void add_on_finished_callback(std::function &&callback); void add_on_error_callback(std::function &&callback); protected: @@ -131,7 +133,7 @@ class OnlineImage : public PollingComponent, void end_connection_(); - CallbackManager download_finished_callback_{}; + CallbackManager download_finished_callback_{}; CallbackManager download_error_callback_{}; std::shared_ptr downloader_{nullptr}; @@ -173,6 +175,14 @@ class OnlineImage : public PollingComponent, * decoded images). */ int buffer_height_; + /** + * The value of the ETag HTTP header provided in the last response. + */ + std::string etag_ = ""; + /** + * The value of the Last-Modified HTTP header provided in the last response. + */ + std::string last_modified_ = ""; time_t start_time_; @@ -202,10 +212,10 @@ template class OnlineImageReleaseAction : public Action { OnlineImage *parent_; }; -class DownloadFinishedTrigger : public Trigger<> { +class DownloadFinishedTrigger : public Trigger { public: explicit DownloadFinishedTrigger(OnlineImage *parent) { - parent->add_on_finished_callback([this]() { this->trigger(); }); + parent->add_on_finished_callback([this](bool cached) { this->trigger(cached); }); } }; diff --git a/esphome/components/output/switch/output_switch.cpp b/esphome/components/output/switch/output_switch.cpp index 0e045d18b4..c30cfd3f56 100644 --- a/esphome/components/output/switch/output_switch.cpp +++ b/esphome/components/output/switch/output_switch.cpp @@ -8,7 +8,7 @@ static const char *const TAG = "output.switch"; void OutputSwitch::dump_config() { LOG_SWITCH("", "Output Switch", this); } void OutputSwitch::setup() { - ESP_LOGCONFIG(TAG, "Setting up Output Switch '%s'...", this->name_.c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->name_.c_str()); bool initial_state = this->get_initial_state_with_restore_mode().value_or(false); diff --git a/esphome/components/pca6416a/pca6416a.cpp b/esphome/components/pca6416a/pca6416a.cpp index 53c0dcaf76..3e76df5015 100644 --- a/esphome/components/pca6416a/pca6416a.cpp +++ b/esphome/components/pca6416a/pca6416a.cpp @@ -24,7 +24,7 @@ enum PCA6416AGPIORegisters { static const char *const TAG = "pca6416a"; void PCA6416AComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up PCA6416A..."); + ESP_LOGCONFIG(TAG, "Running setup"); // Test to see if device exists uint8_t value; if (!this->read_register_(PCA6416A_INPUT0, &value)) { @@ -60,7 +60,7 @@ void PCA6416AComponent::dump_config() { } LOG_I2C_DEVICE(this) if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with PCA6416A failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } } diff --git a/esphome/components/pca9554/pca9554.cpp b/esphome/components/pca9554/pca9554.cpp index 78b877072a..fe4375c171 100644 --- a/esphome/components/pca9554/pca9554.cpp +++ b/esphome/components/pca9554/pca9554.cpp @@ -13,7 +13,7 @@ const uint8_t CONFIG_REG = 3; static const char *const TAG = "pca9554"; void PCA9554Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up PCA9554/PCA9554A..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->reg_width_ = (this->pin_count_ + 7) / 8; // Test to see if device exists if (!this->read_inputs_()) { @@ -49,7 +49,7 @@ void PCA9554Component::dump_config() { ESP_LOGCONFIG(TAG, " I/O Pins: %d", this->pin_count_); LOG_I2C_DEVICE(this) if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with PCA9554 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } } diff --git a/esphome/components/pca9685/pca9685_output.cpp b/esphome/components/pca9685/pca9685_output.cpp index 1998f8d12f..504adc43ff 100644 --- a/esphome/components/pca9685/pca9685_output.cpp +++ b/esphome/components/pca9685/pca9685_output.cpp @@ -26,7 +26,7 @@ static const uint8_t PCA9685_MODE1_AUTOINC = 0b00100000; static const uint8_t PCA9685_MODE1_SLEEP = 0b00010000; void PCA9685Output::setup() { - ESP_LOGCONFIG(TAG, "Setting up PCA9685OutputComponent..."); + ESP_LOGCONFIG(TAG, "Running setup"); ESP_LOGV(TAG, " Resetting devices..."); if (!this->write_bytes(PCA9685_REGISTER_SOFTWARE_RESET, nullptr, 0)) { diff --git a/esphome/components/pcf85063/pcf85063.cpp b/esphome/components/pcf85063/pcf85063.cpp index debc007cb8..d58d35019b 100644 --- a/esphome/components/pcf85063/pcf85063.cpp +++ b/esphome/components/pcf85063/pcf85063.cpp @@ -10,7 +10,7 @@ namespace pcf85063 { static const char *const TAG = "pcf85063"; void PCF85063Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up PCF85063..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (!this->read_rtc_()) { this->mark_failed(); } @@ -22,7 +22,7 @@ void PCF85063Component::dump_config() { ESP_LOGCONFIG(TAG, "PCF85063:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with PCF85063 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } ESP_LOGCONFIG(TAG, " Timezone: '%s'", this->timezone_.c_str()); } diff --git a/esphome/components/pcf8563/pcf8563.cpp b/esphome/components/pcf8563/pcf8563.cpp index f2a82735c5..7dd7a6fea8 100644 --- a/esphome/components/pcf8563/pcf8563.cpp +++ b/esphome/components/pcf8563/pcf8563.cpp @@ -10,7 +10,7 @@ namespace pcf8563 { static const char *const TAG = "PCF8563"; void PCF8563Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up PCF8563..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (!this->read_rtc_()) { this->mark_failed(); } @@ -22,7 +22,7 @@ void PCF8563Component::dump_config() { ESP_LOGCONFIG(TAG, "PCF8563:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with PCF8563 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } ESP_LOGCONFIG(TAG, " Timezone: '%s'", this->timezone_.c_str()); } diff --git a/esphome/components/pcf8574/pcf8574.cpp b/esphome/components/pcf8574/pcf8574.cpp index 6eaf73e8da..dbab0319d7 100644 --- a/esphome/components/pcf8574/pcf8574.cpp +++ b/esphome/components/pcf8574/pcf8574.cpp @@ -7,7 +7,7 @@ namespace pcf8574 { static const char *const TAG = "pcf8574"; void PCF8574Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up PCF8574..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (!this->read_gpio_()) { ESP_LOGE(TAG, "PCF8574 not available under 0x%02X", this->address_); this->mark_failed(); @@ -22,7 +22,7 @@ void PCF8574Component::dump_config() { LOG_I2C_DEVICE(this) ESP_LOGCONFIG(TAG, " Is PCF8575: %s", YESNO(this->pcf8575_)); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with PCF8574 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } } bool PCF8574Component::digital_read(uint8_t pin) { diff --git a/esphome/components/pm1006/pm1006.cpp b/esphome/components/pm1006/pm1006.cpp index 1a89307eee..f28c647721 100644 --- a/esphome/components/pm1006/pm1006.cpp +++ b/esphome/components/pm1006/pm1006.cpp @@ -55,8 +55,8 @@ uint8_t PM1006Component::pm1006_checksum_(const uint8_t *command_data, uint8_t l } optional PM1006Component::check_byte_() const { - uint8_t index = this->data_index_; - uint8_t byte = this->data_[index]; + const uint8_t index = this->data_index_; + const uint8_t byte = this->data_[index]; // index 0..2 are the fixed header if (index < sizeof(PM1006_RESPONSE_HEADER)) { @@ -86,7 +86,7 @@ optional PM1006Component::check_byte_() const { } void PM1006Component::parse_data_() { - const int pm_2_5_concentration = this->get_16_bit_uint_(5); + const uint16_t pm_2_5_concentration = this->get_16_bit_uint_(5); ESP_LOGD(TAG, "Got PM2.5 Concentration: %d µg/m³", pm_2_5_concentration); diff --git a/esphome/components/pm2005/pm2005.cpp b/esphome/components/pm2005/pm2005.cpp index 38847210fd..4b00cd6f2e 100644 --- a/esphome/components/pm2005/pm2005.cpp +++ b/esphome/components/pm2005/pm2005.cpp @@ -39,17 +39,14 @@ static const LogString *pm2005_get_measuring_mode_string(int status) { static inline uint16_t get_sensor_value(const uint8_t *data, uint8_t i) { return data[i] * 0x100 + data[i + 1]; } void PM2005Component::setup() { + ESP_LOGCONFIG(TAG, "Running setup"); if (this->sensor_type_ == PM2005) { - ESP_LOGCONFIG(TAG, "Setting up PM2005..."); - this->situation_value_index_ = 3; this->pm_1_0_value_index_ = 4; this->pm_2_5_value_index_ = 6; this->pm_10_0_value_index_ = 8; this->measuring_value_index_ = 10; } else { - ESP_LOGCONFIG(TAG, "Setting up PM2105..."); - this->situation_value_index_ = 2; this->pm_1_0_value_index_ = 3; this->pm_2_5_value_index_ = 5; @@ -58,7 +55,7 @@ void PM2005Component::setup() { } if (this->read(this->data_buffer_, 12) != i2c::ERROR_OK) { - ESP_LOGE(TAG, "Communication failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); this->mark_failed(); return; } @@ -66,7 +63,7 @@ void PM2005Component::setup() { void PM2005Component::update() { if (this->read(this->data_buffer_, 12) != i2c::ERROR_OK) { - ESP_LOGW(TAG, "Read result failed."); + ESP_LOGW(TAG, "Read result failed"); this->status_set_warning(); return; } @@ -85,10 +82,10 @@ void PM2005Component::update() { return; } - uint16_t pm1 = get_sensor_value(this->data_buffer_, this->pm_1_0_value_index_); - uint16_t pm25 = get_sensor_value(this->data_buffer_, this->pm_2_5_value_index_); - uint16_t pm10 = get_sensor_value(this->data_buffer_, this->pm_10_0_value_index_); - uint16_t sensor_measuring_mode = get_sensor_value(this->data_buffer_, this->measuring_value_index_); + const uint16_t pm1 = get_sensor_value(this->data_buffer_, this->pm_1_0_value_index_); + const uint16_t pm25 = get_sensor_value(this->data_buffer_, this->pm_2_5_value_index_); + const uint16_t pm10 = get_sensor_value(this->data_buffer_, this->pm_10_0_value_index_); + const uint16_t sensor_measuring_mode = get_sensor_value(this->data_buffer_, this->measuring_value_index_); ESP_LOGD(TAG, "PM1.0: %d, PM2.5: %d, PM10: %d, Measuring mode: %s.", pm1, pm25, pm10, LOG_STR_ARG(pm2005_get_measuring_mode_string(sensor_measuring_mode))); @@ -111,7 +108,7 @@ void PM2005Component::dump_config() { LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with PM2%u05 failed!", this->sensor_type_ == PM2105); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_SENSOR(" ", "PM1.0", this->pm_1_0_sensor_); diff --git a/esphome/components/pm2005/sensor.py b/esphome/components/pm2005/sensor.py index 66f630f8ff..3a650560a0 100644 --- a/esphome/components/pm2005/sensor.py +++ b/esphome/components/pm2005/sensor.py @@ -1,8 +1,8 @@ """PM2005/2105 Sensor component for ESPHome.""" import esphome.codegen as cg -import esphome.config_validation as cv from esphome.components import i2c, sensor +import esphome.config_validation as cv from esphome.const import ( CONF_ID, CONF_PM_1_0, diff --git a/esphome/components/pmsa003i/pmsa003i.cpp b/esphome/components/pmsa003i/pmsa003i.cpp index 36f9c9a132..3a5473d759 100644 --- a/esphome/components/pmsa003i/pmsa003i.cpp +++ b/esphome/components/pmsa003i/pmsa003i.cpp @@ -19,7 +19,7 @@ static const uint8_t START_CHARACTER_2 = 0x4D; static const uint8_t READ_DATA_RETRY_COUNT = 3; void PMSA003IComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up pmsa003i..."); + ESP_LOGCONFIG(TAG, "Running setup"); PM25AQIData data; bool successful_read = this->read_data_(&data); diff --git a/esphome/components/pmwcs3/pmwcs3.cpp b/esphome/components/pmwcs3/pmwcs3.cpp index 97ce4c9ae0..95638851b5 100644 --- a/esphome/components/pmwcs3/pmwcs3.cpp +++ b/esphome/components/pmwcs3/pmwcs3.cpp @@ -26,33 +26,31 @@ static const char *const TAG = "pmwcs3"; void PMWCS3Component::new_i2c_address(uint8_t address) { if (!this->write_byte(PMWCS3_SET_I2C_ADDRESS, address)) { this->status_set_warning(); - ESP_LOGW(TAG, "couldn't write the new I2C address %d", address); + ESP_LOGW(TAG, "Setting I2C address failed (%d)", address); return; } this->set_i2c_address(address); // Allows device to continue working until new firmware is written with new address. - ESP_LOGVV(TAG, "changed I2C address to %d", address); + ESP_LOGVV(TAG, "Set I2C address to %d", address); this->status_clear_warning(); } void PMWCS3Component::air_calibration() { if (!this->write_bytes(PMWCS3_REG_CALIBRATE_AIR, nullptr, 0)) { this->status_set_warning(); - ESP_LOGW(TAG, "couldn't start air calibration"); + ESP_LOGW(TAG, "Starting air calibration failed"); return; } - ESP_LOGW(TAG, "Start air calibration during the next 300s"); + ESP_LOGW(TAG, "Running air calibration for 300s"); } void PMWCS3Component::water_calibration() { if (!this->write_bytes(PMWCS3_REG_CALIBRATE_WATER, nullptr, 0)) { this->status_set_warning(); - ESP_LOGW(TAG, "couldn't start water calibration"); + ESP_LOGW(TAG, "Starting water calibration failed"); return; } - ESP_LOGW(TAG, "Start water calibration during the next 300s"); + ESP_LOGW(TAG, "Running water calibration for 300s"); } -void PMWCS3Component::setup() { ESP_LOGCONFIG(TAG, "Setting up PMWCS3..."); } - void PMWCS3Component::update() { this->read_data_(); } float PMWCS3Component::get_setup_priority() const { return setup_priority::DATA; } @@ -61,10 +59,8 @@ void PMWCS3Component::dump_config() { ESP_LOGCONFIG(TAG, "PMWCS3"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with PMWCS3 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } - ESP_LOGI(TAG, "%s", this->is_failed() ? "FAILED" : "OK"); - LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "e25", this->e25_sensor_); LOG_SENSOR(" ", "ec", this->ec_sensor_); @@ -75,7 +71,7 @@ void PMWCS3Component::read_data_() { /////// Super important !!!! first activate reading PMWCS3_REG_READ_START (if not, return always the same values) //// if (!this->write_bytes(PMWCS3_REG_READ_START, nullptr, 0)) { this->status_set_warning(); - ESP_LOGVV(TAG, "Failed to write into REG_READ_START register !!!"); + ESP_LOGVV(TAG, "Writing REG_READ_START failed"); return; } @@ -85,7 +81,7 @@ void PMWCS3Component::read_data_() { uint8_t data[8]; float e25, ec, temperature, vwc; if (!this->read_bytes(PMWCS3_REG_GET_DATA, (uint8_t *) &data, 8)) { - ESP_LOGVV(TAG, "Error reading PMWCS3_REG_GET_DATA registers"); + ESP_LOGVV(TAG, "Reading PMWCS3_REG_GET_DATA failed"); this->mark_failed(); return; } diff --git a/esphome/components/pmwcs3/pmwcs3.h b/esphome/components/pmwcs3/pmwcs3.h index f3916bb868..d60f9d1f61 100644 --- a/esphome/components/pmwcs3/pmwcs3.h +++ b/esphome/components/pmwcs3/pmwcs3.h @@ -12,7 +12,6 @@ namespace pmwcs3 { class PMWCS3Component : public PollingComponent, public i2c::I2CDevice { public: - void setup() override; void update() override; void dump_config() override; float get_setup_priority() const override; diff --git a/esphome/components/pn532/pn532.cpp b/esphome/components/pn532/pn532.cpp index 8088e6c022..facbd0a857 100644 --- a/esphome/components/pn532/pn532.cpp +++ b/esphome/components/pn532/pn532.cpp @@ -15,7 +15,7 @@ namespace pn532 { static const char *const TAG = "pn532"; void PN532::setup() { - ESP_LOGCONFIG(TAG, "Setting up PN532..."); + ESP_LOGCONFIG(TAG, "Running setup"); // Get version data if (!this->write_command_({PN532_COMMAND_VERSION_DATA})) { diff --git a/esphome/components/power_supply/power_supply.cpp b/esphome/components/power_supply/power_supply.cpp index 7474075302..3c449aadd5 100644 --- a/esphome/components/power_supply/power_supply.cpp +++ b/esphome/components/power_supply/power_supply.cpp @@ -7,7 +7,7 @@ namespace power_supply { static const char *const TAG = "power_supply"; void PowerSupply::setup() { - ESP_LOGCONFIG(TAG, "Setting up Power Supply..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->pin_->setup(); this->pin_->digital_write(false); diff --git a/esphome/components/pulse_counter/pulse_counter_sensor.cpp b/esphome/components/pulse_counter/pulse_counter_sensor.cpp index 2bc80c352c..5ad3f1fc33 100644 --- a/esphome/components/pulse_counter/pulse_counter_sensor.cpp +++ b/esphome/components/pulse_counter/pulse_counter_sensor.cpp @@ -156,7 +156,7 @@ pulse_counter_t HwPulseCounterStorage::read_raw_value() { #endif // HAS_PCNT void PulseCounterSensor::setup() { - ESP_LOGCONFIG(TAG, "Setting up pulse counter '%s'...", this->name_.c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->name_.c_str()); if (!this->storage_.pulse_counter_setup(this->pin_)) { this->mark_failed(); return; diff --git a/esphome/components/pylontech/pylontech.cpp b/esphome/components/pylontech/pylontech.cpp index b33f4d4874..cf133742dc 100644 --- a/esphome/components/pylontech/pylontech.cpp +++ b/esphome/components/pylontech/pylontech.cpp @@ -26,7 +26,7 @@ void PylontechComponent::dump_config() { } void PylontechComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up pylontech..."); + ESP_LOGCONFIG(TAG, "Running setup"); while (this->available() != 0) { this->read(); } diff --git a/esphome/components/qmc5883l/qmc5883l.cpp b/esphome/components/qmc5883l/qmc5883l.cpp index 36286244fb..e41d7de644 100644 --- a/esphome/components/qmc5883l/qmc5883l.cpp +++ b/esphome/components/qmc5883l/qmc5883l.cpp @@ -24,7 +24,7 @@ static const uint8_t QMC5883L_REGISTER_CONTROL_2 = 0x0A; static const uint8_t QMC5883L_REGISTER_PERIOD = 0x0B; void QMC5883LComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up QMC5883L..."); + ESP_LOGCONFIG(TAG, "Running setup"); // Soft Reset if (!this->write_byte(QMC5883L_REGISTER_CONTROL_2, 1 << 7)) { this->error_code_ = COMMUNICATION_FAILED; @@ -69,7 +69,7 @@ void QMC5883LComponent::dump_config() { ESP_LOGCONFIG(TAG, "QMC5883L:"); LOG_I2C_DEVICE(this); if (this->error_code_ == COMMUNICATION_FAILED) { - ESP_LOGE(TAG, "Communication with QMC5883L failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); diff --git a/esphome/components/qmp6988/qmp6988.cpp b/esphome/components/qmp6988/qmp6988.cpp index c24780eb25..4c81e124ba 100644 --- a/esphome/components/qmp6988/qmp6988.cpp +++ b/esphome/components/qmp6988/qmp6988.cpp @@ -348,7 +348,7 @@ void QMP6988Component::calculate_pressure_() { } void QMP6988Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up QMP6988"); + ESP_LOGCONFIG(TAG, "Running setup"); bool ret; ret = this->device_check_(); @@ -368,7 +368,7 @@ void QMP6988Component::dump_config() { ESP_LOGCONFIG(TAG, "QMP6988:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with QMP6988 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); diff --git a/esphome/components/qspi_dbi/qspi_dbi.cpp b/esphome/components/qspi_dbi/qspi_dbi.cpp index fda6300d16..2901d40268 100644 --- a/esphome/components/qspi_dbi/qspi_dbi.cpp +++ b/esphome/components/qspi_dbi/qspi_dbi.cpp @@ -6,7 +6,7 @@ namespace esphome { namespace qspi_dbi { void QspiDbi::setup() { - ESP_LOGCONFIG(TAG, "Setting up QSPI_DBI"); + ESP_LOGCONFIG(TAG, "Running setup"); this->spi_setup(); if (this->enable_pin_ != nullptr) { this->enable_pin_->setup(); diff --git a/esphome/components/qwiic_pir/qwiic_pir.cpp b/esphome/components/qwiic_pir/qwiic_pir.cpp index c267554c45..df9da561a2 100644 --- a/esphome/components/qwiic_pir/qwiic_pir.cpp +++ b/esphome/components/qwiic_pir/qwiic_pir.cpp @@ -7,7 +7,7 @@ namespace qwiic_pir { static const char *const TAG = "qwiic_pir"; void QwiicPIRComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up Qwiic PIR..."); + ESP_LOGCONFIG(TAG, "Running setup"); // Verify I2C communcation by reading and verifying the chip ID uint8_t chip_id; @@ -58,7 +58,7 @@ void QwiicPIRComponent::setup() { void QwiicPIRComponent::loop() { // Read Event Register if (!this->read_byte(QWIIC_PIR_EVENT_STATUS, &this->event_register_.reg)) { - ESP_LOGW(TAG, "Failed to communicate with sensor"); + ESP_LOGW(TAG, ESP_LOG_MSG_COMM_FAIL); return; } diff --git a/esphome/components/remote_receiver/remote_receiver_esp32.cpp b/esphome/components/remote_receiver/remote_receiver_esp32.cpp index a8ee186d70..18bf01c8e8 100644 --- a/esphome/components/remote_receiver/remote_receiver_esp32.cpp +++ b/esphome/components/remote_receiver/remote_receiver_esp32.cpp @@ -40,7 +40,7 @@ static bool IRAM_ATTR HOT rmt_callback(rmt_channel_handle_t channel, const rmt_r #endif void RemoteReceiverComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up Remote Receiver..."); + ESP_LOGCONFIG(TAG, "Running setup"); #if ESP_IDF_VERSION_MAJOR >= 5 rmt_rx_channel_config_t channel; memset(&channel, 0, sizeof(channel)); diff --git a/esphome/components/remote_receiver/remote_receiver_esp8266.cpp b/esphome/components/remote_receiver/remote_receiver_esp8266.cpp index c92a134bd8..4c743a6eed 100644 --- a/esphome/components/remote_receiver/remote_receiver_esp8266.cpp +++ b/esphome/components/remote_receiver/remote_receiver_esp8266.cpp @@ -31,7 +31,7 @@ void IRAM_ATTR HOT RemoteReceiverComponentStore::gpio_intr(RemoteReceiverCompone } void RemoteReceiverComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up Remote Receiver..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->pin_->setup(); auto &s = this->store_; s.filter_us = this->filter_us_; diff --git a/esphome/components/remote_receiver/remote_receiver_libretiny.cpp b/esphome/components/remote_receiver/remote_receiver_libretiny.cpp index bfc29b4211..fe84799cae 100644 --- a/esphome/components/remote_receiver/remote_receiver_libretiny.cpp +++ b/esphome/components/remote_receiver/remote_receiver_libretiny.cpp @@ -31,7 +31,7 @@ void IRAM_ATTR HOT RemoteReceiverComponentStore::gpio_intr(RemoteReceiverCompone } void RemoteReceiverComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up Remote Receiver..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->pin_->setup(); auto &s = this->store_; s.filter_us = this->filter_us_; diff --git a/esphome/components/remote_transmitter/remote_transmitter_esp32.cpp b/esphome/components/remote_transmitter/remote_transmitter_esp32.cpp index 01a3980673..a5512c2a55 100644 --- a/esphome/components/remote_transmitter/remote_transmitter_esp32.cpp +++ b/esphome/components/remote_transmitter/remote_transmitter_esp32.cpp @@ -11,7 +11,7 @@ namespace remote_transmitter { static const char *const TAG = "remote_transmitter"; void RemoteTransmitterComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up Remote Transmitter..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->inverted_ = this->pin_->is_inverted(); this->configure_rmt_(); } diff --git a/esphome/components/rotary_encoder/rotary_encoder.cpp b/esphome/components/rotary_encoder/rotary_encoder.cpp index f8e5357a6e..9a9c3a6338 100644 --- a/esphome/components/rotary_encoder/rotary_encoder.cpp +++ b/esphome/components/rotary_encoder/rotary_encoder.cpp @@ -129,7 +129,7 @@ void IRAM_ATTR HOT RotaryEncoderSensorStore::gpio_intr(RotaryEncoderSensorStore } void RotaryEncoderSensor::setup() { - ESP_LOGCONFIG(TAG, "Setting up Rotary Encoder '%s'...", this->name_.c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->name_.c_str()); int32_t initial_value = 0; switch (this->restore_mode_) { diff --git a/esphome/components/rp2040/__init__.py b/esphome/components/rp2040/__init__.py index 3d73cad195..c3e11336a9 100644 --- a/esphome/components/rp2040/__init__.py +++ b/esphome/components/rp2040/__init__.py @@ -10,6 +10,7 @@ from esphome.const import ( CONF_PLATFORM_VERSION, CONF_SOURCE, CONF_VERSION, + CONF_WATCHDOG_TIMEOUT, KEY_CORE, KEY_FRAMEWORK_VERSION, KEY_TARGET_FRAMEWORK, @@ -147,6 +148,10 @@ CONFIG_SCHEMA = cv.All( { cv.Required(CONF_BOARD): cv.string_strict, cv.Optional(CONF_FRAMEWORK, default={}): ARDUINO_FRAMEWORK_SCHEMA, + cv.Optional(CONF_WATCHDOG_TIMEOUT, default="8388ms"): cv.All( + cv.positive_time_period_milliseconds, + cv.Range(max=cv.TimePeriod(milliseconds=8388)), + ), } ), set_core_data, @@ -189,6 +194,8 @@ async def to_code(config): cg.RawExpression(f"VERSION_CODE({ver.major}, {ver.minor}, {ver.patch})"), ) + cg.add_define("USE_RP2040_WATCHDOG_TIMEOUT", config[CONF_WATCHDOG_TIMEOUT]) + def add_pio_file(component: str, key: str, data: str): try: diff --git a/esphome/components/rp2040/core.cpp b/esphome/components/rp2040/core.cpp index c20401c791..d88e9f54b7 100644 --- a/esphome/components/rp2040/core.cpp +++ b/esphome/components/rp2040/core.cpp @@ -1,6 +1,7 @@ #ifdef USE_RP2040 #include "core.h" +#include "esphome/core/defines.h" #include "esphome/core/hal.h" #include "esphome/core/helpers.h" @@ -19,7 +20,13 @@ void arch_restart() { continue; } } -void arch_init() { watchdog_enable(0x7fffff, false); } + +void arch_init() { +#if USE_RP2040_WATCHDOG_TIMEOUT > 0 + watchdog_enable(USE_RP2040_WATCHDOG_TIMEOUT, false); +#endif +} + void IRAM_ATTR HOT arch_feed_wdt() { watchdog_update(); } uint8_t progmem_read_byte(const uint8_t *addr) { diff --git a/esphome/components/rp2040_pio_led_strip/led_strip.cpp b/esphome/components/rp2040_pio_led_strip/led_strip.cpp index 2aaa2ceb19..b675277914 100644 --- a/esphome/components/rp2040_pio_led_strip/led_strip.cpp +++ b/esphome/components/rp2040_pio_led_strip/led_strip.cpp @@ -40,7 +40,7 @@ void RP2040PIOLEDStripLightOutput::dma_write_complete_handler_() { } void RP2040PIOLEDStripLightOutput::setup() { - ESP_LOGCONFIG(TAG, "Setting up RP2040 LED Strip..."); + ESP_LOGCONFIG(TAG, "Running setup"); size_t buffer_size = this->get_buffer_size_(); diff --git a/esphome/components/rp2040_pwm/rp2040_pwm.cpp b/esphome/components/rp2040_pwm/rp2040_pwm.cpp index 170af59905..40920f9351 100644 --- a/esphome/components/rp2040_pwm/rp2040_pwm.cpp +++ b/esphome/components/rp2040_pwm/rp2040_pwm.cpp @@ -17,7 +17,7 @@ namespace rp2040_pwm { static const char *const TAG = "rp2040_pwm"; void RP2040PWM::setup() { - ESP_LOGCONFIG(TAG, "Setting up RP2040 PWM Output..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->setup_pwm_(); } diff --git a/esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.cpp b/esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.cpp index ba09171649..666bac354d 100644 --- a/esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.cpp +++ b/esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.cpp @@ -6,7 +6,7 @@ namespace esphome { namespace rpi_dpi_rgb { void RpiDpiRgb::setup() { - ESP_LOGCONFIG(TAG, "Setting up RPI_DPI_RGB"); + ESP_LOGCONFIG(TAG, "Running setup"); this->reset_display_(); esp_lcd_rgb_panel_config_t config{}; config.flags.fb_in_psram = 1; diff --git a/esphome/components/rtttl/rtttl.cpp b/esphome/components/rtttl/rtttl.cpp index db4cc731e4..6b7071609f 100644 --- a/esphome/components/rtttl/rtttl.cpp +++ b/esphome/components/rtttl/rtttl.cpp @@ -28,14 +28,14 @@ inline double deg2rad(double degrees) { void Rtttl::dump_config() { ESP_LOGCONFIG(TAG, "Rtttl:"); - ESP_LOGCONFIG(TAG, " Gain: %f", gain_); + ESP_LOGCONFIG(TAG, " Gain: %f", this->gain_); } void Rtttl::play(std::string rtttl) { if (this->state_ != State::STATE_STOPPED && this->state_ != State::STATE_STOPPING) { int pos = this->rtttl_.find(':'); auto name = this->rtttl_.substr(0, pos); - ESP_LOGW(TAG, "RTTTL Component is already playing: %s", name.c_str()); + ESP_LOGW(TAG, "Already playing: %s", name.c_str()); return; } @@ -49,11 +49,11 @@ void Rtttl::play(std::string rtttl) { uint8_t num; // Get name - this->position_ = rtttl_.find(':'); + this->position_ = this->rtttl_.find(':'); // it's somewhat documented to be up to 10 characters but let's be a bit flexible here if (this->position_ == std::string::npos || this->position_ > 15) { - ESP_LOGE(TAG, "Missing ':' when looking for name."); + ESP_LOGE(TAG, "Unable to determine name; missing ':'"); return; } @@ -203,7 +203,7 @@ void Rtttl::loop() { if (this->output_ != nullptr && millis() - this->last_note_ < this->note_duration_) return; #endif - if (!this->rtttl_[position_]) { + if (!this->rtttl_[this->position_]) { this->finish_(); return; } @@ -271,7 +271,7 @@ void Rtttl::loop() { scale = this->default_octave_; if (scale < 4 || scale > 7) { - ESP_LOGE(TAG, "Octave out of valid range. Should be between 4 and 7. (Octave: %d)", scale); + ESP_LOGE(TAG, "Octave must be between 4 and 7 (it is %d)", scale); this->finish_(); return; } @@ -281,7 +281,7 @@ void Rtttl::loop() { if (note) { auto note_index = (scale - 4) * 12 + note; if (note_index < 0 || note_index >= (int) sizeof(NOTES)) { - ESP_LOGE(TAG, "Note out of valid range (note: %d, scale: %d, index: %d, max: %d)", note, scale, note_index, + ESP_LOGE(TAG, "Note out of range (note: %d, scale: %d, index: %d, max: %d)", note, scale, note_index, (int) sizeof(NOTES)); this->finish_(); return; @@ -387,7 +387,7 @@ static const LogString *state_to_string(State state) { void Rtttl::set_state_(State state) { State old_state = this->state_; this->state_ = state; - ESP_LOGD(TAG, "State changed from %s to %s", LOG_STR_ARG(state_to_string(old_state)), + ESP_LOGV(TAG, "State changed from %s to %s", LOG_STR_ARG(state_to_string(old_state)), LOG_STR_ARG(state_to_string(state))); } diff --git a/esphome/components/safe_mode/button/safe_mode_button.cpp b/esphome/components/safe_mode/button/safe_mode_button.cpp index 261688807a..bb5b64daf7 100644 --- a/esphome/components/safe_mode/button/safe_mode_button.cpp +++ b/esphome/components/safe_mode/button/safe_mode_button.cpp @@ -13,7 +13,7 @@ void SafeModeButton::set_safe_mode(SafeModeComponent *safe_mode_component) { } void SafeModeButton::press_action() { - ESP_LOGI(TAG, "Restarting device in safe mode..."); + ESP_LOGI(TAG, "Restarting in safe mode"); this->safe_mode_component_->set_safe_mode_pending(true); // Let MQTT settle a bit diff --git a/esphome/components/safe_mode/safe_mode.cpp b/esphome/components/safe_mode/safe_mode.cpp index aa1a4b6822..245d217501 100644 --- a/esphome/components/safe_mode/safe_mode.cpp +++ b/esphome/components/safe_mode/safe_mode.cpp @@ -19,14 +19,13 @@ void SafeModeComponent::dump_config() { ESP_LOGCONFIG(TAG, " Boot considered successful after %" PRIu32 " seconds", this->safe_mode_boot_is_good_after_ / 1000); // because milliseconds ESP_LOGCONFIG(TAG, " Invoke after %u boot attempts", this->safe_mode_num_attempts_); - ESP_LOGCONFIG(TAG, " Remain in safe mode for %" PRIu32 " seconds", + ESP_LOGCONFIG(TAG, " Remain for %" PRIu32 " seconds", this->safe_mode_enable_time_ / 1000); // because milliseconds if (this->safe_mode_rtc_value_ > 1 && this->safe_mode_rtc_value_ != SafeModeComponent::ENTER_SAFE_MODE_MAGIC) { auto remaining_restarts = this->safe_mode_num_attempts_ - this->safe_mode_rtc_value_; if (remaining_restarts) { - ESP_LOGW(TAG, "Last reset occurred too quickly; safe mode will be invoked in %" PRIu32 " restarts", - remaining_restarts); + ESP_LOGW(TAG, "Last reset occurred too quickly; will be invoked in %" PRIu32 " restarts", remaining_restarts); } else { ESP_LOGW(TAG, "SAFE MODE IS ACTIVE"); } @@ -48,7 +47,7 @@ void SafeModeComponent::set_safe_mode_pending(const bool &pending) { uint32_t current_rtc = this->read_rtc_(); if (pending && current_rtc != SafeModeComponent::ENTER_SAFE_MODE_MAGIC) { - ESP_LOGI(TAG, "Device will enter safe mode on next boot"); + ESP_LOGI(TAG, "Device will enter on next boot"); this->write_rtc_(SafeModeComponent::ENTER_SAFE_MODE_MAGIC); } @@ -83,7 +82,7 @@ bool SafeModeComponent::should_enter_safe_mode(uint8_t num_attempts, uint32_t en this->clean_rtc(); if (!is_manual_safe_mode) { - ESP_LOGE(TAG, "Boot loop detected. Proceeding to safe mode"); + ESP_LOGE(TAG, "Boot loop detected. Proceeding"); } this->status_set_error(); diff --git a/esphome/components/safe_mode/switch/safe_mode_switch.cpp b/esphome/components/safe_mode/switch/safe_mode_switch.cpp index 13b35ed210..1637da3059 100644 --- a/esphome/components/safe_mode/switch/safe_mode_switch.cpp +++ b/esphome/components/safe_mode/switch/safe_mode_switch.cpp @@ -17,7 +17,7 @@ void SafeModeSwitch::write_state(bool state) { this->publish_state(false); if (state) { - ESP_LOGI(TAG, "Restarting device in safe mode..."); + ESP_LOGI(TAG, "Restarting in safe mode"); this->safe_mode_component_->set_safe_mode_pending(true); // Let MQTT settle a bit diff --git a/esphome/components/scd30/scd30.cpp b/esphome/components/scd30/scd30.cpp index 3eeca23800..a7283eb680 100644 --- a/esphome/components/scd30/scd30.cpp +++ b/esphome/components/scd30/scd30.cpp @@ -26,7 +26,7 @@ static const uint16_t SCD30_CMD_TEMPERATURE_OFFSET = 0x5403; static const uint16_t SCD30_CMD_SOFT_RESET = 0xD304; void SCD30Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up scd30..."); + ESP_LOGCONFIG(TAG, "Running setup"); #ifdef USE_ESP8266 Wire.setClockStretchLimit(150000); @@ -122,16 +122,16 @@ void SCD30Component::dump_config() { if (this->is_failed()) { switch (this->error_code_) { case COMMUNICATION_FAILED: - ESP_LOGW(TAG, "Communication failed! Is the sensor connected?"); + ESP_LOGW(TAG, ESP_LOG_MSG_COMM_FAIL); break; case MEASUREMENT_INIT_FAILED: - ESP_LOGW(TAG, "Measurement Initialization failed!"); + ESP_LOGW(TAG, "Measurement Initialization failed"); break; case FIRMWARE_IDENTIFICATION_FAILED: ESP_LOGW(TAG, "Unable to read sensor firmware version"); break; default: - ESP_LOGW(TAG, "Unknown setup error!"); + ESP_LOGW(TAG, "Unknown setup error"); break; } } diff --git a/esphome/components/scd4x/scd4x.cpp b/esphome/components/scd4x/scd4x.cpp index a8a4129b48..8cd81f802f 100644 --- a/esphome/components/scd4x/scd4x.cpp +++ b/esphome/components/scd4x/scd4x.cpp @@ -27,7 +27,7 @@ static const uint16_t SCD41_ID = 0x1408; static const uint16_t SCD40_ID = 0x440; void SCD4XComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up scd4x..."); + ESP_LOGCONFIG(TAG, "Running setup"); // the sensor needs 1000 ms to enter the idle state this->set_timeout(1000, [this]() { this->status_clear_error(); @@ -96,16 +96,16 @@ void SCD4XComponent::dump_config() { if (this->is_failed()) { switch (this->error_code_) { case COMMUNICATION_FAILED: - ESP_LOGW(TAG, "Communication failed! Is the sensor connected?"); + ESP_LOGW(TAG, ESP_LOG_MSG_COMM_FAIL); break; case MEASUREMENT_INIT_FAILED: - ESP_LOGW(TAG, "Measurement Initialization failed!"); + ESP_LOGW(TAG, "Measurement Initialization failed"); break; case SERIAL_NUMBER_IDENTIFICATION_FAILED: ESP_LOGW(TAG, "Unable to read sensor firmware version"); break; default: - ESP_LOGW(TAG, "Unknown setup error!"); + ESP_LOGW(TAG, "Unknown setup error"); break; } } diff --git a/esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.cpp b/esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.cpp index 1cf9bd300a..05d0c6eb21 100644 --- a/esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.cpp +++ b/esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.cpp @@ -61,7 +61,7 @@ void MR24HPC1Component::dump_config() { // Initialisation functions void MR24HPC1Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up MR24HPC1..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->check_uart_settings(115200); if (this->custom_mode_number_ != nullptr) { diff --git a/esphome/components/seeed_mr60fda2/seeed_mr60fda2.cpp b/esphome/components/seeed_mr60fda2/seeed_mr60fda2.cpp index d183a1f77f..6bbef085a5 100644 --- a/esphome/components/seeed_mr60fda2/seeed_mr60fda2.cpp +++ b/esphome/components/seeed_mr60fda2/seeed_mr60fda2.cpp @@ -30,7 +30,7 @@ void MR60FDA2Component::dump_config() { // Initialisation functions void MR60FDA2Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up MR60FDA2..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->check_uart_settings(115200); this->current_frame_locate_ = LOCATE_FRAME_HEADER; diff --git a/esphome/components/sen0321/sen0321.cpp b/esphome/components/sen0321/sen0321.cpp index 7801c8c389..c727dda0b1 100644 --- a/esphome/components/sen0321/sen0321.cpp +++ b/esphome/components/sen0321/sen0321.cpp @@ -8,7 +8,7 @@ namespace sen0321_sensor { static const char *const TAG = "sen0321_sensor.sensor"; void Sen0321Sensor::setup() { - ESP_LOGCONFIG(TAG, "Setting up sen0321..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (!this->write_byte(SENSOR_MODE_REGISTER, SENSOR_MODE_AUTO)) { ESP_LOGW(TAG, "Error setting measurement mode."); this->mark_failed(); @@ -21,7 +21,7 @@ void Sen0321Sensor::dump_config() { ESP_LOGCONFIG(TAG, "DF Robot Ozone Sensor sen0321:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with sen0321 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); } diff --git a/esphome/components/sen21231/sen21231.cpp b/esphome/components/sen21231/sen21231.cpp index aa123dff62..67001c3f14 100644 --- a/esphome/components/sen21231/sen21231.cpp +++ b/esphome/components/sen21231/sen21231.cpp @@ -12,7 +12,7 @@ void Sen21231Sensor::dump_config() { ESP_LOGCONFIG(TAG, "SEN21231:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with SEN21231 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } ESP_LOGI(TAG, "SEN21231: %s", this->is_failed() ? "FAILED" : "OK"); LOG_UPDATE_INTERVAL(this); diff --git a/esphome/components/sen5x/sen5x.cpp b/esphome/components/sen5x/sen5x.cpp index f29ba18d6e..d7e1f5f62e 100644 --- a/esphome/components/sen5x/sen5x.cpp +++ b/esphome/components/sen5x/sen5x.cpp @@ -30,7 +30,7 @@ static const int8_t SEN5X_MIN_INDEX_VALUE = 1 * SEN5X_INDEX_SCALE_FACTOR; // static const int16_t SEN5X_MAX_INDEX_VALUE = 500 * SEN5X_INDEX_SCALE_FACTOR; // must be adjusted by the scale factor void SEN5XComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up sen5x..."); + ESP_LOGCONFIG(TAG, "Running setup"); // the sensor needs 1000 ms to enter the idle state this->set_timeout(1000, [this]() { @@ -245,10 +245,10 @@ void SEN5XComponent::dump_config() { if (this->is_failed()) { switch (this->error_code_) { case COMMUNICATION_FAILED: - ESP_LOGW(TAG, "Communication failed! Is the sensor connected?"); + ESP_LOGW(TAG, ESP_LOG_MSG_COMM_FAIL); break; case MEASUREMENT_INIT_FAILED: - ESP_LOGW(TAG, "Measurement Initialization failed!"); + ESP_LOGW(TAG, "Measurement Initialization failed"); break; case SERIAL_NUMBER_IDENTIFICATION_FAILED: ESP_LOGW(TAG, "Unable to read sensor serial id"); @@ -260,7 +260,7 @@ void SEN5XComponent::dump_config() { ESP_LOGW(TAG, "Unable to read sensor firmware version"); break; default: - ESP_LOGW(TAG, "Unknown setup error!"); + ESP_LOGW(TAG, "Unknown setup error"); break; } } diff --git a/esphome/components/sfa30/sfa30.cpp b/esphome/components/sfa30/sfa30.cpp index 20d5ddad5e..c521b3aa02 100644 --- a/esphome/components/sfa30/sfa30.cpp +++ b/esphome/components/sfa30/sfa30.cpp @@ -11,7 +11,7 @@ static const uint16_t SFA30_CMD_START_CONTINUOUS_MEASUREMENTS = 0x0006; static const uint16_t SFA30_CMD_READ_MEASUREMENT = 0x0327; void SFA30Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up sfa30..."); + ESP_LOGCONFIG(TAG, "Running setup"); // Serial Number identification uint16_t raw_device_marking[16]; diff --git a/esphome/components/sgp30/sgp30.cpp b/esphome/components/sgp30/sgp30.cpp index 77e9ef9820..21f98602eb 100644 --- a/esphome/components/sgp30/sgp30.cpp +++ b/esphome/components/sgp30/sgp30.cpp @@ -33,7 +33,7 @@ const uint32_t SHORTEST_BASELINE_STORE_INTERVAL = 3600; const uint32_t MAXIMUM_STORAGE_DIFF = 50; void SGP30Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up SGP30..."); + ESP_LOGCONFIG(TAG, "Running setup"); // Serial Number identification uint16_t raw_serial_number[3]; @@ -232,19 +232,19 @@ void SGP30Component::dump_config() { if (this->is_failed()) { switch (this->error_code_) { case COMMUNICATION_FAILED: - ESP_LOGW(TAG, "Communication failed! Is the sensor connected?"); + ESP_LOGW(TAG, ESP_LOG_MSG_COMM_FAIL); break; case MEASUREMENT_INIT_FAILED: - ESP_LOGW(TAG, "Measurement Initialization failed!"); + ESP_LOGW(TAG, "Measurement Initialization failed"); break; case INVALID_ID: ESP_LOGW(TAG, "Sensor reported an invalid ID. Is this an SGP30?"); break; case UNSUPPORTED_ID: - ESP_LOGW(TAG, "Sensor reported an unsupported ID (SGPC3)."); + ESP_LOGW(TAG, "Sensor reported an unsupported ID (SGPC3)"); break; default: - ESP_LOGW(TAG, "Unknown setup error!"); + ESP_LOGW(TAG, "Unknown setup error"); break; } } else { diff --git a/esphome/components/sgp4x/sgp4x.cpp b/esphome/components/sgp4x/sgp4x.cpp index bf91c90832..1571a8c1e3 100644 --- a/esphome/components/sgp4x/sgp4x.cpp +++ b/esphome/components/sgp4x/sgp4x.cpp @@ -9,7 +9,7 @@ namespace sgp4x { static const char *const TAG = "sgp4x"; void SGP4xComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up SGP4x..."); + ESP_LOGCONFIG(TAG, "Running setup"); // Serial Number identification uint16_t raw_serial_number[3]; @@ -275,17 +275,17 @@ void SGP4xComponent::dump_config() { if (this->is_failed()) { switch (this->error_code_) { case COMMUNICATION_FAILED: - ESP_LOGW(TAG, "Communication failed! Is the sensor connected?"); + ESP_LOGW(TAG, ESP_LOG_MSG_COMM_FAIL); break; case SERIAL_NUMBER_IDENTIFICATION_FAILED: - ESP_LOGW(TAG, "Get Serial number failed."); + ESP_LOGW(TAG, "Get Serial number failed"); break; case SELF_TEST_FAILED: - ESP_LOGW(TAG, "Self test failed."); + ESP_LOGW(TAG, "Self test failed"); break; default: - ESP_LOGW(TAG, "Unknown setup error!"); + ESP_LOGW(TAG, "Unknown setup error"); break; } } else { diff --git a/esphome/components/sht3xd/sht3xd.cpp b/esphome/components/sht3xd/sht3xd.cpp index ffaf5db322..9dc866ddc3 100644 --- a/esphome/components/sht3xd/sht3xd.cpp +++ b/esphome/components/sht3xd/sht3xd.cpp @@ -25,7 +25,7 @@ static const uint16_t SHT3XD_COMMAND_POLLING_H = 0x2400; static const uint16_t SHT3XD_COMMAND_FETCH_DATA = 0xE000; void SHT3XDComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up SHT3xD..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint16_t raw_serial_number[2]; if (!this->get_register(SHT3XD_COMMAND_READ_SERIAL_NUMBER_CLOCK_STRETCHING, raw_serial_number, 2)) { this->error_code_ = READ_SERIAL_STRETCHED_FAILED; diff --git a/esphome/components/sht4x/sht4x.cpp b/esphome/components/sht4x/sht4x.cpp index e4fa16d87a..944b13023e 100644 --- a/esphome/components/sht4x/sht4x.cpp +++ b/esphome/components/sht4x/sht4x.cpp @@ -18,7 +18,7 @@ void SHT4XComponent::start_heater_() { } void SHT4XComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up sht4x..."); + ESP_LOGCONFIG(TAG, "Running setup"); auto err = this->write(nullptr, 0); if (err != i2c::ERROR_OK) { @@ -59,7 +59,7 @@ void SHT4XComponent::dump_config() { ESP_LOGCONFIG(TAG, "SHT4x:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with SHT4x failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } } diff --git a/esphome/components/shtcx/shtcx.cpp b/esphome/components/shtcx/shtcx.cpp index 0de56a8044..770bcf6c6d 100644 --- a/esphome/components/shtcx/shtcx.cpp +++ b/esphome/components/shtcx/shtcx.cpp @@ -25,7 +25,7 @@ inline const char *to_string(SHTCXType type) { } void SHTCXComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up SHTCx..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->wake_up(); this->soft_reset(); @@ -60,7 +60,7 @@ void SHTCXComponent::dump_config() { ESP_LOGCONFIG(TAG, " Model: %s (%04x)", to_string(this->type_), this->sensor_id_); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with SHTCx failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); diff --git a/esphome/components/sm16716/sm16716.cpp b/esphome/components/sm16716/sm16716.cpp index 373fbd4766..b25f935eba 100644 --- a/esphome/components/sm16716/sm16716.cpp +++ b/esphome/components/sm16716/sm16716.cpp @@ -7,7 +7,7 @@ namespace sm16716 { static const char *const TAG = "sm16716"; void SM16716::setup() { - ESP_LOGCONFIG(TAG, "Setting up SM16716OutputComponent..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->data_pin_->setup(); this->data_pin_->digital_write(false); this->clock_pin_->setup(); diff --git a/esphome/components/sm2135/sm2135.cpp b/esphome/components/sm2135/sm2135.cpp index ee5948bb3a..cd647ef3b9 100644 --- a/esphome/components/sm2135/sm2135.cpp +++ b/esphome/components/sm2135/sm2135.cpp @@ -20,7 +20,7 @@ static const uint8_t SM2135_RGB = 0x00; // RGB channel static const uint8_t SM2135_CW = 0x80; // CW channel (Chip default) void SM2135::setup() { - ESP_LOGCONFIG(TAG, "Setting up SM2135OutputComponent..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->data_pin_->setup(); this->data_pin_->digital_write(false); this->data_pin_->pin_mode(gpio::FLAG_OUTPUT); diff --git a/esphome/components/sm2235/sm2235.cpp b/esphome/components/sm2235/sm2235.cpp index f953d41957..3edd1e24a7 100644 --- a/esphome/components/sm2235/sm2235.cpp +++ b/esphome/components/sm2235/sm2235.cpp @@ -7,7 +7,7 @@ namespace sm2235 { static const char *const TAG = "sm2235"; void SM2235::setup() { - ESP_LOGCONFIG(TAG, "Setting up sm2235 Output Component..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->data_pin_->setup(); this->data_pin_->digital_write(true); this->clock_pin_->setup(); diff --git a/esphome/components/sm2335/sm2335.cpp b/esphome/components/sm2335/sm2335.cpp index b6c482b5bb..a891b14ea0 100644 --- a/esphome/components/sm2335/sm2335.cpp +++ b/esphome/components/sm2335/sm2335.cpp @@ -7,7 +7,7 @@ namespace sm2335 { static const char *const TAG = "sm2335"; void SM2335::setup() { - ESP_LOGCONFIG(TAG, "Setting up sm2335 Output Component..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->data_pin_->setup(); this->data_pin_->digital_write(true); this->clock_pin_->setup(); diff --git a/esphome/components/sn74hc165/sn74hc165.cpp b/esphome/components/sn74hc165/sn74hc165.cpp index 7efe8a4c14..69e0df5785 100644 --- a/esphome/components/sn74hc165/sn74hc165.cpp +++ b/esphome/components/sn74hc165/sn74hc165.cpp @@ -7,8 +7,7 @@ namespace sn74hc165 { static const char *const TAG = "sn74hc165"; void SN74HC165Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up SN74HC165..."); - + ESP_LOGCONFIG(TAG, "Running setup"); // initialize pins this->clock_pin_->setup(); this->data_pin_->setup(); diff --git a/esphome/components/sn74hc595/sn74hc595.cpp b/esphome/components/sn74hc595/sn74hc595.cpp index 8a37c3bece..f8d24b898f 100644 --- a/esphome/components/sn74hc595/sn74hc595.cpp +++ b/esphome/components/sn74hc595/sn74hc595.cpp @@ -7,8 +7,7 @@ namespace sn74hc595 { static const char *const TAG = "sn74hc595"; void SN74HC595Component::pre_setup_() { - ESP_LOGCONFIG(TAG, "Setting up SN74HC595..."); - + ESP_LOGCONFIG(TAG, "Running setup"); if (this->have_oe_pin_) { // disable output this->oe_pin_->setup(); this->oe_pin_->digital_write(true); diff --git a/esphome/components/sntp/sntp_component.cpp b/esphome/components/sntp/sntp_component.cpp index 21add1451d..f9a9981c52 100644 --- a/esphome/components/sntp/sntp_component.cpp +++ b/esphome/components/sntp/sntp_component.cpp @@ -15,7 +15,7 @@ namespace sntp { static const char *const TAG = "sntp"; void SNTPComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up SNTP..."); + ESP_LOGCONFIG(TAG, "Running setup"); #if defined(USE_ESP_IDF) if (esp_sntp_enabled()) { esp_sntp_stop(); diff --git a/esphome/components/socket/__init__.py b/esphome/components/socket/__init__.py index 77e8fe51f6..667e30df4b 100644 --- a/esphome/components/socket/__init__.py +++ b/esphome/components/socket/__init__.py @@ -35,5 +35,7 @@ async def to_code(config): cg.add_define("USE_SOCKET_IMPL_LWIP_TCP") elif impl == IMPLEMENTATION_LWIP_SOCKETS: cg.add_define("USE_SOCKET_IMPL_LWIP_SOCKETS") + cg.add_define("USE_SOCKET_SELECT_SUPPORT") elif impl == IMPLEMENTATION_BSD_SOCKETS: cg.add_define("USE_SOCKET_IMPL_BSD_SOCKETS") + cg.add_define("USE_SOCKET_SELECT_SUPPORT") diff --git a/esphome/components/socket/bsd_sockets_impl.cpp b/esphome/components/socket/bsd_sockets_impl.cpp index 1b3916fcab..e056696bcf 100644 --- a/esphome/components/socket/bsd_sockets_impl.cpp +++ b/esphome/components/socket/bsd_sockets_impl.cpp @@ -5,6 +5,7 @@ #ifdef USE_SOCKET_IMPL_BSD_SOCKETS #include +#include "esphome/core/application.h" #ifdef USE_ESP32 #include @@ -40,7 +41,20 @@ std::string format_sockaddr(const struct sockaddr_storage &storage) { class BSDSocketImpl : public Socket { public: - BSDSocketImpl(int fd) : fd_(fd) {} + BSDSocketImpl(int fd, bool monitor_loop = false) : fd_(fd) { +#ifdef USE_SOCKET_SELECT_SUPPORT + // Register new socket with the application for select() if monitoring requested + if (monitor_loop && fd_ >= 0) { + // Only set loop_monitored_ to true if registration succeeds + loop_monitored_ = App.register_socket_fd(fd_); + } else { + loop_monitored_ = false; + } +#else + // Without select support, ignore monitor_loop parameter + (void) monitor_loop; +#endif + } ~BSDSocketImpl() override { if (!closed_) { close(); // NOLINT(clang-analyzer-optin.cplusplus.VirtualCall) @@ -48,16 +62,35 @@ class BSDSocketImpl : public Socket { } int connect(const struct sockaddr *addr, socklen_t addrlen) override { return ::connect(fd_, addr, addrlen); } std::unique_ptr accept(struct sockaddr *addr, socklen_t *addrlen) override { + return accept_impl_(addr, addrlen, false); + } + std::unique_ptr accept_loop_monitored(struct sockaddr *addr, socklen_t *addrlen) override { + return accept_impl_(addr, addrlen, true); + } + + private: + std::unique_ptr accept_impl_(struct sockaddr *addr, socklen_t *addrlen, bool loop_monitored) { int fd = ::accept(fd_, addr, addrlen); if (fd == -1) return {}; - return make_unique(fd); + return make_unique(fd, loop_monitored); } + + public: int bind(const struct sockaddr *addr, socklen_t addrlen) override { return ::bind(fd_, addr, addrlen); } int close() override { - int ret = ::close(fd_); - closed_ = true; - return ret; + if (!closed_) { +#ifdef USE_SOCKET_SELECT_SUPPORT + // Unregister from select() before closing if monitored + if (loop_monitored_) { + App.unregister_socket_fd(fd_); + } +#endif + int ret = ::close(fd_); + closed_ = true; + return ret; + } + return 0; } int shutdown(int how) override { return ::shutdown(fd_, how); } @@ -126,16 +159,27 @@ class BSDSocketImpl : public Socket { return 0; } + int get_fd() const override { return fd_; } + protected: int fd_; bool closed_ = false; }; -std::unique_ptr socket(int domain, int type, int protocol) { +// Helper to create a socket with optional monitoring +static std::unique_ptr create_socket(int domain, int type, int protocol, bool loop_monitored = false) { int ret = ::socket(domain, type, protocol); if (ret == -1) return nullptr; - return std::unique_ptr{new BSDSocketImpl(ret)}; + return std::unique_ptr{new BSDSocketImpl(ret, loop_monitored)}; +} + +std::unique_ptr socket(int domain, int type, int protocol) { + return create_socket(domain, type, protocol, false); +} + +std::unique_ptr socket_loop_monitored(int domain, int type, int protocol) { + return create_socket(domain, type, protocol, true); } } // namespace socket diff --git a/esphome/components/socket/lwip_raw_tcp_impl.cpp b/esphome/components/socket/lwip_raw_tcp_impl.cpp index 1d998902ff..2d64a275df 100644 --- a/esphome/components/socket/lwip_raw_tcp_impl.cpp +++ b/esphome/components/socket/lwip_raw_tcp_impl.cpp @@ -606,6 +606,11 @@ std::unique_ptr socket(int domain, int type, int protocol) { return std::unique_ptr{sock}; } +std::unique_ptr socket_loop_monitored(int domain, int type, int protocol) { + // LWIPRawImpl doesn't use file descriptors, so monitoring is not applicable + return socket(domain, type, protocol); +} + } // namespace socket } // namespace esphome diff --git a/esphome/components/socket/lwip_sockets_impl.cpp b/esphome/components/socket/lwip_sockets_impl.cpp index c41e42fc83..f8a1cbc046 100644 --- a/esphome/components/socket/lwip_sockets_impl.cpp +++ b/esphome/components/socket/lwip_sockets_impl.cpp @@ -5,6 +5,7 @@ #ifdef USE_SOCKET_IMPL_LWIP_SOCKETS #include +#include "esphome/core/application.h" namespace esphome { namespace socket { @@ -33,7 +34,20 @@ std::string format_sockaddr(const struct sockaddr_storage &storage) { class LwIPSocketImpl : public Socket { public: - LwIPSocketImpl(int fd) : fd_(fd) {} + LwIPSocketImpl(int fd, bool monitor_loop = false) : fd_(fd) { +#ifdef USE_SOCKET_SELECT_SUPPORT + // Register new socket with the application for select() if monitoring requested + if (monitor_loop && fd_ >= 0) { + // Only set loop_monitored_ to true if registration succeeds + loop_monitored_ = App.register_socket_fd(fd_); + } else { + loop_monitored_ = false; + } +#else + // Without select support, ignore monitor_loop parameter + (void) monitor_loop; +#endif + } ~LwIPSocketImpl() override { if (!closed_) { close(); // NOLINT(clang-analyzer-optin.cplusplus.VirtualCall) @@ -41,16 +55,35 @@ class LwIPSocketImpl : public Socket { } int connect(const struct sockaddr *addr, socklen_t addrlen) override { return lwip_connect(fd_, addr, addrlen); } std::unique_ptr accept(struct sockaddr *addr, socklen_t *addrlen) override { + return accept_impl_(addr, addrlen, false); + } + std::unique_ptr accept_loop_monitored(struct sockaddr *addr, socklen_t *addrlen) override { + return accept_impl_(addr, addrlen, true); + } + + private: + std::unique_ptr accept_impl_(struct sockaddr *addr, socklen_t *addrlen, bool loop_monitored) { int fd = lwip_accept(fd_, addr, addrlen); if (fd == -1) return {}; - return make_unique(fd); + return make_unique(fd, loop_monitored); } + + public: int bind(const struct sockaddr *addr, socklen_t addrlen) override { return lwip_bind(fd_, addr, addrlen); } int close() override { - int ret = lwip_close(fd_); - closed_ = true; - return ret; + if (!closed_) { +#ifdef USE_SOCKET_SELECT_SUPPORT + // Unregister from select() before closing if monitored + if (loop_monitored_) { + App.unregister_socket_fd(fd_); + } +#endif + int ret = lwip_close(fd_); + closed_ = true; + return ret; + } + return 0; } int shutdown(int how) override { return lwip_shutdown(fd_, how); } @@ -98,16 +131,27 @@ class LwIPSocketImpl : public Socket { return 0; } + int get_fd() const override { return fd_; } + protected: int fd_; bool closed_ = false; }; -std::unique_ptr socket(int domain, int type, int protocol) { +// Helper to create a socket with optional monitoring +static std::unique_ptr create_socket(int domain, int type, int protocol, bool loop_monitored = false) { int ret = lwip_socket(domain, type, protocol); if (ret == -1) return nullptr; - return std::unique_ptr{new LwIPSocketImpl(ret)}; + return std::unique_ptr{new LwIPSocketImpl(ret, loop_monitored)}; +} + +std::unique_ptr socket(int domain, int type, int protocol) { + return create_socket(domain, type, protocol, false); +} + +std::unique_ptr socket_loop_monitored(int domain, int type, int protocol) { + return create_socket(domain, type, protocol, true); } } // namespace socket diff --git a/esphome/components/socket/socket.cpp b/esphome/components/socket/socket.cpp index e260fce05e..1c8e72b8fd 100644 --- a/esphome/components/socket/socket.cpp +++ b/esphome/components/socket/socket.cpp @@ -4,12 +4,35 @@ #include #include #include "esphome/core/log.h" +#include "esphome/core/application.h" namespace esphome { namespace socket { Socket::~Socket() {} +bool Socket::ready() const { +#ifdef USE_SOCKET_SELECT_SUPPORT + if (!loop_monitored_) { + // Non-monitored sockets always return true (assume data may be available) + return true; + } + + // For loop-monitored sockets, check with the Application's select() results + int fd = this->get_fd(); + if (fd < 0) { + // No valid file descriptor, assume ready (fallback behavior) + return true; + } + + return App.is_socket_ready(fd); +#else + // Without select() support, we can't monitor sockets in the loop + // Always return true (assume data may be available) + return true; +#endif +} + std::unique_ptr socket_ip(int type, int protocol) { #if USE_NETWORK_IPV6 return socket(AF_INET6, type, protocol); @@ -18,6 +41,14 @@ std::unique_ptr socket_ip(int type, int protocol) { #endif /* USE_NETWORK_IPV6 */ } +std::unique_ptr socket_ip_loop_monitored(int type, int protocol) { +#if USE_NETWORK_IPV6 + return socket_loop_monitored(AF_INET6, type, protocol); +#else + return socket_loop_monitored(AF_INET, type, protocol); +#endif /* USE_NETWORK_IPV6 */ +} + socklen_t set_sockaddr(struct sockaddr *addr, socklen_t addrlen, const std::string &ip_address, uint16_t port) { #if USE_NETWORK_IPV6 if (ip_address.find(':') != std::string::npos) { diff --git a/esphome/components/socket/socket.h b/esphome/components/socket/socket.h index 917f3c4c7f..8f0d28362e 100644 --- a/esphome/components/socket/socket.h +++ b/esphome/components/socket/socket.h @@ -17,6 +17,11 @@ class Socket { Socket &operator=(const Socket &) = delete; virtual std::unique_ptr accept(struct sockaddr *addr, socklen_t *addrlen) = 0; + /// Accept a connection and monitor it in the main loop + /// NOTE: This function is NOT thread-safe and must only be called from the main loop + virtual std::unique_ptr accept_loop_monitored(struct sockaddr *addr, socklen_t *addrlen) { + return accept(addr, addrlen); // Default implementation for backward compatibility + } virtual int bind(const struct sockaddr *addr, socklen_t addrlen) = 0; virtual int close() = 0; // not supported yet: @@ -44,14 +49,35 @@ class Socket { virtual int setblocking(bool blocking) = 0; virtual int loop() { return 0; }; + + /// Get the underlying file descriptor (returns -1 if not supported) + virtual int get_fd() const { return -1; } + + /// Check if socket has data ready to read + /// For loop-monitored sockets, checks with the Application's select() results + /// For non-monitored sockets, always returns true (assumes data may be available) + bool ready() const; + + protected: +#ifdef USE_SOCKET_SELECT_SUPPORT + bool loop_monitored_{false}; ///< Whether this socket is monitored by the event loop +#endif }; /// Create a socket of the given domain, type and protocol. std::unique_ptr socket(int domain, int type, int protocol); - /// Create a socket in the newest available IP domain (IPv6 or IPv4) of the given type and protocol. std::unique_ptr socket_ip(int type, int protocol); +/// Create a socket and monitor it for data in the main loop. +/// Like socket() but also registers the socket with the Application's select() loop. +/// WARNING: These functions are NOT thread-safe. They must only be called from the main loop +/// as they register the socket file descriptor with the global Application instance. +/// NOTE: On ESP platforms, FD_SETSIZE is typically 10, limiting the number of monitored sockets. +/// File descriptors >= FD_SETSIZE will not be monitored and will log an error. +std::unique_ptr socket_loop_monitored(int domain, int type, int protocol); +std::unique_ptr socket_ip_loop_monitored(int type, int protocol); + /// Set a sockaddr to the specified address and port for the IP version used by socket_ip(). socklen_t set_sockaddr(struct sockaddr *addr, socklen_t addrlen, const std::string &ip_address, uint16_t port); diff --git a/esphome/components/speaker/media_player/__init__.py b/esphome/components/speaker/media_player/__init__.py index cedafe214d..dc2dae2ef1 100644 --- a/esphome/components/speaker/media_player/__init__.py +++ b/esphome/components/speaker/media_player/__init__.py @@ -48,6 +48,7 @@ CONF_ON_UNMUTE = "on_unmute" CONF_ON_VOLUME = "on_volume" CONF_STREAM = "stream" CONF_VOLUME_INCREMENT = "volume_increment" +CONF_VOLUME_INITIAL = "volume_initial" CONF_VOLUME_MIN = "volume_min" CONF_VOLUME_MAX = "volume_max" @@ -282,6 +283,7 @@ CONFIG_SCHEMA = cv.All( cv.Optional(CONF_FILES): cv.ensure_list(MEDIA_FILE_TYPE_SCHEMA), cv.Optional(CONF_TASK_STACK_IN_PSRAM, default=False): cv.boolean, cv.Optional(CONF_VOLUME_INCREMENT, default=0.05): cv.percentage, + cv.Optional(CONF_VOLUME_INITIAL, default=0.5): cv.percentage, cv.Optional(CONF_VOLUME_MAX, default=1.0): cv.percentage, cv.Optional(CONF_VOLUME_MIN, default=0.0): cv.percentage, cv.Optional(CONF_ON_MUTE): automation.validate_automation(single=True), @@ -356,6 +358,7 @@ async def to_code(config): ) cg.add(var.set_volume_increment(config[CONF_VOLUME_INCREMENT])) + cg.add(var.set_volume_initial(config[CONF_VOLUME_INITIAL])) cg.add(var.set_volume_max(config[CONF_VOLUME_MAX])) cg.add(var.set_volume_min(config[CONF_VOLUME_MIN])) diff --git a/esphome/components/speaker/media_player/speaker_media_player.cpp b/esphome/components/speaker/media_player/speaker_media_player.cpp index fed0207c93..2c30f17c78 100644 --- a/esphome/components/speaker/media_player/speaker_media_player.cpp +++ b/esphome/components/speaker/media_player/speaker_media_player.cpp @@ -48,8 +48,6 @@ static const uint32_t MEDIA_CONTROLS_QUEUE_LENGTH = 20; static const UBaseType_t MEDIA_PIPELINE_TASK_PRIORITY = 1; static const UBaseType_t ANNOUNCEMENT_PIPELINE_TASK_PRIORITY = 1; -static const float FIRST_BOOT_DEFAULT_VOLUME = 0.5f; - static const char *const TAG = "speaker_media_player"; void SpeakerMediaPlayer::setup() { @@ -64,7 +62,7 @@ void SpeakerMediaPlayer::setup() { this->set_volume_(volume_restore_state.volume); this->set_mute_state_(volume_restore_state.is_muted); } else { - this->set_volume_(FIRST_BOOT_DEFAULT_VOLUME); + this->set_volume_(this->volume_initial_); this->set_mute_state_(false); } diff --git a/esphome/components/speaker/media_player/speaker_media_player.h b/esphome/components/speaker/media_player/speaker_media_player.h index 67e9859a13..967772d1a5 100644 --- a/esphome/components/speaker/media_player/speaker_media_player.h +++ b/esphome/components/speaker/media_player/speaker_media_player.h @@ -55,6 +55,9 @@ class SpeakerMediaPlayer : public Component, public media_player::MediaPlayer { // Percentage to increase or decrease the volume for volume up or volume down commands void set_volume_increment(float volume_increment) { this->volume_increment_ = volume_increment; } + // Volume used initially on first boot when no volume had been previously saved + void set_volume_initial(float volume_initial) { this->volume_initial_ = volume_initial; } + void set_volume_max(float volume_max) { this->volume_max_ = volume_max; } void set_volume_min(float volume_min) { this->volume_min_ = volume_min; } @@ -128,6 +131,9 @@ class SpeakerMediaPlayer : public Component, public media_player::MediaPlayer { // The amount to change the volume on volume up/down commands float volume_increment_; + // The initial volume used by Setup when no previous volume was saved + float volume_initial_; + float volume_max_; float volume_min_; diff --git a/esphome/components/sps30/sps30.cpp b/esphome/components/sps30/sps30.cpp index cdcd4a6a54..5a0335998f 100644 --- a/esphome/components/sps30/sps30.cpp +++ b/esphome/components/sps30/sps30.cpp @@ -22,7 +22,7 @@ static const size_t SERIAL_NUMBER_LENGTH = 8; static const uint8_t MAX_SKIPPED_DATA_CYCLES_BEFORE_ERROR = 5; void SPS30Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up sps30..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->write_command(SPS30_CMD_SOFT_RESET); /// Deferred Sensor initialization this->set_timeout(500, [this]() { @@ -73,10 +73,10 @@ void SPS30Component::dump_config() { if (this->is_failed()) { switch (this->error_code_) { case COMMUNICATION_FAILED: - ESP_LOGW(TAG, "Communication failed! Is the sensor connected?"); + ESP_LOGW(TAG, ESP_LOG_MSG_COMM_FAIL); break; case MEASUREMENT_INIT_FAILED: - ESP_LOGW(TAG, "Measurement Initialization failed!"); + ESP_LOGW(TAG, "Measurement Initialization failed"); break; case SERIAL_NUMBER_REQUEST_FAILED: ESP_LOGW(TAG, "Unable to request sensor serial number"); @@ -91,7 +91,7 @@ void SPS30Component::dump_config() { ESP_LOGW(TAG, "Unable to read sensor firmware version"); break; default: - ESP_LOGW(TAG, "Unknown setup error!"); + ESP_LOGW(TAG, "Unknown setup error"); break; } } diff --git a/esphome/components/ssd1306_i2c/ssd1306_i2c.cpp b/esphome/components/ssd1306_i2c/ssd1306_i2c.cpp index ed7cf102ee..4013ae7209 100644 --- a/esphome/components/ssd1306_i2c/ssd1306_i2c.cpp +++ b/esphome/components/ssd1306_i2c/ssd1306_i2c.cpp @@ -7,7 +7,7 @@ namespace ssd1306_i2c { static const char *const TAG = "ssd1306_i2c"; void I2CSSD1306::setup() { - ESP_LOGCONFIG(TAG, "Setting up I2C SSD1306..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->init_reset_(); auto err = this->write(nullptr, 0); @@ -33,7 +33,7 @@ void I2CSSD1306::dump_config() { LOG_UPDATE_INTERVAL(this); if (this->error_code_ == COMMUNICATION_FAILED) { - ESP_LOGE(TAG, "Communication with SSD1306 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } } void I2CSSD1306::command(uint8_t value) { this->write_byte(0x00, value); } diff --git a/esphome/components/ssd1306_spi/ssd1306_spi.cpp b/esphome/components/ssd1306_spi/ssd1306_spi.cpp index 0a0debfd65..28425da587 100644 --- a/esphome/components/ssd1306_spi/ssd1306_spi.cpp +++ b/esphome/components/ssd1306_spi/ssd1306_spi.cpp @@ -8,7 +8,7 @@ namespace ssd1306_spi { static const char *const TAG = "ssd1306_spi"; void SPISSD1306::setup() { - ESP_LOGCONFIG(TAG, "Setting up SPI SSD1306..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->spi_setup(); this->dc_pin_->setup(); // OUTPUT diff --git a/esphome/components/ssd1322_spi/ssd1322_spi.cpp b/esphome/components/ssd1322_spi/ssd1322_spi.cpp index a841c5606e..fb2d8afe1c 100644 --- a/esphome/components/ssd1322_spi/ssd1322_spi.cpp +++ b/esphome/components/ssd1322_spi/ssd1322_spi.cpp @@ -8,7 +8,7 @@ namespace ssd1322_spi { static const char *const TAG = "ssd1322_spi"; void SPISSD1322::setup() { - ESP_LOGCONFIG(TAG, "Setting up SPI SSD1322..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->spi_setup(); this->dc_pin_->setup(); // OUTPUT if (this->cs_) diff --git a/esphome/components/ssd1325_spi/ssd1325_spi.cpp b/esphome/components/ssd1325_spi/ssd1325_spi.cpp index 8a95bfeae3..d2a365326f 100644 --- a/esphome/components/ssd1325_spi/ssd1325_spi.cpp +++ b/esphome/components/ssd1325_spi/ssd1325_spi.cpp @@ -8,7 +8,7 @@ namespace ssd1325_spi { static const char *const TAG = "ssd1325_spi"; void SPISSD1325::setup() { - ESP_LOGCONFIG(TAG, "Setting up SPI SSD1325..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->spi_setup(); this->dc_pin_->setup(); // OUTPUT if (this->cs_) diff --git a/esphome/components/ssd1327_i2c/ssd1327_i2c.cpp b/esphome/components/ssd1327_i2c/ssd1327_i2c.cpp index e9e047bfb6..4e1c5e4ea0 100644 --- a/esphome/components/ssd1327_i2c/ssd1327_i2c.cpp +++ b/esphome/components/ssd1327_i2c/ssd1327_i2c.cpp @@ -7,7 +7,7 @@ namespace ssd1327_i2c { static const char *const TAG = "ssd1327_i2c"; void I2CSSD1327::setup() { - ESP_LOGCONFIG(TAG, "Setting up I2C SSD1327..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->init_reset_(); auto err = this->write(nullptr, 0); @@ -27,7 +27,7 @@ void I2CSSD1327::dump_config() { LOG_UPDATE_INTERVAL(this); if (this->error_code_ == COMMUNICATION_FAILED) { - ESP_LOGE(TAG, "Communication with SSD1327 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } } void I2CSSD1327::command(uint8_t value) { this->write_byte(0x00, value); } diff --git a/esphome/components/ssd1327_spi/ssd1327_spi.cpp b/esphome/components/ssd1327_spi/ssd1327_spi.cpp index c6ae377119..a5eaf252c4 100644 --- a/esphome/components/ssd1327_spi/ssd1327_spi.cpp +++ b/esphome/components/ssd1327_spi/ssd1327_spi.cpp @@ -8,7 +8,7 @@ namespace ssd1327_spi { static const char *const TAG = "ssd1327_spi"; void SPISSD1327::setup() { - ESP_LOGCONFIG(TAG, "Setting up SPI SSD1327..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->spi_setup(); this->dc_pin_->setup(); // OUTPUT if (this->cs_) diff --git a/esphome/components/ssd1331_spi/ssd1331_spi.cpp b/esphome/components/ssd1331_spi/ssd1331_spi.cpp index 88116f6c00..aeff2bbbfd 100644 --- a/esphome/components/ssd1331_spi/ssd1331_spi.cpp +++ b/esphome/components/ssd1331_spi/ssd1331_spi.cpp @@ -8,7 +8,7 @@ namespace ssd1331_spi { static const char *const TAG = "ssd1331_spi"; void SPISSD1331::setup() { - ESP_LOGCONFIG(TAG, "Setting up SPI SSD1331..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->spi_setup(); this->dc_pin_->setup(); // OUTPUT if (this->cs_) diff --git a/esphome/components/ssd1351_spi/ssd1351_spi.cpp b/esphome/components/ssd1351_spi/ssd1351_spi.cpp index b71b8f4f88..5ae7c308d4 100644 --- a/esphome/components/ssd1351_spi/ssd1351_spi.cpp +++ b/esphome/components/ssd1351_spi/ssd1351_spi.cpp @@ -8,7 +8,7 @@ namespace ssd1351_spi { static const char *const TAG = "ssd1351_spi"; void SPISSD1351::setup() { - ESP_LOGCONFIG(TAG, "Setting up SPI SSD1351..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->spi_setup(); this->dc_pin_->setup(); // OUTPUT if (this->cs_) diff --git a/esphome/components/st7567_i2c/st7567_i2c.cpp b/esphome/components/st7567_i2c/st7567_i2c.cpp index 05173d1be5..9180409cc0 100644 --- a/esphome/components/st7567_i2c/st7567_i2c.cpp +++ b/esphome/components/st7567_i2c/st7567_i2c.cpp @@ -7,7 +7,7 @@ namespace st7567_i2c { static const char *const TAG = "st7567_i2c"; void I2CST7567::setup() { - ESP_LOGCONFIG(TAG, "Setting up I2C ST7567 display..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->init_reset_(); auto err = this->write(nullptr, 0); @@ -30,7 +30,7 @@ void I2CST7567::dump_config() { LOG_UPDATE_INTERVAL(this); if (this->error_code_ == COMMUNICATION_FAILED) { - ESP_LOGE(TAG, "Communication with I2C ST7567 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } } diff --git a/esphome/components/st7567_spi/st7567_spi.cpp b/esphome/components/st7567_spi/st7567_spi.cpp index 25698d0dd0..c5c5836200 100644 --- a/esphome/components/st7567_spi/st7567_spi.cpp +++ b/esphome/components/st7567_spi/st7567_spi.cpp @@ -7,7 +7,7 @@ namespace st7567_spi { static const char *const TAG = "st7567_spi"; void SPIST7567::setup() { - ESP_LOGCONFIG(TAG, "Setting up SPI ST7567 display..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->spi_setup(); this->dc_pin_->setup(); if (this->cs_) diff --git a/esphome/components/st7735/st7735.cpp b/esphome/components/st7735/st7735.cpp index 5985d8bfb3..f37770a767 100644 --- a/esphome/components/st7735/st7735.cpp +++ b/esphome/components/st7735/st7735.cpp @@ -233,7 +233,7 @@ ST7735::ST7735(ST7735Model model, int width, int height, int colstart, int rowst height_(height) {} void ST7735::setup() { - ESP_LOGCONFIG(TAG, "Setting up ST7735..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->spi_setup(); this->dc_pin_->setup(); // OUTPUT diff --git a/esphome/components/st7789v/st7789v.cpp b/esphome/components/st7789v/st7789v.cpp index 0d2f35aef5..72460d8c89 100644 --- a/esphome/components/st7789v/st7789v.cpp +++ b/esphome/components/st7789v/st7789v.cpp @@ -8,7 +8,7 @@ static const char *const TAG = "st7789v"; static const size_t TEMP_BUFFER_SIZE = 128; void ST7789V::setup() { - ESP_LOGCONFIG(TAG, "Setting up SPI ST7789V..."); + ESP_LOGCONFIG(TAG, "Running setup"); #ifdef USE_POWER_SUPPLY this->power_.request(); // the PowerSupply component takes care of post turn-on delay diff --git a/esphome/components/st7920/st7920.cpp b/esphome/components/st7920/st7920.cpp index 171e7095dd..0623125bfb 100644 --- a/esphome/components/st7920/st7920.cpp +++ b/esphome/components/st7920/st7920.cpp @@ -32,7 +32,7 @@ static const uint8_t LCD_LINE2 = 0x88; static const uint8_t LCD_LINE3 = 0x98; void ST7920::setup() { - ESP_LOGCONFIG(TAG, "Setting up ST7920..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->dump_config(); this->spi_setup(); this->init_internal_(this->get_buffer_length_()); diff --git a/esphome/components/status_led/light/status_led_light.cpp b/esphome/components/status_led/light/status_led_light.cpp index 549024c4df..6d38833ebd 100644 --- a/esphome/components/status_led/light/status_led_light.cpp +++ b/esphome/components/status_led/light/status_led_light.cpp @@ -53,7 +53,7 @@ void StatusLEDLightOutput::write_state(light::LightState *state) { } void StatusLEDLightOutput::setup() { - ESP_LOGCONFIG(TAG, "Setting up Status LED..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (this->pin_ != nullptr) { this->pin_->setup(); diff --git a/esphome/components/status_led/status_led.cpp b/esphome/components/status_led/status_led.cpp index d2d56cf05b..a17d4398fd 100644 --- a/esphome/components/status_led/status_led.cpp +++ b/esphome/components/status_led/status_led.cpp @@ -11,7 +11,7 @@ StatusLED *global_status_led = nullptr; // NOLINT(cppcoreguidelines-avoid-non-c StatusLED::StatusLED(GPIOPin *pin) : pin_(pin) { global_status_led = this; } void StatusLED::pre_setup() { - ESP_LOGCONFIG(TAG, "Setting up Status LED..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->pin_->setup(); this->pin_->digital_write(false); } diff --git a/esphome/components/sts3x/sts3x.cpp b/esphome/components/sts3x/sts3x.cpp index a533bc1d87..29aac24e90 100644 --- a/esphome/components/sts3x/sts3x.cpp +++ b/esphome/components/sts3x/sts3x.cpp @@ -18,7 +18,7 @@ static const uint16_t STS3X_COMMAND_HEATER_DISABLE = 0x3066; static const uint16_t STS3X_COMMAND_FETCH_DATA = 0xE000; void STS3XComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up STS3x..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (!this->write_command(STS3X_COMMAND_READ_SERIAL_NUMBER)) { this->mark_failed(); return; @@ -36,7 +36,7 @@ void STS3XComponent::dump_config() { ESP_LOGCONFIG(TAG, "STS3x:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with ST3x failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); diff --git a/esphome/components/sx1509/sx1509.cpp b/esphome/components/sx1509/sx1509.cpp index a4808c86e2..865bf6f25b 100644 --- a/esphome/components/sx1509/sx1509.cpp +++ b/esphome/components/sx1509/sx1509.cpp @@ -8,7 +8,7 @@ namespace sx1509 { static const char *const TAG = "sx1509"; void SX1509Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up SX1509Component..."); + ESP_LOGCONFIG(TAG, "Running setup"); ESP_LOGV(TAG, " Resetting devices..."); if (!this->write_byte(REG_RESET, 0x12)) { diff --git a/esphome/components/tc74/tc74.cpp b/esphome/components/tc74/tc74.cpp index 2acb71f921..b79bcb5592 100644 --- a/esphome/components/tc74/tc74.cpp +++ b/esphome/components/tc74/tc74.cpp @@ -15,7 +15,7 @@ static const uint8_t TC74_DATA_READY_MASK = 0x40; // It is possible the "Data Ready" bit will not be set if the TC74 has not been powered on for at least 250ms, so it not // being set does not constitute a failure. void TC74Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up TC74..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t config_reg; if (this->read_register(TC74_REGISTER_CONFIGURATION, &config_reg, 1) != i2c::ERROR_OK) { this->mark_failed(); diff --git a/esphome/components/tca9548a/tca9548a.cpp b/esphome/components/tca9548a/tca9548a.cpp index 770fd5e47c..cdeb94ceca 100644 --- a/esphome/components/tca9548a/tca9548a.cpp +++ b/esphome/components/tca9548a/tca9548a.cpp @@ -24,7 +24,7 @@ i2c::ErrorCode TCA9548AChannel::writev(uint8_t address, i2c::WriteBuffer *buffer } void TCA9548AComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up TCA9548A..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t status = 0; if (this->read(&status, 1) != i2c::ERROR_OK) { ESP_LOGE(TAG, "TCA9548A failed"); diff --git a/esphome/components/tca9555/tca9555.cpp b/esphome/components/tca9555/tca9555.cpp index e065398c46..7bd2f44918 100644 --- a/esphome/components/tca9555/tca9555.cpp +++ b/esphome/components/tca9555/tca9555.cpp @@ -16,7 +16,7 @@ namespace tca9555 { static const char *const TAG = "tca9555"; void TCA9555Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up TCA9555..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (!this->read_gpio_modes_()) { this->mark_failed(); return; @@ -30,7 +30,7 @@ void TCA9555Component::dump_config() { ESP_LOGCONFIG(TAG, "TCA9555:"); LOG_I2C_DEVICE(this) if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with TCA9555 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } } void TCA9555Component::pin_mode(uint8_t pin, gpio::Flags flags) { diff --git a/esphome/components/tcs34725/tcs34725.cpp b/esphome/components/tcs34725/tcs34725.cpp index 0830004b5a..0aed2c8f46 100644 --- a/esphome/components/tcs34725/tcs34725.cpp +++ b/esphome/components/tcs34725/tcs34725.cpp @@ -18,7 +18,7 @@ static const uint8_t TCS34725_REGISTER_ENABLE = TCS34725_COMMAND_BIT | 0x00; static const uint8_t TCS34725_REGISTER_CRGBDATAL = TCS34725_COMMAND_BIT | 0x14; void TCS34725Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up TCS34725..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t id; if (this->read_register(TCS34725_REGISTER_ID, &id, 1) != i2c::ERROR_OK) { this->mark_failed(); @@ -46,7 +46,7 @@ void TCS34725Component::dump_config() { ESP_LOGCONFIG(TAG, "TCS34725:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with TCS34725 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); diff --git a/esphome/components/tee501/tee501.cpp b/esphome/components/tee501/tee501.cpp index 22329d40cd..329aee7c52 100644 --- a/esphome/components/tee501/tee501.cpp +++ b/esphome/components/tee501/tee501.cpp @@ -7,7 +7,7 @@ namespace tee501 { static const char *const TAG = "tee501"; void TEE501Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up TEE501..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t address[] = {0x70, 0x29}; this->write(address, 2, false); uint8_t identification[9]; @@ -25,7 +25,7 @@ void TEE501Component::dump_config() { LOG_I2C_DEVICE(this); switch (this->error_code_) { case COMMUNICATION_FAILED: - ESP_LOGE(TAG, "Communication with TEE501 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); break; case CRC_CHECK_FAILED: ESP_LOGE(TAG, "The crc check failed"); diff --git a/esphome/components/tem3200/tem3200.cpp b/esphome/components/tem3200/tem3200.cpp index d8ce48af90..05bf580e11 100644 --- a/esphome/components/tem3200/tem3200.cpp +++ b/esphome/components/tem3200/tem3200.cpp @@ -16,7 +16,7 @@ enum ErrorCode { }; void TEM3200Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up TEM3200..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t status(NONE); uint16_t raw_temperature(0); @@ -24,7 +24,7 @@ void TEM3200Component::setup() { i2c::ErrorCode err = this->read_(status, raw_temperature, raw_pressure); if (err != i2c::ERROR_OK) { - ESP_LOGCONFIG(TAG, " I2C Communication Failed..."); + ESP_LOGCONFIG(TAG, ESP_LOG_MSG_COMM_FAIL); this->mark_failed(); return; } @@ -115,7 +115,7 @@ void TEM3200Component::update() { i2c::ErrorCode err = this->read_(status, raw_temperature, raw_pressure); if (err != i2c::ERROR_OK) { - ESP_LOGW(TAG, "I2C Communication Failed"); + ESP_LOGW(TAG, ESP_LOG_MSG_COMM_FAIL); this->status_set_warning(); return; } diff --git a/esphome/components/template/alarm_control_panel/__init__.py b/esphome/components/template/alarm_control_panel/__init__.py index a406c626ee..5d2421fcbc 100644 --- a/esphome/components/template/alarm_control_panel/__init__.py +++ b/esphome/components/template/alarm_control_panel/__init__.py @@ -10,6 +10,7 @@ CODEOWNERS = ["@grahambrown11", "@hwstar"] CONF_CODES = "codes" CONF_BYPASS_ARMED_HOME = "bypass_armed_home" CONF_BYPASS_ARMED_NIGHT = "bypass_armed_night" +CONF_BYPASS_AUTO = "bypass_auto" CONF_CHIME = "chime" CONF_TRIGGER_MODE = "trigger_mode" CONF_REQUIRES_CODE_TO_ARM = "requires_code_to_arm" @@ -23,6 +24,7 @@ CONF_TRIGGER_TIME = "trigger_time" FLAG_NORMAL = "normal" FLAG_BYPASS_ARMED_HOME = "bypass_armed_home" FLAG_BYPASS_ARMED_NIGHT = "bypass_armed_night" +FLAG_BYPASS_AUTO = "bypass_auto" FLAG_CHIME = "chime" BinarySensorFlags = { @@ -30,6 +32,7 @@ BinarySensorFlags = { FLAG_BYPASS_ARMED_HOME: 1 << 1, FLAG_BYPASS_ARMED_NIGHT: 1 << 2, FLAG_CHIME: 1 << 3, + FLAG_BYPASS_AUTO: 1 << 4, } @@ -68,6 +71,7 @@ TEMPLATE_ALARM_CONTROL_PANEL_BINARY_SENSOR_SCHEMA = cv.maybe_simple_value( cv.Required(CONF_INPUT): cv.use_id(binary_sensor.BinarySensor), cv.Optional(CONF_BYPASS_ARMED_HOME, default=False): cv.boolean, cv.Optional(CONF_BYPASS_ARMED_NIGHT, default=False): cv.boolean, + cv.Optional(CONF_BYPASS_AUTO, default=False): cv.boolean, cv.Optional(CONF_CHIME, default=False): cv.boolean, cv.Optional(CONF_TRIGGER_MODE, default="DELAYED"): cv.enum( ALARM_SENSOR_TYPES, upper=True, space="_" @@ -143,6 +147,8 @@ async def to_code(config): if sensor[CONF_BYPASS_ARMED_NIGHT]: flags |= BinarySensorFlags[FLAG_BYPASS_ARMED_NIGHT] supports_arm_night = True + if sensor[CONF_BYPASS_AUTO]: + flags |= BinarySensorFlags[FLAG_BYPASS_AUTO] if sensor[CONF_CHIME]: flags |= BinarySensorFlags[FLAG_CHIME] cg.add(var.add_sensor(bs, flags, sensor[CONF_TRIGGER_MODE])) diff --git a/esphome/components/template/alarm_control_panel/template_alarm_control_panel.cpp b/esphome/components/template/alarm_control_panel/template_alarm_control_panel.cpp index bf1338edbe..4b81ab1c35 100644 --- a/esphome/components/template/alarm_control_panel/template_alarm_control_panel.cpp +++ b/esphome/components/template/alarm_control_panel/template_alarm_control_panel.cpp @@ -49,6 +49,7 @@ void TemplateAlarmControlPanel::dump_config() { TRUEFALSE(sensor_info.second.flags & BINARY_SENSOR_MODE_BYPASS_ARMED_HOME)); ESP_LOGCONFIG(TAG, " Armed night bypass: %s", TRUEFALSE(sensor_info.second.flags & BINARY_SENSOR_MODE_BYPASS_ARMED_NIGHT)); + ESP_LOGCONFIG(TAG, " Auto bypass: %s", TRUEFALSE(sensor_info.second.flags & BINARY_SENSOR_MODE_BYPASS_AUTO)); ESP_LOGCONFIG(TAG, " Chime mode: %s", TRUEFALSE(sensor_info.second.flags & BINARY_SENSOR_MODE_CHIME)); const char *sensor_type; switch (sensor_info.second.type) { @@ -71,7 +72,7 @@ void TemplateAlarmControlPanel::dump_config() { } void TemplateAlarmControlPanel::setup() { - ESP_LOGCONFIG(TAG, "Setting up Template AlarmControlPanel '%s'...", this->name_.c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->name_.c_str()); switch (this->restore_mode_) { case ALARM_CONTROL_PANEL_ALWAYS_DISARMED: this->current_state_ = ACP_STATE_DISARMED; @@ -101,6 +102,15 @@ void TemplateAlarmControlPanel::loop() { delay = this->arming_night_time_; } if ((millis() - this->last_update_) > delay) { +#ifdef USE_BINARY_SENSOR + for (auto sensor_info : this->sensor_map_) { + // Check for sensors left on and set to bypass automatically and remove them from monitoring + if ((sensor_info.second.flags & BINARY_SENSOR_MODE_BYPASS_AUTO) && (sensor_info.first->state)) { + ESP_LOGW(TAG, "%s is left on and will be automatically bypassed", sensor_info.first->get_name().c_str()); + this->bypassed_sensor_indicies_.push_back(sensor_info.second.store_index); + } + } +#endif this->publish_state(this->desired_state_); } return; @@ -137,6 +147,11 @@ void TemplateAlarmControlPanel::loop() { } // Check for triggered sensors if (sensor_info.first->state) { // Sensor triggered? + // Skip if auto bypassed + if (std::count(this->bypassed_sensor_indicies_.begin(), this->bypassed_sensor_indicies_.end(), + sensor_info.second.store_index) == 1) { + continue; + } // Skip if bypass armed home if (this->current_state_ == ACP_STATE_ARMED_HOME && (sensor_info.second.flags & BINARY_SENSOR_MODE_BYPASS_ARMED_HOME)) { @@ -255,6 +270,9 @@ void TemplateAlarmControlPanel::control(const AlarmControlPanelCall &call) { } this->desired_state_ = ACP_STATE_DISARMED; this->publish_state(ACP_STATE_DISARMED); +#ifdef USE_BINARY_SENSOR + this->bypassed_sensor_indicies_.clear(); +#endif } else if (call.get_state() == ACP_STATE_TRIGGERED) { this->publish_state(ACP_STATE_TRIGGERED); } else if (call.get_state() == ACP_STATE_PENDING) { diff --git a/esphome/components/template/alarm_control_panel/template_alarm_control_panel.h b/esphome/components/template/alarm_control_panel/template_alarm_control_panel.h index b29a48dfd7..0e3a5c77cf 100644 --- a/esphome/components/template/alarm_control_panel/template_alarm_control_panel.h +++ b/esphome/components/template/alarm_control_panel/template_alarm_control_panel.h @@ -22,6 +22,7 @@ enum BinarySensorFlags : uint16_t { BINARY_SENSOR_MODE_BYPASS_ARMED_HOME = 1 << 1, BINARY_SENSOR_MODE_BYPASS_ARMED_NIGHT = 1 << 2, BINARY_SENSOR_MODE_CHIME = 1 << 3, + BINARY_SENSOR_MODE_BYPASS_AUTO = 1 << 4, }; enum AlarmSensorType : uint16_t { @@ -121,7 +122,8 @@ class TemplateAlarmControlPanel : public alarm_control_panel::AlarmControlPanel, #ifdef USE_BINARY_SENSOR // This maps a binary sensor to its type and attribute bits std::map sensor_map_; - + // a list of automatically bypassed sensors + std::vector bypassed_sensor_indicies_; #endif TemplateAlarmControlPanelRestoreMode restore_mode_{}; diff --git a/esphome/components/template/cover/template_cover.cpp b/esphome/components/template/cover/template_cover.cpp index 2d6c3087ae..d32c6ac546 100644 --- a/esphome/components/template/cover/template_cover.cpp +++ b/esphome/components/template/cover/template_cover.cpp @@ -16,7 +16,7 @@ TemplateCover::TemplateCover() position_trigger_(new Trigger()), tilt_trigger_(new Trigger()) {} void TemplateCover::setup() { - ESP_LOGCONFIG(TAG, "Setting up template cover '%s'...", this->name_.c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->name_.c_str()); switch (this->restore_mode_) { case COVER_NO_RESTORE: break; diff --git a/esphome/components/template/select/template_select.cpp b/esphome/components/template/select/template_select.cpp index 88a0d66ed6..599226f4ba 100644 --- a/esphome/components/template/select/template_select.cpp +++ b/esphome/components/template/select/template_select.cpp @@ -11,7 +11,7 @@ void TemplateSelect::setup() { return; std::string value; - ESP_LOGD(TAG, "Setting up Template Select"); + ESP_LOGD(TAG, "Setting up"); if (!this->restore_value_) { value = this->initial_option_; ESP_LOGD(TAG, "State from initial: %s", value.c_str()); diff --git a/esphome/components/template/text/template_text.cpp b/esphome/components/template/text/template_text.cpp index fb0208e198..f8d883e848 100644 --- a/esphome/components/template/text/template_text.cpp +++ b/esphome/components/template/text/template_text.cpp @@ -12,9 +12,8 @@ void TemplateText::setup() { return; } - std::string value; - ESP_LOGD(TAG, "Setting up Template Text Input"); - value = this->initial_value_; + ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->name_.c_str()); + std::string value = this->initial_value_; if (!this->pref_) { ESP_LOGD(TAG, "State from initial: %s", value.c_str()); } else { diff --git a/esphome/components/template/valve/template_valve.cpp b/esphome/components/template/valve/template_valve.cpp index f943e19da9..99bf5e6d8a 100644 --- a/esphome/components/template/valve/template_valve.cpp +++ b/esphome/components/template/valve/template_valve.cpp @@ -16,7 +16,7 @@ TemplateValve::TemplateValve() position_trigger_(new Trigger()) {} void TemplateValve::setup() { - ESP_LOGCONFIG(TAG, "Setting up template valve '%s'...", this->name_.c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->name_.c_str()); switch (this->restore_mode_) { case VALVE_NO_RESTORE: break; diff --git a/esphome/components/tlc59208f/tlc59208f_output.cpp b/esphome/components/tlc59208f/tlc59208f_output.cpp index bd62f8de6d..3441a41a59 100644 --- a/esphome/components/tlc59208f/tlc59208f_output.cpp +++ b/esphome/components/tlc59208f/tlc59208f_output.cpp @@ -71,7 +71,7 @@ static const uint8_t LDR_PWM = 0x02; static const uint8_t LDR_GRPPWM = 0x03; void TLC59208FOutput::setup() { - ESP_LOGCONFIG(TAG, "Setting up TLC59208FOutputComponent..."); + ESP_LOGCONFIG(TAG, "Running setup"); ESP_LOGV(TAG, " Resetting all devices on the bus..."); diff --git a/esphome/components/tm1621/tm1621.cpp b/esphome/components/tm1621/tm1621.cpp index ebaa5a3457..8f18a3d384 100644 --- a/esphome/components/tm1621/tm1621.cpp +++ b/esphome/components/tm1621/tm1621.cpp @@ -29,7 +29,7 @@ const uint8_t TM1621_DIGIT_ROW[2][12] = {{0x5F, 0x50, 0x3D, 0x79, 0x72, 0x6B, 0x {0xF5, 0x05, 0xB6, 0x97, 0x47, 0xD3, 0xF3, 0x85, 0xF7, 0xD7, 0x02, 0x00}}; void TM1621Display::setup() { - ESP_LOGCONFIG(TAG, "Setting up TM1621..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->cs_pin_->setup(); // OUTPUT this->cs_pin_->digital_write(true); diff --git a/esphome/components/tm1637/tm1637.cpp b/esphome/components/tm1637/tm1637.cpp index 2f2d4b707a..db117645bd 100644 --- a/esphome/components/tm1637/tm1637.cpp +++ b/esphome/components/tm1637/tm1637.cpp @@ -125,7 +125,7 @@ const uint8_t TM1637_ASCII_TO_RAW[] PROGMEM = { 0b01100011, // '~', ord 0x7E (degree symbol) }; void TM1637Display::setup() { - ESP_LOGCONFIG(TAG, "Setting up TM1637..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->clk_pin_->setup(); // OUTPUT this->clk_pin_->digital_write(false); // LOW diff --git a/esphome/components/tm1651/tm1651.cpp b/esphome/components/tm1651/tm1651.cpp index 89807f5565..97beefff64 100644 --- a/esphome/components/tm1651/tm1651.cpp +++ b/esphome/components/tm1651/tm1651.cpp @@ -17,7 +17,7 @@ static const uint8_t TM1651_BRIGHTNESS_MEDIUM_HW = 2; static const uint8_t TM1651_BRIGHTNESS_HIGH_HW = 7; void TM1651Display::setup() { - ESP_LOGCONFIG(TAG, "Setting up TM1651..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t clk = clk_pin_->get_pin(); uint8_t dio = dio_pin_->get_pin(); diff --git a/esphome/components/tmp102/tmp102.cpp b/esphome/components/tmp102/tmp102.cpp index f35fbf5d4b..7390d9fcc9 100644 --- a/esphome/components/tmp102/tmp102.cpp +++ b/esphome/components/tmp102/tmp102.cpp @@ -15,13 +15,11 @@ static const uint8_t TMP102_REGISTER_HIGH_LIMIT = 0x03; static const float TMP102_CONVERSION_FACTOR = 0.0625; -void TMP102Component::setup() { ESP_LOGCONFIG(TAG, "Setting up TMP102..."); } - void TMP102Component::dump_config() { ESP_LOGCONFIG(TAG, "TMP102:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with TMP102 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); LOG_SENSOR(" ", "Temperature", this); diff --git a/esphome/components/tmp102/tmp102.h b/esphome/components/tmp102/tmp102.h index 1bbb2d5ae3..657b48c7cf 100644 --- a/esphome/components/tmp102/tmp102.h +++ b/esphome/components/tmp102/tmp102.h @@ -9,10 +9,7 @@ namespace tmp102 { class TMP102Component : public PollingComponent, public i2c::I2CDevice, public sensor::Sensor { public: - /// Setup (reset) the sensor and check connection. - void setup() override; void dump_config() override; - /// Update the sensor values (temperature) void update() override; float get_setup_priority() const override; diff --git a/esphome/components/tmp1075/tmp1075.cpp b/esphome/components/tmp1075/tmp1075.cpp index 68253a11f1..b8f80e4abe 100644 --- a/esphome/components/tmp1075/tmp1075.cpp +++ b/esphome/components/tmp1075/tmp1075.cpp @@ -44,7 +44,7 @@ void TMP1075Sensor::update() { void TMP1075Sensor::dump_config() { LOG_SENSOR("", "TMP1075 Sensor", this); if (this->is_failed()) { - ESP_LOGE(TAG, " Communication with TMP1075 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); return; } ESP_LOGCONFIG(TAG, " limit low : %.4f °C", alert_limit_low_); diff --git a/esphome/components/tmp117/tmp117.cpp b/esphome/components/tmp117/tmp117.cpp index f719ea93b6..5fe8f51414 100644 --- a/esphome/components/tmp117/tmp117.cpp +++ b/esphome/components/tmp117/tmp117.cpp @@ -26,7 +26,7 @@ void TMP117Component::update() { } } void TMP117Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up TMP117..."); + ESP_LOGCONFIG(TAG, "Running setup"); if (!this->write_config_(this->config_)) { this->mark_failed(); @@ -43,7 +43,7 @@ void TMP117Component::dump_config() { ESP_LOGD(TAG, "TMP117:"); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with TMP117 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_SENSOR(" ", "Temperature", this); } diff --git a/esphome/components/tof10120/tof10120_sensor.cpp b/esphome/components/tof10120/tof10120_sensor.cpp index 32cd604be9..e27c7bbd64 100644 --- a/esphome/components/tof10120/tof10120_sensor.cpp +++ b/esphome/components/tof10120/tof10120_sensor.cpp @@ -27,7 +27,7 @@ void TOF10120Sensor::setup() {} void TOF10120Sensor::update() { if (!this->write_bytes(TOF10120_DISTANCE_REGISTER, TOF10120_READ_DISTANCE_CMD, sizeof(TOF10120_READ_DISTANCE_CMD))) { - ESP_LOGE(TAG, "Communication with TOF10120 failed on write"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); this->status_set_warning(); return; } @@ -39,7 +39,7 @@ void TOF10120Sensor::update() { } delay(TOF10120_DEFAULT_DELAY); if (this->read(data, 2) != i2c::ERROR_OK) { - ESP_LOGE(TAG, "Communication with TOF10120 failed on read"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); this->status_set_warning(); return; } diff --git a/esphome/components/tsl2561/tsl2561.cpp b/esphome/components/tsl2561/tsl2561.cpp index e80e9220d8..4a24153dd5 100644 --- a/esphome/components/tsl2561/tsl2561.cpp +++ b/esphome/components/tsl2561/tsl2561.cpp @@ -15,7 +15,7 @@ static const uint8_t TSL2561_REGISTER_DATA_0 = 0x0C; static const uint8_t TSL2561_REGISTER_DATA_1 = 0x0E; void TSL2561Sensor::setup() { - ESP_LOGCONFIG(TAG, "Setting up TSL2561..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t id; if (!this->tsl2561_read_byte(TSL2561_REGISTER_ID, &id)) { this->mark_failed(); @@ -41,7 +41,7 @@ void TSL2561Sensor::dump_config() { LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with TSL2561 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } int gain = this->gain_ == TSL2561_GAIN_1X ? 1 : 16; diff --git a/esphome/components/tsl2591/tsl2591.cpp b/esphome/components/tsl2591/tsl2591.cpp index 977048364c..7799d727ba 100644 --- a/esphome/components/tsl2591/tsl2591.cpp +++ b/esphome/components/tsl2591/tsl2591.cpp @@ -89,7 +89,7 @@ void TSL2591Component::dump_config() { LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with TSL2591 failed earlier, during setup"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); return; } diff --git a/esphome/components/tt21100/touchscreen/tt21100.cpp b/esphome/components/tt21100/touchscreen/tt21100.cpp index d18ce835c1..d4dd1c195f 100644 --- a/esphome/components/tt21100/touchscreen/tt21100.cpp +++ b/esphome/components/tt21100/touchscreen/tt21100.cpp @@ -47,7 +47,7 @@ struct TT21100TouchReport { float TT21100Touchscreen::get_setup_priority() const { return setup_priority::HARDWARE - 1.0f; } void TT21100Touchscreen::setup() { - ESP_LOGCONFIG(TAG, "Setting up TT21100 Touchscreen..."); + ESP_LOGCONFIG(TAG, "Running setup"); // Register interrupt pin if (this->interrupt_pin_ != nullptr) { diff --git a/esphome/components/ttp229_bsf/ttp229_bsf.cpp b/esphome/components/ttp229_bsf/ttp229_bsf.cpp index 93c947d28a..8b58795ebb 100644 --- a/esphome/components/ttp229_bsf/ttp229_bsf.cpp +++ b/esphome/components/ttp229_bsf/ttp229_bsf.cpp @@ -7,7 +7,7 @@ namespace ttp229_bsf { static const char *const TAG = "ttp229_bsf"; void TTP229BSFComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up ttp229_bsf... "); + ESP_LOGCONFIG(TAG, "Running setup"); this->sdo_pin_->setup(); this->scl_pin_->setup(); this->scl_pin_->digital_write(true); diff --git a/esphome/components/ttp229_lsf/ttp229_lsf.cpp b/esphome/components/ttp229_lsf/ttp229_lsf.cpp index 773d51b76e..8e976da4ef 100644 --- a/esphome/components/ttp229_lsf/ttp229_lsf.cpp +++ b/esphome/components/ttp229_lsf/ttp229_lsf.cpp @@ -7,7 +7,7 @@ namespace ttp229_lsf { static const char *const TAG = "ttp229_lsf"; void TTP229LSFComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up ttp229..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t data[2]; if (this->read(data, 2) != i2c::ERROR_OK) { this->error_code_ = COMMUNICATION_FAILED; @@ -20,7 +20,7 @@ void TTP229LSFComponent::dump_config() { LOG_I2C_DEVICE(this); switch (this->error_code_) { case COMMUNICATION_FAILED: - ESP_LOGE(TAG, "Communication with TTP229 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); break; case NONE: default: diff --git a/esphome/components/tx20/tx20.cpp b/esphome/components/tx20/tx20.cpp index a2a3baa46e..4d614c1e4e 100644 --- a/esphome/components/tx20/tx20.cpp +++ b/esphome/components/tx20/tx20.cpp @@ -15,7 +15,7 @@ static const char *const DIRECTIONS[] = {"N", "NNE", "NE", "ENE", "E", "ESE", "S "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"}; void Tx20Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up Tx20"); + ESP_LOGCONFIG(TAG, "Running setup"); this->pin_->setup(); this->store_.buffer = new uint16_t[MAX_BUFFER_SIZE]; diff --git a/esphome/components/uart/uart_component_esp32_arduino.cpp b/esphome/components/uart/uart_component_esp32_arduino.cpp index b241c03de4..0ed1a724e9 100644 --- a/esphome/components/uart/uart_component_esp32_arduino.cpp +++ b/esphome/components/uart/uart_component_esp32_arduino.cpp @@ -74,7 +74,7 @@ uint32_t ESP32ArduinoUARTComponent::get_config() { } void ESP32ArduinoUARTComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up UART..."); + ESP_LOGCONFIG(TAG, "Running setup"); // Use Arduino HardwareSerial UARTs if all used pins match the ones // preconfigured by the platform. For example if RX disabled but TX pin // is 1 we still want to use Serial. diff --git a/esphome/components/uart/uart_component_esp8266.cpp b/esphome/components/uart/uart_component_esp8266.cpp index fa8dc3fb17..b06f553a47 100644 --- a/esphome/components/uart/uart_component_esp8266.cpp +++ b/esphome/components/uart/uart_component_esp8266.cpp @@ -56,7 +56,7 @@ uint32_t ESP8266UartComponent::get_config() { } void ESP8266UartComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up UART bus..."); + ESP_LOGCONFIG(TAG, "Running setup"); // Use Arduino HardwareSerial UARTs if all used pins match the ones // preconfigured by the platform. For example if RX disabled but TX pin // is 1 we still want to use Serial. diff --git a/esphome/components/uart/uart_component_esp_idf.cpp b/esphome/components/uart/uart_component_esp_idf.cpp index 122d4105c8..9d5d22da6b 100644 --- a/esphome/components/uart/uart_component_esp_idf.cpp +++ b/esphome/components/uart/uart_component_esp_idf.cpp @@ -85,12 +85,12 @@ void IDFUARTComponent::setup() { #endif // USE_LOGGER if (next_uart_num >= SOC_UART_NUM) { - ESP_LOGW(TAG, "Maximum number of UART components created already."); + ESP_LOGW(TAG, "Maximum number of UART components created already"); this->mark_failed(); return; } this->uart_num_ = static_cast(next_uart_num++); - ESP_LOGCONFIG(TAG, "Setting up UART %u...", this->uart_num_); + ESP_LOGCONFIG(TAG, "Running setup for UART %u", this->uart_num_); this->lock_ = xSemaphoreCreateMutex(); diff --git a/esphome/components/uart/uart_component_libretiny.cpp b/esphome/components/uart/uart_component_libretiny.cpp index c5e299e9d1..bfb183d964 100644 --- a/esphome/components/uart/uart_component_libretiny.cpp +++ b/esphome/components/uart/uart_component_libretiny.cpp @@ -46,7 +46,7 @@ uint16_t LibreTinyUARTComponent::get_config() { } void LibreTinyUARTComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up UART..."); + ESP_LOGCONFIG(TAG, "Running setup"); int8_t tx_pin = tx_pin_ == nullptr ? -1 : tx_pin_->get_pin(); int8_t rx_pin = rx_pin_ == nullptr ? -1 : rx_pin_->get_pin(); diff --git a/esphome/components/uart/uart_component_rp2040.cpp b/esphome/components/uart/uart_component_rp2040.cpp index e2c47080ac..c1a2e50ae0 100644 --- a/esphome/components/uart/uart_component_rp2040.cpp +++ b/esphome/components/uart/uart_component_rp2040.cpp @@ -52,7 +52,7 @@ uint16_t RP2040UartComponent::get_config() { } void RP2040UartComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up UART bus..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint16_t config = get_config(); diff --git a/esphome/components/ufire_ec/ufire_ec.cpp b/esphome/components/ufire_ec/ufire_ec.cpp index 7af4fadf75..6a418e51b7 100644 --- a/esphome/components/ufire_ec/ufire_ec.cpp +++ b/esphome/components/ufire_ec/ufire_ec.cpp @@ -7,7 +7,7 @@ namespace ufire_ec { static const char *const TAG = "ufire_ec"; void UFireECComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up uFire_ec..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t version; if (!this->read_byte(REGISTER_VERSION, &version) && version != 0xFF) { diff --git a/esphome/components/ufire_ise/ufire_ise.cpp b/esphome/components/ufire_ise/ufire_ise.cpp index 957e6f3299..5d0cb6ec2f 100644 --- a/esphome/components/ufire_ise/ufire_ise.cpp +++ b/esphome/components/ufire_ise/ufire_ise.cpp @@ -9,7 +9,7 @@ namespace ufire_ise { static const char *const TAG = "ufire_ise"; void UFireISEComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up uFire_ise..."); + ESP_LOGCONFIG(TAG, "Running setup"); uint8_t version; if (!this->read_byte(REGISTER_VERSION, &version) && version != 0xFF) { diff --git a/esphome/components/ultrasonic/ultrasonic_sensor.cpp b/esphome/components/ultrasonic/ultrasonic_sensor.cpp index 604e78d6f8..b3ed6833ec 100644 --- a/esphome/components/ultrasonic/ultrasonic_sensor.cpp +++ b/esphome/components/ultrasonic/ultrasonic_sensor.cpp @@ -8,7 +8,7 @@ namespace ultrasonic { static const char *const TAG = "ultrasonic.sensor"; void UltrasonicSensorComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up Ultrasonic Sensor..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->trigger_pin_->setup(); this->trigger_pin_->digital_write(false); this->echo_pin_->setup(); diff --git a/esphome/components/veml3235/veml3235.cpp b/esphome/components/veml3235/veml3235.cpp index 2410bfdda2..965e167942 100644 --- a/esphome/components/veml3235/veml3235.cpp +++ b/esphome/components/veml3235/veml3235.cpp @@ -10,7 +10,7 @@ static const char *const TAG = "veml3235.sensor"; void VEML3235Sensor::setup() { uint8_t device_id[] = {0, 0}; - ESP_LOGCONFIG(TAG, "Setting up VEML3235 '%s'...", this->name_.c_str()); + ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->name_.c_str()); if (!this->refresh_config_reg()) { ESP_LOGE(TAG, "Unable to write configuration"); @@ -212,7 +212,7 @@ void VEML3235Sensor::dump_config() { LOG_SENSOR("", "VEML3235", this); LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication failed"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } LOG_UPDATE_INTERVAL(this); ESP_LOGCONFIG(TAG, " Auto-gain enabled: %s", YESNO(this->auto_gain_)); diff --git a/esphome/components/veml7700/veml7700.cpp b/esphome/components/veml7700/veml7700.cpp index a8c1411c68..25f6c761c8 100644 --- a/esphome/components/veml7700/veml7700.cpp +++ b/esphome/components/veml7700/veml7700.cpp @@ -78,7 +78,7 @@ static const char *get_gain_str(Gain gain) { } void VEML7700Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up VEML7700/6030..."); + ESP_LOGCONFIG(TAG, "Running setup"); auto err = this->configure_(); if (err != i2c::ERROR_OK) { @@ -109,7 +109,7 @@ void VEML7700Component::dump_config() { LOG_SENSOR(" ", "Actual integration time", this->actual_integration_time_sensor_); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with I2C VEML7700/6030 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } } diff --git a/esphome/components/web_server/web_server.cpp b/esphome/components/web_server/web_server.cpp index 63c1d5d4fd..4caac025aa 100644 --- a/esphome/components/web_server/web_server.cpp +++ b/esphome/components/web_server/web_server.cpp @@ -235,7 +235,7 @@ std::string WebServer::get_config_json() { } void WebServer::setup() { - ESP_LOGCONFIG(TAG, "Setting up web server..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->setup_controller(this->include_internal_); this->base_->init(); diff --git a/esphome/components/weikai_i2c/weikai_i2c.cpp b/esphome/components/weikai_i2c/weikai_i2c.cpp index 9d0c9446ec..3b353eb662 100644 --- a/esphome/components/weikai_i2c/weikai_i2c.cpp +++ b/esphome/components/weikai_i2c/weikai_i2c.cpp @@ -142,7 +142,7 @@ void WeikaiRegisterI2C::write_fifo(uint8_t *data, size_t length) { void WeikaiComponentI2C::setup() { // before any manipulation we store the address to base_address_ for future use this->base_address_ = this->address_; - ESP_LOGCONFIG(TAG, "Setting up wk2168_i2c: %s with %d UARTs at @%02X ...", this->get_name(), this->children_.size(), + ESP_LOGCONFIG(TAG, "Running setup for '%s' with %d UARTs at @%02X", this->get_name(), this->children_.size(), this->base_address_); // enable all channels diff --git a/esphome/components/weikai_spi/weikai_spi.cpp b/esphome/components/weikai_spi/weikai_spi.cpp index 22c63bbd2d..a81f69a4aa 100644 --- a/esphome/components/weikai_spi/weikai_spi.cpp +++ b/esphome/components/weikai_spi/weikai_spi.cpp @@ -156,7 +156,7 @@ void WeikaiRegisterSPI::write_fifo(uint8_t *data, size_t length) { /////////////////////////////////////////////////////////////////////////////// void WeikaiComponentSPI::setup() { using namespace weikai; - ESP_LOGCONFIG(TAG, "Setting up wk2168_spi: %s with %d UARTs...", this->get_name(), this->children_.size()); + ESP_LOGCONFIG(TAG, "Running setup for '%s' with %d UARTs...", this->get_name(), this->children_.size()); this->spi_setup(); // enable all channels this->reg(WKREG_GENA, 0) = GENA_C1EN | GENA_C2EN | GENA_C3EN | GENA_C4EN; diff --git a/esphome/components/wifi/wifi_component.cpp b/esphome/components/wifi/wifi_component.cpp index 4a50553305..baa273d39f 100644 --- a/esphome/components/wifi/wifi_component.cpp +++ b/esphome/components/wifi/wifi_component.cpp @@ -45,7 +45,7 @@ static const char *const TAG = "wifi"; float WiFiComponent::get_setup_priority() const { return setup_priority::WIFI; } void WiFiComponent::setup() { - ESP_LOGCONFIG(TAG, "Setting up WiFi..."); + ESP_LOGCONFIG(TAG, "Running setup"); this->wifi_pre_setup_(); if (this->enable_on_boot_) { this->start(); @@ -58,7 +58,7 @@ void WiFiComponent::setup() { } void WiFiComponent::start() { - ESP_LOGCONFIG(TAG, "Starting WiFi..."); + ESP_LOGCONFIG(TAG, "Starting"); ESP_LOGCONFIG(TAG, " Local MAC: %s", get_mac_address_pretty().c_str()); this->last_connected_ = millis(); @@ -71,7 +71,7 @@ void WiFiComponent::start() { SavedWifiSettings save{}; if (this->pref_.load(&save)) { - ESP_LOGD(TAG, "Loaded saved wifi settings: %s", save.ssid); + ESP_LOGD(TAG, "Loaded saved settings: %s", save.ssid); WiFiAP sta{}; sta.set_ssid(save.ssid); @@ -122,7 +122,7 @@ void WiFiComponent::start() { void WiFiComponent::loop() { this->wifi_loop_(); - const uint32_t now = millis(); + const uint32_t now = App.get_loop_component_start_time(); if (this->has_sta()) { if (this->is_connected() != this->handled_connected_state_) { @@ -160,7 +160,7 @@ void WiFiComponent::loop() { case WIFI_COMPONENT_STATE_STA_CONNECTED: { if (!this->is_connected()) { - ESP_LOGW(TAG, "WiFi Connection lost... Reconnecting..."); + ESP_LOGW(TAG, "Connection lost; reconnecting"); this->state_ = WIFI_COMPONENT_STATE_STA_CONNECTING; this->retry_connect(); } else { @@ -201,7 +201,7 @@ void WiFiComponent::loop() { if (!this->has_ap() && this->reboot_timeout_ != 0) { if (now - this->last_connected_ > this->reboot_timeout_) { - ESP_LOGE(TAG, "Can't connect to WiFi, rebooting..."); + ESP_LOGE(TAG, "Can't connect; rebooting"); App.reboot(); } } @@ -310,7 +310,7 @@ void WiFiComponent::save_wifi_sta(const std::string &ssid, const std::string &pa } void WiFiComponent::start_connecting(const WiFiAP &ap, bool two) { - ESP_LOGI(TAG, "WiFi Connecting to '%s'...", ap.get_ssid().c_str()); + ESP_LOGI(TAG, "Connecting to '%s'", ap.get_ssid().c_str()); #ifdef ESPHOME_LOG_HAS_VERBOSE ESP_LOGV(TAG, "Connection Params:"); ESP_LOGV(TAG, " SSID: '%s'", ap.get_ssid().c_str()); @@ -427,7 +427,7 @@ void WiFiComponent::print_connect_params_() { ESP_LOGCONFIG(TAG, " Local MAC: %s", get_mac_address_pretty().c_str()); if (this->is_disabled()) { - ESP_LOGCONFIG(TAG, " WiFi is disabled!"); + ESP_LOGCONFIG(TAG, " Disabled"); return; } ESP_LOGCONFIG(TAG, " SSID: " LOG_SECRET("'%s'"), wifi_ssid().c_str()); @@ -459,7 +459,7 @@ void WiFiComponent::enable() { if (this->state_ != WIFI_COMPONENT_STATE_DISABLED) return; - ESP_LOGD(TAG, "Enabling WIFI..."); + ESP_LOGD(TAG, "Enabling"); this->error_from_callback_ = false; this->state_ = WIFI_COMPONENT_STATE_OFF; this->start(); @@ -469,7 +469,7 @@ void WiFiComponent::disable() { if (this->state_ == WIFI_COMPONENT_STATE_DISABLED) return; - ESP_LOGD(TAG, "Disabling WIFI..."); + ESP_LOGD(TAG, "Disabling"); this->state_ = WIFI_COMPONENT_STATE_DISABLED; this->wifi_disconnect_(); this->wifi_mode_(false, false); @@ -614,7 +614,7 @@ void WiFiComponent::check_connecting_finished() { // We won't retry hidden networks unless a reconnect fails more than three times again this->retry_hidden_ = false; - ESP_LOGI(TAG, "WiFi Connected!"); + ESP_LOGI(TAG, "Connected"); this->print_connect_params_(); if (this->has_ap()) { @@ -644,7 +644,7 @@ void WiFiComponent::check_connecting_finished() { uint32_t now = millis(); if (now - this->action_started_ > 30000) { - ESP_LOGW(TAG, "Timeout while connecting to WiFi."); + ESP_LOGW(TAG, "Connection timeout"); this->retry_connect(); return; } @@ -660,18 +660,18 @@ void WiFiComponent::check_connecting_finished() { } if (status == WiFiSTAConnectStatus::ERROR_NETWORK_NOT_FOUND) { - ESP_LOGW(TAG, "WiFi network can not be found anymore."); + ESP_LOGW(TAG, "Network no longer found"); this->retry_connect(); return; } if (status == WiFiSTAConnectStatus::ERROR_CONNECT_FAILED) { - ESP_LOGW(TAG, "Connecting to WiFi network failed. Are the credentials wrong?"); + ESP_LOGW(TAG, "Connection failed. Check credentials"); this->retry_connect(); return; } - ESP_LOGW(TAG, "WiFi Unknown connection status %d", (int) status); + ESP_LOGW(TAG, "Unknown connection status %d", (int) status); this->retry_connect(); } diff --git a/esphome/components/wifi/wifi_component_esp32_arduino.cpp b/esphome/components/wifi/wifi_component_esp32_arduino.cpp index b7a77fcdc9..23fc03f471 100644 --- a/esphome/components/wifi/wifi_component_esp32_arduino.cpp +++ b/esphome/components/wifi/wifi_component_esp32_arduino.cpp @@ -91,7 +91,7 @@ bool WiFiComponent::wifi_mode_(optional sta, optional ap) { bool ret = WiFiClass::mode(set_mode); if (!ret) { - ESP_LOGW(TAG, "Setting WiFi mode failed!"); + ESP_LOGW(TAG, "Setting mode failed"); return false; } diff --git a/esphome/components/wifi/wifi_component_libretiny.cpp b/esphome/components/wifi/wifi_component_libretiny.cpp index b02f8ef0ce..9f50b62924 100644 --- a/esphome/components/wifi/wifi_component_libretiny.cpp +++ b/esphome/components/wifi/wifi_component_libretiny.cpp @@ -50,7 +50,7 @@ bool WiFiComponent::wifi_mode_(optional sta, optional ap) { bool ret = WiFi.mode(static_cast(mode)); if (!ret) { - ESP_LOGW(TAG, "Setting WiFi mode failed!"); + ESP_LOGW(TAG, "Setting mode failed"); } return ret; diff --git a/esphome/components/x9c/x9c.cpp b/esphome/components/x9c/x9c.cpp index 4e7a94266e..caad16edf9 100644 --- a/esphome/components/x9c/x9c.cpp +++ b/esphome/components/x9c/x9c.cpp @@ -34,7 +34,7 @@ void X9cOutput::trim_value(int change_amount) { } void X9cOutput::setup() { - ESP_LOGCONFIG(TAG, "Setting up X9C Potentiometer with initial value of %f", this->initial_value_); + ESP_LOGCONFIG(TAG, "Running setup"); this->inc_pin_->get_pin(); this->inc_pin_->setup(); diff --git a/esphome/components/xl9535/xl9535.cpp b/esphome/components/xl9535/xl9535.cpp index 93c65a4cb7..7bcd98070f 100644 --- a/esphome/components/xl9535/xl9535.cpp +++ b/esphome/components/xl9535/xl9535.cpp @@ -7,7 +7,7 @@ namespace xl9535 { static const char *const TAG = "xl9535"; void XL9535Component::setup() { - ESP_LOGCONFIG(TAG, "Setting up XL9535..."); + ESP_LOGCONFIG(TAG, "Running setup"); // Check to see if the device can read from the register uint8_t port = 0; @@ -22,7 +22,7 @@ void XL9535Component::dump_config() { LOG_I2C_DEVICE(this); if (this->is_failed()) { - ESP_LOGE(TAG, "Communication with XL9535 failed!"); + ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); } } diff --git a/esphome/const.py b/esphome/const.py index 199064dc3a..2ca79e70c2 100644 --- a/esphome/const.py +++ b/esphome/const.py @@ -963,6 +963,7 @@ CONF_WAND_ID = "wand_id" CONF_WARM_WHITE = "warm_white" CONF_WARM_WHITE_COLOR_TEMPERATURE = "warm_white_color_temperature" CONF_WATCHDOG_THRESHOLD = "watchdog_threshold" +CONF_WATCHDOG_TIMEOUT = "watchdog_timeout" CONF_WEB_SERVER = "web_server" CONF_WEB_SERVER_ID = "web_server_id" CONF_WEIGHT = "weight" diff --git a/esphome/core/application.cpp b/esphome/core/application.cpp index a71b848499..ad1ec33436 100644 --- a/esphome/core/application.cpp +++ b/esphome/core/application.cpp @@ -2,11 +2,30 @@ #include "esphome/core/log.h" #include "esphome/core/version.h" #include "esphome/core/hal.h" +#include #ifdef USE_STATUS_LED #include "esphome/components/status_led/status_led.h" #endif +#ifdef USE_SOCKET_SELECT_SUPPORT +#include + +#ifdef USE_SOCKET_IMPL_LWIP_SOCKETS +// LWIP sockets implementation +#include +#elif defined(USE_SOCKET_IMPL_BSD_SOCKETS) +// BSD sockets implementation +#ifdef USE_ESP32 +// ESP32 "BSD sockets" are actually LWIP under the hood +#include +#else +// True BSD sockets (e.g., host platform) +#include +#endif +#endif +#endif + namespace esphome { static const char *const TAG = "app"; @@ -106,7 +125,64 @@ void Application::loop() { // otherwise interval=0 schedules result in constant looping with almost no sleep next_schedule = std::max(next_schedule, delay_time / 2); delay_time = std::min(next_schedule, delay_time); + +#ifdef USE_SOCKET_SELECT_SUPPORT + if (!this->socket_fds_.empty()) { + // Use select() with timeout when we have sockets to monitor + + // Update fd_set if socket list has changed + if (this->socket_fds_changed_) { + FD_ZERO(&this->base_read_fds_); + for (int fd : this->socket_fds_) { + if (fd >= 0 && fd < FD_SETSIZE) { + FD_SET(fd, &this->base_read_fds_); + } + } + this->socket_fds_changed_ = false; + } + + // Copy base fd_set before each select + this->read_fds_ = this->base_read_fds_; + + // Convert delay_time (milliseconds) to timeval + struct timeval tv; + tv.tv_sec = delay_time / 1000; + tv.tv_usec = (delay_time - tv.tv_sec * 1000) * 1000; + + // Call select with timeout +#if defined(USE_SOCKET_IMPL_LWIP_SOCKETS) || (defined(USE_ESP32) && defined(USE_SOCKET_IMPL_BSD_SOCKETS)) + // Use lwip_select() on platforms with lwIP - it's faster + // Note: On ESP32 with BSD sockets, select() is already mapped to lwip_select() via macros, + // but we explicitly call lwip_select() for clarity and to ensure we get the optimized version + int ret = lwip_select(this->max_fd_ + 1, &this->read_fds_, nullptr, nullptr, &tv); +#else + // Use standard select() on other platforms (e.g., host/native builds) + int ret = ::select(this->max_fd_ + 1, &this->read_fds_, nullptr, nullptr, &tv); +#endif + + // Process select() result: + // ret < 0: error (except EINTR which is normal) + // ret > 0: socket(s) have data ready - normal and expected + // ret == 0: timeout occurred - normal and expected + if (ret < 0) { + if (errno == EINTR) { + // Interrupted by signal - this is normal, just continue + // No need to delay as some time has already passed + ESP_LOGVV(TAG, "select() interrupted by signal"); + } else { + // Actual error - log and fall back to delay + ESP_LOGW(TAG, "select() failed with errno %d", errno); + delay(delay_time); + } + } + } else { + // No sockets registered, use regular delay + delay(delay_time); + } +#else + // No select support, use regular delay delay(delay_time); +#endif } this->last_loop_ = last_op_end_time; @@ -167,6 +243,67 @@ void Application::calculate_looping_components_() { } } +#ifdef USE_SOCKET_SELECT_SUPPORT +bool Application::register_socket_fd(int fd) { + // WARNING: This function is NOT thread-safe and must only be called from the main loop + // It modifies socket_fds_ and related variables without locking + if (fd < 0) + return false; + + if (fd >= FD_SETSIZE) { + ESP_LOGE(TAG, "Cannot monitor socket fd %d: exceeds FD_SETSIZE (%d)", fd, FD_SETSIZE); + ESP_LOGE(TAG, "Socket will not be monitored for data - may cause performance issues!"); + return false; + } + + this->socket_fds_.push_back(fd); + this->socket_fds_changed_ = true; + + if (fd > this->max_fd_) { + this->max_fd_ = fd; + } + + return true; +} + +void Application::unregister_socket_fd(int fd) { + // WARNING: This function is NOT thread-safe and must only be called from the main loop + // It modifies socket_fds_ and related variables without locking + if (fd < 0) + return; + + auto it = std::find(this->socket_fds_.begin(), this->socket_fds_.end(), fd); + if (it != this->socket_fds_.end()) { + // Swap with last element and pop - O(1) removal since order doesn't matter + if (it != this->socket_fds_.end() - 1) { + std::swap(*it, this->socket_fds_.back()); + } + this->socket_fds_.pop_back(); + this->socket_fds_changed_ = true; + + // Only recalculate max_fd if we removed the current max + if (fd == this->max_fd_) { + if (this->socket_fds_.empty()) { + this->max_fd_ = -1; + } else { + // Find new max using std::max_element + this->max_fd_ = *std::max_element(this->socket_fds_.begin(), this->socket_fds_.end()); + } + } + } +} + +bool Application::is_socket_ready(int fd) const { + // This function is thread-safe for reading the result of select() + // However, it should only be called after select() has been executed in the main loop + // The read_fds_ is only modified by select() in the main loop + if (fd < 0 || fd >= FD_SETSIZE) + return false; + + return FD_ISSET(fd, &this->read_fds_); +} +#endif + Application App; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) } // namespace esphome diff --git a/esphome/core/application.h b/esphome/core/application.h index f3444f3d4e..f3aa59ad00 100644 --- a/esphome/core/application.h +++ b/esphome/core/application.h @@ -10,6 +10,10 @@ #include "esphome/core/runtime_stats.h" #include "esphome/core/scheduler.h" +#ifdef USE_SOCKET_SELECT_SUPPORT +#include +#endif + #ifdef USE_BINARY_SENSOR #include "esphome/components/binary_sensor/binary_sensor.h" #endif @@ -480,6 +484,19 @@ class Application { Scheduler scheduler; + /// Register/unregister a socket file descriptor to be monitored for read events. +#ifdef USE_SOCKET_SELECT_SUPPORT + /// These functions update the fd_set used by select() in the main loop. + /// WARNING: These functions are NOT thread-safe. They must only be called from the main loop. + /// NOTE: File descriptors >= FD_SETSIZE (typically 10 on ESP) will be rejected with an error. + /// @return true if registration was successful, false if fd exceeds limits + bool register_socket_fd(int fd); + void unregister_socket_fd(int fd); + /// Check if there's data available on a socket without blocking + /// This function is thread-safe for reading, but should be called after select() has run + bool is_socket_ready(int fd) const; +#endif + protected: friend Component; @@ -568,6 +585,15 @@ class Application { uint32_t app_state_{0}; Component *current_component_{nullptr}; uint32_t loop_component_start_time_{0}; + +#ifdef USE_SOCKET_SELECT_SUPPORT + // Socket select management + std::vector socket_fds_; // Vector of all monitored socket file descriptors + bool socket_fds_changed_{false}; // Flag to rebuild base_read_fds_ when socket_fds_ changes + int max_fd_{-1}; // Highest file descriptor number for select() + fd_set base_read_fds_{}; // Cached fd_set rebuilt only when socket_fds_ changes + fd_set read_fds_{}; // Working fd_set for select(), copied from base_read_fds_ +#endif }; /// Global storage of Application pointer - only one Application can exist. diff --git a/esphome/core/defines.h b/esphome/core/defines.h index 455b404e32..9313f07720 100644 --- a/esphome/core/defines.h +++ b/esphome/core/defines.h @@ -95,6 +95,7 @@ // Feature flags which do not work for zephyr #ifndef USE_ZEPHYR +#define USE_AUDIO_DAC #define USE_AUDIO_FLAC_SUPPORT #define USE_AUDIO_MP3_SUPPORT #define USE_API @@ -139,6 +140,7 @@ #define USE_MICROPHONE #define USE_PSRAM #define USE_SOCKET_IMPL_BSD_SOCKETS +#define USE_SOCKET_SELECT_SUPPORT #define USE_SPEAKER #define USE_SPI #define USE_VOICE_ASSISTANT @@ -198,12 +200,14 @@ #ifdef USE_LIBRETINY #define USE_CAPTIVE_PORTAL #define USE_SOCKET_IMPL_LWIP_SOCKETS +#define USE_SOCKET_SELECT_SUPPORT #define USE_WEBSERVER #define USE_WEBSERVER_PORT 80 // NOLINT #endif #ifdef USE_HOST #define USE_SOCKET_IMPL_BSD_SOCKETS +#define USE_SOCKET_SELECT_SUPPORT #endif // Disabled feature flags diff --git a/esphome/core/log.h b/esphome/core/log.h index 9ab80afe78..adf72e4bac 100644 --- a/esphome/core/log.h +++ b/esphome/core/log.h @@ -1,5 +1,7 @@ #pragma once +#include "log_const_en.h" + #include #include // for PRIu32 and friends diff --git a/esphome/core/log_const_en.h b/esphome/core/log_const_en.h new file mode 100644 index 0000000000..75e71ecd81 --- /dev/null +++ b/esphome/core/log_const_en.h @@ -0,0 +1,11 @@ +#pragma once + +#include "defines.h" + +#ifdef USE_ESP8266 +#define ESP_LOG_MSG_COMM_FAIL "Communication failed" +#define ESP_LOG_MSG_COMM_FAIL_FOR "Communication failed for '%s'" +#else +constexpr const char *const ESP_LOG_MSG_COMM_FAIL = "Communication failed"; +constexpr const char *const ESP_LOG_MSG_COMM_FAIL_FOR = "Communication failed for '%s'"; +#endif diff --git a/platformio.ini b/platformio.ini index 06a0666d67..ec1e54de09 100644 --- a/platformio.ini +++ b/platformio.ini @@ -126,7 +126,7 @@ lib_deps = HTTPClient ; http_request,nextion (Arduino built-in) ESPmDNS ; mdns (Arduino built-in) DNSServer ; captive_portal (Arduino built-in) - esphome/ESP32-audioI2S@2.0.7 ; i2s_audio + esphome/ESP32-audioI2S@2.2.0 ; i2s_audio droscy/esp_wireguard@0.4.2 ; wireguard esphome/esp-audio-libs@1.1.4 ; audio diff --git a/script/ci-custom.py b/script/ci-custom.py index a3a31b2259..fbabbc1e74 100755 --- a/script/ci-custom.py +++ b/script/ci-custom.py @@ -663,6 +663,7 @@ def lint_trailing_whitespace(fname, match): "esphome/components/valve/valve.h", "esphome/core/component.h", "esphome/core/gpio.h", + "esphome/core/log_const_en.h", "esphome/core/log.h", "tests/custom.h", ], diff --git a/script/generate-esp32-boards.py b/script/generate-esp32-boards.py new file mode 100755 index 0000000000..83d0f0c3e0 --- /dev/null +++ b/script/generate-esp32-boards.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python3 + +import json +import os +import subprocess +import tempfile + +from esphome.components.esp32 import ESP_IDF_PLATFORM_VERSION as ver + +version_str = f"{ver.major}.{ver.minor:02d}.{ver.patch:02d}" +print(f"ESP32 Platform Version: {version_str}") + + +def get_boards(): + with tempfile.TemporaryDirectory() as tempdir: + subprocess.run( + [ + "git", + "clone", + "--depth", + "1", + "--branch", + f"{ver.major}.{ver.minor:02d}.{ver.patch:02d}", + "https://github.com/pioarduino/platform-espressif32", + tempdir, + ], + check=True, + ) + boards_file = os.path.join(tempdir, "boards") + boards = {} + for fname in os.listdir(boards_file): + if not fname.endswith(".json"): + continue + with open(os.path.join(boards_file, fname), encoding="utf-8") as f: + board_info = json.load(f) + mcu = board_info["build"]["mcu"] + name = board_info["name"] + board = fname[:-5] + variant = mcu.upper() + boards[board] = { + "name": name, + "variant": f"VARIANT_{variant}", + } + return boards + + +TEMPLATE = """ "%s": { + "name": "%s", + "variant": %s, + }, +""" + + +def main(): + boards = get_boards() + # open boards.py, delete existing BOARDS variable and write the new boards dict + boards_file_path = os.path.join( + os.path.dirname(__file__), "..", "esphome", "components", "esp32", "boards.py" + ) + with open(boards_file_path, encoding="UTF-8") as f: + lines = f.readlines() + + with open(boards_file_path, "w", encoding="UTF-8") as f: + for line in lines: + if line.startswith("BOARDS = {"): + f.write("BOARDS = {\n") + for board, info in sorted(boards.items()): + f.write(TEMPLATE % (board, info["name"], info["variant"])) + f.write("}\n") + break + + f.write(line) + + +if __name__ == "__main__": + main() + print("ESP32 boards updated successfully.") diff --git a/tests/components/alarm_control_panel/common.yaml b/tests/components/alarm_control_panel/common.yaml index 218274bad4..5b8ae5a282 100644 --- a/tests/components/alarm_control_panel/common.yaml +++ b/tests/components/alarm_control_panel/common.yaml @@ -19,6 +19,7 @@ alarm_control_panel: - input: bin1 bypass_armed_home: true bypass_armed_night: true + bypass_auto: true on_state: then: - lambda: !lambda |- @@ -38,6 +39,7 @@ alarm_control_panel: - input: bin1 bypass_armed_home: true bypass_armed_night: true + bypass_auto: true on_disarmed: then: - logger.log: "### DISARMED ###" diff --git a/tests/components/es8388/common.yaml b/tests/components/es8388/common.yaml new file mode 100644 index 0000000000..6a63de5aa1 --- /dev/null +++ b/tests/components/es8388/common.yaml @@ -0,0 +1,25 @@ +esphome: + on_boot: + then: + - audio_dac.mute_off: + - audio_dac.mute_on: + + - audio_dac.set_volume: + volume: 50% + +i2c: + - id: i2c_es8388 + scl: ${scl_pin} + sda: ${sda_pin} + +audio_dac: + - platform: es8388 + id: es8388_parent + +select: + - platform: es8388 + es8388_id: es8388_parent + dac_output: + name: "DAC Output" + adc_input_mic: + name: "ADC Input MIC" diff --git a/tests/components/es8388/test.esp32-ard.yaml b/tests/components/es8388/test.esp32-ard.yaml new file mode 100644 index 0000000000..63c3bd6afd --- /dev/null +++ b/tests/components/es8388/test.esp32-ard.yaml @@ -0,0 +1,5 @@ +substitutions: + scl_pin: GPIO16 + sda_pin: GPIO17 + +<<: !include common.yaml diff --git a/tests/components/es8388/test.esp32-c3-ard.yaml b/tests/components/es8388/test.esp32-c3-ard.yaml new file mode 100644 index 0000000000..ee2c29ca4e --- /dev/null +++ b/tests/components/es8388/test.esp32-c3-ard.yaml @@ -0,0 +1,5 @@ +substitutions: + scl_pin: GPIO5 + sda_pin: GPIO4 + +<<: !include common.yaml diff --git a/tests/components/es8388/test.esp32-c3-idf.yaml b/tests/components/es8388/test.esp32-c3-idf.yaml new file mode 100644 index 0000000000..ee2c29ca4e --- /dev/null +++ b/tests/components/es8388/test.esp32-c3-idf.yaml @@ -0,0 +1,5 @@ +substitutions: + scl_pin: GPIO5 + sda_pin: GPIO4 + +<<: !include common.yaml diff --git a/tests/components/es8388/test.esp32-idf.yaml b/tests/components/es8388/test.esp32-idf.yaml new file mode 100644 index 0000000000..63c3bd6afd --- /dev/null +++ b/tests/components/es8388/test.esp32-idf.yaml @@ -0,0 +1,5 @@ +substitutions: + scl_pin: GPIO16 + sda_pin: GPIO17 + +<<: !include common.yaml diff --git a/tests/components/es8388/test.esp8266-ard.yaml b/tests/components/es8388/test.esp8266-ard.yaml new file mode 100644 index 0000000000..ee2c29ca4e --- /dev/null +++ b/tests/components/es8388/test.esp8266-ard.yaml @@ -0,0 +1,5 @@ +substitutions: + scl_pin: GPIO5 + sda_pin: GPIO4 + +<<: !include common.yaml diff --git a/tests/components/online_image/common.yaml b/tests/components/online_image/common.yaml index 69daa915c5..25809930b5 100644 --- a/tests/components/online_image/common.yaml +++ b/tests/components/online_image/common.yaml @@ -11,6 +11,13 @@ online_image: format: PNG type: BINARY resize: 50x50 + on_download_finished: + lambda: |- + if (cached) { + ESP_LOGD("online_image", "Cache hit: using cached image"); + } else { + ESP_LOGD("online_image", "Cache miss: fresh download"); + } - id: online_binary_transparent_image url: http://www.libpng.org/pub/png/img_png/pnglogo-blk-tiny.png type: BINARY diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 35586519e4..4c798c6b72 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -6,21 +6,22 @@ import asyncio from collections.abc import AsyncGenerator, Generator from contextlib import AbstractAsyncContextManager, asynccontextmanager import logging +import os from pathlib import Path import platform import signal import socket +import sys import tempfile +from typing import TextIO from aioesphomeapi import APIClient, APIConnectionError, ReconnectLogic import pytest import pytest_asyncio -# Skip all integration tests on Windows -if platform.system() == "Windows": - pytest.skip( - "Integration tests are not supported on Windows", allow_module_level=True - ) +import esphome.config +from esphome.core import CORE +from esphome.platformio_api import get_idedata from .const import ( API_CONNECTION_TIMEOUT, @@ -37,9 +38,16 @@ from .types import ( CompileFunction, ConfigWriter, RunCompiledFunction, - RunFunction, ) +# Skip all integration tests on Windows +if platform.system() == "Windows": + pytest.skip( + "Integration tests are not supported on Windows", allow_module_level=True + ) + +import pty # not available on Windows + @pytest.fixture(scope="module", autouse=True) def enable_aioesphomeapi_debug_logging(): @@ -134,75 +142,72 @@ async def write_yaml_config( yield _write_config -async def _run_esphome_command( - command: str, - config_path: Path, - cwd: Path, -) -> asyncio.subprocess.Process: - """Run an ESPHome command with the given arguments.""" - return await asyncio.create_subprocess_exec( - "esphome", - command, - str(config_path), - cwd=cwd, - stdout=None, # Inherit stdout - stderr=None, # Inherit stderr - stdin=asyncio.subprocess.DEVNULL, - # Start in a new process group to isolate signal handling - start_new_session=True, - ) - - @pytest_asyncio.fixture async def compile_esphome( integration_test_dir: Path, ) -> AsyncGenerator[CompileFunction]: - """Compile an ESPHome configuration.""" + """Compile an ESPHome configuration and return the binary path.""" - async def _compile(config_path: Path) -> None: - proc = await _run_esphome_command("compile", config_path, integration_test_dir) - await proc.wait() - if proc.returncode != 0: - raise RuntimeError( - f"Failed to compile {config_path}, return code: {proc.returncode}. " - f"Run with 'pytest -s' to see compilation output." + async def _compile(config_path: Path) -> Path: + # Retry compilation up to 3 times if we get a segfault + max_retries = 3 + for attempt in range(max_retries): + # Compile using subprocess, inheriting stdout/stderr to show progress + proc = await asyncio.create_subprocess_exec( + "esphome", + "compile", + str(config_path), + cwd=integration_test_dir, + stdout=None, # Inherit stdout + stderr=None, # Inherit stderr + stdin=asyncio.subprocess.DEVNULL, + # Start in a new process group to isolate signal handling + start_new_session=True, ) + await proc.wait() + + if proc.returncode == 0: + # Success! + break + elif proc.returncode == -11 and attempt < max_retries - 1: + # Segfault (-11 = SIGSEGV), retry + print( + f"Compilation segfaulted (attempt {attempt + 1}/{max_retries}), retrying..." + ) + await asyncio.sleep(1) # Brief pause before retry + continue + else: + # Other error or final retry + raise RuntimeError( + f"Failed to compile {config_path}, return code: {proc.returncode}. " + f"Run with 'pytest -s' to see compilation output." + ) + + # Load the config to get idedata (blocking call, must use executor) + loop = asyncio.get_running_loop() + + def _read_config_and_get_binary(): + CORE.config_path = str(config_path) + config = esphome.config.read_config( + {"command": "compile", "config": str(config_path)} + ) + if config is None: + raise RuntimeError(f"Failed to read config from {config_path}") + + # Get the compiled binary path + idedata = get_idedata(config) + return Path(idedata.firmware_elf_path) + + binary_path = await loop.run_in_executor(None, _read_config_and_get_binary) + + if not binary_path.exists(): + raise RuntimeError(f"Compiled binary not found at {binary_path}") + + return binary_path yield _compile -@pytest_asyncio.fixture -async def run_esphome_process( - integration_test_dir: Path, -) -> AsyncGenerator[RunFunction]: - """Run an ESPHome process and manage its lifecycle.""" - processes: list[asyncio.subprocess.Process] = [] - - async def _run(config_path: Path) -> asyncio.subprocess.Process: - process = await _run_esphome_command("run", config_path, integration_test_dir) - processes.append(process) - return process - - yield _run - - # Cleanup: terminate all "run" processes gracefully - for process in processes: - if process.returncode is None: - # Send SIGINT (Ctrl+C) for graceful shutdown of the running ESPHome instance - process.send_signal(signal.SIGINT) - try: - await asyncio.wait_for(process.wait(), timeout=SIGINT_TIMEOUT) - except asyncio.TimeoutError: - # If SIGINT didn't work, try SIGTERM - process.terminate() - try: - await asyncio.wait_for(process.wait(), timeout=SIGTERM_TIMEOUT) - except asyncio.TimeoutError: - # Last resort: SIGKILL - process.kill() - await process.wait() - - @asynccontextmanager async def create_api_client( address: str = LOCALHOST, @@ -341,28 +346,140 @@ async def api_client_connected( yield _connect_client -async def wait_for_port_open( - host: str, port: int, timeout: float = PORT_WAIT_TIMEOUT +async def _read_stream_lines( + stream: asyncio.StreamReader, lines: list[str], output_stream: TextIO ) -> None: - """Wait for a TCP port to be open and accepting connections.""" + """Read lines from a stream, append to list, and echo to output stream.""" + while line := await stream.readline(): + decoded_line = line.decode("utf-8", errors="replace") + lines.append(decoded_line.rstrip()) + # Echo to stdout/stderr in real-time + print(decoded_line.rstrip(), file=output_stream, flush=True) + + +@asynccontextmanager +async def run_binary_and_wait_for_port( + binary_path: Path, + host: str, + port: int, + timeout: float = PORT_WAIT_TIMEOUT, +) -> AsyncGenerator[None]: + """Run a binary, wait for it to open a port, and clean up on exit.""" + # Create a pseudo-terminal to make the binary think it's running interactively + # This is needed because the ESPHome host logger checks isatty() + controller_fd, device_fd = pty.openpty() + + # Run the compiled binary with PTY + process = await asyncio.create_subprocess_exec( + str(binary_path), + stdout=device_fd, + stderr=device_fd, + stdin=asyncio.subprocess.DEVNULL, + # Start in a new process group to isolate signal handling + start_new_session=True, + pass_fds=(device_fd,), + ) + + # Close the device end in the parent process + os.close(device_fd) + + # Convert controller_fd to async streams for reading + loop = asyncio.get_running_loop() + controller_reader = asyncio.StreamReader() + controller_protocol = asyncio.StreamReaderProtocol(controller_reader) + controller_transport, _ = await loop.connect_read_pipe( + lambda: controller_protocol, os.fdopen(controller_fd, "rb", 0) + ) + output_reader = controller_reader + + if process.returncode is not None: + raise RuntimeError( + f"Process died immediately with return code {process.returncode}. " + "Ensure the binary is valid and can run successfully." + ) + + # Wait for the API server to start listening loop = asyncio.get_running_loop() start_time = loop.time() - # Small yield to ensure the process has a chance to start - await asyncio.sleep(0) + # Start collecting output + stdout_lines: list[str] = [] + output_tasks: list[asyncio.Task] = [] - while loop.time() - start_time < timeout: - try: - # Try to connect to the port - _, writer = await asyncio.open_connection(host, port) - writer.close() - await writer.wait_closed() - return # Port is open - except (ConnectionRefusedError, OSError): - # Port not open yet, wait a bit and try again - await asyncio.sleep(PORT_POLL_INTERVAL) + try: + # Read from output stream + output_tasks = [ + asyncio.create_task( + _read_stream_lines(output_reader, stdout_lines, sys.stdout) + ) + ] - raise TimeoutError(f"Port {port} on {host} did not open within {timeout} seconds") + # Small yield to ensure the process has a chance to start + await asyncio.sleep(0) + + while loop.time() - start_time < timeout: + try: + # Try to connect to the port + _, writer = await asyncio.open_connection(host, port) + writer.close() + await writer.wait_closed() + # Port is open, yield control + yield + return + except (ConnectionRefusedError, OSError): + # Check if process died + if process.returncode is not None: + break + # Port not open yet, wait a bit and try again + await asyncio.sleep(PORT_POLL_INTERVAL) + + # Timeout or process died - build error message + error_msg = f"Port {port} on {host} did not open within {timeout} seconds" + + if process.returncode is not None: + error_msg += f"\nProcess exited with code: {process.returncode}" + + # Include any output collected so far + if stdout_lines: + error_msg += "\n\n--- Process Output ---\n" + error_msg += "\n".join(stdout_lines[-100:]) # Last 100 lines + + raise TimeoutError(error_msg) + + finally: + # Cancel output collection tasks + for task in output_tasks: + task.cancel() + # Wait for tasks to complete and check for exceptions + results = await asyncio.gather(*output_tasks, return_exceptions=True) + for i, result in enumerate(results): + if isinstance(result, Exception) and not isinstance( + result, asyncio.CancelledError + ): + print( + f"Error reading from PTY: {result}", + file=sys.stderr, + ) + + # Close the PTY transport (Unix only) + if controller_transport is not None: + controller_transport.close() + + # Cleanup: terminate the process gracefully + if process.returncode is None: + # Send SIGINT (Ctrl+C) for graceful shutdown + process.send_signal(signal.SIGINT) + try: + await asyncio.wait_for(process.wait(), timeout=SIGINT_TIMEOUT) + except asyncio.TimeoutError: + # If SIGINT didn't work, try SIGTERM + process.terminate() + try: + await asyncio.wait_for(process.wait(), timeout=SIGTERM_TIMEOUT) + except asyncio.TimeoutError: + # Last resort: SIGKILL + process.kill() + await process.wait() @asynccontextmanager @@ -371,40 +488,29 @@ async def run_compiled_context( filename: str | None, write_yaml_config: ConfigWriter, compile_esphome: CompileFunction, - run_esphome_process: RunFunction, port: int, port_socket: socket.socket | None = None, -) -> AsyncGenerator[asyncio.subprocess.Process]: +) -> AsyncGenerator[None]: """Context manager to write, compile and run an ESPHome configuration.""" # Write the YAML config config_path = await write_yaml_config(yaml_content, filename) - # Compile the configuration - await compile_esphome(config_path) + # Compile the configuration and get binary path + binary_path = await compile_esphome(config_path) # Close the port socket right before running to release the port if port_socket is not None: port_socket.close() - # Run the ESPHome device - process = await run_esphome_process(config_path) - assert process.returncode is None, "Process died immediately" - - # Wait for the API server to start listening - await wait_for_port_open(LOCALHOST, port, timeout=PORT_WAIT_TIMEOUT) - - try: - yield process - finally: - # Process cleanup is handled by run_esphome_process fixture - pass + # Run the binary and wait for the API server to start + async with run_binary_and_wait_for_port(binary_path, LOCALHOST, port): + yield @pytest_asyncio.fixture async def run_compiled( write_yaml_config: ConfigWriter, compile_esphome: CompileFunction, - run_esphome_process: RunFunction, reserved_tcp_port: tuple[int, socket.socket], ) -> AsyncGenerator[RunCompiledFunction]: """Write, compile and run an ESPHome configuration.""" @@ -418,7 +524,6 @@ async def run_compiled( filename, write_yaml_config, compile_esphome, - run_esphome_process, port, port_socket, ) diff --git a/tests/integration/types.py b/tests/integration/types.py index ef1af2add8..6fc3e9435e 100644 --- a/tests/integration/types.py +++ b/tests/integration/types.py @@ -11,11 +11,9 @@ from typing import Protocol from aioesphomeapi import APIClient ConfigWriter = Callable[[str, str | None], Awaitable[Path]] -CompileFunction = Callable[[Path], Awaitable[None]] +CompileFunction = Callable[[Path], Awaitable[Path]] RunFunction = Callable[[Path], Awaitable[asyncio.subprocess.Process]] -RunCompiledFunction = Callable[ - [str, str | None], AbstractAsyncContextManager[asyncio.subprocess.Process] -] +RunCompiledFunction = Callable[[str, str | None], AbstractAsyncContextManager[None]] WaitFunction = Callable[[APIClient, float], Awaitable[bool]]