mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Fix Bang & Olufsen enum naming (#113022)
This commit is contained in:
parent
23f9aea64d
commit
0ea91515cf
@ -10,27 +10,27 @@ from mozart_api.models import Source, SourceArray, SourceTypeEnum
|
||||
from homeassistant.components.media_player import MediaPlayerState, MediaType
|
||||
|
||||
|
||||
class SOURCE_ENUM(StrEnum):
|
||||
class BangOlufsenSource(StrEnum):
|
||||
"""Enum used for associating device source ids with friendly names. May not include all sources."""
|
||||
|
||||
uriStreamer = "Audio Streamer" # noqa: N815
|
||||
bluetooth = "Bluetooth"
|
||||
airPlay = "AirPlay" # noqa: N815
|
||||
chromeCast = "Chromecast built-in" # noqa: N815
|
||||
spotify = "Spotify Connect"
|
||||
generator = "Tone Generator"
|
||||
lineIn = "Line-In" # noqa: N815
|
||||
spdif = "Optical"
|
||||
netRadio = "B&O Radio" # noqa: N815
|
||||
local = "Local"
|
||||
dlna = "DLNA"
|
||||
qplay = "QPlay"
|
||||
wpl = "Wireless Powerlink"
|
||||
pl = "Powerlink"
|
||||
tv = "TV"
|
||||
deezer = "Deezer"
|
||||
beolink = "Networklink"
|
||||
tidalConnect = "Tidal Connect" # noqa: N815
|
||||
URI_STREAMER = "Audio Streamer"
|
||||
BLUETOOTH = "Bluetooth"
|
||||
AIR_PLAY = "AirPlay"
|
||||
CHROMECAST = "Chromecast built-in"
|
||||
SPOTIFY = "Spotify Connect"
|
||||
GENERATOR = "Tone Generator"
|
||||
LINE_IN = "Line-In"
|
||||
SPDIF = "Optical"
|
||||
NET_RADIO = "B&O Radio"
|
||||
LOCAL = "Local"
|
||||
DLNA = "DLNA"
|
||||
QPLAY = "QPlay"
|
||||
WPL = "Wireless Powerlink"
|
||||
PL = "Powerlink"
|
||||
TV = "TV"
|
||||
DEEZER = "Deezer"
|
||||
BEOLINK = "Networklink"
|
||||
TIDAL_CONNECT = "Tidal Connect"
|
||||
|
||||
|
||||
BANG_OLUFSEN_STATES: dict[str, MediaPlayerState] = {
|
||||
@ -48,7 +48,7 @@ BANG_OLUFSEN_STATES: dict[str, MediaPlayerState] = {
|
||||
|
||||
|
||||
# Media types for play_media
|
||||
class BANG_OLUFSEN_MEDIA_TYPE(StrEnum):
|
||||
class BangOlufsenMediaType(StrEnum):
|
||||
"""Bang & Olufsen specific media types."""
|
||||
|
||||
FAVOURITE = "favourite"
|
||||
@ -57,7 +57,7 @@ class BANG_OLUFSEN_MEDIA_TYPE(StrEnum):
|
||||
TTS = "provider"
|
||||
|
||||
|
||||
class MODEL_ENUM(StrEnum):
|
||||
class BangOlufsenModel(StrEnum):
|
||||
"""Enum for compatible model names."""
|
||||
|
||||
BEOLAB_8 = "BeoLab 8"
|
||||
@ -72,7 +72,7 @@ class MODEL_ENUM(StrEnum):
|
||||
|
||||
|
||||
# Dispatcher events
|
||||
class WEBSOCKET_NOTIFICATION(StrEnum):
|
||||
class WebsocketNotification(StrEnum):
|
||||
"""Enum for WebSocket notification types."""
|
||||
|
||||
PLAYBACK_ERROR: Final[str] = "playback_error"
|
||||
@ -94,14 +94,14 @@ class WEBSOCKET_NOTIFICATION(StrEnum):
|
||||
DOMAIN: Final[str] = "bang_olufsen"
|
||||
|
||||
# Default values for configuration.
|
||||
DEFAULT_MODEL: Final[str] = MODEL_ENUM.BEOSOUND_BALANCE
|
||||
DEFAULT_MODEL: Final[str] = BangOlufsenModel.BEOSOUND_BALANCE
|
||||
|
||||
# Configuration.
|
||||
CONF_SERIAL_NUMBER: Final = "serial_number"
|
||||
CONF_BEOLINK_JID: Final = "jid"
|
||||
|
||||
# Models to choose from in manual configuration.
|
||||
COMPATIBLE_MODELS: list[str] = [x.value for x in MODEL_ENUM]
|
||||
COMPATIBLE_MODELS: list[str] = [x.value for x in BangOlufsenModel]
|
||||
|
||||
# Attribute names for zeroconf discovery.
|
||||
ATTR_TYPE_NUMBER: Final[str] = "tn"
|
||||
@ -113,10 +113,10 @@ ATTR_FRIENDLY_NAME: Final[str] = "fn"
|
||||
BANG_OLUFSEN_ON: Final[str] = "on"
|
||||
|
||||
VALID_MEDIA_TYPES: Final[tuple] = (
|
||||
BANG_OLUFSEN_MEDIA_TYPE.FAVOURITE,
|
||||
BANG_OLUFSEN_MEDIA_TYPE.DEEZER,
|
||||
BANG_OLUFSEN_MEDIA_TYPE.RADIO,
|
||||
BANG_OLUFSEN_MEDIA_TYPE.TTS,
|
||||
BangOlufsenMediaType.FAVOURITE,
|
||||
BangOlufsenMediaType.DEEZER,
|
||||
BangOlufsenMediaType.RADIO,
|
||||
BangOlufsenMediaType.TTS,
|
||||
MediaType.MUSIC,
|
||||
MediaType.URL,
|
||||
MediaType.CHANNEL,
|
||||
|
@ -51,16 +51,16 @@ from homeassistant.util.dt import utcnow
|
||||
|
||||
from . import BangOlufsenData
|
||||
from .const import (
|
||||
BANG_OLUFSEN_MEDIA_TYPE,
|
||||
BANG_OLUFSEN_STATES,
|
||||
CONF_BEOLINK_JID,
|
||||
CONNECTION_STATUS,
|
||||
DOMAIN,
|
||||
FALLBACK_SOURCES,
|
||||
HIDDEN_SOURCE_IDS,
|
||||
SOURCE_ENUM,
|
||||
VALID_MEDIA_TYPES,
|
||||
WEBSOCKET_NOTIFICATION,
|
||||
BangOlufsenMediaType,
|
||||
BangOlufsenSource,
|
||||
WebsocketNotification,
|
||||
)
|
||||
from .entity import BangOlufsenEntity
|
||||
|
||||
@ -145,7 +145,7 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
f"{self._unique_id}_{WEBSOCKET_NOTIFICATION.PLAYBACK_ERROR}",
|
||||
f"{self._unique_id}_{WebsocketNotification.PLAYBACK_ERROR}",
|
||||
self._update_playback_error,
|
||||
)
|
||||
)
|
||||
@ -153,7 +153,7 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
f"{self._unique_id}_{WEBSOCKET_NOTIFICATION.PLAYBACK_METADATA}",
|
||||
f"{self._unique_id}_{WebsocketNotification.PLAYBACK_METADATA}",
|
||||
self._update_playback_metadata,
|
||||
)
|
||||
)
|
||||
@ -161,35 +161,35 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
f"{self._unique_id}_{WEBSOCKET_NOTIFICATION.PLAYBACK_PROGRESS}",
|
||||
f"{self._unique_id}_{WebsocketNotification.PLAYBACK_PROGRESS}",
|
||||
self._update_playback_progress,
|
||||
)
|
||||
)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
f"{self._unique_id}_{WEBSOCKET_NOTIFICATION.PLAYBACK_STATE}",
|
||||
f"{self._unique_id}_{WebsocketNotification.PLAYBACK_STATE}",
|
||||
self._update_playback_state,
|
||||
)
|
||||
)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
f"{self._unique_id}_{WEBSOCKET_NOTIFICATION.REMOTE_MENU_CHANGED}",
|
||||
f"{self._unique_id}_{WebsocketNotification.REMOTE_MENU_CHANGED}",
|
||||
self._update_sources,
|
||||
)
|
||||
)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
f"{self._unique_id}_{WEBSOCKET_NOTIFICATION.SOURCE_CHANGE}",
|
||||
f"{self._unique_id}_{WebsocketNotification.SOURCE_CHANGE}",
|
||||
self._update_source_change,
|
||||
)
|
||||
)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
f"{self._unique_id}_{WEBSOCKET_NOTIFICATION.VOLUME}",
|
||||
f"{self._unique_id}_{WebsocketNotification.VOLUME}",
|
||||
self._update_volume,
|
||||
)
|
||||
)
|
||||
@ -335,7 +335,10 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
|
||||
self._source_change = data
|
||||
|
||||
# Check if source is line-in or optical and progress should be updated
|
||||
if self._source_change.id in (SOURCE_ENUM.lineIn, SOURCE_ENUM.spdif):
|
||||
if self._source_change.id in (
|
||||
BangOlufsenSource.LINE_IN,
|
||||
BangOlufsenSource.SPDIF,
|
||||
):
|
||||
self._playback_progress = PlaybackProgress(progress=0)
|
||||
|
||||
async def _update_volume(self, data: VolumeState) -> None:
|
||||
@ -367,7 +370,7 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
|
||||
def media_content_type(self) -> str:
|
||||
"""Return the current media type."""
|
||||
# Hard to determine content type
|
||||
if self.source == SOURCE_ENUM.uriStreamer:
|
||||
if self.source == BangOlufsenSource.URI_STREAMER:
|
||||
return MediaType.URL
|
||||
return MediaType.MUSIC
|
||||
|
||||
@ -425,21 +428,21 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
|
||||
# Try to fix some of the source_change chromecast weirdness.
|
||||
if hasattr(self._playback_metadata, "title"):
|
||||
# source_change is chromecast but line in is selected.
|
||||
if self._playback_metadata.title == SOURCE_ENUM.lineIn:
|
||||
return SOURCE_ENUM.lineIn
|
||||
if self._playback_metadata.title == BangOlufsenSource.LINE_IN:
|
||||
return BangOlufsenSource.LINE_IN
|
||||
|
||||
# source_change is chromecast but bluetooth is selected.
|
||||
if self._playback_metadata.title == SOURCE_ENUM.bluetooth:
|
||||
return SOURCE_ENUM.bluetooth
|
||||
if self._playback_metadata.title == BangOlufsenSource.BLUETOOTH:
|
||||
return BangOlufsenSource.BLUETOOTH
|
||||
|
||||
# source_change is line in, bluetooth or optical but stale metadata is sent through the WebSocket,
|
||||
# And the source has not changed.
|
||||
if self._source_change.id in (
|
||||
SOURCE_ENUM.bluetooth,
|
||||
SOURCE_ENUM.lineIn,
|
||||
SOURCE_ENUM.spdif,
|
||||
BangOlufsenSource.BLUETOOTH,
|
||||
BangOlufsenSource.LINE_IN,
|
||||
BangOlufsenSource.SPDIF,
|
||||
):
|
||||
return SOURCE_ENUM.chromeCast
|
||||
return BangOlufsenSource.CHROMECAST
|
||||
|
||||
# source_change is chromecast and there is metadata but no artwork. Bluetooth does support metadata but not artwork
|
||||
# So i assume that it is bluetooth and not chromecast
|
||||
@ -449,9 +452,9 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
|
||||
):
|
||||
if (
|
||||
len(self._playback_metadata.art) == 0
|
||||
and self._source_change.name == SOURCE_ENUM.bluetooth
|
||||
and self._source_change.name == BangOlufsenSource.BLUETOOTH
|
||||
):
|
||||
return SOURCE_ENUM.bluetooth
|
||||
return BangOlufsenSource.BLUETOOTH
|
||||
|
||||
return self._source_change.name
|
||||
|
||||
@ -494,7 +497,7 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
|
||||
|
||||
async def async_media_seek(self, position: float) -> None:
|
||||
"""Seek to position in ms."""
|
||||
if self.source == SOURCE_ENUM.deezer:
|
||||
if self.source == BangOlufsenSource.DEEZER:
|
||||
await self._client.seek_to_position(position_ms=int(position * 1000))
|
||||
# Try to prevent the playback progress from bouncing in the UI.
|
||||
self._attr_media_position_updated_at = utcnow()
|
||||
@ -568,14 +571,14 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
|
||||
|
||||
# The "provider" media_type may not be suitable for overlay all the time.
|
||||
# Use it for now.
|
||||
elif media_type == BANG_OLUFSEN_MEDIA_TYPE.TTS:
|
||||
elif media_type == BangOlufsenMediaType.TTS:
|
||||
await self._client.post_overlay_play(
|
||||
overlay_play_request=OverlayPlayRequest(
|
||||
uri=Uri(location=media_id),
|
||||
)
|
||||
)
|
||||
|
||||
elif media_type == BANG_OLUFSEN_MEDIA_TYPE.RADIO:
|
||||
elif media_type == BangOlufsenMediaType.RADIO:
|
||||
await self._client.run_provided_scene(
|
||||
scene_properties=SceneProperties(
|
||||
action_list=[
|
||||
@ -587,10 +590,10 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
|
||||
)
|
||||
)
|
||||
|
||||
elif media_type == BANG_OLUFSEN_MEDIA_TYPE.FAVOURITE:
|
||||
elif media_type == BangOlufsenMediaType.FAVOURITE:
|
||||
await self._client.activate_preset(id=int(media_id))
|
||||
|
||||
elif media_type == BANG_OLUFSEN_MEDIA_TYPE.DEEZER:
|
||||
elif media_type == BangOlufsenMediaType.DEEZER:
|
||||
try:
|
||||
if media_id == "flow":
|
||||
deezer_id = None
|
||||
|
@ -24,7 +24,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from .const import (
|
||||
BANG_OLUFSEN_WEBSOCKET_EVENT,
|
||||
CONNECTION_STATUS,
|
||||
WEBSOCKET_NOTIFICATION,
|
||||
WebsocketNotification,
|
||||
)
|
||||
from .entity import BangOlufsenBase
|
||||
from .util import get_device
|
||||
@ -93,17 +93,17 @@ class BangOlufsenWebsocket(BangOlufsenBase):
|
||||
) -> None:
|
||||
"""Send notification dispatch."""
|
||||
if notification.value:
|
||||
if WEBSOCKET_NOTIFICATION.REMOTE_MENU_CHANGED in notification.value:
|
||||
if WebsocketNotification.REMOTE_MENU_CHANGED in notification.value:
|
||||
async_dispatcher_send(
|
||||
self.hass,
|
||||
f"{self._unique_id}_{WEBSOCKET_NOTIFICATION.REMOTE_MENU_CHANGED}",
|
||||
f"{self._unique_id}_{WebsocketNotification.REMOTE_MENU_CHANGED}",
|
||||
)
|
||||
|
||||
def on_playback_error_notification(self, notification: PlaybackError) -> None:
|
||||
"""Send playback_error dispatch."""
|
||||
async_dispatcher_send(
|
||||
self.hass,
|
||||
f"{self._unique_id}_{WEBSOCKET_NOTIFICATION.PLAYBACK_ERROR}",
|
||||
f"{self._unique_id}_{WebsocketNotification.PLAYBACK_ERROR}",
|
||||
notification,
|
||||
)
|
||||
|
||||
@ -113,7 +113,7 @@ class BangOlufsenWebsocket(BangOlufsenBase):
|
||||
"""Send playback_metadata dispatch."""
|
||||
async_dispatcher_send(
|
||||
self.hass,
|
||||
f"{self._unique_id}_{WEBSOCKET_NOTIFICATION.PLAYBACK_METADATA}",
|
||||
f"{self._unique_id}_{WebsocketNotification.PLAYBACK_METADATA}",
|
||||
notification,
|
||||
)
|
||||
|
||||
@ -121,7 +121,7 @@ class BangOlufsenWebsocket(BangOlufsenBase):
|
||||
"""Send playback_progress dispatch."""
|
||||
async_dispatcher_send(
|
||||
self.hass,
|
||||
f"{self._unique_id}_{WEBSOCKET_NOTIFICATION.PLAYBACK_PROGRESS}",
|
||||
f"{self._unique_id}_{WebsocketNotification.PLAYBACK_PROGRESS}",
|
||||
notification,
|
||||
)
|
||||
|
||||
@ -129,7 +129,7 @@ class BangOlufsenWebsocket(BangOlufsenBase):
|
||||
"""Send playback_state dispatch."""
|
||||
async_dispatcher_send(
|
||||
self.hass,
|
||||
f"{self._unique_id}_{WEBSOCKET_NOTIFICATION.PLAYBACK_STATE}",
|
||||
f"{self._unique_id}_{WebsocketNotification.PLAYBACK_STATE}",
|
||||
notification,
|
||||
)
|
||||
|
||||
@ -137,7 +137,7 @@ class BangOlufsenWebsocket(BangOlufsenBase):
|
||||
"""Send source_change dispatch."""
|
||||
async_dispatcher_send(
|
||||
self.hass,
|
||||
f"{self._unique_id}_{WEBSOCKET_NOTIFICATION.SOURCE_CHANGE}",
|
||||
f"{self._unique_id}_{WebsocketNotification.SOURCE_CHANGE}",
|
||||
notification,
|
||||
)
|
||||
|
||||
@ -145,7 +145,7 @@ class BangOlufsenWebsocket(BangOlufsenBase):
|
||||
"""Send volume dispatch."""
|
||||
async_dispatcher_send(
|
||||
self.hass,
|
||||
f"{self._unique_id}_{WEBSOCKET_NOTIFICATION.VOLUME}",
|
||||
f"{self._unique_id}_{WebsocketNotification.VOLUME}",
|
||||
notification,
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user