1 """Support for Elgato button."""
3 from __future__
import annotations
5 from collections.abc
import Awaitable, Callable
6 from dataclasses
import dataclass
9 from elgato
import Elgato, ElgatoError
14 ButtonEntityDescription,
21 from .
import ElgatorConfigEntry
22 from .coordinator
import ElgatoDataUpdateCoordinator
23 from .entity
import ElgatoEntity
26 @dataclass(frozen=True, kw_only=True)
28 """Class describing Elgato button entities."""
30 press_fn: Callable[[Elgato], Awaitable[Any]]
36 device_class=ButtonDeviceClass.IDENTIFY,
37 entity_category=EntityCategory.CONFIG,
38 press_fn=
lambda client: client.identify(),
42 device_class=ButtonDeviceClass.RESTART,
43 entity_category=EntityCategory.CONFIG,
44 press_fn=
lambda client: client.restart(),
51 entry: ElgatorConfigEntry,
52 async_add_entities: AddEntitiesCallback,
54 """Set up Elgato button based on a config entry."""
55 coordinator = entry.runtime_data
58 coordinator=coordinator,
59 description=description,
61 for description
in BUTTONS
66 """Defines an Elgato button."""
68 entity_description: ElgatoButtonEntityDescription
72 coordinator: ElgatoDataUpdateCoordinator,
73 description: ElgatoButtonEntityDescription,
75 """Initialize the button entity."""
76 super().
__init__(coordinator=coordinator)
79 f
"{coordinator.data.info.serial_number}_{description.key}"
83 """Trigger button press on the Elgato device."""
86 except ElgatoError
as error:
88 "An error occurred while communicating with the Elgato Light"