mirror of
https://github.com/esphome/esphome.git
synced 2025-11-01 15:41:52 +00:00
preen
This commit is contained in:
@@ -1008,12 +1008,3 @@ async def to_code(config):
|
|||||||
await automation.build_automation(
|
await automation.build_automation(
|
||||||
var.get_preset_change_trigger(), [], config[CONF_PRESET_CHANGE]
|
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))
|
|
||||||
|
|||||||
@@ -322,9 +322,14 @@ climate::ClimateTraits ThermostatClimate::traits() {
|
|||||||
traits.add_supported_preset(it.first);
|
traits.add_supported_preset(it.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Custom presets are set directly from Python (includes all non-standard preset names from map)
|
// Extract custom preset names from the custom_preset_config_ map
|
||||||
if (!this->additional_custom_presets_.empty()) {
|
if (!this->custom_preset_config_.empty()) {
|
||||||
traits.set_supported_custom_presets(this->additional_custom_presets_);
|
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;
|
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() = default;
|
||||||
|
|
||||||
ThermostatClimateTargetTempConfig::ThermostatClimateTargetTempConfig(float default_temperature)
|
ThermostatClimateTargetTempConfig::ThermostatClimateTargetTempConfig(float default_temperature)
|
||||||
|
|||||||
@@ -133,7 +133,6 @@ class ThermostatClimate : public climate::Climate, public Component {
|
|||||||
|
|
||||||
void set_preset_config(climate::ClimatePreset preset, const ThermostatClimateTargetTempConfig &config);
|
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_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_cool_action_trigger() const;
|
||||||
Trigger<> *get_supplemental_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_{};
|
std::map<climate::ClimatePreset, ThermostatClimateTargetTempConfig> preset_config_{};
|
||||||
/// The set of custom preset configurations this thermostat supports (eg. "My Custom Preset")
|
/// The set of custom preset configurations this thermostat supports (eg. "My Custom Preset")
|
||||||
std::map<std::string, ThermostatClimateTargetTempConfig> custom_preset_config_{};
|
std::map<std::string, ThermostatClimateTargetTempConfig> custom_preset_config_{};
|
||||||
/// Custom preset names (from Python codegen)
|
|
||||||
std::vector<const char *> additional_custom_presets_{};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace thermostat
|
} // namespace thermostat
|
||||||
|
|||||||
@@ -27,10 +27,6 @@ climate:
|
|||||||
- name: Vacation Mode
|
- name: Vacation Mode
|
||||||
default_target_temperature_low: 15°C
|
default_target_temperature_low: 15°C
|
||||||
default_target_temperature_high: 18°C
|
default_target_temperature_high: 18°C
|
||||||
custom_fan_modes:
|
|
||||||
- "Turbo"
|
|
||||||
- "Silent"
|
|
||||||
- "Sleep Mode"
|
|
||||||
idle_action:
|
idle_action:
|
||||||
- logger.log: idle_action
|
- logger.log: idle_action
|
||||||
cool_action:
|
cool_action:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
"""Integration test for climate custom fan modes and presets."""
|
"""Integration test for climate custom presets."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ async def test_climate_custom_fan_modes_and_presets(
|
|||||||
run_compiled: RunCompiledFunction,
|
run_compiled: RunCompiledFunction,
|
||||||
api_client_connected: APIClientConnectedFactory,
|
api_client_connected: APIClientConnectedFactory,
|
||||||
) -> None:
|
) -> 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:
|
async with run_compiled(yaml_config), api_client_connected() as client:
|
||||||
# Get entities and services
|
# Get entities and services
|
||||||
entities, services = await client.list_entities_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]
|
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)
|
# Verify enum presets are exposed (from preset: config map)
|
||||||
assert ClimatePreset.AWAY in test_climate.supported_presets, (
|
assert ClimatePreset.AWAY in test_climate.supported_presets, (
|
||||||
"Expected AWAY in enum presets"
|
"Expected AWAY in enum presets"
|
||||||
|
|||||||
Reference in New Issue
Block a user