Use more meaningful states for snapcast groups and clients (#77449)

* Show muted snapcast groups as idle and use playing/idle state instead of on state for clients

* New module constant STREAM_STATUS

* Fix return type hint in snapcast

---------

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
luar123 2023-03-31 12:38:23 +02:00 committed by GitHub
parent 6bad5f02c6
commit c7e8fc9f9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -42,6 +42,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{vol.Required(CONF_HOST): cv.string, vol.Optional(CONF_PORT): cv.port}
)
STREAM_STATUS = {
"idle": MediaPlayerState.IDLE,
"playing": MediaPlayerState.PLAYING,
"unknown": None,
}
def register_services():
"""Register snapcast services."""
@ -157,11 +163,9 @@ class SnapcastGroupDevice(MediaPlayerEntity):
@property
def state(self) -> MediaPlayerState | None:
"""Return the state of the player."""
return {
"idle": MediaPlayerState.IDLE,
"playing": MediaPlayerState.PLAYING,
"unknown": None,
}.get(self._group.stream_status)
if self.is_volume_muted:
return MediaPlayerState.IDLE
return STREAM_STATUS.get(self._group.stream_status)
@property
def unique_id(self):
@ -289,11 +293,13 @@ class SnapcastClientDevice(MediaPlayerEntity):
return list(self._client.group.streams_by_name().keys())
@property
def state(self) -> MediaPlayerState:
def state(self) -> MediaPlayerState | None:
"""Return the state of the player."""
if self._client.connected:
return MediaPlayerState.ON
return MediaPlayerState.OFF
if self.is_volume_muted or self._client.group.muted:
return MediaPlayerState.IDLE
return STREAM_STATUS.get(self._client.group.stream_status)
return MediaPlayerState.STANDBY
@property
def extra_state_attributes(self):