mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Fix Sonos const comparison (#50482)
* Fix Sonos const comparison * Use constants for playback states
This commit is contained in:
parent
897dd012cd
commit
afe02a4ad2
@ -33,6 +33,9 @@ SONOS_ALBUM_ARTIST = "album_artists"
|
|||||||
SONOS_TRACKS = "tracks"
|
SONOS_TRACKS = "tracks"
|
||||||
SONOS_COMPOSER = "composers"
|
SONOS_COMPOSER = "composers"
|
||||||
|
|
||||||
|
SONOS_STATE_PLAYING = "PLAYING"
|
||||||
|
SONOS_STATE_TRANSITIONING = "TRANSITIONING"
|
||||||
|
|
||||||
EXPANDABLE_MEDIA_TYPES = [
|
EXPANDABLE_MEDIA_TYPES = [
|
||||||
MEDIA_TYPE_ALBUM,
|
MEDIA_TYPE_ALBUM,
|
||||||
MEDIA_TYPE_ARTIST,
|
MEDIA_TYPE_ARTIST,
|
||||||
|
@ -58,6 +58,8 @@ from .const import (
|
|||||||
MEDIA_TYPES_TO_SONOS,
|
MEDIA_TYPES_TO_SONOS,
|
||||||
PLAYABLE_MEDIA_TYPES,
|
PLAYABLE_MEDIA_TYPES,
|
||||||
SONOS_CREATE_MEDIA_PLAYER,
|
SONOS_CREATE_MEDIA_PLAYER,
|
||||||
|
SONOS_STATE_PLAYING,
|
||||||
|
SONOS_STATE_TRANSITIONING,
|
||||||
SOURCE_LINEIN,
|
SOURCE_LINEIN,
|
||||||
SOURCE_TV,
|
SOURCE_TV,
|
||||||
)
|
)
|
||||||
@ -281,7 +283,10 @@ class SonosMediaPlayerEntity(SonosEntity, MediaPlayerEntity):
|
|||||||
if self.media.title is None:
|
if self.media.title is None:
|
||||||
return STATE_IDLE
|
return STATE_IDLE
|
||||||
return STATE_PAUSED
|
return STATE_PAUSED
|
||||||
if self.media.playback_status in ("PLAYING", "TRANSITIONING"):
|
if self.media.playback_status in (
|
||||||
|
SONOS_STATE_PLAYING,
|
||||||
|
SONOS_STATE_TRANSITIONING,
|
||||||
|
):
|
||||||
return STATE_PLAYING
|
return STATE_PLAYING
|
||||||
return STATE_IDLE
|
return STATE_IDLE
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ from pysonos.snapshot import Snapshot
|
|||||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||||
from homeassistant.components.media_player import DOMAIN as MP_DOMAIN
|
from homeassistant.components.media_player import DOMAIN as MP_DOMAIN
|
||||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||||
from homeassistant.const import STATE_PLAYING
|
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import entity_registry as ent_reg
|
from homeassistant.helpers import entity_registry as ent_reg
|
||||||
from homeassistant.helpers.dispatcher import (
|
from homeassistant.helpers.dispatcher import (
|
||||||
@ -43,6 +42,8 @@ from .const import (
|
|||||||
SONOS_ENTITY_UPDATE,
|
SONOS_ENTITY_UPDATE,
|
||||||
SONOS_GROUP_UPDATE,
|
SONOS_GROUP_UPDATE,
|
||||||
SONOS_SEEN,
|
SONOS_SEEN,
|
||||||
|
SONOS_STATE_PLAYING,
|
||||||
|
SONOS_STATE_TRANSITIONING,
|
||||||
SONOS_STATE_UPDATED,
|
SONOS_STATE_UPDATED,
|
||||||
SOURCE_LINEIN,
|
SOURCE_LINEIN,
|
||||||
SOURCE_TV,
|
SOURCE_TV,
|
||||||
@ -578,7 +579,7 @@ class SonosSpeaker:
|
|||||||
) -> list[list[SonosSpeaker]]:
|
) -> list[list[SonosSpeaker]]:
|
||||||
"""Pause all current coordinators and restore groups."""
|
"""Pause all current coordinators and restore groups."""
|
||||||
for speaker in (s for s in speakers if s.is_coordinator):
|
for speaker in (s for s in speakers if s.is_coordinator):
|
||||||
if speaker.media.playback_status == STATE_PLAYING:
|
if speaker.media.playback_status == SONOS_STATE_PLAYING:
|
||||||
hass.async_create_task(speaker.soco.pause())
|
hass.async_create_task(speaker.soco.pause())
|
||||||
|
|
||||||
groups = []
|
groups = []
|
||||||
@ -715,7 +716,7 @@ class SonosSpeaker:
|
|||||||
new_status = transport_info["current_transport_state"]
|
new_status = transport_info["current_transport_state"]
|
||||||
|
|
||||||
# Ignore transitions, we should get the target state soon
|
# Ignore transitions, we should get the target state soon
|
||||||
if new_status == "TRANSITIONING":
|
if new_status == SONOS_STATE_TRANSITIONING:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.media.clear()
|
self.media.clear()
|
||||||
@ -782,7 +783,7 @@ class SonosSpeaker:
|
|||||||
try:
|
try:
|
||||||
uri_meta_data = variables["enqueued_transport_uri_meta_data"]
|
uri_meta_data = variables["enqueued_transport_uri_meta_data"]
|
||||||
if isinstance(uri_meta_data, DidlAudioBroadcast) and (
|
if isinstance(uri_meta_data, DidlAudioBroadcast) and (
|
||||||
self.media.playback_status != STATE_PLAYING
|
self.media.playback_status != SONOS_STATE_PLAYING
|
||||||
or self.soco.music_source_from_uri(self.media.title) == MUSIC_SRC_RADIO
|
or self.soco.music_source_from_uri(self.media.title) == MUSIC_SRC_RADIO
|
||||||
or (
|
or (
|
||||||
isinstance(self.media.title, str)
|
isinstance(self.media.title, str)
|
||||||
@ -814,7 +815,7 @@ class SonosSpeaker:
|
|||||||
|
|
||||||
# position jumped?
|
# position jumped?
|
||||||
if current_position is not None and self.media.position is not None:
|
if current_position is not None and self.media.position is not None:
|
||||||
if self.media.playback_status == STATE_PLAYING:
|
if self.media.playback_status == SONOS_STATE_PLAYING:
|
||||||
assert self.media.position_updated_at is not None
|
assert self.media.position_updated_at is not None
|
||||||
time_delta = dt_util.utcnow() - self.media.position_updated_at
|
time_delta = dt_util.utcnow() - self.media.position_updated_at
|
||||||
time_diff = time_delta.total_seconds()
|
time_diff = time_delta.total_seconds()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user