Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch all programs instead of only the available ones at Home Connect #136949

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions homeassistant/components/home_connect/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
HomeConnectError,
HomeConnectRequestError,
)
from aiohomeconnect.model.program import EnumerateAvailableProgram
from aiohomeconnect.model.program import EnumerateProgram
from propcache.api import cached_property

from homeassistant.config_entries import ConfigEntry
Expand All @@ -48,7 +48,7 @@ class HomeConnectApplianceData:

events: dict[EventKey, Event] = field(default_factory=dict)
info: HomeAppliance
programs: list[EnumerateAvailableProgram] = field(default_factory=list)
programs: list[EnumerateProgram] = field(default_factory=list)
settings: dict[SettingKey, GetSetting]
status: dict[StatusKey, Status]

Expand Down Expand Up @@ -243,9 +243,7 @@ async def _async_update_data(self) -> dict[str, HomeConnectApplianceData]:
):
try:
appliance_data.programs.extend(
(
await self.client.get_available_programs(appliance.ha_id)
).programs
(await self.client.get_all_programs(appliance.ha_id)).programs
)
except HomeConnectError as error:
_LOGGER.debug(
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/home_connect/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from aiohomeconnect.model import EventKey, ProgramKey, SettingKey
from aiohomeconnect.model.error import HomeConnectError
from aiohomeconnect.model.program import EnumerateAvailableProgram
from aiohomeconnect.model.program import EnumerateProgram

from homeassistant.components.automation import automations_with_entity
from homeassistant.components.script import scripts_with_entity
Expand Down Expand Up @@ -184,7 +184,7 @@ def __init__(
self,
coordinator: HomeConnectCoordinator,
appliance: HomeConnectApplianceData,
program: EnumerateAvailableProgram,
program: EnumerateProgram,
) -> None:
"""Initialize the entity."""
desc = " ".join(["Program", program.key.split(".")[-1]])
Expand Down
19 changes: 7 additions & 12 deletions tests/components/home_connect/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

from aiohomeconnect.client import Client as HomeConnectClient
from aiohomeconnect.model import (
ArrayOfAvailablePrograms,
ArrayOfEvents,
ArrayOfHomeAppliances,
ArrayOfPrograms,
ArrayOfSettings,
ArrayOfStatus,
Event,
Expand All @@ -37,9 +37,7 @@
MOCK_APPLIANCES = ArrayOfHomeAppliances.from_dict(
load_json_object_fixture("home_connect/appliances.json")["data"]
)
MOCK_PROGRAMS: dict[str, Any] = load_json_object_fixture(
"home_connect/programs-available.json"
)
MOCK_PROGRAMS: dict[str, Any] = load_json_object_fixture("home_connect/programs.json")
MOCK_SETTINGS: dict[str, Any] = load_json_object_fixture("home_connect/settings.json")
MOCK_STATUS = ArrayOfStatus.from_dict(
load_json_object_fixture("home_connect/status.json")["data"]
Expand Down Expand Up @@ -219,8 +217,8 @@ async def set_key_value_side_effect(ha_id: str, *_, **kwargs) -> None:
return set_key_value_side_effect


async def _get_available_programs_side_effect(ha_id: str) -> ArrayOfAvailablePrograms:
"""Get available programs."""
async def _get_all_programs_side_effect(ha_id: str) -> ArrayOfPrograms:
"""Get all programs."""
appliance_type = next(
appliance
for appliance in MOCK_APPLIANCES.homeappliances
Expand All @@ -229,7 +227,7 @@ async def _get_available_programs_side_effect(ha_id: str) -> ArrayOfAvailablePro
if appliance_type not in MOCK_PROGRAMS:
raise HomeConnectApiError("error.key", "error description")

return ArrayOfAvailablePrograms.from_dict(MOCK_PROGRAMS[appliance_type]["data"])
return ArrayOfPrograms.from_dict(MOCK_PROGRAMS[appliance_type]["data"])


async def _get_settings_side_effect(ha_id: str) -> ArrayOfSettings:
Expand Down Expand Up @@ -290,9 +288,7 @@ async def stream_all_events() -> AsyncGenerator[EventMessage]:
)
mock.get_settings = AsyncMock(side_effect=_get_settings_side_effect)
mock.get_status = AsyncMock(return_value=copy.deepcopy(MOCK_STATUS))
mock.get_available_programs = AsyncMock(
side_effect=_get_available_programs_side_effect
)
mock.get_all_programs = AsyncMock(side_effect=_get_all_programs_side_effect)
mock.put_command = AsyncMock()

mock.side_effect = mock
Expand Down Expand Up @@ -323,15 +319,14 @@ async def stream_all_events() -> AsyncGenerator[EventMessage]:

mock.start_program = AsyncMock(side_effect=exception)
mock.stop_program = AsyncMock(side_effect=exception)
mock.get_available_programs = AsyncMock(side_effect=exception)
mock.set_selected_program = AsyncMock(side_effect=exception)
mock.set_active_program_option = AsyncMock(side_effect=exception)
mock.set_selected_program_option = AsyncMock(side_effect=exception)
mock.set_setting = AsyncMock(side_effect=exception)
mock.get_settings = AsyncMock(side_effect=exception)
mock.get_setting = AsyncMock(side_effect=exception)
mock.get_status = AsyncMock(side_effect=exception)
mock.get_available_programs = AsyncMock(side_effect=exception)
mock.get_all_programs = AsyncMock(side_effect=exception)
mock.put_command = AsyncMock(side_effect=exception)

return mock
Expand Down
30 changes: 14 additions & 16 deletions tests/components/home_connect/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
from unittest.mock import MagicMock

from aiohomeconnect.model import (
ArrayOfAvailablePrograms,
ArrayOfEvents,
ArrayOfPrograms,
Event,
EventKey,
EventMessage,
EventType,
ProgramKey,
)
from aiohomeconnect.model.error import HomeConnectError
from aiohomeconnect.model.program import EnumerateAvailableProgram
from aiohomeconnect.model.program import EnumerateProgram
import pytest

from homeassistant.components.select import (
Expand Down Expand Up @@ -61,14 +61,14 @@ async def test_filter_unknown_programs(
entity_registry: er.EntityRegistry,
) -> None:
"""Test select that only known programs are shown."""
client.get_available_programs.side_effect = None
client.get_available_programs.return_value = ArrayOfAvailablePrograms(
client.get_all_programs.side_effect = None
client.get_all_programs.return_value = ArrayOfPrograms(
[
EnumerateAvailableProgram(
EnumerateProgram(
key=ProgramKey.DISHCARE_DISHWASHER_ECO_50,
raw_key=ProgramKey.DISHCARE_DISHWASHER_ECO_50.value,
),
EnumerateAvailableProgram(
EnumerateProgram(
key=ProgramKey.UNKNOWN,
raw_key="an unknown program",
),
Expand Down Expand Up @@ -202,16 +202,14 @@ async def test_select_exception_handling(
client_with_exception: MagicMock,
) -> None:
"""Test exception handling."""
client_with_exception.get_available_programs.side_effect = None
client_with_exception.get_available_programs.return_value = (
ArrayOfAvailablePrograms(
[
EnumerateAvailableProgram(
key=ProgramKey.DISHCARE_DISHWASHER_ECO_50,
raw_key=ProgramKey.DISHCARE_DISHWASHER_ECO_50.value,
)
]
)
client_with_exception.get_all_programs.side_effect = None
client_with_exception.get_all_programs.return_value = ArrayOfPrograms(
[
EnumerateProgram(
key=ProgramKey.DISHCARE_DISHWASHER_ECO_50,
raw_key=ProgramKey.DISHCARE_DISHWASHER_ECO_50.value,
)
]
)

assert config_entry.state is ConfigEntryState.NOT_LOADED
Expand Down
23 changes: 9 additions & 14 deletions tests/components/home_connect/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
)
from aiohomeconnect.model.error import HomeConnectError
from aiohomeconnect.model.event import ArrayOfEvents, EventType
from aiohomeconnect.model.program import (
ArrayOfAvailablePrograms,
EnumerateAvailableProgram,
)
from aiohomeconnect.model.program import ArrayOfPrograms, EnumerateProgram
from aiohomeconnect.model.setting import SettingConstraints
import pytest

Expand Down Expand Up @@ -250,16 +247,14 @@ async def test_switch_exception_handling(
client_with_exception: MagicMock,
) -> None:
"""Test exception handling."""
client_with_exception.get_available_programs.side_effect = None
client_with_exception.get_available_programs.return_value = (
ArrayOfAvailablePrograms(
[
EnumerateAvailableProgram(
key=ProgramKey.DISHCARE_DISHWASHER_ECO_50,
raw_key=ProgramKey.DISHCARE_DISHWASHER_ECO_50.value,
)
]
)
client_with_exception.get_all_programs.side_effect = None
client_with_exception.get_all_programs.return_value = ArrayOfPrograms(
[
EnumerateProgram(
key=ProgramKey.DISHCARE_DISHWASHER_ECO_50,
raw_key=ProgramKey.DISHCARE_DISHWASHER_ECO_50.value,
)
]
)
client_with_exception.get_settings.side_effect = None
client_with_exception.get_settings.return_value = ArrayOfSettings(
Expand Down