mirror of
https://github.com/esphome/esphome.git
synced 2026-10-14 10:12:52 +00:00
[thermostat] Keep presets in shared flash tables (#20080)
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
---
|
||||
esphome:
|
||||
name: test
|
||||
|
||||
logger:
|
||||
|
||||
esp32:
|
||||
board: esp32dev
|
||||
|
||||
sensor:
|
||||
- platform: template
|
||||
id: temp_sensor
|
||||
lambda: return 21.0;
|
||||
|
||||
climate:
|
||||
- platform: thermostat
|
||||
id: thermo_a
|
||||
name: Thermo A
|
||||
sensor: temp_sensor
|
||||
min_heating_off_time: 300s
|
||||
min_heating_run_time: 300s
|
||||
min_idle_time: 30s
|
||||
heat_action:
|
||||
- logger.log: heat
|
||||
idle_action:
|
||||
- logger.log: idle
|
||||
preset:
|
||||
- name: Away
|
||||
default_target_temperature_low: 15°C
|
||||
mode: HEAT
|
||||
- name: Eco
|
||||
default_target_temperature_low: 17°C
|
||||
- name: Night Mode
|
||||
default_target_temperature_low: 16°C
|
||||
- platform: thermostat
|
||||
id: thermo_b
|
||||
name: Thermo B
|
||||
sensor: temp_sensor
|
||||
min_heating_off_time: 300s
|
||||
min_heating_run_time: 300s
|
||||
min_idle_time: 30s
|
||||
heat_action:
|
||||
- logger.log: heat
|
||||
idle_action:
|
||||
- logger.log: idle
|
||||
preset:
|
||||
- name: Away
|
||||
default_target_temperature_low: 15°C
|
||||
mode: HEAT
|
||||
- name: Eco
|
||||
default_target_temperature_low: 17°C
|
||||
- name: Night Mode
|
||||
default_target_temperature_low: 16°C
|
||||
@@ -0,0 +1,28 @@
|
||||
"""Tests for the thermostat preset codegen."""
|
||||
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
|
||||
def test_presets_shared_progmem_tables(
|
||||
generate_main: Callable[[str | Path], str],
|
||||
component_config_path: Callable[[str], Path],
|
||||
) -> None:
|
||||
"""Thermostats with the same presets share one PROGMEM table per kind."""
|
||||
main_cpp = generate_main(component_config_path("presets.yaml"))
|
||||
|
||||
standard = re.findall(
|
||||
r"static constexpr thermostat::ThermostatPresetEntry (\w+)\[\] PROGMEM",
|
||||
main_cpp,
|
||||
)
|
||||
custom = re.findall(
|
||||
r"static constexpr thermostat::ThermostatCustomPresetEntry (\w+)\[\] PROGMEM",
|
||||
main_cpp,
|
||||
)
|
||||
assert len(standard) == 1
|
||||
assert len(custom) == 1
|
||||
for var in ("thermo_a", "thermo_b"):
|
||||
assert f"{var}->set_preset_config({standard[0]}, 2);" in main_cpp
|
||||
assert f"{var}->set_custom_preset_config({custom[0]}, 1);" in main_cpp
|
||||
assert "climate::CLIMATE_MODE_HEAT" in main_cpp
|
||||
Reference in New Issue
Block a user