1 """Buttons for the RainMachine integration."""
3 from __future__
import annotations
5 from collections.abc
import Awaitable, Callable
6 from dataclasses
import dataclass
8 from regenmaschine.controller
import Controller
9 from regenmaschine.errors
import RainMachineError
14 ButtonEntityDescription,
22 from .
import RainMachineConfigEntry
23 from .const
import DATA_PROVISION_SETTINGS
24 from .entity
import RainMachineEntity, RainMachineEntityDescription
27 @dataclass(frozen=True, kw_only=True)
29 ButtonEntityDescription, RainMachineEntityDescription
31 """Describe a RainMachine button description."""
33 push_action: Callable[[Controller], Awaitable]
36 BUTTON_KIND_REBOOT =
"reboot"
40 """Reboot the RainMachine."""
41 await controller.machine.reboot()
44 BUTTON_DESCRIPTIONS = (
46 key=BUTTON_KIND_REBOOT,
47 api_category=DATA_PROVISION_SETTINGS,
48 push_action=_async_reboot,
55 entry: RainMachineConfigEntry,
56 async_add_entities: AddEntitiesCallback,
58 """Set up RainMachine buttons based on a config entry."""
59 data = entry.runtime_data
62 for description
in BUTTON_DESCRIPTIONS
67 """Define a RainMachine button."""
69 _attr_device_class = ButtonDeviceClass.RESTART
70 _attr_entity_category = EntityCategory.CONFIG
72 entity_description: RainMachineButtonDescription
75 """Send out a restart command."""
78 except RainMachineError
as err:
80 f
'Error while pressing button "{self.entity_id}": {err}'
None async_dispatcher_send(HomeAssistant hass, str signal, *Any args)