mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +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."""
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
@ -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"),
|
||||
[
|
||||
|
Loading…
x
Reference in New Issue
Block a user