Skip to content

Commit

Permalink
Use temperature of current preset when set fritz HVAC mode to HEAT
Browse files Browse the repository at this point in the history
If the HVAC mode of the Fritzbox thermostats changes from `HVACMode.OFF`
to `HVAMode.HEAT`, the current preset (COMFORT / ECO) should be
observed. Depending on the status of the current preset, the set
temperature of comfort / eco is set as the new temperature.
  • Loading branch information
naruxde committed Sep 16, 2024
1 parent 4fbc5a9 commit 5df75de
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions homeassistant/components/fritzbox/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
)
from .coordinator import FritzboxConfigEntry, FritzboxDataUpdateCoordinator
from .model import ClimateExtraAttributes
from .sensor import value_scheduled_preset

HVAC_MODES = [HVACMode.HEAT, HVACMode.OFF]
PRESET_HOLIDAY = "holiday"
Expand Down Expand Up @@ -174,6 +175,8 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
return
if hvac_mode == HVACMode.OFF:
await self.async_set_temperature(temperature=OFF_REPORT_SET_TEMPERATURE)
elif value_scheduled_preset(self.data) is PRESET_ECO:
await self.async_set_temperature(temperature=self.data.eco_temperature)
else:
await self.async_set_temperature(temperature=self.data.comfort_temperature)

Expand Down
21 changes: 21 additions & 0 deletions tests/components/fritzbox/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,27 @@ async def test_set_hvac_mode_heat(hass: HomeAssistant, fritz: Mock) -> None:
assert device.set_target_temperature.call_args_list == [call(22)]

Check failure on line 376 in tests/components/fritzbox/test_climate.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.12 (fritzbox)

test_set_hvac_mode_heat assert [call(16.0)] == [call(22)] At index 0 diff: call(16.0) != call(22) Full diff: + [call(16.0)] - [ - call(22), - ]


async def test_set_hvac_mode_heat_eco(hass: HomeAssistant, fritz: Mock) -> None:
"""Test setting hvac mode with current scheduled eco preset."""
device = FritzDeviceClimateMock()
device.target_temperature = 0.0

# Prepare scheduled_preset to PRESET_ECO
device.nextchange_temperature = device.comfort_temperature

assert await setup_config_entry(
hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz
)

await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_HVAC_MODE,
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_HVAC_MODE: HVACMode.HEAT},
True,
)
assert device.set_target_temperature.call_args_list == [call(16)]


async def test_set_preset_mode_comfort(hass: HomeAssistant, fritz: Mock) -> None:
"""Test setting preset mode."""
device = FritzDeviceClimateMock()
Expand Down

0 comments on commit 5df75de

Please sign in to comment.