1 """Platform for button integration."""
3 from __future__
import annotations
5 from collections.abc
import Awaitable, Callable
6 from dataclasses
import dataclass
8 from devolo_plc_api.device
import Device
9 from devolo_plc_api.exceptions.device
import DevicePasswordProtected, DeviceUnavailable
14 ButtonEntityDescription,
21 from .
import DevoloHomeNetworkConfigEntry
22 from .const
import DOMAIN, IDENTIFY, PAIRING, RESTART, START_WPS
23 from .entity
import DevoloEntity
28 @dataclass(frozen=True, kw_only=True)
30 """Describes devolo button entity."""
32 press_func: Callable[[Device], Awaitable[bool]]
35 BUTTON_TYPES: dict[str, DevoloButtonEntityDescription] = {
38 entity_category=EntityCategory.DIAGNOSTIC,
39 device_class=ButtonDeviceClass.IDENTIFY,
40 press_func=
lambda device: device.plcnet.async_identify_device_start(),
44 press_func=
lambda device: device.plcnet.async_pair_device(),
48 device_class=ButtonDeviceClass.RESTART,
49 entity_category=EntityCategory.CONFIG,
50 press_func=
lambda device: device.device.async_restart(),
54 press_func=
lambda device: device.device.async_start_wps(),
61 entry: DevoloHomeNetworkConfigEntry,
62 async_add_entities: AddEntitiesCallback,
64 """Get all devices and buttons and setup them via config entry."""
65 device = entry.runtime_data.device
67 entities: list[DevoloButtonEntity] = []
72 BUTTON_TYPES[IDENTIFY],
78 BUTTON_TYPES[PAIRING],
81 if device.device
and "restart" in device.device.features:
85 BUTTON_TYPES[RESTART],
88 if device.device
and "wifi1" in device.device.features:
92 BUTTON_TYPES[START_WPS],
99 """Representation of a devolo button."""
101 entity_description: DevoloButtonEntityDescription
105 entry: DevoloHomeNetworkConfigEntry,
106 description: DevoloButtonEntityDescription,
108 """Initialize entity."""
113 """Handle the button press."""
116 except DevicePasswordProtected
as ex:
117 self.
entryentry.async_start_reauth(self.
hasshass)
119 translation_domain=DOMAIN,
120 translation_key=
"password_protected",
121 translation_placeholders={
"title": self.
entryentry.title},
123 except DeviceUnavailable
as ex:
125 translation_domain=DOMAIN,
126 translation_key=
"no_response",
127 translation_placeholders={
"title": self.
entryentry.title},