1 """Base entity for Russound RIO integration."""
3 from collections.abc
import Awaitable, Callable, Coroutine
4 from functools
import wraps
5 from typing
import Any, Concatenate
7 from aiorussound
import Controller, RussoundClient, RussoundTcpConnectionHandler
8 from aiorussound.models
import CallbackType
14 from .const
import DOMAIN, RUSSOUND_RIO_EXCEPTIONS
17 def command[_EntityT: RussoundBaseEntity, **_P](
18 func: Callable[Concatenate[_EntityT, _P], Awaitable[
None]],
19 ) -> Callable[Concatenate[_EntityT, _P], Coroutine[Any, Any,
None]]:
20 """Wrap async calls to raise on request error."""
23 async
def decorator(self: _EntityT, *args: _P.args, **kwargs: _P.kwargs) ->
None:
24 """Wrap all command methods."""
26 await func(self, *args, **kwargs)
27 except RUSSOUND_RIO_EXCEPTIONS
as exc:
29 translation_domain=DOMAIN,
30 translation_key=
"command_error",
31 translation_placeholders={
32 "function_name": func.__name__,
33 "entity_id": self.entity_id,
41 """Russound Base Entity."""
43 _attr_has_entity_name =
True
44 _attr_should_poll =
False
48 controller: Controller,
50 """Initialize the entity."""
54 controller.mac_address
or self.
_client_client.controllers[1].mac_address
58 or f
"{self._primary_mac_address}-{self._controller.controller_id}"
63 manufacturer=
"Russound",
64 name=controller.controller_type,
65 model=controller.controller_type,
66 sw_version=controller.firmware_version,
68 if isinstance(self.
_client_client.connection_handler, RussoundTcpConnectionHandler):
70 f
"http://{self._client.connection_handler.host}"
72 if controller.controller_id != 1:
73 assert self.
_client_client.controllers[1].mac_address
76 self.
_client_client.controllers[1].mac_address,
79 assert controller.mac_address
81 (CONNECTION_NETWORK_MAC, controller.mac_address)
85 self, _client: RussoundClient, _callback_type: CallbackType
87 """Call when the device is notified of changes."""
88 if _callback_type == CallbackType.CONNECTION:
94 """Register callback handlers."""
98 """Remove callbacks."""
None _state_update_callback(self, RussoundClient _client, CallbackType _callback_type)
None async_added_to_hass(self)
None __init__(self, Controller controller)
None async_will_remove_from_hass(self)
None async_write_ha_state(self)