From 341123cd40e8bfa23c1d538f19bf8831f384cd86 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 3 Mar 2026 13:24:51 -1000 Subject: [PATCH 1/8] return ON --- esphome/components/ballu/ballu.cpp | 2 +- esphome/components/climate_ir_lg/climate_ir_lg.cpp | 2 +- esphome/components/coolix/coolix.cpp | 2 +- esphome/components/daikin/daikin.cpp | 2 +- esphome/components/daikin_arc/daikin_arc.cpp | 2 +- esphome/components/daikin_brc/daikin_brc.cpp | 2 +- esphome/components/delonghi/delonghi.cpp | 2 +- esphome/components/emmeti/emmeti.cpp | 2 +- esphome/components/fujitsu_general/fujitsu_general.cpp | 2 +- esphome/components/gree/gree.cpp | 4 ++-- esphome/components/heatpumpir/heatpumpir.cpp | 2 +- esphome/components/hitachi_ac344/hitachi_ac344.cpp | 2 +- esphome/components/hitachi_ac424/hitachi_ac424.cpp | 2 +- esphome/components/mitsubishi/mitsubishi.cpp | 4 ++-- esphome/components/noblex/noblex.cpp | 2 +- esphome/components/tcl112/tcl112.cpp | 2 +- esphome/components/toshiba/toshiba.cpp | 8 ++++---- esphome/components/whirlpool/whirlpool.cpp | 2 +- esphome/components/whynter/whynter.cpp | 2 +- esphome/components/zhlt01/zhlt01.cpp | 2 +- 20 files changed, 25 insertions(+), 25 deletions(-) diff --git a/esphome/components/ballu/ballu.cpp b/esphome/components/ballu/ballu.cpp index cc8fb6fc80..deb742f8c6 100644 --- a/esphome/components/ballu/ballu.cpp +++ b/esphome/components/ballu/ballu.cpp @@ -47,7 +47,7 @@ void BalluClimate::transmit_state() { remote_state[11] = 0x1e; // Fan speed - switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) { + switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) { case climate::CLIMATE_FAN_HIGH: remote_state[4] |= BALLU_FAN_HIGH; break; diff --git a/esphome/components/climate_ir_lg/climate_ir_lg.cpp b/esphome/components/climate_ir_lg/climate_ir_lg.cpp index 8970185e8e..90e3d006a8 100644 --- a/esphome/components/climate_ir_lg/climate_ir_lg.cpp +++ b/esphome/components/climate_ir_lg/climate_ir_lg.cpp @@ -79,7 +79,7 @@ void LgIrClimate::transmit_state() { if (this->mode == climate::CLIMATE_MODE_OFF) { remote_state |= FAN_AUTO; } else { - switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) { + switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) { case climate::CLIMATE_FAN_HIGH: remote_state |= FAN_MAX; break; diff --git a/esphome/components/coolix/coolix.cpp b/esphome/components/coolix/coolix.cpp index 98c817b0d5..d8ea676478 100644 --- a/esphome/components/coolix/coolix.cpp +++ b/esphome/components/coolix/coolix.cpp @@ -83,7 +83,7 @@ void CoolixClimate::transmit_state() { this->fan_mode = climate::CLIMATE_FAN_AUTO; remote_state |= COOLIX_FAN_MODE_AUTO_DRY; } else { - switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) { + switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) { case climate::CLIMATE_FAN_HIGH: remote_state |= COOLIX_FAN_MAX; break; diff --git a/esphome/components/daikin/daikin.cpp b/esphome/components/daikin/daikin.cpp index 7a2f429a08..a285f3613d 100644 --- a/esphome/components/daikin/daikin.cpp +++ b/esphome/components/daikin/daikin.cpp @@ -94,7 +94,7 @@ uint8_t DaikinClimate::operation_mode_() const { uint16_t DaikinClimate::fan_speed_() const { uint16_t fan_speed; - switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) { + switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) { case climate::CLIMATE_FAN_QUIET: fan_speed = DAIKIN_FAN_SILENT << 8; break; diff --git a/esphome/components/daikin_arc/daikin_arc.cpp b/esphome/components/daikin_arc/daikin_arc.cpp index a1f6855d48..9fdf00a80b 100644 --- a/esphome/components/daikin_arc/daikin_arc.cpp +++ b/esphome/components/daikin_arc/daikin_arc.cpp @@ -176,7 +176,7 @@ uint8_t DaikinArcClimate::operation_mode_() { uint16_t DaikinArcClimate::fan_speed_() { uint16_t fan_speed; - switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) { + switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) { case climate::CLIMATE_FAN_LOW: fan_speed = DAIKIN_FAN_1 << 8; break; diff --git a/esphome/components/daikin_brc/daikin_brc.cpp b/esphome/components/daikin_brc/daikin_brc.cpp index 19e0f5a6d5..1179cb07d7 100644 --- a/esphome/components/daikin_brc/daikin_brc.cpp +++ b/esphome/components/daikin_brc/daikin_brc.cpp @@ -111,7 +111,7 @@ uint8_t DaikinBrcClimate::operation_mode_() { uint8_t DaikinBrcClimate::fan_speed_swing_() { uint16_t fan_speed; - switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) { + switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) { case climate::CLIMATE_FAN_LOW: fan_speed = DAIKIN_BRC_FAN_1; break; diff --git a/esphome/components/delonghi/delonghi.cpp b/esphome/components/delonghi/delonghi.cpp index f1ea037ab8..19af703ab2 100644 --- a/esphome/components/delonghi/delonghi.cpp +++ b/esphome/components/delonghi/delonghi.cpp @@ -64,7 +64,7 @@ uint8_t DelonghiClimate::operation_mode_() { uint16_t DelonghiClimate::fan_speed_() { uint16_t fan_speed; - switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) { + switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) { case climate::CLIMATE_FAN_LOW: fan_speed = DELONGHI_FAN_LOW; break; diff --git a/esphome/components/emmeti/emmeti.cpp b/esphome/components/emmeti/emmeti.cpp index 2d02397b84..04976d95d7 100644 --- a/esphome/components/emmeti/emmeti.cpp +++ b/esphome/components/emmeti/emmeti.cpp @@ -28,7 +28,7 @@ uint8_t EmmetiClimate::set_mode_() { } uint8_t EmmetiClimate::set_fan_speed_() { - switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) { + switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) { case climate::CLIMATE_FAN_LOW: return EMMETI_FAN_1; case climate::CLIMATE_FAN_MEDIUM: diff --git a/esphome/components/fujitsu_general/fujitsu_general.cpp b/esphome/components/fujitsu_general/fujitsu_general.cpp index 617489fec7..8aa0f51728 100644 --- a/esphome/components/fujitsu_general/fujitsu_general.cpp +++ b/esphome/components/fujitsu_general/fujitsu_general.cpp @@ -141,7 +141,7 @@ void FujitsuGeneralClimate::transmit_state() { } // Set fan - switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) { + switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) { case climate::CLIMATE_FAN_HIGH: SET_NIBBLE(remote_state, FUJITSU_GENERAL_FAN_NIBBLE, FUJITSU_GENERAL_FAN_HIGH); break; diff --git a/esphome/components/gree/gree.cpp b/esphome/components/gree/gree.cpp index 8201e4620e..8a9f264932 100644 --- a/esphome/components/gree/gree.cpp +++ b/esphome/components/gree/gree.cpp @@ -180,7 +180,7 @@ uint8_t GreeClimate::operation_mode_() { uint8_t GreeClimate::fan_speed_() { // YX1FF has 4 fan speeds -- we treat low as quiet and turbo as high if (this->model_ == GREE_YX1FF) { - switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) { + switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) { case climate::CLIMATE_FAN_QUIET: return GREE_FAN_1; case climate::CLIMATE_FAN_LOW: @@ -195,7 +195,7 @@ uint8_t GreeClimate::fan_speed_() { } } - switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) { + switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) { case climate::CLIMATE_FAN_LOW: return GREE_FAN_1; case climate::CLIMATE_FAN_MEDIUM: diff --git a/esphome/components/heatpumpir/heatpumpir.cpp b/esphome/components/heatpumpir/heatpumpir.cpp index 6b73a24dc4..937e8cd473 100644 --- a/esphome/components/heatpumpir/heatpumpir.cpp +++ b/esphome/components/heatpumpir/heatpumpir.cpp @@ -187,7 +187,7 @@ void HeatpumpIRClimate::transmit_state() { swing_h_cmd = HDIR_SWING; } - switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) { + switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) { case climate::CLIMATE_FAN_LOW: fan_speed_cmd = FAN_2; break; diff --git a/esphome/components/hitachi_ac344/hitachi_ac344.cpp b/esphome/components/hitachi_ac344/hitachi_ac344.cpp index e6f3f8d78c..69469cab2e 100644 --- a/esphome/components/hitachi_ac344/hitachi_ac344.cpp +++ b/esphome/components/hitachi_ac344/hitachi_ac344.cpp @@ -175,7 +175,7 @@ void HitachiClimate::transmit_state() { set_temp_(static_cast(this->target_temperature)); - switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) { + switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) { case climate::CLIMATE_FAN_LOW: set_fan_(HITACHI_AC344_FAN_LOW); break; diff --git a/esphome/components/hitachi_ac424/hitachi_ac424.cpp b/esphome/components/hitachi_ac424/hitachi_ac424.cpp index 3da9993bca..0b3cc99a82 100644 --- a/esphome/components/hitachi_ac424/hitachi_ac424.cpp +++ b/esphome/components/hitachi_ac424/hitachi_ac424.cpp @@ -176,7 +176,7 @@ void HitachiClimate::transmit_state() { set_temp_(static_cast(this->target_temperature)); - switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) { + switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) { case climate::CLIMATE_FAN_LOW: set_fan_(HITACHI_AC424_FAN_LOW); break; diff --git a/esphome/components/mitsubishi/mitsubishi.cpp b/esphome/components/mitsubishi/mitsubishi.cpp index 9cafa3905d..882163ff5d 100644 --- a/esphome/components/mitsubishi/mitsubishi.cpp +++ b/esphome/components/mitsubishi/mitsubishi.cpp @@ -180,7 +180,7 @@ void MitsubishiClimate::transmit_state() { // For 5Level: Low = 1, Middle = 2, Medium = 3, High = 4 // For 4Level + Quiet: Low = 1, Middle = 2, Medium = 3, High = 4, Quiet = 5 - switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) { + switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) { case climate::CLIMATE_FAN_LOW: remote_state[9] = 1; break; @@ -209,7 +209,7 @@ void MitsubishiClimate::transmit_state() { break; } - ESP_LOGD(TAG, "fan: %02x state: %02x", static_cast(this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)), + ESP_LOGD(TAG, "fan: %02x state: %02x", static_cast(this->fan_mode.value_or(climate::CLIMATE_FAN_ON)), remote_state[9]); // Vertical Vane diff --git a/esphome/components/noblex/noblex.cpp b/esphome/components/noblex/noblex.cpp index abff52fef2..f1e76eabf2 100644 --- a/esphome/components/noblex/noblex.cpp +++ b/esphome/components/noblex/noblex.cpp @@ -71,7 +71,7 @@ void NoblexClimate::transmit_state() { break; } - switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) { + switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) { case climate::CLIMATE_FAN_LOW: remote_state[0] |= (IRNoblexFan::IR_NOBLEX_FAN_LOW << 2); break; diff --git a/esphome/components/tcl112/tcl112.cpp b/esphome/components/tcl112/tcl112.cpp index c7ceb66dcb..afeee3d739 100644 --- a/esphome/components/tcl112/tcl112.cpp +++ b/esphome/components/tcl112/tcl112.cpp @@ -89,7 +89,7 @@ void Tcl112Climate::transmit_state() { // Set fan uint8_t selected_fan; - switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) { + switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) { case climate::CLIMATE_FAN_HIGH: selected_fan = TCL112_FAN_HIGH; break; diff --git a/esphome/components/toshiba/toshiba.cpp b/esphome/components/toshiba/toshiba.cpp index 6fe43c6fdd..e0c150537a 100644 --- a/esphome/components/toshiba/toshiba.cpp +++ b/esphome/components/toshiba/toshiba.cpp @@ -502,7 +502,7 @@ void ToshibaClimate::transmit_generic_() { } uint8_t fan; - switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) { + switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) { case climate::CLIMATE_FAN_QUIET: fan = TOSHIBA_FAN_SPEED_QUIET; break; @@ -567,7 +567,7 @@ void ToshibaClimate::transmit_rac_pt1411hwru_() { message[2] = RAC_PT1411HWRU_NO_FAN.code1; message[7] = RAC_PT1411HWRU_NO_FAN.code2; } else { - switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) { + switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) { case climate::CLIMATE_FAN_LOW: message[2] = RAC_PT1411HWRU_FAN_LOW.code1; message[7] = RAC_PT1411HWRU_FAN_LOW.code2; @@ -811,12 +811,12 @@ void ToshibaClimate::transmit_ras_2819t_() { uint8_t temp_code = get_ras_2819t_temp_code(temperature); // Get fan speed encoding for rc_code_1 - climate::ClimateFanMode effective_fan_mode = this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO); + climate::ClimateFanMode effective_fan_mode = this->fan_mode.value_or(climate::CLIMATE_FAN_ON); // Dry mode only supports AUTO fan speed if (this->mode == climate::CLIMATE_MODE_DRY) { effective_fan_mode = climate::CLIMATE_FAN_AUTO; - if (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO) != climate::CLIMATE_FAN_AUTO) { + if (this->fan_mode.value_or(climate::CLIMATE_FAN_ON) != climate::CLIMATE_FAN_AUTO) { ESP_LOGW(TAG, "Dry mode only supports AUTO fan speed, forcing AUTO"); } } diff --git a/esphome/components/whirlpool/whirlpool.cpp b/esphome/components/whirlpool/whirlpool.cpp index 5ae4ce9455..e9f602e97f 100644 --- a/esphome/components/whirlpool/whirlpool.cpp +++ b/esphome/components/whirlpool/whirlpool.cpp @@ -82,7 +82,7 @@ void WhirlpoolClimate::transmit_state() { remote_state[3] |= (uint8_t) (temp - this->temperature_min_()) << 4; // Fan speed - switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) { + switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) { case climate::CLIMATE_FAN_HIGH: remote_state[2] |= WHIRLPOOL_FAN_HIGH; break; diff --git a/esphome/components/whynter/whynter.cpp b/esphome/components/whynter/whynter.cpp index e78795ac3c..003d2e0ba6 100644 --- a/esphome/components/whynter/whynter.cpp +++ b/esphome/components/whynter/whynter.cpp @@ -69,7 +69,7 @@ void Whynter::transmit_state() { } mode_before_ = this->mode; - switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) { + switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) { case climate::CLIMATE_FAN_LOW: remote_state |= FAN_LOW; break; diff --git a/esphome/components/zhlt01/zhlt01.cpp b/esphome/components/zhlt01/zhlt01.cpp index ccadd036c4..e5ab5915e4 100644 --- a/esphome/components/zhlt01/zhlt01.cpp +++ b/esphome/components/zhlt01/zhlt01.cpp @@ -55,7 +55,7 @@ void ZHLT01Climate::transmit_state() { ir_message[7] |= AC1_FAN_SILENT; break; default: - switch (this->fan_mode.value_or(climate::CLIMATE_FAN_AUTO)) { + switch (this->fan_mode.value_or(climate::CLIMATE_FAN_ON)) { case climate::CLIMATE_FAN_LOW: ir_message[7] |= AC1_FAN1; break; From 92cd08aa38adb8f58c4f07af222a5fa57015394c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 3 Mar 2026 13:25:55 -1000 Subject: [PATCH 2/8] return ON part 2 --- esphome/components/haier/hon_climate.cpp | 2 +- esphome/components/haier/smartair2_climate.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/esphome/components/haier/hon_climate.cpp b/esphome/components/haier/hon_climate.cpp index 1fa00857a5..be5035caa1 100644 --- a/esphome/components/haier/hon_climate.cpp +++ b/esphome/components/haier/hon_climate.cpp @@ -938,7 +938,7 @@ haier_protocol::HandlerError HonClimate::process_status_message_(const uint8_t * break; } should_publish = should_publish || (!old_fan_mode.has_value()) || - (old_fan_mode.value_or(CLIMATE_FAN_AUTO) != this->fan_mode.value_or(CLIMATE_FAN_AUTO)); + (old_fan_mode.value_or(CLIMATE_FAN_ON) != this->fan_mode.value_or(CLIMATE_FAN_ON)); } // Display status // should be before "Climate mode" because it is changing this->mode diff --git a/esphome/components/haier/smartair2_climate.cpp b/esphome/components/haier/smartair2_climate.cpp index e4806a9de0..d24f8ad849 100644 --- a/esphome/components/haier/smartair2_climate.cpp +++ b/esphome/components/haier/smartair2_climate.cpp @@ -448,7 +448,7 @@ haier_protocol::HandlerError Smartair2Climate::process_status_message_(const uin break; } should_publish = should_publish || (!old_fan_mode.has_value()) || - (old_fan_mode.value_or(CLIMATE_FAN_AUTO) != this->fan_mode.value_or(CLIMATE_FAN_AUTO)); + (old_fan_mode.value_or(CLIMATE_FAN_ON) != this->fan_mode.value_or(CLIMATE_FAN_ON)); } // Display status // should be before "Climate mode" because it is changing this->mode From d74a8ea385a56b904094662f4d9129f65420e859 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 3 Mar 2026 13:30:27 -1000 Subject: [PATCH 3/8] expand all sites --- esphome/components/am43/cover/am43_cover.cpp | 3 +- esphome/components/anova/anova.cpp | 10 +++-- .../bang_bang/bang_bang_climate.cpp | 20 +++++---- .../bedjet/climate/bedjet_climate.cpp | 20 +++++---- esphome/components/bedjet/fan/bedjet_fan.cpp | 8 ++-- esphome/components/binary/fan/binary_fan.cpp | 15 ++++--- esphome/components/climate_ir/climate_ir.cpp | 25 ++++++----- esphome/components/copy/cover/copy_cover.cpp | 15 ++++--- esphome/components/copy/fan/copy_fan.cpp | 20 +++++---- .../components/copy/select/copy_select.cpp | 3 +- .../current_based/current_based_cover.cpp | 3 +- esphome/components/daikin_arc/daikin_arc.cpp | 5 ++- esphome/components/endstop/endstop_cover.cpp | 3 +- .../components/feedback/feedback_cover.cpp | 5 ++- .../components/hbridge/fan/hbridge_fan.cpp | 20 +++++---- esphome/components/he60r/he60r.cpp | 5 ++- .../media_player/i2s_audio_media_player.cpp | 12 +++-- esphome/components/infrared/infrared.cpp | 3 +- esphome/components/mcp4461/mcp4461.cpp | 3 +- esphome/components/midea/air_conditioner.cpp | 25 ++++++----- esphome/components/pid/pid_climate.cpp | 10 +++-- .../media_player/speaker_media_player.cpp | 15 ++++--- esphome/components/speed/fan/speed_fan.cpp | 20 +++++---- esphome/components/sprinkler/sprinkler.cpp | 3 +- .../template/cover/template_cover.cpp | 6 ++- .../components/template/fan/template_fan.cpp | 20 +++++---- .../template/valve/template_valve.cpp | 3 +- .../water_heater/template_water_heater.cpp | 15 ++++--- .../thermostat/thermostat_climate.cpp | 44 +++++++++++-------- .../time_based/time_based_cover.cpp | 3 +- .../components/tormatic/tormatic_cover.cpp | 3 +- .../components/tuya/climate/tuya_climate.cpp | 27 ++++++++---- .../climate/uponor_smatrix_climate.cpp | 3 +- esphome/components/yashima/yashima.cpp | 10 +++-- 34 files changed, 251 insertions(+), 154 deletions(-) diff --git a/esphome/components/am43/cover/am43_cover.cpp b/esphome/components/am43/cover/am43_cover.cpp index 24776e1502..2fa26d266a 100644 --- a/esphome/components/am43/cover/am43_cover.cpp +++ b/esphome/components/am43/cover/am43_cover.cpp @@ -63,7 +63,8 @@ void Am43Component::control(const CoverCall &call) { ESP_LOGW(TAG, "[%s] Error writing stop command to device, error = %d", this->get_name().c_str(), status); } } - if (auto opt_pos = call.get_position(); opt_pos.has_value()) { + auto opt_pos = call.get_position(); + if (opt_pos.has_value()) { auto pos = *opt_pos; if (this->invert_position_) diff --git a/esphome/components/anova/anova.cpp b/esphome/components/anova/anova.cpp index 226df51b93..b625f92115 100644 --- a/esphome/components/anova/anova.cpp +++ b/esphome/components/anova/anova.cpp @@ -24,8 +24,9 @@ void Anova::loop() { } void Anova::control(const ClimateCall &call) { - if (auto val = call.get_mode(); val.has_value()) { - ClimateMode mode = *val; + auto mode_val = call.get_mode(); + if (mode_val.has_value()) { + ClimateMode mode = *mode_val; AnovaPacket *pkt; switch (mode) { case climate::CLIMATE_MODE_OFF: @@ -45,8 +46,9 @@ void Anova::control(const ClimateCall &call) { ESP_LOGW(TAG, "[%s] esp_ble_gattc_write_char failed, status=%d", this->parent_->address_str(), status); } } - if (auto val = call.get_target_temperature(); val.has_value()) { - auto *pkt = this->codec_->get_set_target_temp_request(*val); + auto target_temp = call.get_target_temperature(); + if (target_temp.has_value()) { + auto *pkt = this->codec_->get_set_target_temp_request(*target_temp); auto status = esp_ble_gattc_write_char(this->parent_->get_gattc_if(), this->parent_->get_conn_id(), this->char_handle_, pkt->length, pkt->data, ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE); diff --git a/esphome/components/bang_bang/bang_bang_climate.cpp b/esphome/components/bang_bang/bang_bang_climate.cpp index 60436b8839..1058bce6a4 100644 --- a/esphome/components/bang_bang/bang_bang_climate.cpp +++ b/esphome/components/bang_bang/bang_bang_climate.cpp @@ -45,17 +45,21 @@ void BangBangClimate::setup() { } void BangBangClimate::control(const climate::ClimateCall &call) { - if (auto val = call.get_mode(); val.has_value()) { - this->mode = *val; + auto mode = call.get_mode(); + if (mode.has_value()) { + this->mode = *mode; } - if (auto val = call.get_target_temperature_low(); val.has_value()) { - this->target_temperature_low = *val; + auto target_temperature_low = call.get_target_temperature_low(); + if (target_temperature_low.has_value()) { + this->target_temperature_low = *target_temperature_low; } - if (auto val = call.get_target_temperature_high(); val.has_value()) { - this->target_temperature_high = *val; + auto target_temperature_high = call.get_target_temperature_high(); + if (target_temperature_high.has_value()) { + this->target_temperature_high = *target_temperature_high; } - if (auto val = call.get_preset(); val.has_value()) { - this->change_away_(*val == climate::CLIMATE_PRESET_AWAY); + auto preset = call.get_preset(); + if (preset.has_value()) { + this->change_away_(*preset == climate::CLIMATE_PRESET_AWAY); } this->compute_state_(); diff --git a/esphome/components/bedjet/climate/bedjet_climate.cpp b/esphome/components/bedjet/climate/bedjet_climate.cpp index 24c678d875..a17407f08f 100644 --- a/esphome/components/bedjet/climate/bedjet_climate.cpp +++ b/esphome/components/bedjet/climate/bedjet_climate.cpp @@ -96,8 +96,9 @@ void BedJetClimate::control(const ClimateCall &call) { return; } - if (auto val = call.get_mode(); val.has_value()) { - ClimateMode mode = *val; + auto mode_opt = call.get_mode(); + if (mode_opt.has_value()) { + ClimateMode mode = *mode_opt; bool button_result; switch (mode) { case CLIMATE_MODE_OFF: @@ -125,8 +126,9 @@ void BedJetClimate::control(const ClimateCall &call) { } } - if (auto val = call.get_target_temperature(); val.has_value()) { - auto target_temp = *val; + auto target_temp_opt = call.get_target_temperature(); + if (target_temp_opt.has_value()) { + auto target_temp = *target_temp_opt; auto result = this->parent_->set_target_temp(target_temp); if (result) { @@ -134,8 +136,9 @@ void BedJetClimate::control(const ClimateCall &call) { } } - if (auto val = call.get_preset(); val.has_value()) { - ClimatePreset preset = *val; + auto preset_opt = call.get_preset(); + if (preset_opt.has_value()) { + ClimatePreset preset = *preset_opt; bool result; if (preset == CLIMATE_PRESET_BOOST) { @@ -187,10 +190,11 @@ void BedJetClimate::control(const ClimateCall &call) { } } - if (auto val = call.get_fan_mode(); val.has_value()) { + auto fan_mode_opt = call.get_fan_mode(); + if (fan_mode_opt.has_value()) { // Climate fan mode only supports low/med/high, but the BedJet supports 5-100% increments. // We can still support a ClimateCall that requests low/med/high, and just translate it to a step increment here. - auto fan_mode = *val; + auto fan_mode = *fan_mode_opt; bool result; if (fan_mode == CLIMATE_FAN_LOW) { result = this->parent_->set_fan_speed(20); diff --git a/esphome/components/bedjet/fan/bedjet_fan.cpp b/esphome/components/bedjet/fan/bedjet_fan.cpp index 1713ac9e48..9539e169a4 100644 --- a/esphome/components/bedjet/fan/bedjet_fan.cpp +++ b/esphome/components/bedjet/fan/bedjet_fan.cpp @@ -19,7 +19,8 @@ void BedJetFan::control(const fan::FanCall &call) { } bool did_change = false; - if (auto val = call.get_state(); val.has_value() && this->state != *val) { + auto state_opt = call.get_state(); + if (state_opt.has_value() && this->state != *state_opt) { // Turning off is easy: if (this->state && this->parent_->button_off()) { this->state = false; @@ -36,8 +37,9 @@ void BedJetFan::control(const fan::FanCall &call) { } // ignore speed changes if not on or turning on - if (auto val = call.get_speed(); this->state && val.has_value()) { - auto speed = *val; + auto speed_opt = call.get_speed(); + if (this->state && speed_opt.has_value()) { + auto speed = *speed_opt; if (speed >= 1) { this->speed = speed; // Fan.speed is 1-20, but Bedjet expects 0-19, so subtract 1 diff --git a/esphome/components/binary/fan/binary_fan.cpp b/esphome/components/binary/fan/binary_fan.cpp index 354b26e9a3..17d4df095a 100644 --- a/esphome/components/binary/fan/binary_fan.cpp +++ b/esphome/components/binary/fan/binary_fan.cpp @@ -18,12 +18,15 @@ fan::FanTraits BinaryFan::get_traits() { return fan::FanTraits(this->oscillating_ != nullptr, false, this->direction_ != nullptr, 0); } void BinaryFan::control(const fan::FanCall &call) { - if (auto val = call.get_state(); val.has_value()) - this->state = *val; - if (auto val = call.get_oscillating(); val.has_value()) - this->oscillating = *val; - if (auto val = call.get_direction(); val.has_value()) - this->direction = *val; + auto state = call.get_state(); + if (state.has_value()) + this->state = *state; + auto oscillating = call.get_oscillating(); + if (oscillating.has_value()) + this->oscillating = *oscillating; + auto direction = call.get_direction(); + if (direction.has_value()) + this->direction = *direction; this->write_state_(); this->publish_state(); diff --git a/esphome/components/climate_ir/climate_ir.cpp b/esphome/components/climate_ir/climate_ir.cpp index 8380e5e9d0..cc291ff17c 100644 --- a/esphome/components/climate_ir/climate_ir.cpp +++ b/esphome/components/climate_ir/climate_ir.cpp @@ -71,16 +71,21 @@ void ClimateIR::setup() { } void ClimateIR::control(const climate::ClimateCall &call) { - if (auto val = call.get_mode(); val.has_value()) - this->mode = *val; - if (auto val = call.get_target_temperature(); val.has_value()) - this->target_temperature = *val; - if (auto val = call.get_fan_mode(); val.has_value()) - this->fan_mode = val; - if (auto val = call.get_swing_mode(); val.has_value()) - this->swing_mode = *val; - if (auto val = call.get_preset(); val.has_value()) - this->preset = val; + auto mode = call.get_mode(); + if (mode.has_value()) + this->mode = *mode; + auto target_temperature = call.get_target_temperature(); + if (target_temperature.has_value()) + this->target_temperature = *target_temperature; + auto fan_mode = call.get_fan_mode(); + if (fan_mode.has_value()) + this->fan_mode = fan_mode; + auto swing_mode = call.get_swing_mode(); + if (swing_mode.has_value()) + this->swing_mode = *swing_mode; + auto preset = call.get_preset(); + if (preset.has_value()) + this->preset = preset; this->transmit_state(); this->publish_state(); } diff --git a/esphome/components/copy/cover/copy_cover.cpp b/esphome/components/copy/cover/copy_cover.cpp index 819cf865c8..c139869d8f 100644 --- a/esphome/components/copy/cover/copy_cover.cpp +++ b/esphome/components/copy/cover/copy_cover.cpp @@ -38,12 +38,15 @@ cover::CoverTraits CopyCover::get_traits() { void CopyCover::control(const cover::CoverCall &call) { auto call2 = source_->make_call(); call2.set_stop(call.get_stop()); - if (auto val = call.get_tilt(); val.has_value()) - call2.set_tilt(*val); - if (auto val = call.get_position(); val.has_value()) - call2.set_position(*val); - if (auto val = call.get_tilt(); val.has_value()) - call2.set_tilt(*val); + auto tilt = call.get_tilt(); + if (tilt.has_value()) + call2.set_tilt(*tilt); + auto position = call.get_position(); + if (position.has_value()) + call2.set_position(*position); + auto tilt2 = call.get_tilt(); + if (tilt2.has_value()) + call2.set_tilt(*tilt2); call2.perform(); } diff --git a/esphome/components/copy/fan/copy_fan.cpp b/esphome/components/copy/fan/copy_fan.cpp index 76c5727493..14c600d71f 100644 --- a/esphome/components/copy/fan/copy_fan.cpp +++ b/esphome/components/copy/fan/copy_fan.cpp @@ -45,14 +45,18 @@ fan::FanTraits CopyFan::get_traits() { void CopyFan::control(const fan::FanCall &call) { auto call2 = source_->make_call(); - if (auto val = call.get_state(); val.has_value()) - call2.set_state(*val); - if (auto val = call.get_oscillating(); val.has_value()) - call2.set_oscillating(*val); - if (auto val = call.get_speed(); val.has_value()) - call2.set_speed(*val); - if (auto val = call.get_direction(); val.has_value()) - call2.set_direction(*val); + auto state = call.get_state(); + if (state.has_value()) + call2.set_state(*state); + auto oscillating = call.get_oscillating(); + if (oscillating.has_value()) + call2.set_oscillating(*oscillating); + auto speed = call.get_speed(); + if (speed.has_value()) + call2.set_speed(*speed); + auto direction = call.get_direction(); + if (direction.has_value()) + call2.set_direction(*direction); if (call.has_preset_mode()) call2.set_preset_mode(call.get_preset_mode()); call2.perform(); diff --git a/esphome/components/copy/select/copy_select.cpp b/esphome/components/copy/select/copy_select.cpp index e4ea68744c..227fe33182 100644 --- a/esphome/components/copy/select/copy_select.cpp +++ b/esphome/components/copy/select/copy_select.cpp @@ -11,7 +11,8 @@ void CopySelect::setup() { traits.set_options(source_->traits.get_options()); - if (auto idx = this->source_->active_index(); idx.has_value()) + auto idx = this->source_->active_index(); + if (idx.has_value()) this->publish_state(*idx); } diff --git a/esphome/components/current_based/current_based_cover.cpp b/esphome/components/current_based/current_based_cover.cpp index a2b093a5ba..13bf11b991 100644 --- a/esphome/components/current_based/current_based_cover.cpp +++ b/esphome/components/current_based/current_based_cover.cpp @@ -37,7 +37,8 @@ void CurrentBasedCover::control(const CoverCall &call) { } } } - if (auto opt_pos = call.get_position(); opt_pos.has_value()) { + auto opt_pos = call.get_position(); + if (opt_pos.has_value()) { auto pos = *opt_pos; if (fabsf(this->position - pos) < 0.01) { // already at target diff --git a/esphome/components/daikin_arc/daikin_arc.cpp b/esphome/components/daikin_arc/daikin_arc.cpp index 9fdf00a80b..c45fa307a7 100644 --- a/esphome/components/daikin_arc/daikin_arc.cpp +++ b/esphome/components/daikin_arc/daikin_arc.cpp @@ -485,8 +485,9 @@ bool DaikinArcClimate::on_receive(remote_base::RemoteReceiveData data) { } void DaikinArcClimate::control(const climate::ClimateCall &call) { - if (auto val = call.get_target_humidity(); val.has_value()) { - this->target_humidity = *val; + auto target_humidity = call.get_target_humidity(); + if (target_humidity.has_value()) { + this->target_humidity = *target_humidity; } climate_ir::ClimateIR::control(call); } diff --git a/esphome/components/endstop/endstop_cover.cpp b/esphome/components/endstop/endstop_cover.cpp index 51d172b339..5e0b9c72d3 100644 --- a/esphome/components/endstop/endstop_cover.cpp +++ b/esphome/components/endstop/endstop_cover.cpp @@ -37,7 +37,8 @@ void EndstopCover::control(const CoverCall &call) { } } } - if (auto opt_pos = call.get_position(); opt_pos.has_value()) { + auto opt_pos = call.get_position(); + if (opt_pos.has_value()) { auto pos = *opt_pos; if (pos == this->position) { // already at target diff --git a/esphome/components/feedback/feedback_cover.cpp b/esphome/components/feedback/feedback_cover.cpp index 859b17607f..d247bada33 100644 --- a/esphome/components/feedback/feedback_cover.cpp +++ b/esphome/components/feedback/feedback_cover.cpp @@ -269,7 +269,10 @@ void FeedbackCover::control(const CoverCall &call) { this->start_direction_(COVER_OPERATION_CLOSING); } } - } else if (auto pos_opt = call.get_position(); pos_opt.has_value()) { + } else { + auto pos_opt = call.get_position(); + if (!pos_opt.has_value()) + return; // go to position action auto pos = *pos_opt; if (pos == this->position) { diff --git a/esphome/components/hbridge/fan/hbridge_fan.cpp b/esphome/components/hbridge/fan/hbridge_fan.cpp index 913fdedd3f..89c162eebf 100644 --- a/esphome/components/hbridge/fan/hbridge_fan.cpp +++ b/esphome/components/hbridge/fan/hbridge_fan.cpp @@ -49,14 +49,18 @@ void HBridgeFan::dump_config() { } void HBridgeFan::control(const fan::FanCall &call) { - if (auto val = call.get_state(); val.has_value()) - this->state = *val; - if (auto val = call.get_speed(); val.has_value()) - this->speed = *val; - if (auto val = call.get_oscillating(); val.has_value()) - this->oscillating = *val; - if (auto val = call.get_direction(); val.has_value()) - this->direction = *val; + auto call_state = call.get_state(); + if (call_state.has_value()) + this->state = *call_state; + auto call_speed = call.get_speed(); + if (call_speed.has_value()) + this->speed = *call_speed; + auto call_oscillating = call.get_oscillating(); + if (call_oscillating.has_value()) + this->oscillating = *call_oscillating; + auto call_direction = call.get_direction(); + if (call_direction.has_value()) + this->direction = *call_direction; this->apply_preset_mode_(call); this->write_state_(); diff --git a/esphome/components/he60r/he60r.cpp b/esphome/components/he60r/he60r.cpp index 07b7d3f7a2..fdcd1a29c0 100644 --- a/esphome/components/he60r/he60r.cpp +++ b/esphome/components/he60r/he60r.cpp @@ -171,7 +171,10 @@ void HE60rCover::control(const CoverCall &call) { } else { this->toggles_needed_++; } - } else if (auto pos_opt = call.get_position(); pos_opt.has_value()) { + } else { + auto pos_opt = call.get_position(); + if (!pos_opt.has_value()) + return; // go to position action auto pos = *pos_opt; // are we at the target? 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 2213e988a7..369c964a85 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 @@ -11,10 +11,12 @@ static const char *const TAG = "audio"; void I2SAudioMediaPlayer::control(const media_player::MediaPlayerCall &call) { media_player::MediaPlayerState play_state = media_player::MEDIA_PLAYER_STATE_PLAYING; - if (auto announcement = call.get_announcement(); announcement.has_value()) { + auto announcement = call.get_announcement(); + if (announcement.has_value()) { play_state = *announcement ? media_player::MEDIA_PLAYER_STATE_ANNOUNCING : media_player::MEDIA_PLAYER_STATE_PLAYING; } - if (auto media_url = call.get_media_url(); media_url.has_value()) { + auto media_url = call.get_media_url(); + if (media_url.has_value()) { this->current_url_ = media_url; if (this->i2s_state_ != I2S_STATE_STOPPED && this->audio_ != nullptr) { if (this->audio_->isRunning()) { @@ -31,12 +33,14 @@ void I2SAudioMediaPlayer::control(const media_player::MediaPlayerCall &call) { this->is_announcement_ = true; } - if (auto vol = call.get_volume(); vol.has_value()) { + auto vol = call.get_volume(); + if (vol.has_value()) { this->volume = *vol; this->set_volume_(volume); this->unmute_(); } - if (auto cmd = call.get_command(); cmd.has_value()) { + auto cmd = call.get_command(); + if (cmd.has_value()) { switch (*cmd) { case media_player::MEDIA_PLAYER_COMMAND_MUTE: this->mute_(); diff --git a/esphome/components/infrared/infrared.cpp b/esphome/components/infrared/infrared.cpp index 514c31021f..658c9fd0df 100644 --- a/esphome/components/infrared/infrared.cpp +++ b/esphome/components/infrared/infrared.cpp @@ -90,7 +90,8 @@ void Infrared::control(const InfraredCall &call) { auto *transmit_data = transmit_call.get_data(); // Set carrier frequency - if (auto freq = call.get_carrier_frequency(); freq.has_value()) { + auto freq = call.get_carrier_frequency(); + if (freq.has_value()) { transmit_data->set_carrier_frequency(*freq); } diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index 53ccd86065..dc7e7019aa 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -19,7 +19,8 @@ void Mcp4461Component::setup() { // save WP/WL status this->update_write_protection_status_(); for (uint8_t i = 0; i < 8; i++) { - if (auto init_val = this->reg_[i].initial_value; init_val.has_value()) { + auto init_val = this->reg_[i].initial_value; + if (init_val.has_value()) { uint16_t initial_state = static_cast(*init_val * 256.0f); this->write_wiper_level_(i, initial_state); } diff --git a/esphome/components/midea/air_conditioner.cpp b/esphome/components/midea/air_conditioner.cpp index 512a53470e..4d59a4fbbc 100644 --- a/esphome/components/midea/air_conditioner.cpp +++ b/esphome/components/midea/air_conditioner.cpp @@ -56,20 +56,25 @@ void AirConditioner::on_status_change() { void AirConditioner::control(const ClimateCall &call) { dudanov::midea::ac::Control ctrl{}; - if (auto val = call.get_target_temperature(); val.has_value()) - ctrl.targetTemp = *val; - if (auto val = call.get_swing_mode(); val.has_value()) - ctrl.swingMode = Converters::to_midea_swing_mode(*val); - if (auto val = call.get_mode(); val.has_value()) - ctrl.mode = Converters::to_midea_mode(*val); - if (auto val = call.get_preset(); val.has_value()) { - ctrl.preset = Converters::to_midea_preset(*val); + auto target_temp_val = call.get_target_temperature(); + if (target_temp_val.has_value()) + ctrl.targetTemp = *target_temp_val; + auto swing_mode_val = call.get_swing_mode(); + if (swing_mode_val.has_value()) + ctrl.swingMode = Converters::to_midea_swing_mode(*swing_mode_val); + auto mode_val = call.get_mode(); + if (mode_val.has_value()) + ctrl.mode = Converters::to_midea_mode(*mode_val); + auto preset_val = call.get_preset(); + if (preset_val.has_value()) { + ctrl.preset = Converters::to_midea_preset(*preset_val); } else if (call.has_custom_preset()) { // get_custom_preset() returns StringRef pointing to null-terminated string literals from codegen ctrl.preset = Converters::to_midea_preset(call.get_custom_preset().c_str()); } - if (auto val = call.get_fan_mode(); val.has_value()) { - ctrl.fanMode = Converters::to_midea_fan_mode(*val); + auto fan_mode_val = call.get_fan_mode(); + if (fan_mode_val.has_value()) { + ctrl.fanMode = Converters::to_midea_fan_mode(*fan_mode_val); } else if (call.has_custom_fan_mode()) { // get_custom_fan_mode() returns StringRef pointing to null-terminated string literals from codegen ctrl.fanMode = Converters::to_midea_fan_mode(call.get_custom_fan_mode().c_str()); diff --git a/esphome/components/pid/pid_climate.cpp b/esphome/components/pid/pid_climate.cpp index 526fb69162..54b7a688b4 100644 --- a/esphome/components/pid/pid_climate.cpp +++ b/esphome/components/pid/pid_climate.cpp @@ -41,10 +41,12 @@ void PIDClimate::setup() { } } void PIDClimate::control(const climate::ClimateCall &call) { - if (auto val = call.get_mode(); val.has_value()) - this->mode = *val; - if (auto val = call.get_target_temperature(); val.has_value()) - this->target_temperature = *val; + auto call_mode = call.get_mode(); + if (call_mode.has_value()) + this->mode = *call_mode; + auto call_target = call.get_target_temperature(); + if (call_target.has_value()) + this->target_temperature = *call_target; // If switching to off mode, set output immediately if (this->mode == climate::CLIMATE_MODE_OFF) diff --git a/esphome/components/speaker/media_player/speaker_media_player.cpp b/esphome/components/speaker/media_player/speaker_media_player.cpp index ebbeeb142e..9f168f854d 100644 --- a/esphome/components/speaker/media_player/speaker_media_player.cpp +++ b/esphome/components/speaker/media_player/speaker_media_player.cpp @@ -495,17 +495,20 @@ void SpeakerMediaPlayer::control(const media_player::MediaPlayerCall &call) { MediaCallCommand media_command; - if (auto ann = call.get_announcement(); this->single_pipeline_() || (ann.has_value() && *ann)) { + auto ann = call.get_announcement(); + if (this->single_pipeline_() || (ann.has_value() && *ann)) { media_command.announce = true; } else { media_command.announce = false; } - if (auto media_url = call.get_media_url(); media_url.has_value()) { + auto media_url = call.get_media_url(); + if (media_url.has_value()) { media_command.url = new std::string(*media_url); // Must be manually deleted after receiving media_command from a queue - if (auto cmd = call.get_command(); cmd.has_value()) { + auto cmd = call.get_command(); + if (cmd.has_value()) { if (*cmd == media_player::MEDIA_PLAYER_COMMAND_ENQUEUE) { media_command.enqueue = true; } @@ -515,14 +518,16 @@ void SpeakerMediaPlayer::control(const media_player::MediaPlayerCall &call) { return; } - if (auto vol = call.get_volume(); vol.has_value()) { + auto vol = call.get_volume(); + if (vol.has_value()) { media_command.volume = vol; // Wait 0 ticks for queue to be free, volume sets aren't that important! xQueueSend(this->media_control_command_queue_, &media_command, 0); return; } - if (auto cmd = call.get_command(); cmd.has_value()) { + auto cmd = call.get_command(); + if (cmd.has_value()) { media_command.command = cmd; TickType_t ticks_to_wait = portMAX_DELAY; if ((*cmd == media_player::MEDIA_PLAYER_COMMAND_VOLUME_UP) || diff --git a/esphome/components/speed/fan/speed_fan.cpp b/esphome/components/speed/fan/speed_fan.cpp index 0cc2583493..d45237c467 100644 --- a/esphome/components/speed/fan/speed_fan.cpp +++ b/esphome/components/speed/fan/speed_fan.cpp @@ -21,14 +21,18 @@ void SpeedFan::setup() { void SpeedFan::dump_config() { LOG_FAN("", "Speed Fan", this); } void SpeedFan::control(const fan::FanCall &call) { - if (auto val = call.get_state(); val.has_value()) - this->state = *val; - if (auto val = call.get_speed(); val.has_value()) - this->speed = *val; - if (auto val = call.get_oscillating(); val.has_value()) - this->oscillating = *val; - if (auto val = call.get_direction(); val.has_value()) - this->direction = *val; + auto call_state = call.get_state(); + if (call_state.has_value()) + this->state = *call_state; + auto call_speed = call.get_speed(); + if (call_speed.has_value()) + this->speed = *call_speed; + auto call_oscillating = call.get_oscillating(); + if (call_oscillating.has_value()) + this->oscillating = *call_oscillating; + auto call_direction = call.get_direction(); + if (call_direction.has_value()) + this->direction = *call_direction; this->apply_preset_mode_(call); this->write_state_(); diff --git a/esphome/components/sprinkler/sprinkler.cpp b/esphome/components/sprinkler/sprinkler.cpp index 814b2560d8..d1f7452054 100644 --- a/esphome/components/sprinkler/sprinkler.cpp +++ b/esphome/components/sprinkler/sprinkler.cpp @@ -1193,7 +1193,8 @@ switch_::Switch *Sprinkler::valve_switch(const size_t valve_number) { switch_::Switch *Sprinkler::valve_pump_switch(const size_t valve_number) { if (this->is_a_valid_valve(valve_number)) { - if (auto idx = this->valve_[valve_number].pump_switch_index; idx.has_value()) { + auto idx = this->valve_[valve_number].pump_switch_index; + if (idx.has_value()) { return this->pump_[*idx]; } } diff --git a/esphome/components/template/cover/template_cover.cpp b/esphome/components/template/cover/template_cover.cpp index 128e1a6f21..d5e0967e1e 100644 --- a/esphome/components/template/cover/template_cover.cpp +++ b/esphome/components/template/cover/template_cover.cpp @@ -74,7 +74,8 @@ void TemplateCover::control(const CoverCall &call) { this->prev_command_trigger_ = &this->toggle_trigger_; this->publish_state(); } - if (auto pos_val = call.get_position(); pos_val.has_value()) { + auto pos_val = call.get_position(); + if (pos_val.has_value()) { auto pos = *pos_val; this->stop_prev_trigger_(); @@ -93,7 +94,8 @@ void TemplateCover::control(const CoverCall &call) { } } - if (auto tilt_val = call.get_tilt(); tilt_val.has_value()) { + auto tilt_val = call.get_tilt(); + if (tilt_val.has_value()) { auto tilt = *tilt_val; this->tilt_trigger_.trigger(tilt); diff --git a/esphome/components/template/fan/template_fan.cpp b/esphome/components/template/fan/template_fan.cpp index d909f9183a..46a5cba9bb 100644 --- a/esphome/components/template/fan/template_fan.cpp +++ b/esphome/components/template/fan/template_fan.cpp @@ -20,14 +20,18 @@ void TemplateFan::setup() { void TemplateFan::dump_config() { LOG_FAN("", "Template Fan", this); } void TemplateFan::control(const fan::FanCall &call) { - if (auto val = call.get_state(); val.has_value()) - this->state = *val; - if (auto val = call.get_speed(); val.has_value() && (this->speed_count_ > 0)) - this->speed = *val; - if (auto val = call.get_oscillating(); val.has_value() && this->has_oscillating_) - this->oscillating = *val; - if (auto val = call.get_direction(); val.has_value() && this->has_direction_) - this->direction = *val; + auto call_state = call.get_state(); + if (call_state.has_value()) + this->state = *call_state; + auto call_speed = call.get_speed(); + if (call_speed.has_value() && (this->speed_count_ > 0)) + this->speed = *call_speed; + auto call_oscillating = call.get_oscillating(); + if (call_oscillating.has_value() && this->has_oscillating_) + this->oscillating = *call_oscillating; + auto call_direction = call.get_direction(); + if (call_direction.has_value() && this->has_direction_) + this->direction = *call_direction; this->apply_preset_mode_(call); this->publish_state(); diff --git a/esphome/components/template/valve/template_valve.cpp b/esphome/components/template/valve/template_valve.cpp index b47656cb9b..3ebeec1285 100644 --- a/esphome/components/template/valve/template_valve.cpp +++ b/esphome/components/template/valve/template_valve.cpp @@ -77,7 +77,8 @@ void TemplateValve::control(const ValveCall &call) { this->prev_command_trigger_ = &this->toggle_trigger_; this->publish_state(); } - if (auto pos_val = call.get_position(); pos_val.has_value()) { + auto pos_val = call.get_position(); + if (pos_val.has_value()) { auto pos = *pos_val; this->stop_prev_trigger_(); diff --git a/esphome/components/template/water_heater/template_water_heater.cpp b/esphome/components/template/water_heater/template_water_heater.cpp index d50ba70827..73081d204b 100644 --- a/esphome/components/template/water_heater/template_water_heater.cpp +++ b/esphome/components/template/water_heater/template_water_heater.cpp @@ -101,9 +101,10 @@ water_heater::WaterHeaterCallInternal TemplateWaterHeater::make_call() { } void TemplateWaterHeater::control(const water_heater::WaterHeaterCall &call) { - if (auto val = call.get_mode(); val.has_value()) { + auto mode_val = call.get_mode(); + if (mode_val.has_value()) { if (this->optimistic_) { - this->mode_ = *val; + this->mode_ = *mode_val; } } if (!std::isnan(call.get_target_temperature())) { @@ -112,14 +113,16 @@ void TemplateWaterHeater::control(const water_heater::WaterHeaterCall &call) { } } - if (auto val = call.get_away(); val.has_value()) { + auto away_val = call.get_away(); + if (away_val.has_value()) { if (this->optimistic_) { - this->set_state_flag_(water_heater::WATER_HEATER_STATE_AWAY, *val); + this->set_state_flag_(water_heater::WATER_HEATER_STATE_AWAY, *away_val); } } - if (auto val = call.get_on(); val.has_value()) { + auto on_val = call.get_on(); + if (on_val.has_value()) { if (this->optimistic_) { - this->set_state_flag_(water_heater::WATER_HEATER_STATE_ON, *val); + this->set_state_flag_(water_heater::WATER_HEATER_STATE_ON, *on_val); } } diff --git a/esphome/components/thermostat/thermostat_climate.cpp b/esphome/components/thermostat/thermostat_climate.cpp index 0f3c5fd813..d52a22f880 100644 --- a/esphome/components/thermostat/thermostat_climate.cpp +++ b/esphome/components/thermostat/thermostat_climate.cpp @@ -211,12 +211,13 @@ void ThermostatClimate::validate_target_humidity() { void ThermostatClimate::control(const climate::ClimateCall &call) { bool target_temperature_high_changed = false; - if (auto val = call.get_preset(); val.has_value()) { + auto preset = call.get_preset(); + if (preset.has_value()) { // setup_complete_ blocks modifying/resetting the temps immediately after boot if (this->setup_complete_) { - this->change_preset_(*val); + this->change_preset_(*preset); } else { - this->preset = val; + this->preset = preset; } } if (call.has_custom_preset()) { @@ -229,34 +230,41 @@ void ThermostatClimate::control(const climate::ClimateCall &call) { } } - if (auto val = call.get_mode(); val.has_value()) { - this->mode = *val; + auto mode = call.get_mode(); + if (mode.has_value()) { + this->mode = *mode; } - if (auto val = call.get_fan_mode(); val.has_value()) { - this->fan_mode = val; + auto fan_mode = call.get_fan_mode(); + if (fan_mode.has_value()) { + this->fan_mode = fan_mode; } - if (auto val = call.get_swing_mode(); val.has_value()) { - this->swing_mode = *val; + auto swing_mode = call.get_swing_mode(); + if (swing_mode.has_value()) { + this->swing_mode = *swing_mode; } if (this->supports_two_points_) { - if (auto val = call.get_target_temperature_low(); val.has_value()) { - this->target_temperature_low = *val; + auto target_temp_low = call.get_target_temperature_low(); + if (target_temp_low.has_value()) { + this->target_temperature_low = *target_temp_low; } - if (auto val = call.get_target_temperature_high(); val.has_value()) { - target_temperature_high_changed = this->target_temperature_high != *val; - this->target_temperature_high = *val; + auto target_temp_high = call.get_target_temperature_high(); + if (target_temp_high.has_value()) { + target_temperature_high_changed = this->target_temperature_high != *target_temp_high; + this->target_temperature_high = *target_temp_high; } // ensure the two set points are valid and adjust one of them if necessary this->validate_target_temperatures(target_temperature_high_changed || (this->prev_mode_ == climate::CLIMATE_MODE_COOL)); } else { - if (auto val = call.get_target_temperature(); val.has_value()) { - this->target_temperature = *val; + auto target_temp = call.get_target_temperature(); + if (target_temp.has_value()) { + this->target_temperature = *target_temp; this->validate_target_temperature(); } } - if (auto val = call.get_target_humidity(); val.has_value()) { - this->target_humidity = *val; + auto target_humidity = call.get_target_humidity(); + if (target_humidity.has_value()) { + this->target_humidity = *target_humidity; this->validate_target_humidity(); } // make any changes happen diff --git a/esphome/components/time_based/time_based_cover.cpp b/esphome/components/time_based/time_based_cover.cpp index b4cd5cb7cd..c83829ff59 100644 --- a/esphome/components/time_based/time_based_cover.cpp +++ b/esphome/components/time_based/time_based_cover.cpp @@ -79,7 +79,8 @@ void TimeBasedCover::control(const CoverCall &call) { } } } - if (auto pos_val = call.get_position(); pos_val.has_value()) { + auto pos_val = call.get_position(); + if (pos_val.has_value()) { auto pos = *pos_val; if (pos == this->position) { // already at target diff --git a/esphome/components/tormatic/tormatic_cover.cpp b/esphome/components/tormatic/tormatic_cover.cpp index c3fbcdee18..f567be0674 100644 --- a/esphome/components/tormatic/tormatic_cover.cpp +++ b/esphome/components/tormatic/tormatic_cover.cpp @@ -66,7 +66,8 @@ void Tormatic::control(const cover::CoverCall &call) { return; } - if (auto pos_val = call.get_position(); pos_val.has_value()) { + auto pos_val = call.get_position(); + if (pos_val.has_value()) { auto pos = *pos_val; this->control_position_(pos); return; diff --git a/esphome/components/tuya/climate/tuya_climate.cpp b/esphome/components/tuya/climate/tuya_climate.cpp index 772aaabb06..9cea9a2e67 100644 --- a/esphome/components/tuya/climate/tuya_climate.cpp +++ b/esphome/components/tuya/climate/tuya_climate.cpp @@ -7,7 +7,8 @@ namespace tuya { static const char *const TAG = "tuya.climate"; void TuyaClimate::setup() { - if (auto switch_id = this->switch_id_; switch_id.has_value()) { + auto switch_id = this->switch_id_; + if (switch_id.has_value()) { this->parent_->register_listener(*switch_id, [this](const TuyaDatapoint &datapoint) { ESP_LOGV(TAG, "MCU reported switch is: %s", ONOFF(datapoint.value_bool)); this->mode = climate::CLIMATE_MODE_OFF; @@ -32,7 +33,8 @@ void TuyaClimate::setup() { this->cooling_state_pin_->setup(); this->cooling_state_ = this->cooling_state_pin_->digital_read(); } - if (auto active_state_id = this->active_state_id_; active_state_id.has_value()) { + auto active_state_id = this->active_state_id_; + if (active_state_id.has_value()) { this->parent_->register_listener(*active_state_id, [this](const TuyaDatapoint &datapoint) { ESP_LOGV(TAG, "MCU reported active state is: %u", datapoint.value_enum); this->active_state_ = datapoint.value_enum; @@ -40,7 +42,8 @@ void TuyaClimate::setup() { this->publish_state(); }); } - if (auto target_temp_id = this->target_temperature_id_; target_temp_id.has_value()) { + auto target_temp_id = this->target_temperature_id_; + if (target_temp_id.has_value()) { this->parent_->register_listener(*target_temp_id, [this](const TuyaDatapoint &datapoint) { this->manual_temperature_ = datapoint.value_int * this->target_temperature_multiplier_; if (this->reports_fahrenheit_) { @@ -53,7 +56,8 @@ void TuyaClimate::setup() { this->publish_state(); }); } - if (auto current_temp_id = this->current_temperature_id_; current_temp_id.has_value()) { + auto current_temp_id = this->current_temperature_id_; + if (current_temp_id.has_value()) { this->parent_->register_listener(*current_temp_id, [this](const TuyaDatapoint &datapoint) { this->current_temperature = datapoint.value_int * this->current_temperature_multiplier_; if (this->reports_fahrenheit_) { @@ -65,7 +69,8 @@ void TuyaClimate::setup() { this->publish_state(); }); } - if (auto eco_id = this->eco_id_; eco_id.has_value()) { + auto eco_id = this->eco_id_; + if (eco_id.has_value()) { this->parent_->register_listener(*eco_id, [this](const TuyaDatapoint &datapoint) { // Whether data type is BOOL or ENUM, it will still be a 1 or a 0, so the functions below are valid in both cases this->eco_ = datapoint.value_bool; @@ -76,7 +81,8 @@ void TuyaClimate::setup() { this->publish_state(); }); } - if (auto sleep_id = this->sleep_id_; sleep_id.has_value()) { + auto sleep_id = this->sleep_id_; + if (sleep_id.has_value()) { this->parent_->register_listener(*sleep_id, [this](const TuyaDatapoint &datapoint) { this->sleep_ = datapoint.value_bool; ESP_LOGV(TAG, "MCU reported sleep is: %s", ONOFF(this->sleep_)); @@ -85,7 +91,8 @@ void TuyaClimate::setup() { this->publish_state(); }); } - if (auto swing_vert_id = this->swing_vertical_id_; swing_vert_id.has_value()) { + auto swing_vert_id = this->swing_vertical_id_; + if (swing_vert_id.has_value()) { this->parent_->register_listener(*swing_vert_id, [this](const TuyaDatapoint &datapoint) { this->swing_vertical_ = datapoint.value_bool; ESP_LOGV(TAG, "MCU reported vertical swing is: %s", ONOFF(datapoint.value_bool)); @@ -94,7 +101,8 @@ void TuyaClimate::setup() { }); } - if (auto swing_horiz_id = this->swing_horizontal_id_; swing_horiz_id.has_value()) { + auto swing_horiz_id = this->swing_horizontal_id_; + if (swing_horiz_id.has_value()) { this->parent_->register_listener(*swing_horiz_id, [this](const TuyaDatapoint &datapoint) { this->swing_horizontal_ = datapoint.value_bool; ESP_LOGV(TAG, "MCU reported horizontal swing is: %s", ONOFF(datapoint.value_bool)); @@ -103,7 +111,8 @@ void TuyaClimate::setup() { }); } - if (auto fan_speed_id = this->fan_speed_id_; fan_speed_id.has_value()) { + auto fan_speed_id = this->fan_speed_id_; + if (fan_speed_id.has_value()) { this->parent_->register_listener(*fan_speed_id, [this](const TuyaDatapoint &datapoint) { ESP_LOGV(TAG, "MCU reported Fan Speed Mode is: %u", datapoint.value_enum); this->fan_state_ = datapoint.value_enum; diff --git a/esphome/components/uponor_smatrix/climate/uponor_smatrix_climate.cpp b/esphome/components/uponor_smatrix/climate/uponor_smatrix_climate.cpp index 5b0ea5625e..3eae4d2d96 100644 --- a/esphome/components/uponor_smatrix/climate/uponor_smatrix_climate.cpp +++ b/esphome/components/uponor_smatrix/climate/uponor_smatrix_climate.cpp @@ -42,7 +42,8 @@ climate::ClimateTraits UponorSmatrixClimate::traits() { } void UponorSmatrixClimate::control(const climate::ClimateCall &call) { - if (auto val = call.get_target_temperature(); val.has_value()) { + auto val = call.get_target_temperature(); + if (val.has_value()) { uint16_t temp = celsius_to_raw(*val); if (this->preset == climate::CLIMATE_PRESET_ECO) { // During ECO mode, the thermostat automatically substracts the setback value from the setpoint, diff --git a/esphome/components/yashima/yashima.cpp b/esphome/components/yashima/yashima.cpp index 83899dc7dc..4a64e6c41c 100644 --- a/esphome/components/yashima/yashima.cpp +++ b/esphome/components/yashima/yashima.cpp @@ -120,10 +120,12 @@ void YashimaClimate::setup() { } void YashimaClimate::control(const climate::ClimateCall &call) { - if (auto val = call.get_mode(); val.has_value()) - this->mode = *val; - if (auto val = call.get_target_temperature(); val.has_value()) - this->target_temperature = *val; + auto call_mode = call.get_mode(); + if (call_mode.has_value()) + this->mode = *call_mode; + auto call_target = call.get_target_temperature(); + if (call_target.has_value()) + this->target_temperature = *call_target; this->transmit_state_(); this->publish_state(); From aca73e84385320c2678c1cf27f5326284b551c26 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 3 Mar 2026 13:30:49 -1000 Subject: [PATCH 4/8] expand all sites, part 2 --- .../components/tuya/climate/tuya_climate.cpp | 67 ++++++++++++------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/esphome/components/tuya/climate/tuya_climate.cpp b/esphome/components/tuya/climate/tuya_climate.cpp index 9cea9a2e67..b031702e1e 100644 --- a/esphome/components/tuya/climate/tuya_climate.cpp +++ b/esphome/components/tuya/climate/tuya_climate.cpp @@ -148,27 +148,34 @@ void TuyaClimate::loop() { } void TuyaClimate::control(const climate::ClimateCall &call) { - if (auto mode = call.get_mode(); mode.has_value()) { + auto mode = call.get_mode(); + if (mode.has_value()) { const bool switch_state = *mode != climate::CLIMATE_MODE_OFF; ESP_LOGV(TAG, "Setting switch: %s", ONOFF(switch_state)); - if (auto id = this->switch_id_; id.has_value()) { - this->parent_->set_boolean_datapoint_value(*id, switch_state); + auto switch_dp_id = this->switch_id_; + if (switch_dp_id.has_value()) { + this->parent_->set_boolean_datapoint_value(*switch_dp_id, switch_state); } const climate::ClimateMode new_mode = *mode; - if (auto id = this->active_state_id_; id.has_value()) { + auto active_state_dp_id = this->active_state_id_; + if (active_state_dp_id.has_value()) { if (new_mode == climate::CLIMATE_MODE_HEAT && this->supports_heat_) { - if (auto val = this->active_state_heating_value_; val.has_value()) - this->parent_->set_enum_datapoint_value(*id, *val); + auto heating_val = this->active_state_heating_value_; + if (heating_val.has_value()) + this->parent_->set_enum_datapoint_value(*active_state_dp_id, *heating_val); } else if (new_mode == climate::CLIMATE_MODE_COOL && this->supports_cool_) { - if (auto val = this->active_state_cooling_value_; val.has_value()) - this->parent_->set_enum_datapoint_value(*id, *val); + auto cooling_val = this->active_state_cooling_value_; + if (cooling_val.has_value()) + this->parent_->set_enum_datapoint_value(*active_state_dp_id, *cooling_val); } else if (new_mode == climate::CLIMATE_MODE_DRY) { - if (auto val = this->active_state_drying_value_; val.has_value()) - this->parent_->set_enum_datapoint_value(*id, *val); + auto drying_val = this->active_state_drying_value_; + if (drying_val.has_value()) + this->parent_->set_enum_datapoint_value(*active_state_dp_id, *drying_val); } else if (new_mode == climate::CLIMATE_MODE_FAN_ONLY) { - if (auto val = this->active_state_fanonly_value_; val.has_value()) - this->parent_->set_enum_datapoint_value(*id, *val); + auto fanonly_val = this->active_state_fanonly_value_; + if (fanonly_val.has_value()) + this->parent_->set_enum_datapoint_value(*active_state_dp_id, *fanonly_val); } } else { ESP_LOGW(TAG, "Active state (mode) datapoint not configured"); @@ -178,33 +185,38 @@ void TuyaClimate::control(const climate::ClimateCall &call) { control_swing_mode_(call); control_fan_mode_(call); - if (auto target_temp = call.get_target_temperature(); target_temp.has_value()) { + auto target_temp = call.get_target_temperature(); + if (target_temp.has_value()) { float target_temperature = *target_temp; if (this->reports_fahrenheit_) target_temperature = (target_temperature * 9 / 5) + 32; ESP_LOGV(TAG, "Setting target temperature: %.1f", target_temperature); - if (auto id = this->target_temperature_id_; id.has_value()) { - this->parent_->set_integer_datapoint_value(*id, + auto target_temp_dp_id = this->target_temperature_id_; + if (target_temp_dp_id.has_value()) { + this->parent_->set_integer_datapoint_value(*target_temp_dp_id, (int) (target_temperature / this->target_temperature_multiplier_)); } } - if (auto preset_val = call.get_preset(); preset_val.has_value()) { + auto preset_val = call.get_preset(); + if (preset_val.has_value()) { const climate::ClimatePreset preset = *preset_val; - if (auto id = this->eco_id_; id.has_value()) { + auto eco_dp_id = this->eco_id_; + if (eco_dp_id.has_value()) { const bool eco = preset == climate::CLIMATE_PRESET_ECO; ESP_LOGV(TAG, "Setting eco: %s", ONOFF(eco)); if (this->eco_type_ == TuyaDatapointType::ENUM) { - this->parent_->set_enum_datapoint_value(*id, eco); + this->parent_->set_enum_datapoint_value(*eco_dp_id, eco); } else { - this->parent_->set_boolean_datapoint_value(*id, eco); + this->parent_->set_boolean_datapoint_value(*eco_dp_id, eco); } } - if (auto id = this->sleep_id_; id.has_value()) { + auto sleep_dp_id = this->sleep_id_; + if (sleep_dp_id.has_value()) { const bool sleep = preset == climate::CLIMATE_PRESET_SLEEP; ESP_LOGV(TAG, "Setting sleep: %s", ONOFF(sleep)); - this->parent_->set_boolean_datapoint_value(*id, sleep); + this->parent_->set_boolean_datapoint_value(*sleep_dp_id, sleep); } } } @@ -213,7 +225,8 @@ void TuyaClimate::control_swing_mode_(const climate::ClimateCall &call) { bool vertical_swing_changed = false; bool horizontal_swing_changed = false; - if (auto swing_mode_val = call.get_swing_mode(); swing_mode_val.has_value()) { + auto swing_mode_val = call.get_swing_mode(); + if (swing_mode_val.has_value()) { const auto swing_mode = *swing_mode_val; switch (swing_mode) { @@ -258,14 +271,16 @@ void TuyaClimate::control_swing_mode_(const climate::ClimateCall &call) { } } - if (auto id = this->swing_vertical_id_; vertical_swing_changed && id.has_value()) { + auto vert_dp_id = this->swing_vertical_id_; + if (vertical_swing_changed && vert_dp_id.has_value()) { ESP_LOGV(TAG, "Setting vertical swing: %s", ONOFF(swing_vertical_)); - this->parent_->set_boolean_datapoint_value(*id, swing_vertical_); + this->parent_->set_boolean_datapoint_value(*vert_dp_id, swing_vertical_); } - if (auto id = this->swing_horizontal_id_; horizontal_swing_changed && id.has_value()) { + auto horiz_dp_id = this->swing_horizontal_id_; + if (horizontal_swing_changed && horiz_dp_id.has_value()) { ESP_LOGV(TAG, "Setting horizontal swing: %s", ONOFF(swing_horizontal_)); - this->parent_->set_boolean_datapoint_value(*id, swing_horizontal_); + this->parent_->set_boolean_datapoint_value(*horiz_dp_id, swing_horizontal_); } // Publish the state after updating the swing mode From a34e36e22e101c9150013cb23c48529bf1d8ea5e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 3 Mar 2026 13:31:08 -1000 Subject: [PATCH 5/8] expand all sites, part 3 --- .../components/tuya/climate/tuya_climate.cpp | 48 +++++++++++-------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/esphome/components/tuya/climate/tuya_climate.cpp b/esphome/components/tuya/climate/tuya_climate.cpp index b031702e1e..6602ccd8c9 100644 --- a/esphome/components/tuya/climate/tuya_climate.cpp +++ b/esphome/components/tuya/climate/tuya_climate.cpp @@ -288,7 +288,8 @@ void TuyaClimate::control_swing_mode_(const climate::ClimateCall &call) { } void TuyaClimate::control_fan_mode_(const climate::ClimateCall &call) { - if (auto fan_mode_val = call.get_fan_mode(); fan_mode_val.has_value()) { + auto fan_mode_val = call.get_fan_mode(); + if (fan_mode_val.has_value()) { climate::ClimateFanMode fan_mode = *fan_mode_val; uint8_t tuya_fan_speed; @@ -313,8 +314,9 @@ void TuyaClimate::control_fan_mode_(const climate::ClimateCall &call) { break; } - if (auto id = this->fan_speed_id_; id.has_value()) { - this->parent_->set_enum_datapoint_value(*id, tuya_fan_speed); + auto fan_speed_dp_id = this->fan_speed_id_; + if (fan_speed_dp_id.has_value()) { + this->parent_->set_enum_datapoint_value(*fan_speed_dp_id, tuya_fan_speed); } } } @@ -369,31 +371,39 @@ climate::ClimateTraits TuyaClimate::traits() { void TuyaClimate::dump_config() { LOG_CLIMATE("", "Tuya Climate", this); - if (auto id = this->switch_id_; id.has_value()) { - ESP_LOGCONFIG(TAG, " Switch has datapoint ID %u", *id); + auto switch_dp_id = this->switch_id_; + if (switch_dp_id.has_value()) { + ESP_LOGCONFIG(TAG, " Switch has datapoint ID %u", *switch_dp_id); } - if (auto id = this->active_state_id_; id.has_value()) { - ESP_LOGCONFIG(TAG, " Active state has datapoint ID %u", *id); + auto active_state_dp_id = this->active_state_id_; + if (active_state_dp_id.has_value()) { + ESP_LOGCONFIG(TAG, " Active state has datapoint ID %u", *active_state_dp_id); } - if (auto id = this->target_temperature_id_; id.has_value()) { - ESP_LOGCONFIG(TAG, " Target Temperature has datapoint ID %u", *id); + auto target_temp_dp_id = this->target_temperature_id_; + if (target_temp_dp_id.has_value()) { + ESP_LOGCONFIG(TAG, " Target Temperature has datapoint ID %u", *target_temp_dp_id); } - if (auto id = this->current_temperature_id_; id.has_value()) { - ESP_LOGCONFIG(TAG, " Current Temperature has datapoint ID %u", *id); + auto current_temp_dp_id = this->current_temperature_id_; + if (current_temp_dp_id.has_value()) { + ESP_LOGCONFIG(TAG, " Current Temperature has datapoint ID %u", *current_temp_dp_id); } LOG_PIN(" Heating State Pin: ", this->heating_state_pin_); LOG_PIN(" Cooling State Pin: ", this->cooling_state_pin_); - if (auto id = this->eco_id_; id.has_value()) { - ESP_LOGCONFIG(TAG, " Eco has datapoint ID %u", *id); + auto eco_dp_id = this->eco_id_; + if (eco_dp_id.has_value()) { + ESP_LOGCONFIG(TAG, " Eco has datapoint ID %u", *eco_dp_id); } - if (auto id = this->sleep_id_; id.has_value()) { - ESP_LOGCONFIG(TAG, " Sleep has datapoint ID %u", *id); + auto sleep_dp_id = this->sleep_id_; + if (sleep_dp_id.has_value()) { + ESP_LOGCONFIG(TAG, " Sleep has datapoint ID %u", *sleep_dp_id); } - if (auto id = this->swing_vertical_id_; id.has_value()) { - ESP_LOGCONFIG(TAG, " Swing Vertical has datapoint ID %u", *id); + auto swing_vert_dp_id = this->swing_vertical_id_; + if (swing_vert_dp_id.has_value()) { + ESP_LOGCONFIG(TAG, " Swing Vertical has datapoint ID %u", *swing_vert_dp_id); } - if (auto id = this->swing_horizontal_id_; id.has_value()) { - ESP_LOGCONFIG(TAG, " Swing Horizontal has datapoint ID %u", *id); + auto swing_horiz_dp_id = this->swing_horizontal_id_; + if (swing_horiz_dp_id.has_value()) { + ESP_LOGCONFIG(TAG, " Swing Horizontal has datapoint ID %u", *swing_horiz_dp_id); } } From 92e2f806667e9edf6a5d9f2c085bceea6d8ae901 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 3 Mar 2026 13:31:51 -1000 Subject: [PATCH 6/8] expand all sites, part 4 --- esphome/components/tuya/fan/tuya_fan.cpp | 32 +++++++++++++++--------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/esphome/components/tuya/fan/tuya_fan.cpp b/esphome/components/tuya/fan/tuya_fan.cpp index a36249b73e..ffe092b11b 100644 --- a/esphome/components/tuya/fan/tuya_fan.cpp +++ b/esphome/components/tuya/fan/tuya_fan.cpp @@ -7,7 +7,8 @@ namespace tuya { static const char *const TAG = "tuya.fan"; void TuyaFan::setup() { - if (auto speed_id = this->speed_id_; speed_id.has_value()) { + auto speed_id = this->speed_id_; + if (speed_id.has_value()) { this->parent_->register_listener(*speed_id, [this](const TuyaDatapoint &datapoint) { if (datapoint.type == TuyaDatapointType::ENUM) { ESP_LOGV(TAG, "MCU reported speed of: %d", datapoint.value_enum); @@ -25,14 +26,16 @@ void TuyaFan::setup() { this->speed_type_ = datapoint.type; }); } - if (auto switch_id = this->switch_id_; switch_id.has_value()) { + auto switch_id = this->switch_id_; + if (switch_id.has_value()) { this->parent_->register_listener(*switch_id, [this](const TuyaDatapoint &datapoint) { ESP_LOGV(TAG, "MCU reported switch is: %s", ONOFF(datapoint.value_bool)); this->state = datapoint.value_bool; this->publish_state(); }); } - if (auto oscillation_id = this->oscillation_id_; oscillation_id.has_value()) { + auto oscillation_id = this->oscillation_id_; + if (oscillation_id.has_value()) { this->parent_->register_listener(*oscillation_id, [this](const TuyaDatapoint &datapoint) { // Whether data type is BOOL or ENUM, it will still be a 1 or a 0, so the functions below are valid in both // scenarios @@ -43,7 +46,8 @@ void TuyaFan::setup() { this->oscillation_type_ = datapoint.type; }); } - if (auto direction_id = this->direction_id_; direction_id.has_value()) { + auto direction_id = this->direction_id_; + if (direction_id.has_value()) { this->parent_->register_listener(*direction_id, [this](const TuyaDatapoint &datapoint) { ESP_LOGD(TAG, "MCU reported reverse direction is: %s", ONOFF(datapoint.value_bool)); this->direction = datapoint.value_bool ? fan::FanDirection::REVERSE : fan::FanDirection::FORWARD; @@ -60,17 +64,21 @@ void TuyaFan::setup() { void TuyaFan::dump_config() { LOG_FAN("", "Tuya Fan", this); - if (auto id = this->speed_id_; id.has_value()) { - ESP_LOGCONFIG(TAG, " Speed has datapoint ID %u", *id); + auto speed_dp_id = this->speed_id_; + if (speed_dp_id.has_value()) { + ESP_LOGCONFIG(TAG, " Speed has datapoint ID %u", *speed_dp_id); } - if (auto id = this->switch_id_; id.has_value()) { - ESP_LOGCONFIG(TAG, " Switch has datapoint ID %u", *id); + auto switch_dp_id = this->switch_id_; + if (switch_dp_id.has_value()) { + ESP_LOGCONFIG(TAG, " Switch has datapoint ID %u", *switch_dp_id); } - if (auto id = this->oscillation_id_; id.has_value()) { - ESP_LOGCONFIG(TAG, " Oscillation has datapoint ID %u", *id); + auto oscillation_dp_id = this->oscillation_id_; + if (oscillation_dp_id.has_value()) { + ESP_LOGCONFIG(TAG, " Oscillation has datapoint ID %u", *oscillation_dp_id); } - if (auto id = this->direction_id_; id.has_value()) { - ESP_LOGCONFIG(TAG, " Direction has datapoint ID %u", *id); + auto direction_dp_id = this->direction_id_; + if (direction_dp_id.has_value()) { + ESP_LOGCONFIG(TAG, " Direction has datapoint ID %u", *direction_dp_id); } } From e8c88062675d6a0187b0bc859a566c36334afd32 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 3 Mar 2026 13:32:25 -1000 Subject: [PATCH 7/8] expand all sites, part 5 --- esphome/components/tuya/cover/tuya_cover.cpp | 3 ++- esphome/components/tuya/fan/tuya_fan.cpp | 24 +++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/esphome/components/tuya/cover/tuya_cover.cpp b/esphome/components/tuya/cover/tuya_cover.cpp index bb956c612d..125afec048 100644 --- a/esphome/components/tuya/cover/tuya_cover.cpp +++ b/esphome/components/tuya/cover/tuya_cover.cpp @@ -72,7 +72,8 @@ void TuyaCover::control(const cover::CoverCall &call) { this->parent_->force_set_integer_datapoint_value(*this->position_id_, position_int); } } - if (auto pos_opt = call.get_position(); pos_opt.has_value()) { + auto pos_opt = call.get_position(); + if (pos_opt.has_value()) { auto pos = *pos_opt; if (this->control_id_.has_value() && (pos == COVER_OPEN || pos == COVER_CLOSED)) { if (pos == COVER_OPEN) { diff --git a/esphome/components/tuya/fan/tuya_fan.cpp b/esphome/components/tuya/fan/tuya_fan.cpp index ffe092b11b..a387606b77 100644 --- a/esphome/components/tuya/fan/tuya_fan.cpp +++ b/esphome/components/tuya/fan/tuya_fan.cpp @@ -88,13 +88,17 @@ fan::FanTraits TuyaFan::get_traits() { } void TuyaFan::control(const fan::FanCall &call) { - if (auto switch_id = this->switch_id_; switch_id.has_value()) { - if (auto state = call.get_state(); state.has_value()) { + auto switch_id = this->switch_id_; + if (switch_id.has_value()) { + auto state = call.get_state(); + if (state.has_value()) { this->parent_->set_boolean_datapoint_value(*switch_id, *state); } } - if (auto osc_id = this->oscillation_id_; osc_id.has_value()) { - if (auto oscillating = call.get_oscillating(); oscillating.has_value()) { + auto osc_id = this->oscillation_id_; + if (osc_id.has_value()) { + auto oscillating = call.get_oscillating(); + if (oscillating.has_value()) { if (this->oscillation_type_ == TuyaDatapointType::ENUM) { this->parent_->set_enum_datapoint_value(*osc_id, *oscillating); } else if (this->oscillation_type_ == TuyaDatapointType::BOOLEAN) { @@ -102,14 +106,18 @@ void TuyaFan::control(const fan::FanCall &call) { } } } - if (auto dir_id = this->direction_id_; dir_id.has_value()) { - if (auto direction = call.get_direction(); direction.has_value()) { + auto dir_id = this->direction_id_; + if (dir_id.has_value()) { + auto direction = call.get_direction(); + if (direction.has_value()) { bool enable = *direction == fan::FanDirection::REVERSE; this->parent_->set_enum_datapoint_value(*dir_id, enable); } } - if (auto spd_id = this->speed_id_; spd_id.has_value()) { - if (auto speed = call.get_speed(); speed.has_value()) { + auto spd_id = this->speed_id_; + if (spd_id.has_value()) { + auto speed = call.get_speed(); + if (speed.has_value()) { if (this->speed_type_ == TuyaDatapointType::ENUM) { this->parent_->set_enum_datapoint_value(*spd_id, *speed - 1); } else if (this->speed_type_ == TuyaDatapointType::INTEGER) { From 103653c44f665b0a564f62990b8cb3068a2ce32e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 3 Mar 2026 13:32:53 -1000 Subject: [PATCH 8/8] expand all sites, part 6 --- esphome/components/esp32_rmt_led_strip/led_strip.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/esphome/components/esp32_rmt_led_strip/led_strip.cpp b/esphome/components/esp32_rmt_led_strip/led_strip.cpp index f0d0a557d6..66b41931aa 100644 --- a/esphome/components/esp32_rmt_led_strip/led_strip.cpp +++ b/esphome/components/esp32_rmt_led_strip/led_strip.cpp @@ -162,7 +162,8 @@ void ESP32RMTLEDStripLightOutput::set_led_params(uint32_t bit0_high, uint32_t bi void ESP32RMTLEDStripLightOutput::write_state(light::LightState *state) { // protect from refreshing too often uint32_t now = micros(); - if (auto rate = this->max_refresh_rate_.value_or(0); rate != 0 && (now - this->last_refresh_) < rate) { + auto rate = this->max_refresh_rate_.value_or(0); + if (rate != 0 && (now - this->last_refresh_) < rate) { // try again next loop iteration, so that this change won't get lost this->schedule_show(); return;