mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 17:49:37 +01:00
Keep options values when chaging or starting program on Home Connect (#168575)
This commit is contained in:
committed by
GitHub
parent
e4e4785225
commit
6552cf8f7a
@@ -637,16 +637,19 @@ class HomeConnectApplianceCoordinator(DataUpdateCoordinator[HomeConnectAppliance
|
||||
options.update(await self.get_options_definitions(resolved_program_key))
|
||||
|
||||
for option in options.values():
|
||||
option_value = option.constraints.default if option.constraints else None
|
||||
if option_value is not None:
|
||||
option_event_key = EventKey(option.key)
|
||||
option_event_key = EventKey(option.key)
|
||||
if (
|
||||
option_event_key not in events
|
||||
and option.constraints
|
||||
and (option_default_value := option.constraints.default) is not None
|
||||
):
|
||||
events[option_event_key] = Event(
|
||||
option_event_key,
|
||||
option.key.value,
|
||||
0,
|
||||
"",
|
||||
"",
|
||||
option_value,
|
||||
option_default_value,
|
||||
option.name,
|
||||
unit=option.unit,
|
||||
)
|
||||
|
||||
@@ -28,7 +28,15 @@ from aiohomeconnect.model.error import (
|
||||
TooManyRequestsError,
|
||||
UnauthorizedError,
|
||||
)
|
||||
from aiohomeconnect.model.program import Option, OptionKey, Program, ProgramKey
|
||||
from aiohomeconnect.model.program import (
|
||||
Option,
|
||||
OptionKey,
|
||||
Program,
|
||||
ProgramDefinition,
|
||||
ProgramDefinitionConstraints,
|
||||
ProgramDefinitionOption,
|
||||
ProgramKey,
|
||||
)
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
|
||||
@@ -986,3 +994,99 @@ async def test_fetch_base_program_options_when_favorite_program_event(
|
||||
client.get_available_program.assert_awaited_once_with(
|
||||
appliance.ha_id, program_key=ProgramKey.DISHCARE_DISHWASHER_ECO_50
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("appliance", ["Dishwasher"], indirect=True)
|
||||
@pytest.mark.parametrize(
|
||||
"event_key",
|
||||
[
|
||||
EventKey.BSH_COMMON_ROOT_ACTIVE_PROGRAM,
|
||||
EventKey.BSH_COMMON_ROOT_SELECTED_PROGRAM,
|
||||
],
|
||||
)
|
||||
async def test_option_values_kept_after_changing_program(
|
||||
hass: HomeAssistant,
|
||||
client: MagicMock,
|
||||
config_entry: MockConfigEntry,
|
||||
integration_setup: Callable[[MagicMock], Awaitable[bool]],
|
||||
appliance: HomeAppliance,
|
||||
event_key: EventKey,
|
||||
) -> None:
|
||||
"""Test that when a program is changed, the options are kept and defaults are not used."""
|
||||
appliance_ha_id = appliance.ha_id
|
||||
entity_id = "switch.dishwasher_half_load"
|
||||
client.get_available_program = AsyncMock(
|
||||
return_value=ProgramDefinition(
|
||||
ProgramKey.DISHCARE_DISHWASHER_AUTO_1,
|
||||
options=[
|
||||
ProgramDefinitionOption(
|
||||
OptionKey.DISHCARE_DISHWASHER_HALF_LOAD,
|
||||
"Boolean",
|
||||
constraints=ProgramDefinitionConstraints(default=False),
|
||||
)
|
||||
],
|
||||
)
|
||||
)
|
||||
assert await integration_setup(client)
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
assert not hass.states.is_state(entity_id, "on")
|
||||
await client.add_events(
|
||||
[
|
||||
EventMessage(
|
||||
appliance_ha_id,
|
||||
EventType.NOTIFY,
|
||||
data=ArrayOfEvents(
|
||||
[
|
||||
Event(
|
||||
key=EventKey.DISHCARE_DISHWASHER_OPTION_HALF_LOAD,
|
||||
raw_key=EventKey.DISHCARE_DISHWASHER_OPTION_HALF_LOAD.value,
|
||||
timestamp=0,
|
||||
level="",
|
||||
handling="",
|
||||
value=True,
|
||||
),
|
||||
]
|
||||
),
|
||||
)
|
||||
]
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.is_state(entity_id, "on")
|
||||
|
||||
client.get_available_program = AsyncMock(
|
||||
return_value=ProgramDefinition(
|
||||
ProgramKey.DISHCARE_DISHWASHER_ECO_50,
|
||||
options=[
|
||||
ProgramDefinitionOption(
|
||||
OptionKey.DISHCARE_DISHWASHER_HALF_LOAD,
|
||||
"Boolean",
|
||||
constraints=ProgramDefinitionConstraints(default=False),
|
||||
)
|
||||
],
|
||||
)
|
||||
)
|
||||
await client.add_events(
|
||||
[
|
||||
EventMessage(
|
||||
appliance_ha_id,
|
||||
EventType.NOTIFY,
|
||||
data=ArrayOfEvents(
|
||||
[
|
||||
Event(
|
||||
key=event_key,
|
||||
raw_key=event_key.value,
|
||||
timestamp=0,
|
||||
level="",
|
||||
handling="",
|
||||
value=ProgramKey.DISHCARE_DISHWASHER_ECO_50.value,
|
||||
),
|
||||
]
|
||||
),
|
||||
)
|
||||
]
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.is_state(entity_id, "on")
|
||||
|
||||
Reference in New Issue
Block a user