core/homeassistant/components/directv/media_player.py

341 lines
9.8 KiB
Python
Raw Normal View History

"""Support for the DirecTV receivers."""
2021-03-17 22:43:55 +00:00
from __future__ import annotations
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
import logging
from directv import DIRECTV
from homeassistant.components.media_player import (
MediaPlayerDeviceClass,
MediaPlayerEntity,
)
from homeassistant.components.media_player.const import (
2019-07-31 19:25:30 +00:00
MEDIA_TYPE_CHANNEL,
MEDIA_TYPE_MOVIE,
MEDIA_TYPE_MUSIC,
2019-07-31 19:25:30 +00:00
MEDIA_TYPE_TVSHOW,
SUPPORT_NEXT_TRACK,
SUPPORT_PAUSE,
SUPPORT_PLAY,
SUPPORT_PLAY_MEDIA,
SUPPORT_PREVIOUS_TRACK,
SUPPORT_STOP,
SUPPORT_TURN_OFF,
SUPPORT_TURN_ON,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import STATE_OFF, STATE_PAUSED, STATE_PLAYING
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util import dt as dt_util
from .const import (
ATTR_MEDIA_CURRENTLY_RECORDING,
ATTR_MEDIA_RATING,
ATTR_MEDIA_RECORDED,
ATTR_MEDIA_START_TIME,
DOMAIN,
)
from .entity import DIRECTVEntity
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
_LOGGER = logging.getLogger(__name__)
KNOWN_MEDIA_TYPES = [MEDIA_TYPE_MOVIE, MEDIA_TYPE_MUSIC, MEDIA_TYPE_TVSHOW]
2019-07-31 19:25:30 +00:00
SUPPORT_DTV = (
SUPPORT_PAUSE
| SUPPORT_TURN_ON
| SUPPORT_TURN_OFF
| SUPPORT_PLAY_MEDIA
| SUPPORT_STOP
| SUPPORT_NEXT_TRACK
| SUPPORT_PREVIOUS_TRACK
| SUPPORT_PLAY
)
SUPPORT_DTV_CLIENT = (
SUPPORT_PAUSE
| SUPPORT_PLAY_MEDIA
| SUPPORT_STOP
| SUPPORT_NEXT_TRACK
| SUPPORT_PREVIOUS_TRACK
| SUPPORT_PLAY
)
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the DirecTV config entry."""
dtv = hass.data[DOMAIN][entry.entry_id]
entities = []
Add available property to DirecTV (#18168) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Fix issue in checking if DTV device is already configured If a DTV device was configured before, then discovery would add this device again seperately if the name specified in the configuration is different from the name on the DTV. This issue is fixed now. Part of the fix also ensure to allow multiple "primary" devices on the network to be discovered. Further also added debug logging to the setup_platform. * Further improvements Some additional improvements related to handling the DATA_DIRECTV in hass.data. * Fixed flake8 issue Fixed flake8 issue * Added available property Added available property * Updated to use get_locations() Replaced doing the request for getLocations with the get_locations() API from DirectPy instead. * Fix for checking if device is available Fix for checking if device is available and small update to debug log message. * Fixed lint issue Fixed lint issue with unused variable by adding ingore for it as this is for a enumerate * Updated try/except and removed available Updated tr/except having the except by the statement we're doing except on. Removed available, will be a different PR. * Add available property Add the available property to the entiry.
2018-11-05 15:19:03 +00:00
for location in dtv.device.locations:
entities.append(
DIRECTVMediaPlayer(
2020-08-27 11:56:20 +00:00
dtv=dtv,
name=str.title(location.name),
address=location.address,
)
)
async_add_entities(entities, True)
class DIRECTVMediaPlayer(DIRECTVEntity, MediaPlayerEntity):
"""Representation of a DirecTV receiver on the network."""
def __init__(self, *, dtv: DIRECTV, name: str, address: str = "0") -> None:
"""Initialize DirecTV media player."""
super().__init__(
2020-08-27 11:56:20 +00:00
dtv=dtv,
address=address,
)
self._attr_unique_id = self._device_id
self._attr_name = name
self._attr_device_class = MediaPlayerDeviceClass.RECEIVER
self._attr_available = False
self._is_recorded = None
self._is_standby = True
self._last_position = None
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
self._last_update = None
self._paused = None
self._program = None
self._state = None
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
async def async_update(self):
"""Retrieve latest state."""
self._state = await self.dtv.state(self._address)
self._attr_available = self._state.available
self._is_standby = self._state.standby
self._program = self._state.program
if self._is_standby:
self._attr_assumed_state = False
self._is_recorded = None
self._last_position = None
self._last_update = None
self._paused = None
elif self._program is not None:
self._paused = self._last_position == self._program.position
self._is_recorded = self._program.recorded
self._last_position = self._program.position
self._last_update = self._state.at
self._attr_assumed_state = self._is_recorded
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
@property
def extra_state_attributes(self):
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
"""Return device specific state attributes."""
if self._is_standby:
return {}
return {
ATTR_MEDIA_CURRENTLY_RECORDING: self.media_currently_recording,
ATTR_MEDIA_RATING: self.media_rating,
ATTR_MEDIA_RECORDED: self.media_recorded,
ATTR_MEDIA_START_TIME: self.media_start_time,
}
# MediaPlayerEntity properties and methods
@property
def state(self):
"""Return the state of the device."""
if self._is_standby:
return STATE_OFF
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
# For recorded media we can determine if it is paused or not.
# For live media we're unable to determine and will always return
# playing instead.
if self._paused:
return STATE_PAUSED
return STATE_PLAYING
@property
def media_content_id(self):
"""Return the content ID of current playing media."""
if self._is_standby or self._program is None:
return None
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
return self._program.program_id
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
@property
def media_content_type(self):
"""Return the content type of current playing media."""
if self._is_standby or self._program is None:
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
return None
if self._program.program_type in KNOWN_MEDIA_TYPES:
return self._program.program_type
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
return MEDIA_TYPE_MOVIE
@property
def media_duration(self):
"""Return the duration of current playing media in seconds."""
if self._is_standby or self._program is None:
return None
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
return self._program.duration
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
@property
def media_position(self):
"""Position of current playing media in seconds."""
if self._is_standby:
return None
return self._last_position
@property
def media_position_updated_at(self):
"""When was the position of the current playing media valid."""
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
if self._is_standby:
return None
return self._last_update
@property
def media_title(self):
"""Return the title of current playing media."""
if self._is_standby or self._program is None:
return None
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
if self.media_content_type == MEDIA_TYPE_MUSIC:
return self._program.music_title
return self._program.title
@property
def media_artist(self):
"""Artist of current playing media, music track only."""
if self._is_standby or self._program is None:
return None
return self._program.music_artist
@property
def media_album_name(self):
"""Album name of current playing media, music track only."""
if self._is_standby or self._program is None:
return None
return self._program.music_album
@property
def media_series_title(self):
"""Return the title of current episode of TV show."""
if self._is_standby or self._program is None:
return None
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
return self._program.episode_title
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
@property
def media_channel(self):
"""Return the channel current playing media."""
if self._is_standby or self._program is None:
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
return None
return f"{self._program.channel_name} ({self._program.channel})"
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
@property
def source(self):
"""Name of the current input source."""
if self._is_standby or self._program is None:
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
return None
return self._program.channel
@property
def supported_features(self):
"""Flag media player features that are supported."""
return SUPPORT_DTV_CLIENT if self._is_client else SUPPORT_DTV
@property
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
def media_currently_recording(self):
"""If the media is currently being recorded or not."""
if self._is_standby or self._program is None:
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
return None
return self._program.recording
@property
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
def media_rating(self):
"""TV Rating of the current playing media."""
if self._is_standby or self._program is None:
return None
return self._program.rating
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
@property
def media_recorded(self):
"""If the media was recorded or live."""
if self._is_standby:
return None
return self._is_recorded
@property
def media_start_time(self):
"""Start time the program aired."""
if self._is_standby or self._program is None:
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
return None
return dt_util.as_local(self._program.start_time)
async def async_turn_on(self):
"""Turn on the receiver."""
if self._is_client:
raise NotImplementedError()
_LOGGER.debug("Turn on %s", self.name)
await self.dtv.remote("poweron", self._address)
async def async_turn_off(self):
"""Turn off the receiver."""
if self._is_client:
raise NotImplementedError()
_LOGGER.debug("Turn off %s", self.name)
await self.dtv.remote("poweroff", self._address)
async def async_media_play(self):
"""Send play command."""
_LOGGER.debug("Play on %s", self.name)
await self.dtv.remote("play", self._address)
async def async_media_pause(self):
"""Send pause command."""
_LOGGER.debug("Pause on %s", self.name)
await self.dtv.remote("pause", self._address)
async def async_media_stop(self):
"""Send stop command."""
_LOGGER.debug("Stop on %s", self.name)
await self.dtv.remote("stop", self._address)
async def async_media_previous_track(self):
"""Send rewind command."""
_LOGGER.debug("Rewind on %s", self.name)
await self.dtv.remote("rew", self._address)
async def async_media_next_track(self):
"""Send fast forward command."""
_LOGGER.debug("Fast forward on %s", self.name)
await self.dtv.remote("ffwd", self._address)
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
async def async_play_media(self, media_type, media_id, **kwargs):
Change source, add attributes, and improve state of DirecTV (#17536) * Enhancements for DirecTV media player Following enhancements have been made: 1. Added debug logging 2. Added ability to change channel using select_source service of the remote platform. 3. State will now show paused if a recorded program is paused, for live TV playing will always be returned. 4. Added the following attributes: a. media_position: current position of the media (in seconds) b. media_position_updated_at: timestamp when media_position was updated. c. source: current source (channel). d. media_isbeingrecorded: if current media is being recorded or not. e. media_rating: TV/Movie rating of the media f. media_recorded: if current media is recorded or live TV g. media_starttime: Timestamp media was aired Reordered properties to follow same order as how they are in __init__.py of remote platform. * Fixed error and cleaned up few items Fixed an issue when determining if a program is recorded or not. Cleaned up some coding. * Attribute last position update only updated when position changed. The attribute media_position_updated_at will only be updated if the position changed (thus media is playing for recorded or live TV). Added assumed_state; will be set to False if in standby or when a recorded show is watched. For live TV it will be set to True. * Added some empty lines for easier reading Added some empty lines before returns to improve readability. * Seperated words in constants Seperated the words in constants. * Fix _lastupdate to _last_update Split words in _lastupdate to _last_update as I missed it.
2018-10-29 20:06:37 +00:00
"""Select input source."""
if media_type != MEDIA_TYPE_CHANNEL:
2019-07-31 19:25:30 +00:00
_LOGGER.error(
"Invalid media type %s. Only %s is supported",
media_type,
MEDIA_TYPE_CHANNEL,
)
return
_LOGGER.debug("Changing channel on %s to %s", self.name, media_id)
await self.dtv.tune(media_id, self._address)