Rework available Sonos sources (#67931)

This commit is contained in:
jjlawren 2022-03-11 17:57:57 -06:00 committed by GitHub
parent 41df798375
commit 80ff497cfc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 12 deletions

View file

@ -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)

View file

@ -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: