1 """Buttons for the Elexa Guardian integration."""
3 from __future__
import annotations
5 from collections.abc
import Awaitable, Callable
6 from dataclasses
import dataclass
8 from aioguardian
import Client
13 ButtonEntityDescription,
21 from .
import GuardianData
22 from .const
import API_SYSTEM_DIAGNOSTICS, DOMAIN
23 from .entity
import ValveControllerEntity, ValveControllerEntityDescription
24 from .util
import convert_exceptions_to_homeassistant_error
27 @dataclass(frozen=True, kw_only=True)
29 ButtonEntityDescription, ValveControllerEntityDescription
31 """Describe a Guardian valve controller button."""
33 push_action: Callable[[Client], Awaitable]
36 BUTTON_KIND_REBOOT =
"reboot"
37 BUTTON_KIND_RESET_VALVE_DIAGNOSTICS =
"reset_valve_diagnostics"
41 """Reboot the Guardian."""
42 await client.system.reboot()
46 """Reset the valve diagnostics on the Guardian."""
47 await client.valve.reset()
50 BUTTON_DESCRIPTIONS = (
52 key=BUTTON_KIND_REBOOT,
53 push_action=_async_reboot,
54 device_class=ButtonDeviceClass.RESTART,
57 api_category=API_SYSTEM_DIAGNOSTICS,
60 key=BUTTON_KIND_RESET_VALVE_DIAGNOSTICS,
61 translation_key=
"reset_diagnostics",
62 push_action=_async_valve_reset,
65 api_category=API_SYSTEM_DIAGNOSTICS,
71 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
73 """Set up Guardian buttons based on a config entry."""
74 data: GuardianData = hass.data[DOMAIN][entry.entry_id]
77 GuardianButton(entry, data, description)
for description
in BUTTON_DESCRIPTIONS
82 """Define a Guardian button."""
84 _attr_device_class = ButtonDeviceClass.RESTART
85 _attr_entity_category = EntityCategory.CONFIG
87 entity_description: ValveControllerButtonDescription
93 description: ValveControllerButtonDescription,
96 super().
__init__(entry, data.valve_controller_coordinators, description)
100 @convert_exceptions_to_homeassistant_error
102 """Send out a restart command."""
None async_dispatcher_send(HomeAssistant hass, str signal, *Any args)