1 """Buttons for Hunter Douglas Powerview advanced features."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
7 from typing
import Any, Final
9 from aiopvapi.helpers.constants
import (
15 from aiopvapi.hub
import Hub
16 from aiopvapi.resources.shade
import BaseShade
21 ButtonEntityDescription,
27 from .coordinator
import PowerviewShadeUpdateCoordinator
28 from .entity
import ShadeEntity
29 from .model
import PowerviewConfigEntry, PowerviewDeviceInfo
32 @dataclass(frozen=True)
34 """Mixin to describe a Button entity."""
36 press_action: Callable[[BaseShade | Hub], Any]
37 create_entity_fn: Callable[[BaseShade | Hub], bool]
40 @dataclass(frozen=True)
42 ButtonEntityDescription, PowerviewButtonDescriptionMixin
44 """Class to describe a Button entity."""
47 BUTTONS_SHADE: Final = [
50 translation_key=
"calibrate",
51 icon=
"mdi:swap-vertical-circle-outline",
52 entity_category=EntityCategory.DIAGNOSTIC,
53 create_entity_fn=
lambda shade: shade.is_supported(MOTION_CALIBRATE),
54 press_action=
lambda shade: shade.calibrate(),
58 device_class=ButtonDeviceClass.IDENTIFY,
59 entity_category=EntityCategory.DIAGNOSTIC,
60 create_entity_fn=
lambda shade: shade.is_supported(MOTION_JOG),
61 press_action=
lambda shade: shade.jog(),
65 translation_key=
"favorite",
67 entity_category=EntityCategory.DIAGNOSTIC,
68 create_entity_fn=
lambda shade: shade.is_supported(MOTION_FAVORITE),
69 press_action=
lambda shade: shade.favorite(),
76 entry: PowerviewConfigEntry,
77 async_add_entities: AddEntitiesCallback,
79 """Set up the hunter douglas advanced feature buttons."""
80 pv_entry = entry.runtime_data
81 entities: list[ButtonEntity] = []
82 for shade
in pv_entry.shade_data.values():
83 room_name = getattr(pv_entry.room_data.get(shade.room_id), ATTR_NAME,
"")
93 for description
in BUTTONS_SHADE
94 if description.create_entity_fn(shade)
100 """Representation of an advanced feature button."""
104 coordinator: PowerviewShadeUpdateCoordinator,
105 device_info: PowerviewDeviceInfo,
109 description: PowerviewButtonDescription,
111 """Initialize the button entity."""
112 super().
__init__(coordinator, device_info, room_name, shade, name)
113 self.entity_description: PowerviewButtonDescription = description
117 """Handle the button press."""
118 async
with self.coordinator.radio_operation_lock: