Improve Bang & Olufsen notification type comparison (#123067)

* Change notification comparison

* Use try_parse_enum to determine notification type
pull/124361/head
Markus Jacobsen 2024-08-21 11:31:19 +02:00 committed by GitHub
parent 1d1a6ee52f
commit f33328308c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 6 deletions

View File

@ -20,6 +20,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.util.enum import try_parse_enum
from .const import (
BANG_OLUFSEN_WEBSOCKET_EVENT,
@ -92,12 +93,14 @@ class BangOlufsenWebsocket(BangOlufsenBase):
self, notification: WebsocketNotificationTag
) -> None:
"""Send notification dispatch."""
if notification.value:
if WebsocketNotification.REMOTE_MENU_CHANGED in notification.value:
async_dispatcher_send(
self.hass,
f"{self._unique_id}_{WebsocketNotification.REMOTE_MENU_CHANGED}",
)
# Try to match the notification type with available WebsocketNotification members
notification_type = try_parse_enum(WebsocketNotification, notification.value)
if notification_type is WebsocketNotification.REMOTE_MENU_CHANGED:
async_dispatcher_send(
self.hass,
f"{self._unique_id}_{WebsocketNotification.REMOTE_MENU_CHANGED}",
)
def on_playback_error_notification(self, notification: PlaybackError) -> None:
"""Send playback_error dispatch."""