mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Fix preset handling issue in ViCare (#128167)
* add test case * fix test case * fix issue * change order
This commit is contained in:
parent
a8836ca7b6
commit
0ccff9fc54
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
@ -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"),
|
||||||
[
|
[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user