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
class BangOlufsenSource(StrEnum):
"""Enum used for associating device source ids with friendly names. May not include all sources."""
class BangOlufsenSource:
"""Class used for associating device source ids with friendly names. May not include all sources."""
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"
URI_STREAMER: Final[Source] = Source(name="Audio Streamer", id="uriStreamer")
BLUETOOTH: Final[Source] = Source(name="Bluetooth", id="bluetooth")
CHROMECAST: Final[Source] = Source(name="Chromecast built-in", id="chromeCast")
LINE_IN: Final[Source] = Source(name="Line-In", id="lineIn")
SPDIF: Final[Source] = Source(name="Optical", id="spdif")
NET_RADIO: Final[Source] = Source(name="B&O Radio", id="netRadio")
DEEZER: Final[Source] = Source(name="Deezer", id="deezer")
TIDAL: Final[Source] = Source(name="Tidal", id="tidal")
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
if self._source_change.id in (
BangOlufsenSource.LINE_IN,
BangOlufsenSource.SPDIF,
BangOlufsenSource.LINE_IN.id,
BangOlufsenSource.SPDIF.id,
):
self._playback_progress = PlaybackProgress(progress=0)
@ -381,7 +381,7 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
def media_content_type(self) -> str:
"""Return the current media 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.MUSIC
@ -437,21 +437,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 == BangOlufsenSource.LINE_IN:
return BangOlufsenSource.LINE_IN
if self._playback_metadata.title == BangOlufsenSource.LINE_IN.name:
return BangOlufsenSource.LINE_IN.name
# source_change is chromecast but bluetooth is selected.
if self._playback_metadata.title == BangOlufsenSource.BLUETOOTH:
return BangOlufsenSource.BLUETOOTH
if self._playback_metadata.title == BangOlufsenSource.BLUETOOTH.name:
return BangOlufsenSource.BLUETOOTH.name
# 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 (
BangOlufsenSource.BLUETOOTH,
BangOlufsenSource.LINE_IN,
BangOlufsenSource.SPDIF,
BangOlufsenSource.BLUETOOTH.id,
BangOlufsenSource.LINE_IN.id,
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
# So i assume that it is bluetooth and not chromecast
@ -461,9 +461,9 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
):
if (
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
@ -506,7 +506,7 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
async def async_media_seek(self, position: float) -> None:
"""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))
# Try to prevent the playback progress from bouncing in the UI.
self._attr_media_position_updated_at = utcnow()