mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Tweak Sonos activity monitoring (#66207)
* Tweak Sonos activity monitoring * Support new 'sleeping' vanish reason * Check availability before last-ditch check * Use short-timeout call for last-ditch check * Adjust reboot logging message and severity * Simplify activity check failure
This commit is contained in:
parent
fe38e6ba87
commit
e86c82e675
@ -79,6 +79,7 @@ SUBSCRIPTION_SERVICES = [
|
|||||||
"renderingControl",
|
"renderingControl",
|
||||||
"zoneGroupTopology",
|
"zoneGroupTopology",
|
||||||
]
|
]
|
||||||
|
SUPPORTED_VANISH_REASONS = ("sleeping", "upgrade")
|
||||||
UNAVAILABLE_VALUES = {"", "NOT_IMPLEMENTED", None}
|
UNAVAILABLE_VALUES = {"", "NOT_IMPLEMENTED", None}
|
||||||
UNUSED_DEVICE_KEYS = ["SPID", "TargetRoomName"]
|
UNUSED_DEVICE_KEYS = ["SPID", "TargetRoomName"]
|
||||||
|
|
||||||
@ -553,25 +554,29 @@ class SonosSpeaker:
|
|||||||
|
|
||||||
async def async_check_activity(self, now: datetime.datetime) -> None:
|
async def async_check_activity(self, now: datetime.datetime) -> None:
|
||||||
"""Validate availability of the speaker based on recent activity."""
|
"""Validate availability of the speaker based on recent activity."""
|
||||||
|
if not self.available:
|
||||||
|
return
|
||||||
if time.monotonic() - self._last_activity < AVAILABILITY_TIMEOUT:
|
if time.monotonic() - self._last_activity < AVAILABILITY_TIMEOUT:
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_ = await self.hass.async_add_executor_job(getattr, self.soco, "volume")
|
# Make a short-timeout call as a final check
|
||||||
except (OSError, SoCoException):
|
# before marking this speaker as unavailable
|
||||||
pass
|
await self.hass.async_add_executor_job(
|
||||||
|
partial(
|
||||||
|
self.soco.renderingControl.GetVolume,
|
||||||
|
[("InstanceID", 0), ("Channel", "Master")],
|
||||||
|
timeout=1,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
except OSError:
|
||||||
|
_LOGGER.warning(
|
||||||
|
"No recent activity and cannot reach %s, marking unavailable",
|
||||||
|
self.zone_name,
|
||||||
|
)
|
||||||
|
await self.async_offline()
|
||||||
else:
|
else:
|
||||||
self.speaker_activity("timeout poll")
|
self.speaker_activity("timeout poll")
|
||||||
return
|
|
||||||
|
|
||||||
if not self.available:
|
|
||||||
return
|
|
||||||
|
|
||||||
_LOGGER.warning(
|
|
||||||
"No recent activity and cannot reach %s, marking unavailable",
|
|
||||||
self.zone_name,
|
|
||||||
)
|
|
||||||
await self.async_offline()
|
|
||||||
|
|
||||||
async def async_offline(self) -> None:
|
async def async_offline(self) -> None:
|
||||||
"""Handle removal of speaker when unavailable."""
|
"""Handle removal of speaker when unavailable."""
|
||||||
@ -603,8 +608,8 @@ class SonosSpeaker:
|
|||||||
|
|
||||||
async def async_rebooted(self, soco: SoCo) -> None:
|
async def async_rebooted(self, soco: SoCo) -> None:
|
||||||
"""Handle a detected speaker reboot."""
|
"""Handle a detected speaker reboot."""
|
||||||
_LOGGER.warning(
|
_LOGGER.debug(
|
||||||
"%s rebooted or lost network connectivity, reconnecting with %s",
|
"%s rebooted, reconnecting with %s",
|
||||||
self.zone_name,
|
self.zone_name,
|
||||||
soco,
|
soco,
|
||||||
)
|
)
|
||||||
@ -717,7 +722,9 @@ class SonosSpeaker:
|
|||||||
if xml := event.variables.get("zone_group_state"):
|
if xml := event.variables.get("zone_group_state"):
|
||||||
zgs = ET.fromstring(xml)
|
zgs = ET.fromstring(xml)
|
||||||
for vanished_device in zgs.find("VanishedDevices") or []:
|
for vanished_device in zgs.find("VanishedDevices") or []:
|
||||||
if (reason := vanished_device.get("Reason")) != "sleeping":
|
if (
|
||||||
|
reason := vanished_device.get("Reason")
|
||||||
|
) not in SUPPORTED_VANISH_REASONS:
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Ignoring %s marked %s as vanished with reason: %s",
|
"Ignoring %s marked %s as vanished with reason: %s",
|
||||||
self.zone_name,
|
self.zone_name,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user