Handle Sonos connection issues better when polling (#51376)

pull/51400/head
jjlawren 2021-06-02 23:10:27 -05:00 committed by GitHub
parent ba6a0b5793
commit 2c9e6bd927
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 11 deletions

View File

@ -5,6 +5,7 @@ import datetime
import logging
from pysonos.core import SoCo
from pysonos.exceptions import SoCoException
import homeassistant.helpers.device_registry as dr
from homeassistant.helpers.dispatcher import (
@ -70,7 +71,10 @@ class SonosEntity(Entity):
self.speaker.subscription_address,
)
self.speaker.is_first_poll = False
await self.async_update() # pylint: disable=no-member
try:
await self.async_update() # pylint: disable=no-member
except (OSError, SoCoException) as ex:
_LOGGER.debug("Error connecting to %s: %s", self.entity_id, ex)
@property
def soco(self) -> SoCo:

View File

@ -13,7 +13,7 @@ from pysonos.core import (
PLAY_MODE_BY_MEANING,
PLAY_MODES,
)
from pysonos.exceptions import SoCoException, SoCoUPnPException
from pysonos.exceptions import SoCoUPnPException
from pysonos.plugins.sharelink import ShareLinkPlugin
import voluptuous as vol
@ -294,18 +294,15 @@ class SonosMediaPlayerEntity(SonosEntity, MediaPlayerEntity):
return STATE_IDLE
async def async_update(self) -> None:
"""Retrieve latest state."""
"""Retrieve latest state by polling."""
await self.hass.async_add_executor_job(self._update)
def _update(self) -> None:
"""Retrieve latest state."""
try:
self.speaker.update_groups()
self.speaker.update_volume()
if self.speaker.is_coordinator:
self.speaker.update_media()
except SoCoException:
pass
"""Retrieve latest state by polling."""
self.speaker.update_groups()
self.speaker.update_volume()
if self.speaker.is_coordinator:
self.speaker.update_media()
@property
def volume_level(self) -> float | None: