mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
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:
parent
6bad5f02c6
commit
c7e8fc9f9d
@ -42,6 +42,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
{vol.Required(CONF_HOST): cv.string, vol.Optional(CONF_PORT): cv.port}
|
{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():
|
def register_services():
|
||||||
"""Register snapcast services."""
|
"""Register snapcast services."""
|
||||||
@ -157,11 +163,9 @@ class SnapcastGroupDevice(MediaPlayerEntity):
|
|||||||
@property
|
@property
|
||||||
def state(self) -> MediaPlayerState | None:
|
def state(self) -> MediaPlayerState | None:
|
||||||
"""Return the state of the player."""
|
"""Return the state of the player."""
|
||||||
return {
|
if self.is_volume_muted:
|
||||||
"idle": MediaPlayerState.IDLE,
|
return MediaPlayerState.IDLE
|
||||||
"playing": MediaPlayerState.PLAYING,
|
return STREAM_STATUS.get(self._group.stream_status)
|
||||||
"unknown": None,
|
|
||||||
}.get(self._group.stream_status)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
@ -289,11 +293,13 @@ class SnapcastClientDevice(MediaPlayerEntity):
|
|||||||
return list(self._client.group.streams_by_name().keys())
|
return list(self._client.group.streams_by_name().keys())
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self) -> MediaPlayerState:
|
def state(self) -> MediaPlayerState | None:
|
||||||
"""Return the state of the player."""
|
"""Return the state of the player."""
|
||||||
if self._client.connected:
|
if self._client.connected:
|
||||||
return MediaPlayerState.ON
|
if self.is_volume_muted or self._client.group.muted:
|
||||||
return MediaPlayerState.OFF
|
return MediaPlayerState.IDLE
|
||||||
|
return STREAM_STATUS.get(self._client.group.stream_status)
|
||||||
|
return MediaPlayerState.STANDBY
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user