diff --git a/homeassistant/components/sonos/const.py b/homeassistant/components/sonos/const.py index 6c4bdd07b31..7b85828377a 100644 --- a/homeassistant/components/sonos/const.py +++ b/homeassistant/components/sonos/const.py @@ -171,6 +171,20 @@ SOURCE_LINEIN = "Line-in" SOURCE_SPOTIFY_CONNECT = "Spotify Connect" SOURCE_TV = "TV" +MODELS_LINEIN_ONLY = ( + "CONNECT", + "CONNECT:AMP", + "PORT", + "PLAY:5", +) +MODELS_TV_ONLY = ( + "ARC", + "BEAM", + "PLAYBAR", + "PLAYBASE", +) +MODELS_LINEIN_AND_TV = ("AMP",) + AVAILABILITY_CHECK_INTERVAL = datetime.timedelta(minutes=1) AVAILABILITY_TIMEOUT = AVAILABILITY_CHECK_INTERVAL.total_seconds() * 4.5 BATTERY_SCAN_INTERVAL = datetime.timedelta(minutes=15) diff --git a/homeassistant/components/sonos/media_player.py b/homeassistant/components/sonos/media_player.py index 65e8c4111ae..0968f5d024c 100644 --- a/homeassistant/components/sonos/media_player.py +++ b/homeassistant/components/sonos/media_player.py @@ -64,6 +64,9 @@ from .const import ( DATA_SONOS, DOMAIN as SONOS_DOMAIN, MEDIA_TYPES_TO_SONOS, + MODELS_LINEIN_AND_TV, + MODELS_LINEIN_ONLY, + MODELS_TV_ONLY, PLAYABLE_MEDIA_TYPES, SONOS_CREATE_MEDIA_PLAYER, SONOS_MEDIA_UPDATED, @@ -474,20 +477,17 @@ class SonosMediaPlayerEntity(SonosEntity, MediaPlayerEntity): soco.add_to_queue(favorite.reference) soco.play_from_queue(0) - @property # type: ignore[misc] + @property def source_list(self) -> list[str]: """List of available input sources.""" - sources = [fav.title for fav in self.speaker.favorites] - - model = self.coordinator.model_name.upper() - if "PLAY:5" in model or "CONNECT" in model: - sources += [SOURCE_LINEIN] - elif "PLAYBAR" in model: - sources += [SOURCE_LINEIN, SOURCE_TV] - elif "BEAM" in model or "PLAYBASE" in model: - sources += [SOURCE_TV] - - return sources + model = self.coordinator.model_name.split()[-1].upper() + if model in MODELS_LINEIN_ONLY: + return [SOURCE_LINEIN] + if model in MODELS_TV_ONLY: + return [SOURCE_TV] + if model in MODELS_LINEIN_AND_TV: + return [SOURCE_LINEIN, SOURCE_TV] + return [] @soco_error(UPNP_ERRORS_TO_IGNORE) def media_play(self) -> None: