1 """Support for hunterdouglass_powerview settings."""
3 from __future__
import annotations
5 from collections.abc
import Callable, Coroutine
6 from dataclasses
import dataclass
7 from typing
import Any, Final
9 from aiopvapi.helpers.constants
import ATTR_NAME, FUNCTION_SET_POWER
10 from aiopvapi.resources.shade
import BaseShade
17 from .coordinator
import PowerviewShadeUpdateCoordinator
18 from .entity
import ShadeEntity
19 from .model
import PowerviewConfigEntry, PowerviewDeviceInfo
22 @dataclass(frozen=True)
24 """Mixin to describe a select entity."""
26 current_fn: Callable[[BaseShade], Any]
27 select_fn: Callable[[BaseShade, str], Coroutine[Any, Any, bool]]
28 create_entity_fn: Callable[[BaseShade], bool]
29 options_fn: Callable[[BaseShade], list[str]]
32 @dataclass(frozen=True)
34 SelectEntityDescription, PowerviewSelectDescriptionMixin
36 """A class that describes select entities."""
38 entity_category: EntityCategory = EntityCategory.CONFIG
44 translation_key=
"power_source",
45 icon=
"mdi:power-plug-outline",
46 current_fn=
lambda shade: shade.get_power_source(),
47 options_fn=
lambda shade: shade.supported_power_sources(),
48 select_fn=
lambda shade, option: shade.set_power_source(option),
49 create_entity_fn=
lambda shade: shade.is_supported(FUNCTION_SET_POWER),
56 entry: PowerviewConfigEntry,
57 async_add_entities: AddEntitiesCallback,
59 """Set up the hunter douglas select entities."""
60 pv_entry = entry.runtime_data
61 entities: list[PowerViewSelect] = []
62 for shade
in pv_entry.shade_data.values():
63 if not shade.has_battery_info():
65 room_name = getattr(pv_entry.room_data.get(shade.room_id), ATTR_NAME,
"")
75 for description
in DROPDOWNS
76 if description.create_entity_fn(shade)
82 """Representation of a select entity."""
86 coordinator: PowerviewShadeUpdateCoordinator,
87 device_info: PowerviewDeviceInfo,
91 description: PowerviewSelectDescription,
93 """Initialize the select entity."""
94 super().
__init__(coordinator, device_info, room_name, shade, name)
95 self.entity_description: PowerviewSelectDescription = description
100 """Return the selected entity option to represent the entity state."""
101 return self.entity_description.current_fn(self.
_shade_shade)
105 """Return a set of selectable options."""
106 return self.entity_description.options_fn(self.
_shade_shade)
109 """Change the selected option."""
110 await self.entity_description.select_fn(self.
_shade_shade, option)
112 async
with self.coordinator.radio_operation_lock:
113 await self.
_shade_shade.refresh(suppress_timeout=
True)
None __init__(self, PowerviewShadeUpdateCoordinator coordinator, PowerviewDeviceInfo device_info, str room_name, BaseShade shade, str name, PowerviewSelectDescription description)
str|None current_option(self)
None async_select_option(self, str option)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, PowerviewConfigEntry entry, AddEntitiesCallback async_add_entities)