Clamp tado air conditioning target temperature to the mode limits (#192819)

This commit is contained in:
julnav
2026-11-15 22:30:24 +01:00
committed by GitHub
parent fa833f6508
commit 7afac14ea2
5 changed files with 195 additions and 4 deletions
+12 -2
View File
@@ -627,8 +627,18 @@ class TadoClimate(TadoZoneEntity, ClimateEntity):
# This can happen when we switch from Off to On
if self._target_temp is None:
self._target_temp = self._tado_zone_data.current_temp
elif self._current_tado_hvac_mode == CONST_MODE_COOL:
self._target_temp = adjust_temp(self._cool_min_temp, self._cool_max_temp)
if self._target_temp is None:
return
# tado silently ignores an overlay whose temperature is outside the mode limits
capabilities: str | dict[str, Any] = self._current_tado_capabilities.get(
self._current_tado_hvac_mode, {}
)
if isinstance(capabilities, dict) and "temperatures" in capabilities:
celsius = capabilities["temperatures"]["celsius"]
self._target_temp = adjust_temp(
float(celsius["min"]), float(celsius["max"])
)
elif self._current_tado_hvac_mode == CONST_MODE_HEAT:
self._target_temp = adjust_temp(self._heat_min_temp, self._heat_max_temp)
+21 -2
View File
@@ -10,6 +10,7 @@ from pytest_homeassistant.common import (
MockConfigEntry,
async_fire_time_changed,
async_load_fixture,
async_load_json_object_fixture,
load_json_object_fixture,
)
import requests_mock
@@ -62,7 +63,17 @@ def mock_config_entry() -> MockConfigEntry:
@pytest.fixture
async def init_integration(hass: HomeAssistant, freezer: FrozenDateTimeFactory):
def zone_states_overrides() -> dict[str, str]:
"""Return zone state fixtures to use instead of the ones in zone_states.json."""
return {}
@pytest.fixture
async def init_integration(
hass: HomeAssistant,
freezer: FrozenDateTimeFactory,
zone_states_overrides: dict[str, str],
):
"""Set up the tado integration in Home Assistant."""
token_fixture = "token.json"
@@ -108,6 +119,14 @@ async def init_integration(hass: HomeAssistant, freezer: FrozenDateTimeFactory):
# Zone Default Overlay
zone_def_overlay = "zone_default_overlay.json"
zone_states = await async_load_json_object_fixture(
hass, zone_states_fixture, DOMAIN
)
for zone_id, fixture in zone_states_overrides.items():
zone_states["zoneStates"][zone_id] = await async_load_json_object_fixture(
hass, fixture, DOMAIN
)
with (
requests_mock.mock() as m,
patch(
@@ -173,7 +192,7 @@ async def init_integration(hass: HomeAssistant, freezer: FrozenDateTimeFactory):
)
m.get(
"https://my.tado.com/api/v2/homes/1/zoneStates",
text=await async_load_fixture(hass, zone_states_fixture, DOMAIN),
json=zone_states,
)
m.get(
"https://my.tado.com/api/v2/homes/1/zones/6/capabilities",
@@ -0,0 +1,55 @@
{
"tadoMode": "AWAY",
"sensorDataPoints": {
"insideTemperature": {
"fahrenheit": 59.0,
"timestamp": "2020-03-05T01:21:44.089Z",
"celsius": 15.0,
"type": "TEMPERATURE",
"precision": {
"fahrenheit": 0.1,
"celsius": 0.1
}
},
"humidity": {
"timestamp": "2020-03-05T01:21:44.089Z",
"percentage": 48.2,
"type": "PERCENTAGE"
}
},
"link": {
"state": "ONLINE"
},
"openWindow": null,
"geolocationOverride": false,
"geolocationOverrideDisableTime": null,
"overlay": {
"termination": {
"typeSkillBasedApp": "MANUAL",
"projectedExpiry": null,
"type": "MANUAL"
},
"setting": {
"type": "AIR_CONDITIONING",
"power": "OFF"
},
"type": "MANUAL"
},
"activityDataPoints": {
"acPower": {
"timestamp": "2020-02-29T05:34:10.318Z",
"type": "POWER",
"value": "OFF"
}
},
"nextTimeBlock": {
"start": "2020-03-05T04:00:00.000Z"
},
"preparation": null,
"overlayType": "MANUAL",
"nextScheduleChange": null,
"setting": {
"type": "AIR_CONDITIONING",
"power": "OFF"
}
}
@@ -0,0 +1,45 @@
{
"tadoMode": "AWAY",
"sensorDataPoints": {
"humidity": {
"timestamp": "2020-03-05T01:21:44.089Z",
"percentage": 48.2,
"type": "PERCENTAGE"
}
},
"link": {
"state": "ONLINE"
},
"openWindow": null,
"geolocationOverride": false,
"geolocationOverrideDisableTime": null,
"overlay": {
"termination": {
"typeSkillBasedApp": "MANUAL",
"projectedExpiry": null,
"type": "MANUAL"
},
"setting": {
"type": "AIR_CONDITIONING",
"power": "OFF"
},
"type": "MANUAL"
},
"activityDataPoints": {
"acPower": {
"timestamp": "2020-02-29T05:34:10.318Z",
"type": "POWER",
"value": "OFF"
}
},
"nextTimeBlock": {
"start": "2020-03-05T04:00:00.000Z"
},
"preparation": null,
"overlayType": "MANUAL",
"nextScheduleChange": null,
"setting": {
"type": "AIR_CONDITIONING",
"power": "OFF"
}
}
+62
View File
@@ -20,6 +20,11 @@ from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
AIRCON_WITH_SWING = "climate.air_conditioning_with_swing_air_conditioning_with_swing"
AIRCON_WITH_FANLEVEL = (
"climate.air_conditioning_with_fanlevel_air_conditioning_with_fanlevel"
)
@pytest.fixture(autouse=True)
def setup_platforms() -> Generator[None]:
@@ -138,3 +143,60 @@ async def test_aircon_set_hvac_mode(
mock_set_state.assert_called_once()
snapshot.assert_match(mock_set_state.call_args)
@pytest.mark.parametrize(
("zone_states_overrides", "entity_id", "hvac_mode", "expected_temperature"),
[
pytest.param(
{"5": "smartac3.off_cold_room.json"},
AIRCON_WITH_SWING,
HVACMode.COOL,
18.0,
id="cool",
),
pytest.param(
{"5": "smartac3.off_cold_room.json"},
AIRCON_WITH_SWING,
HVACMode.HEAT,
16.0,
id="heat",
),
pytest.param(
{"6": "smartac3.off_cold_room.json"},
AIRCON_WITH_FANLEVEL,
HVACMode.DRY,
16.0,
id="dry",
),
pytest.param(
{"5": "smartac3.off_no_temperature.json"},
AIRCON_WITH_SWING,
HVACMode.COOL,
None,
id="no_room_temperature",
),
],
)
@pytest.mark.usefixtures("init_integration")
async def test_aircon_turn_on_from_off(
hass: HomeAssistant,
entity_id: str,
hvac_mode: HVACMode,
expected_temperature: float | None,
) -> None:
"""Test the room temperature is clamped to the mode limits when turning on."""
assert hass.states.get(entity_id).state == HVACMode.OFF
with patch(
"homeassistant.components.tado.PyTado.interface.api.Tado.set_zone_overlay"
) as mock_set_state:
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_HVAC_MODE,
{ATTR_ENTITY_ID: entity_id, ATTR_HVAC_MODE: hvac_mode},
blocking=True,
)
mock_set_state.assert_called_once()
assert mock_set_state.call_args.args[2] == expected_temperature