1 """Update coordinator and WebSocket listener(s) for the Bang & Olufsen integration."""
3 from __future__
import annotations
7 from mozart_api.models
import (
9 PlaybackContentMetadata,
16 WebsocketNotificationTag,
18 from mozart_api.mozart_client
import BaseWebSocketResponse, MozartClient
27 BANG_OLUFSEN_WEBSOCKET_EVENT,
29 WebsocketNotification,
31 from .entity
import BangOlufsenBase
32 from .util
import get_device
34 _LOGGER = logging.getLogger(__name__)
38 """The WebSocket listeners."""
41 self, hass: HomeAssistant, entry: ConfigEntry, client: MozartClient
43 """Initialize the WebSocket listeners."""
45 BangOlufsenBase.__init__(self, entry, client)
54 self.
_client_client.get_active_listening_mode_notifications(
57 self.
_client_client.get_playback_error_notifications(
60 self.
_client_client.get_playback_metadata_notifications(
63 self.
_client_client.get_playback_progress_notifications(
66 self.
_client_client.get_playback_source_notifications(
69 self.
_client_client.get_playback_state_notifications(
72 self.
_client_client.get_software_update_state_notifications(
82 """Update all entities of the connection status."""
85 f
"{self._unique_id}_{CONNECTION_STATUS}",
86 self.
_client_client.websocket_connected,
90 """Handle WebSocket connection made."""
91 _LOGGER.debug(
"Connected to the %s notification channel", self.entry.title)
95 """Handle WebSocket connection lost."""
96 _LOGGER.error(
"Lost connection to the %s", self.entry.title)
100 """Send active_listening_mode dispatch."""
103 f
"{self._unique_id}_{WebsocketNotification.ACTIVE_LISTENING_MODE}",
108 self, notification: WebsocketNotificationTag
110 """Send notification dispatch."""
112 notification_type = try_parse_enum(WebsocketNotification, notification.value)
114 if notification_type
in (
115 WebsocketNotification.BEOLINK_PEERS,
116 WebsocketNotification.BEOLINK_LISTENERS,
117 WebsocketNotification.BEOLINK_AVAILABLE_LISTENERS,
121 f
"{self._unique_id}_{WebsocketNotification.BEOLINK}",
123 elif notification_type
is WebsocketNotification.CONFIGURATION:
126 f
"{self._unique_id}_{WebsocketNotification.CONFIGURATION}",
128 elif notification_type
is WebsocketNotification.REMOTE_MENU_CHANGED:
131 f
"{self._unique_id}_{WebsocketNotification.REMOTE_MENU_CHANGED}",
135 """Send playback_error dispatch."""
138 f
"{self._unique_id}_{WebsocketNotification.PLAYBACK_ERROR}",
143 self, notification: PlaybackContentMetadata
145 """Send playback_metadata dispatch."""
148 f
"{self._unique_id}_{WebsocketNotification.PLAYBACK_METADATA}",
153 """Send playback_progress dispatch."""
156 f
"{self._unique_id}_{WebsocketNotification.PLAYBACK_PROGRESS}",
161 """Send playback_state dispatch."""
164 f
"{self._unique_id}_{WebsocketNotification.PLAYBACK_STATE}",
169 """Send playback_source dispatch."""
172 f
"{self._unique_id}_{WebsocketNotification.PLAYBACK_SOURCE}",
177 """Send source_change dispatch."""
180 f
"{self._unique_id}_{WebsocketNotification.SOURCE_CHANGE}",
185 """Send volume dispatch."""
188 f
"{self._unique_id}_{WebsocketNotification.VOLUME}",
193 """Check device sw version."""
194 software_status = await self.
_client_client.get_softwareupdate_status()
197 if software_status.software_version != self.
_device_device.sw_version:
198 device_registry = dr.async_get(self.
hasshass)
200 device_registry.async_update_device(
201 device_id=self.
_device_device.id,
202 sw_version=software_status.software_version,
206 """Receive all notifications."""
207 debug_notification = {
208 "device_id": self.
_device_device.id,
209 "serial_number":
int(self._unique_id),
213 _LOGGER.debug(
"%s", debug_notification)
214 self.
hasshass.bus.async_fire(BANG_OLUFSEN_WEBSOCKET_EVENT, debug_notification)
None on_source_change_notification(self, Source notification)
None on_playback_error_notification(self, PlaybackError notification)
None _update_connection_status(self)
None on_active_listening_mode(self, ListeningModeProps notification)
None on_notification_notification(self, WebsocketNotificationTag notification)
None on_all_notifications_raw(self, BaseWebSocketResponse notification)
None on_volume_notification(self, VolumeState notification)
None on_software_update_state(self, SoftwareUpdateState notification)
None on_playback_metadata_notification(self, PlaybackContentMetadata notification)
None on_playback_source_notification(self, Source notification)
None on_playback_state_notification(self, RenderingState notification)
None on_connection_lost(self)
None on_playback_progress_notification(self, PlaybackProgress notification)
None __init__(self, HomeAssistant hass, ConfigEntry entry, MozartClient client)
DeviceEntry get_device(HomeAssistant hass, str unique_id)
None async_dispatcher_send(HomeAssistant hass, str signal, *Any args)