mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
Add extended device info and some attributes to Apple TV (#44277)
This commit is contained in:
parent
524db33f13
commit
fe7109acf4
@ -15,6 +15,7 @@ from homeassistant.const import (
|
|||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.dispatcher import (
|
from homeassistant.helpers.dispatcher import (
|
||||||
async_dispatcher_connect,
|
async_dispatcher_connect,
|
||||||
@ -135,15 +136,6 @@ class AppleTVEntity(Entity):
|
|||||||
def async_device_disconnected(self):
|
def async_device_disconnected(self):
|
||||||
"""Handle when connection was lost to device."""
|
"""Handle when connection was lost to device."""
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self):
|
|
||||||
"""Return the device info."""
|
|
||||||
return {
|
|
||||||
"identifiers": {(DOMAIN, self._identifier)},
|
|
||||||
"manufacturer": "Apple",
|
|
||||||
"name": self.name,
|
|
||||||
}
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the device."""
|
"""Return the name of the device."""
|
||||||
@ -337,6 +329,8 @@ class AppleTVManager:
|
|||||||
self._dispatch_send(SIGNAL_CONNECTED, self.atv)
|
self._dispatch_send(SIGNAL_CONNECTED, self.atv)
|
||||||
self._address_updated(str(conf.address))
|
self._address_updated(str(conf.address))
|
||||||
|
|
||||||
|
await self._async_setup_device_registry()
|
||||||
|
|
||||||
self._connection_attempts = 0
|
self._connection_attempts = 0
|
||||||
if self._connection_was_lost:
|
if self._connection_was_lost:
|
||||||
_LOGGER.info(
|
_LOGGER.info(
|
||||||
@ -344,6 +338,27 @@ class AppleTVManager:
|
|||||||
)
|
)
|
||||||
self._connection_was_lost = False
|
self._connection_was_lost = False
|
||||||
|
|
||||||
|
async def _async_setup_device_registry(self):
|
||||||
|
attrs = {
|
||||||
|
"identifiers": {(DOMAIN, self.config_entry.unique_id)},
|
||||||
|
"manufacturer": "Apple",
|
||||||
|
"name": self.config_entry.data[CONF_NAME],
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.atv:
|
||||||
|
dev_info = self.atv.device_info
|
||||||
|
|
||||||
|
attrs["model"] = "Apple TV " + dev_info.model.name.replace("Gen", "")
|
||||||
|
attrs["sw_version"] = dev_info.version
|
||||||
|
|
||||||
|
if dev_info.mac:
|
||||||
|
attrs["connections"] = {(dr.CONNECTION_NETWORK_MAC, dev_info.mac)}
|
||||||
|
|
||||||
|
device_registry = await dr.async_get_registry(self.hass)
|
||||||
|
device_registry.async_get_or_create(
|
||||||
|
config_entry_id=self.config_entry.entry_id, **attrs
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_connecting(self):
|
def is_connecting(self):
|
||||||
"""Return true if connection is in progress."""
|
"""Return true if connection is in progress."""
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""Support for Apple TV media player."""
|
"""Support for Apple TV media player."""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pyatv.const import DeviceState, MediaType
|
from pyatv.const import DeviceState, FeatureName, FeatureState, MediaType
|
||||||
|
|
||||||
from homeassistant.components.media_player import MediaPlayerEntity
|
from homeassistant.components.media_player import MediaPlayerEntity
|
||||||
from homeassistant.components.media_player.const import (
|
from homeassistant.components.media_player.const import (
|
||||||
@ -107,6 +107,22 @@ class AppleTvMediaPlayer(AppleTVEntity, MediaPlayerEntity):
|
|||||||
self._playing = None
|
self._playing = None
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def app_id(self):
|
||||||
|
"""ID of the current running app."""
|
||||||
|
if self.atv:
|
||||||
|
if self.atv.features.in_state(FeatureState.Available, FeatureName.App):
|
||||||
|
return self.atv.metadata.app.identifier
|
||||||
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def app_name(self):
|
||||||
|
"""Name of the current running app."""
|
||||||
|
if self.atv:
|
||||||
|
if self.atv.features.in_state(FeatureState.Available, FeatureName.App):
|
||||||
|
return self.atv.metadata.app.name
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def media_content_type(self):
|
def media_content_type(self):
|
||||||
"""Content type of current playing media."""
|
"""Content type of current playing media."""
|
||||||
@ -168,11 +184,31 @@ class AppleTvMediaPlayer(AppleTVEntity, MediaPlayerEntity):
|
|||||||
return self._playing.title
|
return self._playing.title
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def media_artist(self):
|
||||||
|
"""Artist of current playing media, music track only."""
|
||||||
|
if self._is_feature_available(FeatureName.Artist):
|
||||||
|
return self._playing.artist
|
||||||
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def media_album_name(self):
|
||||||
|
"""Album name of current playing media, music track only."""
|
||||||
|
if self._is_feature_available(FeatureName.Album):
|
||||||
|
return self._playing.album
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
"""Flag media player features that are supported."""
|
"""Flag media player features that are supported."""
|
||||||
return SUPPORT_APPLE_TV
|
return SUPPORT_APPLE_TV
|
||||||
|
|
||||||
|
def _is_feature_available(self, feature):
|
||||||
|
"""Return if a feature is available."""
|
||||||
|
if self.atv and self._playing:
|
||||||
|
return self.atv.features.in_state(FeatureState.Available, feature)
|
||||||
|
return False
|
||||||
|
|
||||||
async def async_turn_on(self):
|
async def async_turn_on(self):
|
||||||
"""Turn the media player on."""
|
"""Turn the media player on."""
|
||||||
await self.manager.connect()
|
await self.manager.connect()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user