1 """OpenGarage button."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
7 from typing
import Any, cast
9 from opengarage
import OpenGarage
14 ButtonEntityDescription,
21 from .const
import DOMAIN
22 from .coordinator
import OpenGarageDataUpdateCoordinator
23 from .entity
import OpenGarageEntity
26 @dataclass(frozen=True, kw_only=True)
28 """OpenGarage Browser button description."""
30 press_action: Callable[[OpenGarage], Any]
33 BUTTONS: tuple[OpenGarageButtonEntityDescription, ...] = (
36 device_class=ButtonDeviceClass.RESTART,
37 entity_category=EntityCategory.CONFIG,
38 press_action=
lambda opengarage: opengarage.reboot(),
45 config_entry: ConfigEntry,
46 async_add_entities: AddEntitiesCallback,
48 """Set up the OpenGarage button entities."""
49 coordinator: OpenGarageDataUpdateCoordinator = hass.data[DOMAIN][
55 coordinator, cast(str, config_entry.unique_id), description
57 for description
in BUTTONS
62 """Representation of an OpenGarage button."""
64 entity_description: OpenGarageButtonEntityDescription
68 coordinator: OpenGarageDataUpdateCoordinator,
70 description: OpenGarageButtonEntityDescription,
72 """Initialize the button."""
73 super().
__init__(coordinator, device_id, description)
76 """Press the button."""
78 self.coordinator.open_garage_connection