mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Handle Sonos connection issues better when polling (#51376)
This commit is contained in:
parent
ba6a0b5793
commit
2c9e6bd927
@ -5,6 +5,7 @@ import datetime
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pysonos.core import SoCo
|
from pysonos.core import SoCo
|
||||||
|
from pysonos.exceptions import SoCoException
|
||||||
|
|
||||||
import homeassistant.helpers.device_registry as dr
|
import homeassistant.helpers.device_registry as dr
|
||||||
from homeassistant.helpers.dispatcher import (
|
from homeassistant.helpers.dispatcher import (
|
||||||
@ -70,7 +71,10 @@ class SonosEntity(Entity):
|
|||||||
self.speaker.subscription_address,
|
self.speaker.subscription_address,
|
||||||
)
|
)
|
||||||
self.speaker.is_first_poll = False
|
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
|
@property
|
||||||
def soco(self) -> SoCo:
|
def soco(self) -> SoCo:
|
||||||
|
@ -13,7 +13,7 @@ from pysonos.core import (
|
|||||||
PLAY_MODE_BY_MEANING,
|
PLAY_MODE_BY_MEANING,
|
||||||
PLAY_MODES,
|
PLAY_MODES,
|
||||||
)
|
)
|
||||||
from pysonos.exceptions import SoCoException, SoCoUPnPException
|
from pysonos.exceptions import SoCoUPnPException
|
||||||
from pysonos.plugins.sharelink import ShareLinkPlugin
|
from pysonos.plugins.sharelink import ShareLinkPlugin
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -294,18 +294,15 @@ class SonosMediaPlayerEntity(SonosEntity, MediaPlayerEntity):
|
|||||||
return STATE_IDLE
|
return STATE_IDLE
|
||||||
|
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
"""Retrieve latest state."""
|
"""Retrieve latest state by polling."""
|
||||||
await self.hass.async_add_executor_job(self._update)
|
await self.hass.async_add_executor_job(self._update)
|
||||||
|
|
||||||
def _update(self) -> None:
|
def _update(self) -> None:
|
||||||
"""Retrieve latest state."""
|
"""Retrieve latest state by polling."""
|
||||||
try:
|
self.speaker.update_groups()
|
||||||
self.speaker.update_groups()
|
self.speaker.update_volume()
|
||||||
self.speaker.update_volume()
|
if self.speaker.is_coordinator:
|
||||||
if self.speaker.is_coordinator:
|
self.speaker.update_media()
|
||||||
self.speaker.update_media()
|
|
||||||
except SoCoException:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def volume_level(self) -> float | None:
|
def volume_level(self) -> float | None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user