Skip to content

Commit

Permalink
Handle Sonos connection issues better when polling (#51376)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjlawren committed Jun 3, 2021
1 parent ba6a0b5 commit 2c9e6bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
6 changes: 5 additions & 1 deletion homeassistant/components/sonos/entity.py
Expand Up @@ -5,6 +5,7 @@
import logging

from pysonos.core import SoCo
from pysonos.exceptions import SoCoException

import homeassistant.helpers.device_registry as dr
from homeassistant.helpers.dispatcher import (
Expand Down Expand Up @@ -70,7 +71,10 @@ async def async_poll(self, now: datetime.datetime) -> None:
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:
Expand Down
17 changes: 7 additions & 10 deletions homeassistant/components/sonos/media_player.py
Expand Up @@ -13,7 +13,7 @@
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

Expand Down Expand Up @@ -294,18 +294,15 @@ def state(self) -> str:
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:
Expand Down

0 comments on commit 2c9e6bd

Please sign in to comment.