Set up polling task with subscriptions in Sonos (#54355)
parent
c3316df31d
commit
b3e84c6ee8
homeassistant/components/sonos
|
@ -323,6 +323,18 @@ class SonosSpeaker:
|
||||||
async def async_subscribe(self) -> bool:
|
async def async_subscribe(self) -> bool:
|
||||||
"""Initiate event subscriptions."""
|
"""Initiate event subscriptions."""
|
||||||
_LOGGER.debug("Creating subscriptions for %s", self.zone_name)
|
_LOGGER.debug("Creating subscriptions for %s", self.zone_name)
|
||||||
|
|
||||||
|
# Create a polling task in case subscriptions fail or callback events do not arrive
|
||||||
|
if not self._poll_timer:
|
||||||
|
self._poll_timer = self.hass.helpers.event.async_track_time_interval(
|
||||||
|
partial(
|
||||||
|
async_dispatcher_send,
|
||||||
|
self.hass,
|
||||||
|
f"{SONOS_POLL_UPDATE}-{self.soco.uid}",
|
||||||
|
),
|
||||||
|
SCAN_INTERVAL,
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self.hass.async_add_executor_job(self.set_basic_info)
|
await self.hass.async_add_executor_job(self.set_basic_info)
|
||||||
|
|
||||||
|
@ -337,10 +349,10 @@ class SonosSpeaker:
|
||||||
for service in SUBSCRIPTION_SERVICES
|
for service in SUBSCRIPTION_SERVICES
|
||||||
]
|
]
|
||||||
await asyncio.gather(*subscriptions)
|
await asyncio.gather(*subscriptions)
|
||||||
return True
|
|
||||||
except SoCoException as ex:
|
except SoCoException as ex:
|
||||||
_LOGGER.warning("Could not connect %s: %s", self.zone_name, ex)
|
_LOGGER.warning("Could not connect %s: %s", self.zone_name, ex)
|
||||||
return False
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
async def _subscribe(
|
async def _subscribe(
|
||||||
self, target: SubscriptionBase, sub_callback: Callable
|
self, target: SubscriptionBase, sub_callback: Callable
|
||||||
|
@ -497,15 +509,6 @@ class SonosSpeaker:
|
||||||
self.soco.ip_address,
|
self.soco.ip_address,
|
||||||
)
|
)
|
||||||
|
|
||||||
self._poll_timer = self.hass.helpers.event.async_track_time_interval(
|
|
||||||
partial(
|
|
||||||
async_dispatcher_send,
|
|
||||||
self.hass,
|
|
||||||
f"{SONOS_POLL_UPDATE}-{self.soco.uid}",
|
|
||||||
),
|
|
||||||
SCAN_INTERVAL,
|
|
||||||
)
|
|
||||||
|
|
||||||
if self._is_ready and not self.subscriptions_failed:
|
if self._is_ready and not self.subscriptions_failed:
|
||||||
done = await self.async_subscribe()
|
done = await self.async_subscribe()
|
||||||
if not done:
|
if not done:
|
||||||
|
@ -567,15 +570,6 @@ class SonosSpeaker:
|
||||||
self._seen_timer = self.hass.helpers.event.async_call_later(
|
self._seen_timer = self.hass.helpers.event.async_call_later(
|
||||||
SEEN_EXPIRE_TIME.total_seconds(), self.async_unseen
|
SEEN_EXPIRE_TIME.total_seconds(), self.async_unseen
|
||||||
)
|
)
|
||||||
if not self._poll_timer:
|
|
||||||
self._poll_timer = self.hass.helpers.event.async_track_time_interval(
|
|
||||||
partial(
|
|
||||||
async_dispatcher_send,
|
|
||||||
self.hass,
|
|
||||||
f"{SONOS_POLL_UPDATE}-{self.soco.uid}",
|
|
||||||
),
|
|
||||||
SCAN_INTERVAL,
|
|
||||||
)
|
|
||||||
self.async_write_entity_states()
|
self.async_write_entity_states()
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue