From d74a8ea385a56b904094662f4d9129f65420e859 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 3 Mar 2026 13:30:27 -1000 Subject: [PATCH] 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();