Add logs on disconnect/reconnect for Cambridge Audio (#125904)

* Bump aiostreammagic to 2.3.0

* Add logging on disconnect/reconnect for Cambridge Audio
This commit is contained in:
Noah Husby 2024-09-13 10:57:39 -04:00 committed by GitHub
parent d855f70e3b
commit d507953c70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,18 +3,22 @@
from __future__ import annotations
import asyncio
import logging
from aiostreammagic import StreamMagicClient
from aiostreammagic.models import CallbackType
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, Platform
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryNotReady
from .const import CONNECT_TIMEOUT, STREAM_MAGIC_EXCEPTIONS
PLATFORMS: list[Platform] = [Platform.MEDIA_PLAYER]
_LOGGER = logging.getLogger(__name__)
type CambridgeAudioConfigEntry = ConfigEntry[StreamMagicClient]
@ -25,6 +29,19 @@ async def async_setup_entry(
client = StreamMagicClient(entry.data[CONF_HOST])
@callback
async def _connection_update_callback(
_client: StreamMagicClient, _callback_type: CallbackType
) -> None:
"""Call when the device is notified of changes."""
if _callback_type == CallbackType.CONNECTION:
if _client.is_connected():
_LOGGER.warning("Reconnected to device at %s", entry.data[CONF_HOST])
else:
_LOGGER.warning("Disconnected from device at %s", entry.data[CONF_HOST])
await client.register_state_update_callbacks(_connection_update_callback)
try:
async with asyncio.timeout(CONNECT_TIMEOUT):
await client.connect()