1 """Base class for IKEA TRADFRI."""
3 from __future__
import annotations
5 from abc
import abstractmethod
6 from collections.abc
import Callable, Coroutine
7 from functools
import wraps
8 from typing
import Any, cast
10 from pytradfri.command
import Command
11 from pytradfri.device
import Device
12 from pytradfri.error
import RequestError
18 from .const
import DOMAIN, LOGGER
19 from .coordinator
import TradfriDeviceDataUpdateCoordinator
23 func: Callable[[Command | list[Command]], Any],
24 ) -> Callable[[Command | list[Command]], Coroutine[Any, Any,
None]]:
25 """Handle tradfri api call error."""
28 async
def wrapper(command: Command | list[Command]) ->
None:
29 """Decorate api call."""
32 except RequestError
as err:
33 LOGGER.error(
"Unable to execute command %s: %s", command, err)
39 """Base Tradfri device."""
41 _attr_has_entity_name =
True
45 device_coordinator: TradfriDeviceDataUpdateCoordinator,
47 api: Callable[[Command | list[Command]], Any],
49 """Initialize a device."""
54 self._device: Device = device_coordinator.data
59 info = self._device.device_info
61 identifiers={(DOMAIN, self.
_device_id_device_id)},
62 manufacturer=info.manufacturer,
63 model=info.model_number,
64 name=self._device.name,
65 sw_version=info.firmware_version,
66 via_device=(DOMAIN, gateway_id),
73 """Refresh device data."""
77 """Handle updated data from the coordinator.
79 Tests fails without this method.
86 """Return if entity is available."""
87 return cast(bool, self._device.reachable)
and super().available
None __init__(self, TradfriDeviceDataUpdateCoordinator device_coordinator, str gateway_id, Callable[[Command|list[Command]], Any] api)
None _handle_coordinator_update(self)
Callable[[Command|list[Command]], Coroutine[Any, Any, None]] handle_error(Callable[[Command|list[Command]], Any] func)