1 """Support for the DirecTV receivers."""
3 from __future__
import annotations
8 from directv
import DIRECTV
11 MediaPlayerDeviceClass,
13 MediaPlayerEntityFeature,
23 ATTR_MEDIA_CURRENTLY_RECORDING,
26 ATTR_MEDIA_START_TIME,
29 from .entity
import DIRECTVEntity
31 _LOGGER = logging.getLogger(__name__)
33 KNOWN_MEDIA_TYPES = {MediaType.MOVIE, MediaType.MUSIC, MediaType.TVSHOW}
36 MediaPlayerEntityFeature.PAUSE
37 | MediaPlayerEntityFeature.TURN_ON
38 | MediaPlayerEntityFeature.TURN_OFF
39 | MediaPlayerEntityFeature.PLAY_MEDIA
40 | MediaPlayerEntityFeature.STOP
41 | MediaPlayerEntityFeature.NEXT_TRACK
42 | MediaPlayerEntityFeature.PREVIOUS_TRACK
43 | MediaPlayerEntityFeature.PLAY
46 SUPPORT_DTV_CLIENT = (
47 MediaPlayerEntityFeature.PAUSE
48 | MediaPlayerEntityFeature.PLAY_MEDIA
49 | MediaPlayerEntityFeature.STOP
50 | MediaPlayerEntityFeature.NEXT_TRACK
51 | MediaPlayerEntityFeature.PREVIOUS_TRACK
52 | MediaPlayerEntityFeature.PLAY
59 async_add_entities: AddEntitiesCallback,
61 """Set up the DirecTV config entry."""
62 dtv = hass.data[DOMAIN][entry.entry_id]
68 name=str.title(location.name),
69 address=location.address,
71 for location
in dtv.device.locations
78 """Representation of a DirecTV receiver on the network."""
80 def __init__(self, *, dtv: DIRECTV, name: str, address: str =
"0") ->
None:
81 """Initialize DirecTV media player."""
100 """Retrieve latest state."""
104 self.
_program_program = state.program
112 elif self.
_program_program
is not None:
122 """Return device specific state attributes."""
134 def state(self) -> MediaPlayerState:
135 """Return the state of the device."""
137 return MediaPlayerState.OFF
143 return MediaPlayerState.PAUSED
145 return MediaPlayerState.PLAYING
149 """Return the content ID of current playing media."""
153 return self.
_program_program.program_id
157 """Return the content type of current playing media."""
161 if self.
_program_program.program_type
in KNOWN_MEDIA_TYPES:
162 return self.
_program_program.program_type
164 return MediaType.MOVIE
168 """Return the duration of current playing media in seconds."""
172 return self.
_program_program.duration
176 """Position of current playing media in seconds."""
184 """When was the position of the current playing media valid."""
192 """Return the title of current playing media."""
197 return self.
_program_program.music_title
203 """Artist of current playing media, music track only."""
207 return self.
_program_program.music_artist
211 """Album name of current playing media, music track only."""
215 return self.
_program_program.music_album
219 """Return the title of current episode of TV show."""
223 return self.
_program_program.episode_title
227 """Return the channel current playing media."""
231 return f
"{self._program.channel_name} ({self._program.channel})"
235 """Name of the current input source."""
239 return self.
_program_program.channel
243 """Flag media player features that are supported."""
244 return SUPPORT_DTV_CLIENT
if self.
_is_client_is_client
else SUPPORT_DTV
248 """If the media is currently being recorded or not."""
252 return self.
_program_program.recording
256 """TV Rating of the current playing media."""
264 """If the media was recorded or live."""
272 """Start time the program aired."""
276 return dt_util.as_local(self.
_program_program.start_time)
279 """Turn on the receiver."""
281 raise NotImplementedError
283 _LOGGER.debug(
"Turn on %s", self.
namename)
284 await self.
dtvdtv.remote(
"poweron", self.
_address_address)
287 """Turn off the receiver."""
289 raise NotImplementedError
291 _LOGGER.debug(
"Turn off %s", self.
namename)
292 await self.
dtvdtv.remote(
"poweroff", self.
_address_address)
295 """Send play command."""
296 _LOGGER.debug(
"Play on %s", self.
namename)
297 await self.
dtvdtv.remote(
"play", self.
_address_address)
300 """Send pause command."""
301 _LOGGER.debug(
"Pause on %s", self.
namename)
302 await self.
dtvdtv.remote(
"pause", self.
_address_address)
305 """Send stop command."""
306 _LOGGER.debug(
"Stop on %s", self.
namename)
307 await self.
dtvdtv.remote(
"stop", self.
_address_address)
310 """Send rewind command."""
311 _LOGGER.debug(
"Rewind on %s", self.
namename)
312 await self.
dtvdtv.remote(
"rew", self.
_address_address)
315 """Send fast forward command."""
316 _LOGGER.debug(
"Fast forward on %s", self.
namename)
317 await self.
dtvdtv.remote(
"ffwd", self.
_address_address)
320 self, media_type: MediaType | str, media_id: str, **kwargs: Any
322 """Select input source."""
323 if media_type != MediaType.CHANNEL:
325 "Invalid media type %s. Only %s is supported",
331 _LOGGER.debug(
"Changing channel on %s to %s", self.
namename, media_id)
332 await self.
dtvdtv.tune(media_id, self.
_address_address)
str|UndefinedType|None name(self)