1 """The russound_rio component."""
6 from aiorussound
import RussoundClient, RussoundTcpConnectionHandler
7 from aiorussound.models
import CallbackType
14 from .const
import CONNECT_TIMEOUT, DOMAIN, RUSSOUND_RIO_EXCEPTIONS
16 PLATFORMS = [Platform.MEDIA_PLAYER]
18 _LOGGER = logging.getLogger(__name__)
20 type RussoundConfigEntry = ConfigEntry[RussoundClient]
24 """Set up a config entry."""
26 host = entry.data[CONF_HOST]
27 port = entry.data[CONF_PORT]
28 client = RussoundClient(RussoundTcpConnectionHandler(host, port))
30 async
def _connection_update_callback(
31 _client: RussoundClient, _callback_type: CallbackType
33 """Call when the device is notified of changes."""
34 if _callback_type == CallbackType.CONNECTION:
35 if _client.is_connected():
36 _LOGGER.warning(
"Reconnected to device at %s", entry.data[CONF_HOST])
38 _LOGGER.warning(
"Disconnected from device at %s", entry.data[CONF_HOST])
40 await client.register_state_update_callbacks(_connection_update_callback)
43 async
with asyncio.timeout(CONNECT_TIMEOUT):
44 await client.connect()
45 except RUSSOUND_RIO_EXCEPTIONS
as err:
47 translation_domain=DOMAIN,
48 translation_key=
"entry_cannot_connect",
49 translation_placeholders={
54 entry.runtime_data = client
56 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
62 """Unload a config entry."""
63 if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
64 await entry.runtime_data.disconnect()
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, RussoundConfigEntry entry)