Fix BangOlufsenSource enum member names (#116052)

This commit is contained in:
Markus Jacobsen 2024-07-07 23:53:49 +02:00 committed by GitHub
parent cd478c356e
commit e30f315565
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 34 deletions

View File

@ -10,27 +10,17 @@ from mozart_api.models import Source, SourceArray, SourceTypeEnum
from homeassistant.components.media_player import MediaPlayerState, MediaType from homeassistant.components.media_player import MediaPlayerState, MediaType
class BangOlufsenSource(StrEnum): class BangOlufsenSource:
"""Enum used for associating device source ids with friendly names. May not include all sources.""" """Class used for associating device source ids with friendly names. May not include all sources."""
URI_STREAMER = "Audio Streamer" URI_STREAMER: Final[Source] = Source(name="Audio Streamer", id="uriStreamer")
BLUETOOTH = "Bluetooth" BLUETOOTH: Final[Source] = Source(name="Bluetooth", id="bluetooth")
AIR_PLAY = "AirPlay" CHROMECAST: Final[Source] = Source(name="Chromecast built-in", id="chromeCast")
CHROMECAST = "Chromecast built-in" LINE_IN: Final[Source] = Source(name="Line-In", id="lineIn")
SPOTIFY = "Spotify Connect" SPDIF: Final[Source] = Source(name="Optical", id="spdif")
GENERATOR = "Tone Generator" NET_RADIO: Final[Source] = Source(name="B&O Radio", id="netRadio")
LINE_IN = "Line-In" DEEZER: Final[Source] = Source(name="Deezer", id="deezer")
SPDIF = "Optical" TIDAL: Final[Source] = Source(name="Tidal", id="tidal")
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] = { BANG_OLUFSEN_STATES: dict[str, MediaPlayerState] = {

View File

@ -344,8 +344,8 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
# Check if source is line-in or optical and progress should be updated # Check if source is line-in or optical and progress should be updated
if self._source_change.id in ( if self._source_change.id in (
BangOlufsenSource.LINE_IN, BangOlufsenSource.LINE_IN.id,
BangOlufsenSource.SPDIF, BangOlufsenSource.SPDIF.id,
): ):
self._playback_progress = PlaybackProgress(progress=0) self._playback_progress = PlaybackProgress(progress=0)
@ -381,7 +381,7 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
def media_content_type(self) -> str: def media_content_type(self) -> str:
"""Return the current media type.""" """Return the current media type."""
# Hard to determine content type # Hard to determine content type
if self.source == BangOlufsenSource.URI_STREAMER: if self._source_change.id == BangOlufsenSource.URI_STREAMER.id:
return MediaType.URL return MediaType.URL
return MediaType.MUSIC return MediaType.MUSIC
@ -437,21 +437,21 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
# Try to fix some of the source_change chromecast weirdness. # Try to fix some of the source_change chromecast weirdness.
if hasattr(self._playback_metadata, "title"): if hasattr(self._playback_metadata, "title"):
# source_change is chromecast but line in is selected. # source_change is chromecast but line in is selected.
if self._playback_metadata.title == BangOlufsenSource.LINE_IN: if self._playback_metadata.title == BangOlufsenSource.LINE_IN.name:
return BangOlufsenSource.LINE_IN return BangOlufsenSource.LINE_IN.name
# source_change is chromecast but bluetooth is selected. # source_change is chromecast but bluetooth is selected.
if self._playback_metadata.title == BangOlufsenSource.BLUETOOTH: if self._playback_metadata.title == BangOlufsenSource.BLUETOOTH.name:
return BangOlufsenSource.BLUETOOTH return BangOlufsenSource.BLUETOOTH.name
# source_change is line in, bluetooth or optical but stale metadata is sent through the WebSocket, # source_change is line in, bluetooth or optical but stale metadata is sent through the WebSocket,
# And the source has not changed. # And the source has not changed.
if self._source_change.id in ( if self._source_change.id in (
BangOlufsenSource.BLUETOOTH, BangOlufsenSource.BLUETOOTH.id,
BangOlufsenSource.LINE_IN, BangOlufsenSource.LINE_IN.id,
BangOlufsenSource.SPDIF, BangOlufsenSource.SPDIF.id,
): ):
return BangOlufsenSource.CHROMECAST return BangOlufsenSource.CHROMECAST.name
# source_change is chromecast and there is metadata but no artwork. Bluetooth does support metadata but not artwork # 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 # So i assume that it is bluetooth and not chromecast
@ -461,9 +461,9 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
): ):
if ( if (
len(self._playback_metadata.art) == 0 len(self._playback_metadata.art) == 0
and self._source_change.name == BangOlufsenSource.BLUETOOTH and self._source_change.id == BangOlufsenSource.BLUETOOTH.id
): ):
return BangOlufsenSource.BLUETOOTH return BangOlufsenSource.BLUETOOTH.name
return self._source_change.name return self._source_change.name
@ -506,7 +506,7 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
async def async_media_seek(self, position: float) -> None: async def async_media_seek(self, position: float) -> None:
"""Seek to position in ms.""" """Seek to position in ms."""
if self.source == BangOlufsenSource.DEEZER: if self._source_change.id == BangOlufsenSource.DEEZER.id:
await self._client.seek_to_position(position_ms=int(position * 1000)) await self._client.seek_to_position(position_ms=int(position * 1000))
# Try to prevent the playback progress from bouncing in the UI. # Try to prevent the playback progress from bouncing in the UI.
self._attr_media_position_updated_at = utcnow() self._attr_media_position_updated_at = utcnow()