1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-19 19:52:20 +01:00

Merge branch 'warning_strings_flash' into integration

This commit is contained in:
J. Nick Koston
2025-09-05 22:13:20 -05:00
26 changed files with 72 additions and 55 deletions

View File

@@ -64,7 +64,7 @@ void AbsoluteHumidityComponent::loop() {
ESP_LOGW(TAG, "No valid state from humidity sensor!"); ESP_LOGW(TAG, "No valid state from humidity sensor!");
} }
this->publish_state(NAN); this->publish_state(NAN);
this->status_set_warning("Unable to calculate absolute humidity."); this->status_set_warning(LOG_STR("Unable to calculate absolute humidity."));
return; return;
} }

View File

@@ -96,7 +96,7 @@ void AHT10Component::read_data_() {
ESP_LOGD(TAG, "Read attempt %d at %ums", this->read_count_, (unsigned) (millis() - this->start_time_)); ESP_LOGD(TAG, "Read attempt %d at %ums", this->read_count_, (unsigned) (millis() - this->start_time_));
} }
if (this->read(data, 6) != i2c::ERROR_OK) { if (this->read(data, 6) != i2c::ERROR_OK) {
this->status_set_warning("Read failed, will retry"); this->status_set_warning(LOG_STR("Read failed, will retry"));
this->restart_read_(); this->restart_read_();
return; return;
} }
@@ -113,7 +113,7 @@ void AHT10Component::read_data_() {
} else { } else {
ESP_LOGD(TAG, "Invalid humidity, retrying"); ESP_LOGD(TAG, "Invalid humidity, retrying");
if (this->write(AHT10_MEASURE_CMD, sizeof(AHT10_MEASURE_CMD)) != i2c::ERROR_OK) { if (this->write(AHT10_MEASURE_CMD, sizeof(AHT10_MEASURE_CMD)) != i2c::ERROR_OK) {
this->status_set_warning(ESP_LOG_MSG_COMM_FAIL); this->status_set_warning(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
} }
this->restart_read_(); this->restart_read_();
return; return;
@@ -144,7 +144,7 @@ void AHT10Component::update() {
return; return;
this->start_time_ = millis(); this->start_time_ = millis();
if (this->write(AHT10_MEASURE_CMD, sizeof(AHT10_MEASURE_CMD)) != i2c::ERROR_OK) { if (this->write(AHT10_MEASURE_CMD, sizeof(AHT10_MEASURE_CMD)) != i2c::ERROR_OK) {
this->status_set_warning(ESP_LOG_MSG_COMM_FAIL); this->status_set_warning(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
return; return;
} }
this->restart_read_(); this->restart_read_();

View File

@@ -12,7 +12,7 @@ constexpr static const uint8_t AXS_READ_TOUCHPAD[11] = {0xb5, 0xab, 0xa5, 0x5a,
#define ERROR_CHECK(err) \ #define ERROR_CHECK(err) \
if ((err) != i2c::ERROR_OK) { \ if ((err) != i2c::ERROR_OK) { \
this->status_set_warning("Failed to communicate"); \ this->status_set_warning(LOG_STR("Failed to communicate")); \
return; \ return; \
} }

View File

@@ -149,7 +149,7 @@ void BL0942::setup() {
this->write_reg_(BL0942_REG_USR_WRPROT, 0); this->write_reg_(BL0942_REG_USR_WRPROT, 0);
if (this->read_reg_(BL0942_REG_MODE) != mode) if (this->read_reg_(BL0942_REG_MODE) != mode)
this->status_set_warning("BL0942 setup failed!"); this->status_set_warning(LOG_STR("BL0942 setup failed!"));
this->flush(); this->flush();
} }

View File

@@ -64,7 +64,7 @@ bool DallasTemperatureSensor::read_scratch_pad_() {
} }
} else { } else {
ESP_LOGW(TAG, "'%s' - reading scratch pad failed bus reset", this->get_name().c_str()); ESP_LOGW(TAG, "'%s' - reading scratch pad failed bus reset", this->get_name().c_str());
this->status_set_warning("bus reset failed"); this->status_set_warning(LOG_STR("bus reset failed"));
} }
return success; return success;
} }
@@ -124,7 +124,7 @@ bool DallasTemperatureSensor::check_scratch_pad_() {
crc8(this->scratch_pad_, 8)); crc8(this->scratch_pad_, 8));
#endif #endif
if (!chksum_validity) { if (!chksum_validity) {
this->status_set_warning("scratch pad checksum invalid"); this->status_set_warning(LOG_STR("scratch pad checksum invalid"));
ESP_LOGD(TAG, "Scratch pad: %02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X (%02X)", this->scratch_pad_[0], 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], this->scratch_pad_[1], this->scratch_pad_[2], this->scratch_pad_[3], this->scratch_pad_[4],
this->scratch_pad_[5], this->scratch_pad_[6], this->scratch_pad_[7], this->scratch_pad_[8], this->scratch_pad_[5], this->scratch_pad_[6], this->scratch_pad_[7], this->scratch_pad_[8],

View File

@@ -492,7 +492,7 @@ void EthernetComponent::start_connect_() {
global_eth_component->ipv6_count_ = 0; global_eth_component->ipv6_count_ = 0;
#endif /* USE_NETWORK_IPV6 */ #endif /* USE_NETWORK_IPV6 */
this->connect_begin_ = millis(); this->connect_begin_ = millis();
this->status_set_warning("waiting for IP configuration"); this->status_set_warning(LOG_STR("waiting for IP configuration"));
esp_err_t err; esp_err_t err;
err = esp_netif_set_hostname(this->eth_netif_, App.get_name().c_str()); err = esp_netif_set_hostname(this->eth_netif_, App.get_name().c_str());

View File

@@ -11,22 +11,22 @@ static const uint8_t NUMBER_OF_READ_RETRIES = 5;
void GDK101Component::update() { void GDK101Component::update() {
uint8_t data[2]; uint8_t data[2];
if (!this->read_dose_1m_(data)) { if (!this->read_dose_1m_(data)) {
this->status_set_warning("Failed to read dose 1m"); this->status_set_warning(LOG_STR("Failed to read dose 1m"));
return; return;
} }
if (!this->read_dose_10m_(data)) { if (!this->read_dose_10m_(data)) {
this->status_set_warning("Failed to read dose 10m"); this->status_set_warning(LOG_STR("Failed to read dose 10m"));
return; return;
} }
if (!this->read_status_(data)) { if (!this->read_status_(data)) {
this->status_set_warning("Failed to read status"); this->status_set_warning(LOG_STR("Failed to read status"));
return; return;
} }
if (!this->read_measurement_duration_(data)) { if (!this->read_measurement_duration_(data)) {
this->status_set_warning("Failed to read measurement duration"); this->status_set_warning(LOG_STR("Failed to read measurement duration"));
return; return;
} }
this->status_clear_warning(); this->status_clear_warning();

View File

@@ -20,7 +20,7 @@ static const size_t MAX_BUTTONS = 4; // max number of buttons scanned
#define ERROR_CHECK(err) \ #define ERROR_CHECK(err) \
if ((err) != i2c::ERROR_OK) { \ if ((err) != i2c::ERROR_OK) { \
this->status_set_warning(ESP_LOG_MSG_COMM_FAIL); \ this->status_set_warning(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); \
return; \ return; \
} }

View File

@@ -15,7 +15,7 @@ static const char *const TAG = "honeywellabp2";
void HONEYWELLABP2Sensor::read_sensor_data() { void HONEYWELLABP2Sensor::read_sensor_data() {
if (this->read(raw_data_, 7) != i2c::ERROR_OK) { if (this->read(raw_data_, 7) != i2c::ERROR_OK) {
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
this->status_set_warning("couldn't read sensor data"); this->status_set_warning(LOG_STR("couldn't read sensor data"));
return; return;
} }
float press_counts = encode_uint24(raw_data_[1], raw_data_[2], raw_data_[3]); // calculate digital pressure counts float press_counts = encode_uint24(raw_data_[1], raw_data_[2], raw_data_[3]); // calculate digital pressure counts
@@ -31,7 +31,7 @@ void HONEYWELLABP2Sensor::read_sensor_data() {
void HONEYWELLABP2Sensor::start_measurement() { void HONEYWELLABP2Sensor::start_measurement() {
if (this->write(i2c_cmd_, 3) != i2c::ERROR_OK) { if (this->write(i2c_cmd_, 3) != i2c::ERROR_OK) {
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
this->status_set_warning("couldn't start measurement"); this->status_set_warning(LOG_STR("couldn't start measurement"));
return; return;
} }
this->measurement_running_ = true; this->measurement_running_ = true;
@@ -40,7 +40,7 @@ void HONEYWELLABP2Sensor::start_measurement() {
bool HONEYWELLABP2Sensor::is_measurement_ready() { bool HONEYWELLABP2Sensor::is_measurement_ready() {
if (this->read(raw_data_, 1) != i2c::ERROR_OK) { if (this->read(raw_data_, 1) != i2c::ERROR_OK) {
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL); ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
this->status_set_warning("couldn't check measurement"); this->status_set_warning(LOG_STR("couldn't check measurement"));
return false; return false;
} }
if ((raw_data_[0] & (0x1 << STATUS_BIT_BUSY)) > 0) { if ((raw_data_[0] & (0x1 << STATUS_BIT_BUSY)) > 0) {
@@ -53,7 +53,7 @@ bool HONEYWELLABP2Sensor::is_measurement_ready() {
void HONEYWELLABP2Sensor::measurement_timeout() { void HONEYWELLABP2Sensor::measurement_timeout() {
ESP_LOGE(TAG, "Timeout!"); ESP_LOGE(TAG, "Timeout!");
this->measurement_running_ = false; this->measurement_running_ = false;
this->status_set_warning("measurement timed out"); this->status_set_warning(LOG_STR("measurement timed out"));
} }
float HONEYWELLABP2Sensor::get_pressure() { return this->last_pressure_; } float HONEYWELLABP2Sensor::get_pressure() { return this->last_pressure_; }

View File

@@ -6,7 +6,7 @@ namespace m5stack_8angle {
void M5Stack8AngleSwitchBinarySensor::update() { void M5Stack8AngleSwitchBinarySensor::update() {
int8_t out = this->parent_->read_switch(); int8_t out = this->parent_->read_switch();
if (out == -1) { if (out == -1) {
this->status_set_warning("Could not read binary sensor state from M5Stack 8Angle."); this->status_set_warning(LOG_STR("Could not read binary sensor state from M5Stack 8Angle."));
return; return;
} }
this->publish_state(out != 0); this->publish_state(out != 0);

View File

@@ -7,7 +7,7 @@ void M5Stack8AngleKnobSensor::update() {
if (this->parent_ != nullptr) { if (this->parent_ != nullptr) {
int32_t raw_pos = this->parent_->read_knob_pos_raw(this->channel_, this->bits_); int32_t raw_pos = this->parent_->read_knob_pos_raw(this->channel_, this->bits_);
if (raw_pos == -1) { if (raw_pos == -1) {
this->status_set_warning("Could not read knob position from M5Stack 8Angle."); this->status_set_warning(LOG_STR("Could not read knob position from M5Stack 8Angle."));
return; return;
} }
if (this->raw_) { if (this->raw_) {

View File

@@ -22,7 +22,7 @@ void MAX17043Component::update() {
if (this->voltage_sensor_ != nullptr) { if (this->voltage_sensor_ != nullptr) {
if (!this->read_byte_16(MAX17043_VCELL, &raw_voltage)) { if (!this->read_byte_16(MAX17043_VCELL, &raw_voltage)) {
this->status_set_warning("Unable to read MAX17043_VCELL"); this->status_set_warning(LOG_STR("Unable to read MAX17043_VCELL"));
} else { } else {
float voltage = (1.25 * (float) (raw_voltage >> 4)) / 1000.0; float voltage = (1.25 * (float) (raw_voltage >> 4)) / 1000.0;
this->voltage_sensor_->publish_state(voltage); this->voltage_sensor_->publish_state(voltage);
@@ -31,7 +31,7 @@ void MAX17043Component::update() {
} }
if (this->battery_remaining_sensor_ != nullptr) { if (this->battery_remaining_sensor_ != nullptr) {
if (!this->read_byte_16(MAX17043_SOC, &raw_percent)) { if (!this->read_byte_16(MAX17043_SOC, &raw_percent)) {
this->status_set_warning("Unable to read MAX17043_SOC"); this->status_set_warning(LOG_STR("Unable to read MAX17043_SOC"));
} else { } else {
float percent = (float) ((raw_percent >> 8) + 0.003906f * (raw_percent & 0x00ff)); float percent = (float) ((raw_percent >> 8) + 0.003906f * (raw_percent & 0x00ff));
this->battery_remaining_sensor_->publish_state(percent); this->battery_remaining_sensor_->publish_state(percent);

View File

@@ -8,7 +8,7 @@ static const char *const TAG = "mcp23x08_base";
bool MCP23X08Base::digital_read_hw(uint8_t pin) { bool MCP23X08Base::digital_read_hw(uint8_t pin) {
if (!this->read_reg(mcp23x08_base::MCP23X08_GPIO, &this->input_mask_)) { if (!this->read_reg(mcp23x08_base::MCP23X08_GPIO, &this->input_mask_)) {
this->status_set_warning(ESP_LOG_MSG_COMM_FAIL); this->status_set_warning(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
return false; return false;
} }
return true; return true;

View File

@@ -11,13 +11,13 @@ bool MCP23X17Base::digital_read_hw(uint8_t pin) {
uint8_t data; uint8_t data;
if (pin < 8) { if (pin < 8) {
if (!this->read_reg(mcp23x17_base::MCP23X17_GPIOA, &data)) { if (!this->read_reg(mcp23x17_base::MCP23X17_GPIOA, &data)) {
this->status_set_warning(ESP_LOG_MSG_COMM_FAIL); this->status_set_warning(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
return false; return false;
} }
this->input_mask_ = encode_uint16(this->input_mask_ >> 8, data); this->input_mask_ = encode_uint16(this->input_mask_ >> 8, data);
} else { } else {
if (!this->read_reg(mcp23x17_base::MCP23X17_GPIOB, &data)) { if (!this->read_reg(mcp23x17_base::MCP23X17_GPIOB, &data)) {
this->status_set_warning(ESP_LOG_MSG_COMM_FAIL); this->status_set_warning(LOG_STR(ESP_LOG_MSG_COMM_FAIL));
return false; return false;
} }
this->input_mask_ = encode_uint16(data, this->input_mask_ & 0xFF); this->input_mask_ = encode_uint16(data, this->input_mask_ & 0xFF);

View File

@@ -68,7 +68,7 @@ bool PI4IOE5V6408Component::read_gpio_outputs_() {
uint8_t data; uint8_t data;
if (!this->read_byte(PI4IOE5V6408_REGISTER_OUT_SET, &data)) { if (!this->read_byte(PI4IOE5V6408_REGISTER_OUT_SET, &data)) {
this->status_set_warning("Failed to read output register"); this->status_set_warning(LOG_STR("Failed to read output register"));
return false; return false;
} }
this->output_mask_ = data; this->output_mask_ = data;
@@ -82,7 +82,7 @@ bool PI4IOE5V6408Component::read_gpio_modes_() {
uint8_t data; uint8_t data;
if (!this->read_byte(PI4IOE5V6408_REGISTER_IO_DIR, &data)) { if (!this->read_byte(PI4IOE5V6408_REGISTER_IO_DIR, &data)) {
this->status_set_warning("Failed to read GPIO modes"); this->status_set_warning(LOG_STR("Failed to read GPIO modes"));
return false; return false;
} }
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE #if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
@@ -99,7 +99,7 @@ bool PI4IOE5V6408Component::digital_read_hw(uint8_t pin) {
uint8_t data; uint8_t data;
if (!this->read_byte(PI4IOE5V6408_REGISTER_IN_STATE, &data)) { if (!this->read_byte(PI4IOE5V6408_REGISTER_IN_STATE, &data)) {
this->status_set_warning("Failed to read GPIO state"); this->status_set_warning(LOG_STR("Failed to read GPIO state"));
return false; return false;
} }
this->input_mask_ = data; this->input_mask_ = data;
@@ -117,7 +117,7 @@ void PI4IOE5V6408Component::digital_write_hw(uint8_t pin, bool value) {
this->output_mask_ &= ~(1 << pin); this->output_mask_ &= ~(1 << pin);
} }
if (!this->write_byte(PI4IOE5V6408_REGISTER_OUT_SET, this->output_mask_)) { if (!this->write_byte(PI4IOE5V6408_REGISTER_OUT_SET, this->output_mask_)) {
this->status_set_warning("Failed to write output register"); this->status_set_warning(LOG_STR("Failed to write output register"));
return; return;
} }
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE #if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
@@ -131,15 +131,15 @@ bool PI4IOE5V6408Component::write_gpio_modes_() {
return false; return false;
if (!this->write_byte(PI4IOE5V6408_REGISTER_IO_DIR, this->mode_mask_)) { if (!this->write_byte(PI4IOE5V6408_REGISTER_IO_DIR, this->mode_mask_)) {
this->status_set_warning("Failed to write GPIO modes"); this->status_set_warning(LOG_STR("Failed to write GPIO modes"));
return false; return false;
} }
if (!this->write_byte(PI4IOE5V6408_REGISTER_PULL_SELECT, this->pull_up_down_mask_)) { if (!this->write_byte(PI4IOE5V6408_REGISTER_PULL_SELECT, this->pull_up_down_mask_)) {
this->status_set_warning("Failed to write GPIO pullup/pulldown"); this->status_set_warning(LOG_STR("Failed to write GPIO pullup/pulldown"));
return false; return false;
} }
if (!this->write_byte(PI4IOE5V6408_REGISTER_PULL_ENABLE, this->pull_enable_mask_)) { if (!this->write_byte(PI4IOE5V6408_REGISTER_PULL_ENABLE, this->pull_enable_mask_)) {
this->status_set_warning("Failed to write GPIO pull enable"); this->status_set_warning(LOG_STR("Failed to write GPIO pull enable"));
return false; return false;
} }
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE #if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE

View File

@@ -211,7 +211,7 @@ void SGP4xComponent::measure_raw_() {
if (!this->write_command(command, data, 2)) { if (!this->write_command(command, data, 2)) {
ESP_LOGD(TAG, "write error (%d)", this->last_error_); ESP_LOGD(TAG, "write error (%d)", this->last_error_);
this->status_set_warning("measurement request failed"); this->status_set_warning(LOG_STR("measurement request failed"));
return; return;
} }
@@ -220,7 +220,7 @@ void SGP4xComponent::measure_raw_() {
raw_data[1] = 0; raw_data[1] = 0;
if (!this->read_data(raw_data, response_words)) { if (!this->read_data(raw_data, response_words)) {
ESP_LOGD(TAG, "read error (%d)", this->last_error_); ESP_LOGD(TAG, "read error (%d)", this->last_error_);
this->status_set_warning("measurement read failed"); this->status_set_warning(LOG_STR("measurement read failed"));
this->voc_index_ = this->nox_index_ = UINT16_MAX; this->voc_index_ = this->nox_index_ = UINT16_MAX;
return; return;
} }

View File

@@ -65,7 +65,7 @@ void SHT4XComponent::update() {
// Send command // Send command
if (!this->write_command(MEASURECOMMANDS[this->precision_])) { if (!this->write_command(MEASURECOMMANDS[this->precision_])) {
// Warning will be printed only if warning status is not set yet // Warning will be printed only if warning status is not set yet
this->status_set_warning("Failed to send measurement command"); this->status_set_warning(LOG_STR("Failed to send measurement command"));
return; return;
} }

View File

@@ -56,7 +56,7 @@ void SoundLevelComponent::loop() {
} }
} else { } else {
if (!this->status_has_warning()) { if (!this->status_has_warning()) {
this->status_set_warning("Microphone isn't running, can't compute statistics"); this->status_set_warning(LOG_STR("Microphone isn't running, can't compute statistics"));
// Deallocate buffers, if necessary // Deallocate buffers, if necessary
this->stop_(); this->stop_();

View File

@@ -50,7 +50,7 @@ bool TCA9555Component::read_gpio_outputs_() {
return false; return false;
uint8_t data[2]; uint8_t data[2];
if (!this->read_bytes(TCA9555_OUTPUT_PORT_REGISTER_0, data, 2)) { if (!this->read_bytes(TCA9555_OUTPUT_PORT_REGISTER_0, data, 2)) {
this->status_set_warning("Failed to read output register"); this->status_set_warning(LOG_STR("Failed to read output register"));
return false; return false;
} }
this->output_mask_ = (uint16_t(data[1]) << 8) | (uint16_t(data[0]) << 0); this->output_mask_ = (uint16_t(data[1]) << 8) | (uint16_t(data[0]) << 0);
@@ -64,7 +64,7 @@ bool TCA9555Component::read_gpio_modes_() {
uint8_t data[2]; uint8_t data[2];
bool success = this->read_bytes(TCA9555_CONFIGURATION_PORT_0, data, 2); bool success = this->read_bytes(TCA9555_CONFIGURATION_PORT_0, data, 2);
if (!success) { if (!success) {
this->status_set_warning("Failed to read mode register"); this->status_set_warning(LOG_STR("Failed to read mode register"));
return false; return false;
} }
this->mode_mask_ = (uint16_t(data[1]) << 8) | (uint16_t(data[0]) << 0); this->mode_mask_ = (uint16_t(data[1]) << 8) | (uint16_t(data[0]) << 0);
@@ -79,7 +79,7 @@ bool TCA9555Component::digital_read_hw(uint8_t pin) {
uint8_t bank_number = pin < 8 ? 0 : 1; uint8_t bank_number = pin < 8 ? 0 : 1;
uint8_t register_to_read = bank_number ? TCA9555_INPUT_PORT_REGISTER_1 : TCA9555_INPUT_PORT_REGISTER_0; uint8_t register_to_read = bank_number ? TCA9555_INPUT_PORT_REGISTER_1 : TCA9555_INPUT_PORT_REGISTER_0;
if (!this->read_bytes(register_to_read, &data, 1)) { if (!this->read_bytes(register_to_read, &data, 1)) {
this->status_set_warning("Failed to read input register"); this->status_set_warning(LOG_STR("Failed to read input register"));
return false; return false;
} }
uint8_t second_half = this->input_mask_ >> 8; uint8_t second_half = this->input_mask_ >> 8;
@@ -108,7 +108,7 @@ void TCA9555Component::digital_write_hw(uint8_t pin, bool value) {
data[0] = this->output_mask_; data[0] = this->output_mask_;
data[1] = this->output_mask_ >> 8; data[1] = this->output_mask_ >> 8;
if (!this->write_bytes(TCA9555_OUTPUT_PORT_REGISTER_0, data, 2)) { if (!this->write_bytes(TCA9555_OUTPUT_PORT_REGISTER_0, data, 2)) {
this->status_set_warning("Failed to write output register"); this->status_set_warning(LOG_STR("Failed to write output register"));
return; return;
} }
@@ -123,7 +123,7 @@ bool TCA9555Component::write_gpio_modes_() {
data[0] = this->mode_mask_; data[0] = this->mode_mask_;
data[1] = this->mode_mask_ >> 8; data[1] = this->mode_mask_ >> 8;
if (!this->write_bytes(TCA9555_CONFIGURATION_PORT_0, data, 2)) { if (!this->write_bytes(TCA9555_CONFIGURATION_PORT_0, data, 2)) {
this->status_set_warning("Failed to write mode register"); this->status_set_warning(LOG_STR("Failed to write mode register"));
return false; return false;
} }
this->status_clear_warning(); this->status_clear_warning();

View File

@@ -32,7 +32,7 @@ void TMP1075Sensor::update() {
uint16_t regvalue; uint16_t regvalue;
if (!read_byte_16(REG_TEMP, &regvalue)) { if (!read_byte_16(REG_TEMP, &regvalue)) {
ESP_LOGW(TAG, "'%s' - unable to read temperature register", this->name_.c_str()); ESP_LOGW(TAG, "'%s' - unable to read temperature register", this->name_.c_str());
this->status_set_warning("can't read"); this->status_set_warning(LOG_STR("can't read"));
return; return;
} }
this->status_clear_warning(); this->status_clear_warning();

View File

@@ -28,12 +28,12 @@ void UDPComponent::setup() {
int enable = 1; int enable = 1;
auto err = this->broadcast_socket_->setsockopt(SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)); auto err = this->broadcast_socket_->setsockopt(SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int));
if (err != 0) { if (err != 0) {
this->status_set_warning("Socket unable to set reuseaddr"); this->status_set_warning(LOG_STR("Socket unable to set reuseaddr"));
// we can still continue // we can still continue
} }
err = this->broadcast_socket_->setsockopt(SOL_SOCKET, SO_BROADCAST, &enable, sizeof(int)); err = this->broadcast_socket_->setsockopt(SOL_SOCKET, SO_BROADCAST, &enable, sizeof(int));
if (err != 0) { if (err != 0) {
this->status_set_warning("Socket unable to set broadcast"); this->status_set_warning(LOG_STR("Socket unable to set broadcast"));
} }
} }
// create listening socket if we either want to subscribe to providers, or need to listen // create listening socket if we either want to subscribe to providers, or need to listen
@@ -55,7 +55,7 @@ void UDPComponent::setup() {
int enable = 1; int enable = 1;
err = this->listen_socket_->setsockopt(SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)); err = this->listen_socket_->setsockopt(SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable));
if (err != 0) { if (err != 0) {
this->status_set_warning("Socket unable to set reuseaddr"); this->status_set_warning(LOG_STR("Socket unable to set reuseaddr"));
// we can still continue // we can still continue
} }
struct sockaddr_in server {}; struct sockaddr_in server {};

View File

@@ -266,7 +266,7 @@ void USBUartTypeCdcAcm::on_connected() {
for (auto *channel : this->channels_) { for (auto *channel : this->channels_) {
if (i == cdc_devs.size()) { if (i == cdc_devs.size()) {
ESP_LOGE(TAG, "No configuration found for channel %d", channel->index_); ESP_LOGE(TAG, "No configuration found for channel %d", channel->index_);
this->status_set_warning("No configuration found for channel"); this->status_set_warning(LOG_STR("No configuration found for channel"));
break; break;
} }
channel->cdc_dev_ = cdc_devs[i++]; channel->cdc_dev_ = cdc_devs[i++];

View File

@@ -74,12 +74,12 @@ void WakeOnLanButton::setup() {
int enable = 1; int enable = 1;
auto err = this->broadcast_socket_->setsockopt(SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)); auto err = this->broadcast_socket_->setsockopt(SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int));
if (err != 0) { if (err != 0) {
this->status_set_warning("Socket unable to set reuseaddr"); this->status_set_warning(LOG_STR("Socket unable to set reuseaddr"));
// we can still continue // we can still continue
} }
err = this->broadcast_socket_->setsockopt(SOL_SOCKET, SO_BROADCAST, &enable, sizeof(int)); err = this->broadcast_socket_->setsockopt(SOL_SOCKET, SO_BROADCAST, &enable, sizeof(int));
if (err != 0) { if (err != 0) {
this->status_set_warning("Socket unable to set broadcast"); this->status_set_warning(LOG_STR("Socket unable to set broadcast"));
} }
#endif #endif
} }

View File

@@ -148,7 +148,7 @@ void WiFiComponent::loop() {
switch (this->state_) { switch (this->state_) {
case WIFI_COMPONENT_STATE_COOLDOWN: { case WIFI_COMPONENT_STATE_COOLDOWN: {
this->status_set_warning("waiting to reconnect"); this->status_set_warning(LOG_STR("waiting to reconnect"));
if (millis() - this->action_started_ > 5000) { if (millis() - this->action_started_ > 5000) {
if (this->fast_connect_ || this->retry_hidden_) { if (this->fast_connect_ || this->retry_hidden_) {
if (!this->selected_ap_.get_bssid().has_value()) if (!this->selected_ap_.get_bssid().has_value())
@@ -161,13 +161,13 @@ void WiFiComponent::loop() {
break; break;
} }
case WIFI_COMPONENT_STATE_STA_SCANNING: { case WIFI_COMPONENT_STATE_STA_SCANNING: {
this->status_set_warning("scanning for networks"); this->status_set_warning(LOG_STR("scanning for networks"));
this->check_scanning_finished(); this->check_scanning_finished();
break; break;
} }
case WIFI_COMPONENT_STATE_STA_CONNECTING: case WIFI_COMPONENT_STATE_STA_CONNECTING:
case WIFI_COMPONENT_STATE_STA_CONNECTING_2: { case WIFI_COMPONENT_STATE_STA_CONNECTING_2: {
this->status_set_warning("associating to network"); this->status_set_warning(LOG_STR("associating to network"));
this->check_connecting_finished(); this->check_connecting_finished();
break; break;
} }

View File

@@ -16,7 +16,6 @@
namespace esphome { namespace esphome {
static const char *const TAG = "component"; static const char *const TAG = "component";
static const char *const UNSPECIFIED_MESSAGE = "unspecified";
// Global vectors for component data that doesn't belong in every instance. // Global vectors for component data that doesn't belong in every instance.
// Using vector instead of unordered_map for both because: // Using vector instead of unordered_map for both because:
@@ -143,7 +142,7 @@ void Component::call_dump_config() {
} }
} }
ESP_LOGE(TAG, " %s is marked FAILED: %s", LOG_STR_ARG(this->get_component_log_str()), ESP_LOGE(TAG, " %s is marked FAILED: %s", LOG_STR_ARG(this->get_component_log_str()),
error_msg ? error_msg : UNSPECIFIED_MESSAGE); error_msg ? error_msg : LOG_STR_LITERAL("unspecified"));
} }
} }
@@ -278,6 +277,7 @@ bool Component::is_ready() const {
bool Component::can_proceed() { return true; } bool Component::can_proceed() { return true; }
bool Component::status_has_warning() const { return this->component_state_ & STATUS_LED_WARNING; } bool Component::status_has_warning() const { return this->component_state_ & STATUS_LED_WARNING; }
bool Component::status_has_error() const { return this->component_state_ & STATUS_LED_ERROR; } bool Component::status_has_error() const { return this->component_state_ & STATUS_LED_ERROR; }
void Component::status_set_warning(const char *message) { void Component::status_set_warning(const char *message) {
// Don't spam the log. This risks missing different warning messages though. // Don't spam the log. This risks missing different warning messages though.
if ((this->component_state_ & STATUS_LED_WARNING) != 0) if ((this->component_state_ & STATUS_LED_WARNING) != 0)
@@ -285,15 +285,26 @@ void Component::status_set_warning(const char *message) {
this->component_state_ |= STATUS_LED_WARNING; this->component_state_ |= STATUS_LED_WARNING;
App.app_state_ |= STATUS_LED_WARNING; App.app_state_ |= STATUS_LED_WARNING;
ESP_LOGW(TAG, "%s set Warning flag: %s", LOG_STR_ARG(this->get_component_log_str()), ESP_LOGW(TAG, "%s set Warning flag: %s", LOG_STR_ARG(this->get_component_log_str()),
message ? message : UNSPECIFIED_MESSAGE); message ? message : LOG_STR_LITERAL("unspecified"));
} }
#ifdef USE_STORE_LOG_STR_IN_FLASH
void Component::status_set_warning(const LogString *message) {
// Don't spam the log. This risks missing different warning messages though.
if ((this->component_state_ & STATUS_LED_WARNING) != 0)
return;
this->component_state_ |= STATUS_LED_WARNING;
App.app_state_ |= STATUS_LED_WARNING;
ESP_LOGW(TAG, "%s set Warning flag: %s", this->get_component_source(),
message ? LOG_STR_ARG(message) : LOG_STR_LITERAL("unspecified"));
}
#endif
void Component::status_set_error(const char *message) { void Component::status_set_error(const char *message) {
if ((this->component_state_ & STATUS_LED_ERROR) != 0) if ((this->component_state_ & STATUS_LED_ERROR) != 0)
return; return;
this->component_state_ |= STATUS_LED_ERROR; this->component_state_ |= STATUS_LED_ERROR;
App.app_state_ |= STATUS_LED_ERROR; App.app_state_ |= STATUS_LED_ERROR;
ESP_LOGE(TAG, "%s set Error flag: %s", LOG_STR_ARG(this->get_component_log_str()), ESP_LOGE(TAG, "%s set Error flag: %s", LOG_STR_ARG(this->get_component_log_str()),
message ? message : UNSPECIFIED_MESSAGE); message ? message : LOG_STR_LITERAL("unspecified"));
if (message != nullptr) { if (message != nullptr) {
// Lazy allocate the error messages vector if needed // Lazy allocate the error messages vector if needed
if (!component_error_messages) { if (!component_error_messages) {

View File

@@ -10,6 +10,9 @@
namespace esphome { namespace esphome {
// Forward declaration for LogString
struct LogString;
/** Default setup priorities for components of different types. /** Default setup priorities for components of different types.
* *
* Components should return one of these setup priorities in get_setup_priority. * Components should return one of these setup priorities in get_setup_priority.
@@ -204,6 +207,9 @@ class Component {
bool status_has_error() const; bool status_has_error() const;
void status_set_warning(const char *message = nullptr); void status_set_warning(const char *message = nullptr);
#ifdef USE_STORE_LOG_STR_IN_FLASH
void status_set_warning(const LogString *message);
#endif
void status_set_error(const char *message = nullptr); void status_set_error(const char *message = nullptr);