mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Implement @plugwise_command for Plugwise Select platform (#120509)
This commit is contained in:
parent
0c0f666a28
commit
41026b9227
@ -17,6 +17,7 @@ FLOW_SMILE: Final = "smile (Adam/Anna/P1)"
|
|||||||
FLOW_STRETCH: Final = "stretch (Stretch)"
|
FLOW_STRETCH: Final = "stretch (Stretch)"
|
||||||
FLOW_TYPE: Final = "flow_type"
|
FLOW_TYPE: Final = "flow_type"
|
||||||
GATEWAY: Final = "gateway"
|
GATEWAY: Final = "gateway"
|
||||||
|
LOCATION: Final = "location"
|
||||||
PW_TYPE: Final = "plugwise_type"
|
PW_TYPE: Final = "plugwise_type"
|
||||||
SMILE: Final = "smile"
|
SMILE: Final = "smile"
|
||||||
STRETCH: Final = "stretch"
|
STRETCH: Final = "stretch"
|
||||||
|
@ -2,27 +2,24 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Awaitable, Callable
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from plugwise import Smile
|
|
||||||
|
|
||||||
from homeassistant.components.select import SelectEntity, SelectEntityDescription
|
from homeassistant.components.select import SelectEntity, SelectEntityDescription
|
||||||
from homeassistant.const import STATE_ON, EntityCategory
|
from homeassistant.const import STATE_ON, EntityCategory
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import PlugwiseConfigEntry
|
from . import PlugwiseConfigEntry
|
||||||
from .const import SelectOptionsType, SelectType
|
from .const import LOCATION, SelectOptionsType, SelectType
|
||||||
from .coordinator import PlugwiseDataUpdateCoordinator
|
from .coordinator import PlugwiseDataUpdateCoordinator
|
||||||
from .entity import PlugwiseEntity
|
from .entity import PlugwiseEntity
|
||||||
|
from .util import plugwise_command
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, kw_only=True)
|
@dataclass(frozen=True, kw_only=True)
|
||||||
class PlugwiseSelectEntityDescription(SelectEntityDescription):
|
class PlugwiseSelectEntityDescription(SelectEntityDescription):
|
||||||
"""Class describing Plugwise Select entities."""
|
"""Class describing Plugwise Select entities."""
|
||||||
|
|
||||||
command: Callable[[Smile, str, str], Awaitable[None]]
|
|
||||||
key: SelectType
|
key: SelectType
|
||||||
options_key: SelectOptionsType
|
options_key: SelectOptionsType
|
||||||
|
|
||||||
@ -31,28 +28,24 @@ SELECT_TYPES = (
|
|||||||
PlugwiseSelectEntityDescription(
|
PlugwiseSelectEntityDescription(
|
||||||
key="select_schedule",
|
key="select_schedule",
|
||||||
translation_key="select_schedule",
|
translation_key="select_schedule",
|
||||||
command=lambda api, loc, opt: api.set_schedule_state(loc, STATE_ON, opt),
|
|
||||||
options_key="available_schedules",
|
options_key="available_schedules",
|
||||||
),
|
),
|
||||||
PlugwiseSelectEntityDescription(
|
PlugwiseSelectEntityDescription(
|
||||||
key="select_regulation_mode",
|
key="select_regulation_mode",
|
||||||
translation_key="regulation_mode",
|
translation_key="regulation_mode",
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
command=lambda api, loc, opt: api.set_regulation_mode(opt),
|
|
||||||
options_key="regulation_modes",
|
options_key="regulation_modes",
|
||||||
),
|
),
|
||||||
PlugwiseSelectEntityDescription(
|
PlugwiseSelectEntityDescription(
|
||||||
key="select_dhw_mode",
|
key="select_dhw_mode",
|
||||||
translation_key="dhw_mode",
|
translation_key="dhw_mode",
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
command=lambda api, loc, opt: api.set_dhw_mode(opt),
|
|
||||||
options_key="dhw_modes",
|
options_key="dhw_modes",
|
||||||
),
|
),
|
||||||
PlugwiseSelectEntityDescription(
|
PlugwiseSelectEntityDescription(
|
||||||
key="select_gateway_mode",
|
key="select_gateway_mode",
|
||||||
translation_key="gateway_mode",
|
translation_key="gateway_mode",
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
command=lambda api, loc, opt: api.set_gateway_mode(opt),
|
|
||||||
options_key="gateway_modes",
|
options_key="gateway_modes",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -109,10 +102,12 @@ class PlugwiseSelectEntity(PlugwiseEntity, SelectEntity):
|
|||||||
"""Return the available select-options."""
|
"""Return the available select-options."""
|
||||||
return self.device[self.entity_description.options_key]
|
return self.device[self.entity_description.options_key]
|
||||||
|
|
||||||
|
@plugwise_command
|
||||||
async def async_select_option(self, option: str) -> None:
|
async def async_select_option(self, option: str) -> None:
|
||||||
"""Change to the selected entity option."""
|
"""Change to the selected entity option.
|
||||||
await self.entity_description.command(
|
|
||||||
self.coordinator.api, self.device["location"], option
|
|
||||||
)
|
|
||||||
|
|
||||||
await self.coordinator.async_request_refresh()
|
self.device[LOCATION] and STATE_ON are required for the thermostat-schedule select.
|
||||||
|
"""
|
||||||
|
await self.coordinator.api.set_select(
|
||||||
|
self.entity_description.key, self.device[LOCATION], STATE_ON, option
|
||||||
|
)
|
||||||
|
@ -38,8 +38,9 @@ async def test_adam_change_select_entity(
|
|||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert mock_smile_adam.set_schedule_state.call_count == 1
|
assert mock_smile_adam.set_select.call_count == 1
|
||||||
mock_smile_adam.set_schedule_state.assert_called_with(
|
mock_smile_adam.set_select.assert_called_with(
|
||||||
|
"select_schedule",
|
||||||
"c50f167537524366a5af7aa3942feb1e",
|
"c50f167537524366a5af7aa3942feb1e",
|
||||||
"on",
|
"on",
|
||||||
"Badkamer Schema",
|
"Badkamer Schema",
|
||||||
@ -69,5 +70,10 @@ async def test_adam_select_regulation_mode(
|
|||||||
},
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert mock_smile_adam_3.set_regulation_mode.call_count == 1
|
assert mock_smile_adam_3.set_select.call_count == 1
|
||||||
mock_smile_adam_3.set_regulation_mode.assert_called_with("heating")
|
mock_smile_adam_3.set_select.assert_called_with(
|
||||||
|
"select_regulation_mode",
|
||||||
|
"bc93488efab249e5bc54fd7e175a6f91",
|
||||||
|
"on",
|
||||||
|
"heating",
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user