Fix preset handling issue in ViCare (#128167)

* add test case

* fix test case

* fix issue

* change order
This commit is contained in:
Christopher Fenner 2024-10-11 17:15:16 +02:00 committed by Franck Nijhof
parent a8836ca7b6
commit 0ccff9fc54
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
2 changed files with 19 additions and 3 deletions

View File

@ -1,6 +1,7 @@
"""Types for the ViCare integration.""" """Types for the ViCare integration."""
from collections.abc import Callable from collections.abc import Callable
from contextlib import suppress
from dataclasses import dataclass from dataclasses import dataclass
import enum import enum
from typing import Any from typing import Any
@ -48,8 +49,12 @@ class HeatingProgram(enum.StrEnum):
) -> str | None: ) -> str | None:
"""Return the mapped ViCare heating program for the Home Assistant preset.""" """Return the mapped ViCare heating program for the Home Assistant preset."""
for program in supported_heating_programs: for program in supported_heating_programs:
if VICARE_TO_HA_PRESET_HEATING.get(HeatingProgram(program)) == ha_preset: with suppress(ValueError):
return program if (
VICARE_TO_HA_PRESET_HEATING.get(HeatingProgram(program))
== ha_preset
):
return program
return None return None

View File

@ -39,7 +39,7 @@ async def test_ha_preset_to_heating_program(
ha_preset: str | None, ha_preset: str | None,
expected_result: str | None, expected_result: str | None,
) -> None: ) -> None:
"""Testing HA Preset tp ViCare HeatingProgram.""" """Testing HA Preset to ViCare HeatingProgram."""
supported_programs = [ supported_programs = [
HeatingProgram.COMFORT, HeatingProgram.COMFORT,
@ -52,6 +52,17 @@ async def test_ha_preset_to_heating_program(
) )
async def test_ha_preset_to_heating_program_error() -> None:
"""Testing HA Preset to ViCare HeatingProgram."""
supported_programs = [
"test",
]
assert (
HeatingProgram.from_ha_preset(HeatingProgram.NORMAL, supported_programs) is None
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
("vicare_mode", "expected_result"), ("vicare_mode", "expected_result"),
[ [