Expose Sonos features as switch entities (#54502)

Co-authored-by: Tobias Sauerwein <cgtobi@users.noreply.github.com>
This commit is contained in:
jjlawren 2021-10-23 16:11:27 -05:00 committed by GitHub
parent 21daffe905
commit 084fd2d19f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 184 additions and 82 deletions

View file

@ -1,6 +1,7 @@
"""Entity representing a Sonos player."""
from __future__ import annotations
from abc import abstractmethod
import datetime
import logging
@ -30,6 +31,8 @@ _LOGGER = logging.getLogger(__name__)
class SonosEntity(Entity):
"""Representation of a Sonos entity."""
_attr_should_poll = False
def __init__(self, speaker: SonosSpeaker) -> None:
"""Initialize a SonosEntity."""
self.speaker = speaker
@ -78,10 +81,14 @@ class SonosEntity(Entity):
self.speaker.subscriptions_failed = True
await self.speaker.async_unsubscribe()
try:
await self.async_update() # pylint: disable=no-member
await self._async_poll()
except (OSError, SoCoException) as ex:
_LOGGER.debug("Error connecting to %s: %s", self.entity_id, ex)
@abstractmethod
async def _async_poll(self) -> None:
"""Poll the specific functionality. Should be implemented by platforms if needed."""
@property
def soco(self) -> SoCo:
"""Return the speaker SoCo instance."""
@ -108,8 +115,3 @@ class SonosEntity(Entity):
def available(self) -> bool:
"""Return whether this device is available."""
return self.speaker.available
@property
def should_poll(self) -> bool:
"""Return that we should not be polled (we handle that internally)."""
return False