Refactor Sonos polling (#65722)
* Refactor Sonos polling Explicitly rename fallback polling Catch soco exceptions centrally where possible Create SonosPollingEntity subclass Remove unnecessary soco_error fixture argument Remove unnecessary polling in update_volume() Adjust log levels and wording Set explicit timeout on library * Adjust logging to use raised exceptions * Simplify availabiliity checks when using built-in poller * Fix typing for return values
This commit is contained in:
parent
4efebcb86c
commit
a7fd477c64
14 changed files with 89 additions and 85 deletions
|
@ -12,7 +12,6 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||
|
||||
from .const import SONOS_CREATE_LEVELS
|
||||
from .entity import SonosEntity
|
||||
from .exception import SpeakerUnavailable
|
||||
from .helpers import soco_error
|
||||
from .speaker import SonosSpeaker
|
||||
|
||||
|
@ -75,16 +74,13 @@ class SonosLevelEntity(SonosEntity, NumberEntity):
|
|||
self.level_type = level_type
|
||||
self._attr_min_value, self._attr_max_value = valid_range
|
||||
|
||||
async def _async_poll(self) -> None:
|
||||
async def _async_fallback_poll(self) -> None:
|
||||
"""Poll the value if subscriptions are not working."""
|
||||
await self.hass.async_add_executor_job(self.update)
|
||||
|
||||
@soco_error(raise_on_err=False)
|
||||
def update(self) -> None:
|
||||
"""Fetch number state if necessary."""
|
||||
if not self.available:
|
||||
raise SpeakerUnavailable
|
||||
await self.hass.async_add_executor_job(self.poll_state)
|
||||
|
||||
@soco_error()
|
||||
def poll_state(self) -> None:
|
||||
"""Poll the device for the current state."""
|
||||
state = getattr(self.soco, self.level_type)
|
||||
setattr(self.speaker, self.level_type, state)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue