mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Improve Sonos activity tracking (#60642)
This commit is contained in:
parent
0cf228d5a1
commit
cb7e7e9bd1
@ -64,6 +64,7 @@ from .const import (
|
|||||||
from .favorites import SonosFavorites
|
from .favorites import SonosFavorites
|
||||||
from .helpers import soco_error
|
from .helpers import soco_error
|
||||||
|
|
||||||
|
NEVER_TIME = -1200.0
|
||||||
EVENT_CHARGING = {
|
EVENT_CHARGING = {
|
||||||
"CHARGING": True,
|
"CHARGING": True,
|
||||||
"NOT_CHARGING": False,
|
"NOT_CHARGING": False,
|
||||||
@ -159,7 +160,6 @@ class SonosSpeaker:
|
|||||||
self.available = True
|
self.available = True
|
||||||
|
|
||||||
# Synchronization helpers
|
# Synchronization helpers
|
||||||
self._is_ready: bool = False
|
|
||||||
self._platforms_ready: set[str] = set()
|
self._platforms_ready: set[str] = set()
|
||||||
|
|
||||||
# Subscriptions and events
|
# Subscriptions and events
|
||||||
@ -167,7 +167,7 @@ class SonosSpeaker:
|
|||||||
self._subscriptions: list[SubscriptionBase] = []
|
self._subscriptions: list[SubscriptionBase] = []
|
||||||
self._resubscription_lock: asyncio.Lock | None = None
|
self._resubscription_lock: asyncio.Lock | None = None
|
||||||
self._event_dispatchers: dict[str, Callable] = {}
|
self._event_dispatchers: dict[str, Callable] = {}
|
||||||
self._last_activity: datetime.datetime | None = None
|
self._last_activity: float = NEVER_TIME
|
||||||
|
|
||||||
# Scheduled callback handles
|
# Scheduled callback handles
|
||||||
self._poll_timer: Callable | None = None
|
self._poll_timer: Callable | None = None
|
||||||
@ -280,7 +280,6 @@ class SonosSpeaker:
|
|||||||
if self._platforms_ready == PLATFORMS:
|
if self._platforms_ready == PLATFORMS:
|
||||||
self._resubscription_lock = asyncio.Lock()
|
self._resubscription_lock = asyncio.Lock()
|
||||||
await self.async_subscribe()
|
await self.async_subscribe()
|
||||||
self._is_ready = True
|
|
||||||
|
|
||||||
def write_entity_states(self) -> None:
|
def write_entity_states(self) -> None:
|
||||||
"""Write states for associated SonosEntity instances."""
|
"""Write states for associated SonosEntity instances."""
|
||||||
@ -965,6 +964,7 @@ class SonosSpeaker:
|
|||||||
#
|
#
|
||||||
# Media and playback state handlers
|
# Media and playback state handlers
|
||||||
#
|
#
|
||||||
|
@soco_error()
|
||||||
def update_volume(self) -> None:
|
def update_volume(self) -> None:
|
||||||
"""Update information about current volume settings."""
|
"""Update information about current volume settings."""
|
||||||
self.volume = self.soco.volume
|
self.volume = self.soco.volume
|
||||||
@ -979,6 +979,7 @@ class SonosSpeaker:
|
|||||||
except SoCoSlaveException:
|
except SoCoSlaveException:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@soco_error()
|
||||||
def update_media(self, event: SonosEvent | None = None) -> None:
|
def update_media(self, event: SonosEvent | None = None) -> None:
|
||||||
"""Update information about currently playing media."""
|
"""Update information about currently playing media."""
|
||||||
variables = event and event.variables
|
variables = event and event.variables
|
||||||
|
Loading…
x
Reference in New Issue
Block a user