Skip to content

Commit

Permalink
Fix preset handling issue in ViCare (#128167)
Browse files Browse the repository at this point in the history
* add test case

* fix test case

* fix issue

* change order
  • Loading branch information
CFenner authored and frenck committed Oct 11, 2024
1 parent a8836ca commit 0ccff9f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 7 additions & 2 deletions homeassistant/components/vicare/types.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -48,8 +49,12 @@ def from_ha_preset(
) -> 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


Expand Down
13 changes: 12 additions & 1 deletion tests/components/vicare/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"),
[
Expand Down

0 comments on commit 0ccff9f

Please sign in to comment.