1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-31 15:12:06 +00:00
This commit is contained in:
J. Nick Koston
2025-10-30 10:46:32 -05:00
parent ccfdd0cf06
commit bf1514e672
5 changed files with 10 additions and 36 deletions

View File

@@ -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))

View File

@@ -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<const char *> 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<const char *> custom_presets) {
this->additional_custom_presets_ = custom_presets;
}
ThermostatClimateTargetTempConfig::ThermostatClimateTargetTempConfig() = default;
ThermostatClimateTargetTempConfig::ThermostatClimateTargetTempConfig(float default_temperature)

View File

@@ -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<const char *> 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<climate::ClimatePreset, ThermostatClimateTargetTempConfig> preset_config_{};
/// The set of custom preset configurations this thermostat supports (eg. "My Custom Preset")
std::map<std::string, ThermostatClimateTargetTempConfig> custom_preset_config_{};
/// Custom preset names (from Python codegen)
std::vector<const char *> additional_custom_presets_{};
};
} // namespace thermostat

View File

@@ -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:

View File

@@ -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"