Use entity class attributes for apple_tv (#52664)
* Use entity class attributes for apple_tv * fix pylint * tweak
This commit is contained in:
parent
8c812bc25c
commit
ad0ccc1b70
3 changed files with 12 additions and 37 deletions
|
@ -83,12 +83,17 @@ async def async_unload_entry(hass, entry):
|
|||
class AppleTVEntity(Entity):
|
||||
"""Device that sends commands to an Apple TV."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, name, identifier, manager):
|
||||
"""Initialize device."""
|
||||
self.atv = None
|
||||
self.manager = manager
|
||||
self._name = name
|
||||
self._identifier = identifier
|
||||
self._attr_name = name
|
||||
self._attr_unique_id = identifier
|
||||
self._attr_device_info = {
|
||||
"identifiers": {(DOMAIN, identifier)},
|
||||
}
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Handle when an entity is about to be added to Home Assistant."""
|
||||
|
@ -109,13 +114,13 @@ class AppleTVEntity(Entity):
|
|||
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, f"{SIGNAL_CONNECTED}_{self._identifier}", _async_connected
|
||||
self.hass, f"{SIGNAL_CONNECTED}_{self.unique_id}", _async_connected
|
||||
)
|
||||
)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
f"{SIGNAL_DISCONNECTED}_{self._identifier}",
|
||||
f"{SIGNAL_DISCONNECTED}_{self.unique_id}",
|
||||
_async_disconnected,
|
||||
)
|
||||
)
|
||||
|
@ -126,28 +131,6 @@ class AppleTVEntity(Entity):
|
|||
def async_device_disconnected(self):
|
||||
"""Handle when connection was lost to device."""
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the device."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return a unique ID."""
|
||||
return self._identifier
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""No polling needed for Apple TV."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return the device info."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self._identifier)},
|
||||
}
|
||||
|
||||
|
||||
class AppleTVManager:
|
||||
"""Connection and power manager for an Apple TV.
|
||||
|
|
|
@ -75,6 +75,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
class AppleTvMediaPlayer(AppleTVEntity, MediaPlayerEntity):
|
||||
"""Representation of an Apple TV media player."""
|
||||
|
||||
_attr_supported_features = SUPPORT_APPLE_TV
|
||||
|
||||
def __init__(self, name, identifier, manager, **kwargs):
|
||||
"""Initialize the Apple TV media player."""
|
||||
super().__init__(name, identifier, manager, **kwargs)
|
||||
|
@ -229,11 +231,6 @@ class AppleTvMediaPlayer(AppleTVEntity, MediaPlayerEntity):
|
|||
return self._playing.shuffle != ShuffleState.Off
|
||||
return None
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Flag media player features that are supported."""
|
||||
return SUPPORT_APPLE_TV
|
||||
|
||||
def _is_feature_available(self, feature):
|
||||
"""Return if a feature is available."""
|
||||
if self.atv and self._playing:
|
||||
|
|
|
@ -34,11 +34,6 @@ class AppleTVRemote(AppleTVEntity, RemoteEntity):
|
|||
"""Return true if device is on."""
|
||||
return self.atv is not None
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""No polling needed for Apple TV."""
|
||||
return False
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn the device on."""
|
||||
await self.manager.connect()
|
||||
|
@ -53,7 +48,7 @@ class AppleTVRemote(AppleTVEntity, RemoteEntity):
|
|||
delay = kwargs.get(ATTR_DELAY_SECS, DEFAULT_DELAY_SECS)
|
||||
|
||||
if not self.is_on:
|
||||
_LOGGER.error("Unable to send commands, not connected to %s", self._name)
|
||||
_LOGGER.error("Unable to send commands, not connected to %s", self.name)
|
||||
return
|
||||
|
||||
for _ in range(num_repeats):
|
||||
|
|
Loading…
Add table
Reference in a new issue