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

View File

@ -39,7 +39,7 @@ async def test_ha_preset_to_heating_program(
ha_preset: str | None,
expected_result: str | None,
) -> None:
"""Testing HA Preset tp ViCare HeatingProgram."""
"""Testing HA Preset to ViCare HeatingProgram."""
supported_programs = [
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(
("vicare_mode", "expected_result"),
[