1 """Creates button entities for the Husqvarna Automower integration."""
3 from collections.abc
import Awaitable, Callable
4 from dataclasses
import dataclass
8 from aioautomower.model
import MowerAttributes
9 from aioautomower.session
import AutomowerSession
15 from .
import AutomowerConfigEntry
16 from .coordinator
import AutomowerDataUpdateCoordinator
18 AutomowerAvailableEntity,
20 handle_sending_exception,
23 _LOGGER = logging.getLogger(__name__)
28 @dataclass(frozen=True, kw_only=True)
30 """Describes Automower button entities."""
32 available_fn: Callable[[MowerAttributes], bool] =
lambda _:
True
33 exists_fn: Callable[[MowerAttributes], bool] =
lambda _:
True
34 press_fn: Callable[[AutomowerSession, str], Awaitable[Any]]
37 MOWER_BUTTON_TYPES: tuple[AutomowerButtonEntityDescription, ...] = (
40 translation_key=
"confirm_error",
41 available_fn=
lambda data: data.mower.is_error_confirmable,
42 exists_fn=
lambda data: data.capabilities.can_confirm_error,
43 press_fn=
lambda session, mower_id: session.commands.error_confirm(mower_id),
47 translation_key=
"sync_clock",
48 available_fn=_check_error_free,
49 press_fn=
lambda session, mower_id: session.commands.set_datetime(mower_id),
56 entry: AutomowerConfigEntry,
57 async_add_entities: AddEntitiesCallback,
59 """Set up button platform."""
60 coordinator = entry.runtime_data
63 for mower_id
in coordinator.data
64 for description
in MOWER_BUTTON_TYPES
65 if description.exists_fn(coordinator.data[mower_id])
70 """Defining the AutomowerButtonEntity."""
72 entity_description: AutomowerButtonEntityDescription
77 coordinator: AutomowerDataUpdateCoordinator,
78 description: AutomowerButtonEntityDescription,
80 """Set up AutomowerButtonEntity."""
81 super().
__init__(mower_id, coordinator)
87 """Return the available attribute of the entity."""
90 @handle_sending_exception()
92 """Send a command to the mower."""
MowerAttributes mower_attributes(self)