From bf1514e6722b774f353716cdbaaeae34596fc632 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 30 Oct 2025 10:46:32 -0500 Subject: [PATCH] preen --- esphome/components/thermostat/climate.py | 9 --------- .../components/thermostat/thermostat_climate.cpp | 15 ++++++++------- .../components/thermostat/thermostat_climate.h | 3 --- .../climate_custom_fan_modes_and_presets.yaml | 4 ---- tests/integration/test_climate_custom_modes.py | 15 ++------------- 5 files changed, 10 insertions(+), 36 deletions(-) diff --git a/esphome/components/thermostat/climate.py b/esphome/components/thermostat/climate.py index a883c47582..a928d208f3 100644 --- a/esphome/components/thermostat/climate.py +++ b/esphome/components/thermostat/climate.py @@ -1008,12 +1008,3 @@ async def to_code(config): await automation.build_automation( var.get_preset_change_trigger(), [], config[CONF_PRESET_CHANGE] ) - - # Collect custom preset names from preset map (non-standard preset names only) - custom_preset_names = [ - preset_config[CONF_NAME] - for preset_config in config.get(CONF_PRESET, []) - if preset_config[CONF_NAME].upper() not in climate.CLIMATE_PRESETS - ] - if custom_preset_names: - cg.add(var.set_custom_presets(custom_preset_names)) diff --git a/esphome/components/thermostat/thermostat_climate.cpp b/esphome/components/thermostat/thermostat_climate.cpp index 752204004a..6842bd4be8 100644 --- a/esphome/components/thermostat/thermostat_climate.cpp +++ b/esphome/components/thermostat/thermostat_climate.cpp @@ -322,9 +322,14 @@ climate::ClimateTraits ThermostatClimate::traits() { traits.add_supported_preset(it.first); } - // Custom presets are set directly from Python (includes all non-standard preset names from map) - if (!this->additional_custom_presets_.empty()) { - traits.set_supported_custom_presets(this->additional_custom_presets_); + // Extract custom preset names from the custom_preset_config_ map + if (!this->custom_preset_config_.empty()) { + std::vector custom_preset_names; + custom_preset_names.reserve(this->custom_preset_config_.size()); + for (const auto &it : this->custom_preset_config_) { + custom_preset_names.push_back(it.first.c_str()); + } + traits.set_supported_custom_presets(custom_preset_names); } return traits; @@ -1616,10 +1621,6 @@ void ThermostatClimate::dump_config() { } } -void ThermostatClimate::set_custom_presets(std::initializer_list custom_presets) { - this->additional_custom_presets_ = custom_presets; -} - ThermostatClimateTargetTempConfig::ThermostatClimateTargetTempConfig() = default; ThermostatClimateTargetTempConfig::ThermostatClimateTargetTempConfig(float default_temperature) diff --git a/esphome/components/thermostat/thermostat_climate.h b/esphome/components/thermostat/thermostat_climate.h index d4ee178f4b..42adab7751 100644 --- a/esphome/components/thermostat/thermostat_climate.h +++ b/esphome/components/thermostat/thermostat_climate.h @@ -133,7 +133,6 @@ class ThermostatClimate : public climate::Climate, public Component { void set_preset_config(climate::ClimatePreset preset, const ThermostatClimateTargetTempConfig &config); void set_custom_preset_config(const std::string &name, const ThermostatClimateTargetTempConfig &config); - void set_custom_presets(std::initializer_list custom_presets); Trigger<> *get_cool_action_trigger() const; Trigger<> *get_supplemental_cool_action_trigger() const; @@ -538,8 +537,6 @@ class ThermostatClimate : public climate::Climate, public Component { std::map preset_config_{}; /// The set of custom preset configurations this thermostat supports (eg. "My Custom Preset") std::map custom_preset_config_{}; - /// Custom preset names (from Python codegen) - std::vector additional_custom_presets_{}; }; } // namespace thermostat diff --git a/tests/integration/fixtures/climate_custom_fan_modes_and_presets.yaml b/tests/integration/fixtures/climate_custom_fan_modes_and_presets.yaml index f006bb4352..bf4ef9eafd 100644 --- a/tests/integration/fixtures/climate_custom_fan_modes_and_presets.yaml +++ b/tests/integration/fixtures/climate_custom_fan_modes_and_presets.yaml @@ -27,10 +27,6 @@ climate: - name: Vacation Mode default_target_temperature_low: 15°C default_target_temperature_high: 18°C - custom_fan_modes: - - "Turbo" - - "Silent" - - "Sleep Mode" idle_action: - logger.log: idle_action cool_action: diff --git a/tests/integration/test_climate_custom_modes.py b/tests/integration/test_climate_custom_modes.py index 4e0e8522ca..ce34959d88 100644 --- a/tests/integration/test_climate_custom_modes.py +++ b/tests/integration/test_climate_custom_modes.py @@ -1,4 +1,4 @@ -"""Integration test for climate custom fan modes and presets.""" +"""Integration test for climate custom presets.""" from __future__ import annotations @@ -14,7 +14,7 @@ async def test_climate_custom_fan_modes_and_presets( run_compiled: RunCompiledFunction, api_client_connected: APIClientConnectedFactory, ) -> None: - """Test that custom fan modes and presets are properly exposed via API.""" + """Test that custom presets are properly exposed via API.""" async with run_compiled(yaml_config), api_client_connected() as client: # Get entities and services entities, services = await client.list_entities_services() @@ -23,17 +23,6 @@ async def test_climate_custom_fan_modes_and_presets( test_climate = climate_infos[0] - # Verify custom fan modes are exposed - custom_fan_modes = test_climate.supported_custom_fan_modes - assert len(custom_fan_modes) == 3, ( - f"Expected 3 custom fan modes, got {len(custom_fan_modes)}" - ) - assert "Turbo" in custom_fan_modes, "Expected 'Turbo' in custom fan modes" - assert "Silent" in custom_fan_modes, "Expected 'Silent' in custom fan modes" - assert "Sleep Mode" in custom_fan_modes, ( - "Expected 'Sleep Mode' in custom fan modes" - ) - # Verify enum presets are exposed (from preset: config map) assert ClimatePreset.AWAY in test_climate.supported_presets, ( "Expected AWAY in enum presets"