Add volume and tv metadata to Apple TV (#61107)

pull/61149/head
Pierre Ståhl 2021-12-07 08:36:13 +01:00 committed by GitHub
parent 5161126b58
commit a87a6d3072
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 44 additions and 0 deletions

View File

@ -31,6 +31,7 @@ from homeassistant.components.media_player.const import (
SUPPORT_STOP, SUPPORT_STOP,
SUPPORT_TURN_OFF, SUPPORT_TURN_OFF,
SUPPORT_TURN_ON, SUPPORT_TURN_ON,
SUPPORT_VOLUME_SET,
SUPPORT_VOLUME_STEP, SUPPORT_VOLUME_STEP,
) )
from homeassistant.const import ( from homeassistant.const import (
@ -66,6 +67,7 @@ SUPPORT_APPLE_TV = (
| SUPPORT_STOP | SUPPORT_STOP
| SUPPORT_NEXT_TRACK | SUPPORT_NEXT_TRACK
| SUPPORT_PREVIOUS_TRACK | SUPPORT_PREVIOUS_TRACK
| SUPPORT_VOLUME_SET
| SUPPORT_VOLUME_STEP | SUPPORT_VOLUME_STEP
| SUPPORT_REPEAT_SET | SUPPORT_REPEAT_SET
| SUPPORT_SHUFFLE_SET | SUPPORT_SHUFFLE_SET
@ -86,6 +88,7 @@ SUPPORT_FEATURE_MAPPING = {
FeatureName.VolumeDown: SUPPORT_VOLUME_STEP, FeatureName.VolumeDown: SUPPORT_VOLUME_STEP,
FeatureName.SetRepeat: SUPPORT_REPEAT_SET, FeatureName.SetRepeat: SUPPORT_REPEAT_SET,
FeatureName.SetShuffle: SUPPORT_SHUFFLE_SET, FeatureName.SetShuffle: SUPPORT_SHUFFLE_SET,
FeatureName.SetVolume: SUPPORT_VOLUME_SET,
} }
@ -206,6 +209,20 @@ class AppleTvMediaPlayer(AppleTVEntity, MediaPlayerEntity):
}.get(self._playing.media_type) }.get(self._playing.media_type)
return None return None
@property
def media_content_id(self):
"""Content ID of current playing media."""
if self._playing:
return self._playing.content_identifier
return None
@property
def volume_level(self):
"""Volume level of the media player (0..1)."""
if self._is_feature_available(FeatureName.Volume):
return self.atv.audio.volume / 100.0 # from percent
return None
@property @property
def media_duration(self): def media_duration(self):
"""Duration of current playing media in seconds.""" """Duration of current playing media in seconds."""
@ -285,6 +302,27 @@ class AppleTvMediaPlayer(AppleTVEntity, MediaPlayerEntity):
return self._playing.album return self._playing.album
return None return None
@property
def media_series_title(self):
"""Title of series of current playing media, TV show only."""
if self._is_feature_available(FeatureName.SeriesName):
return self._playing.series_name
return None
@property
def media_season(self):
"""Season of current playing media, TV show only."""
if self._is_feature_available(FeatureName.SeasonNumber):
return str(self._playing.season_number)
return None
@property
def media_episode(self):
"""Episode of current playing media, TV show only."""
if self._is_feature_available(FeatureName.EpisodeNumber):
return str(self._playing.episode_number)
return None
@property @property
def repeat(self): def repeat(self):
"""Return current repeat mode.""" """Return current repeat mode."""
@ -366,6 +404,12 @@ class AppleTvMediaPlayer(AppleTVEntity, MediaPlayerEntity):
if self.atv: if self.atv:
await self.atv.audio.volume_down() await self.atv.audio.volume_down()
async def async_set_volume_level(self, volume):
"""Set volume level, range 0..1."""
if self.atv:
# pyatv expects volume in percent
await self.atv.audio.set_volume(volume * 100.0)
async def async_set_repeat(self, repeat): async def async_set_repeat(self, repeat):
"""Set repeat mode.""" """Set repeat mode."""
if self.atv: if self.atv: