Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use temperature of current preset when set fritz HVAC mode to HEAT #126044

Merged
merged 5 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion homeassistant/components/fritzbox/climate.py
mib1185 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from .coordinator import FritzboxConfigEntry, FritzboxDataUpdateCoordinator
from .entity import FritzBoxDeviceEntity
from .model import ClimateExtraAttributes
from .sensor import value_scheduled_preset

HVAC_MODES = [HVACMode.HEAT, HVACMode.OFF]
PRESET_HOLIDAY = "holiday"
Expand Down Expand Up @@ -177,7 +178,11 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
if hvac_mode == HVACMode.OFF:
await self.async_set_temperature(temperature=OFF_REPORT_SET_TEMPERATURE)
else:
await self.async_set_temperature(temperature=self.data.comfort_temperature)
if value_scheduled_preset(self.data) == PRESET_ECO:
target_temp = self.data.eco_temperature
else:
target_temp = self.data.comfort_temperature
await self.async_set_temperature(temperature=target_temp)

@property
def preset_mode(self) -> str | None:
Expand Down
31 changes: 26 additions & 5 deletions tests/components/fritzbox/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,24 +313,45 @@ async def test_set_temperature(


@pytest.mark.parametrize(
("service_data", "target_temperature", "expected_call_args"),
("service_data", "target_temperature", "current_preset", "expected_call_args"),
[
({ATTR_HVAC_MODE: HVACMode.OFF}, 22, [call(0)]),
({ATTR_HVAC_MODE: HVACMode.HEAT}, 0.0, [call(22)]),
({ATTR_HVAC_MODE: HVACMode.HEAT}, 18, []),
({ATTR_HVAC_MODE: HVACMode.HEAT}, 22, []),
# mode off always sets target temperature to 0
({ATTR_HVAC_MODE: HVACMode.OFF}, 22, PRESET_COMFORT, [call(0)]),
({ATTR_HVAC_MODE: HVACMode.OFF}, 16, PRESET_ECO, [call(0)]),
({ATTR_HVAC_MODE: HVACMode.OFF}, 16, None, [call(0)]),
# mode heat sets target temperature based on current scheduled preset,
# when not already in mode heat
({ATTR_HVAC_MODE: HVACMode.HEAT}, 0.0, PRESET_COMFORT, [call(22)]),
({ATTR_HVAC_MODE: HVACMode.HEAT}, 0.0, PRESET_ECO, [call(16)]),
({ATTR_HVAC_MODE: HVACMode.HEAT}, 0.0, None, [call(22)]),
# mode heat does not set target temperature, when already in mode heat
({ATTR_HVAC_MODE: HVACMode.HEAT}, 16, PRESET_COMFORT, []),
({ATTR_HVAC_MODE: HVACMode.HEAT}, 16, PRESET_ECO, []),
({ATTR_HVAC_MODE: HVACMode.HEAT}, 16, None, []),
({ATTR_HVAC_MODE: HVACMode.HEAT}, 22, PRESET_COMFORT, []),
({ATTR_HVAC_MODE: HVACMode.HEAT}, 22, PRESET_ECO, []),
({ATTR_HVAC_MODE: HVACMode.HEAT}, 22, None, []),
],
)
async def test_set_hvac_mode(
hass: HomeAssistant,
fritz: Mock,
service_data: dict,
target_temperature: float,
current_preset: str,
expected_call_args: list[_Call],
) -> None:
"""Test setting hvac mode."""
device = FritzDeviceClimateMock()
device.target_temperature = target_temperature

if current_preset is PRESET_COMFORT:
device.nextchange_temperature = device.eco_temperature
elif current_preset is PRESET_ECO:
device.nextchange_temperature = device.comfort_temperature
else:
device.nextchange_endperiod = 0

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