Fix PEP257 issues
This commit is contained in:
1 parent
7f1e181c9b
commit
cf7c2c492a
14 files changed
+460
-473
No files matched your search
@@ -1,7 +1,5 @@
|
||||
"""
|
||||
homeassistant.components.media_player.universal
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Combines multiple media players into one for a universal controller.
|
||||
Combination of multiple media players into one for a universal controller.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/media_player.universal/
|
||||
@@ -47,7 +45,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" sets up the universal media players """
|
||||
"""Setup the universal media players."""
|
||||
if not validate_config(config):
|
||||
return
|
||||
|
||||
@@ -61,10 +59,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
|
||||
|
||||
def validate_config(config):
|
||||
""" validate universal media player configuration """
|
||||
"""Validate universal media player configuration."""
|
||||
del config[CONF_PLATFORM]
|
||||
|
||||
# validate name
|
||||
# Validate name
|
||||
if CONF_NAME not in config:
|
||||
_LOGGER.error('Universal Media Player configuration requires name')
|
||||
return False
|
||||
@@ -87,7 +85,7 @@ def validate_config(config):
|
||||
|
||||
|
||||
def validate_children(config):
|
||||
""" validate children """
|
||||
"""Validate children."""
|
||||
if CONF_CHILDREN not in config:
|
||||
_LOGGER.info(
|
||||
'No children under Universal Media Player (%s)', config[CONF_NAME])
|
||||
@@ -101,7 +99,7 @@ def validate_children(config):
|
||||
|
||||
|
||||
def validate_commands(config):
|
||||
""" validate commands """
|
||||
"""Validate commands."""
|
||||
if CONF_COMMANDS not in config:
|
||||
config[CONF_COMMANDS] = {}
|
||||
elif not isinstance(config[CONF_COMMANDS], dict):
|
||||
@@ -113,7 +111,7 @@ def validate_commands(config):
|
||||
|
||||
|
||||
def validate_attributes(config):
|
||||
""" validate attributes """
|
||||
"""Validate attributes."""
|
||||
if CONF_ATTRS not in config:
|
||||
config[CONF_ATTRS] = {}
|
||||
elif not isinstance(config[CONF_ATTRS], dict):
|
||||
@@ -131,10 +129,11 @@ def validate_attributes(config):
|
||||
|
||||
|
||||
class UniversalMediaPlayer(MediaPlayerDevice):
|
||||
""" Represents a universal media player in HA """
|
||||
# pylint: disable=too-many-public-methods
|
||||
"""Representation of an universal media player."""
|
||||
|
||||
# pylint: disable=too-many-public-methods
|
||||
def __init__(self, hass, name, children, commands, attributes):
|
||||
"""Initialize the Universal media device."""
|
||||
# pylint: disable=too-many-arguments
|
||||
self.hass = hass
|
||||
self._name = name
|
||||
@@ -144,7 +143,7 @@ class UniversalMediaPlayer(MediaPlayerDevice):
|
||||
self._child_state = None
|
||||
|
||||
def on_dependency_update(*_):
|
||||
""" update ha state when dependencies update """
|
||||
"""Update ha state when dependencies update."""
|
||||
self.update_ha_state(True)
|
||||
|
||||
depend = copy(children)
|
||||
@@ -154,7 +153,7 @@ class UniversalMediaPlayer(MediaPlayerDevice):
|
||||
track_state_change(hass, depend, on_dependency_update)
|
||||
|
||||
def _entity_lkp(self, entity_id, state_attr=None):
|
||||
""" Looks up an entity state from hass """
|
||||
"""Look up an entity state."""
|
||||
state_obj = self.hass.states.get(entity_id)
|
||||
|
||||
if state_obj is None:
|
||||
@@ -165,7 +164,7 @@ class UniversalMediaPlayer(MediaPlayerDevice):
|
||||
return state_obj.state
|
||||
|
||||
def _override_or_child_attr(self, attr_name):
|
||||
""" returns either the override or the active child for attr_name """
|
||||
"""Return either the override or the active child for attr_name."""
|
||||
if attr_name in self._attrs:
|
||||
return self._entity_lkp(self._attrs[attr_name][0],
|
||||
self._attrs[attr_name][1])
|
||||
@@ -173,13 +172,13 @@ class UniversalMediaPlayer(MediaPlayerDevice):
|
||||
return self._child_attr(attr_name)
|
||||
|
||||
def _child_attr(self, attr_name):
|
||||
""" returns the active child's attr """
|
||||
"""Return the active child's attributes."""
|
||||
active_child = self._child_state
|
||||
return active_child.attributes.get(attr_name) if active_child else None
|
||||
|
||||
def _call_service(self, service_name, service_data=None,
|
||||
allow_override=False):
|
||||
""" calls either a specified or active child's service """
|
||||
"""Call either a specified or active child's service."""
|
||||
if allow_override and service_name in self._cmds:
|
||||
call_from_config(
|
||||
self.hass, self._cmds[service_name], blocking=True)
|
||||
@@ -196,12 +195,12 @@ class UniversalMediaPlayer(MediaPlayerDevice):
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
""" Indicates whether HA should poll for updates """
|
||||
"""No polling needed."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def master_state(self):
|
||||
""" gets the master state from entity or none """
|
||||
"""Get the master state from entity or none."""
|
||||
if CONF_STATE in self._attrs:
|
||||
master_state = self._entity_lkp(self._attrs[CONF_STATE][0],
|
||||
self._attrs[CONF_STATE][1])
|
||||
@@ -211,17 +210,16 @@ class UniversalMediaPlayer(MediaPlayerDevice):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" name of universal player """
|
||||
"""Return the name of universal player."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""
|
||||
Current state of media player
|
||||
"""Current state of media player.
|
||||
|
||||
Off if master state is off
|
||||
ELSE Status of first active child
|
||||
ELSE master state or off
|
||||
else Status of first active child
|
||||
else master state or off
|
||||
"""
|
||||
master_state = self.master_state # avoid multiple lookups
|
||||
if master_state == STATE_OFF:
|
||||
@@ -235,98 +233,98 @@ class UniversalMediaPlayer(MediaPlayerDevice):
|
||||
|
||||
@property
|
||||
def volume_level(self):
|
||||
""" Volume level of entity specified in attributes or active child """
|
||||
"""Volume level of entity specified in attributes or active child."""
|
||||
return self._child_attr(ATTR_MEDIA_VOLUME_LEVEL)
|
||||
|
||||
@property
|
||||
def is_volume_muted(self):
|
||||
""" boolean if volume is muted """
|
||||
"""Boolean if volume is muted."""
|
||||
return self._override_or_child_attr(ATTR_MEDIA_VOLUME_MUTED) \
|
||||
in [True, STATE_ON]
|
||||
|
||||
@property
|
||||
def media_content_id(self):
|
||||
""" Content ID of current playing media. """
|
||||
"""Content ID of current playing media."""
|
||||
return self._child_attr(ATTR_MEDIA_CONTENT_ID)
|
||||
|
||||
@property
|
||||
def media_content_type(self):
|
||||
""" Content type of current playing media. """
|
||||
"""Content type of current playing media."""
|
||||
return self._child_attr(ATTR_MEDIA_CONTENT_TYPE)
|
||||
|
||||
@property
|
||||
def media_duration(self):
|
||||
""" Duration of current playing media in seconds. """
|
||||
"""Duration of current playing media in seconds."""
|
||||
return self._child_attr(ATTR_MEDIA_DURATION)
|
||||
|
||||
@property
|
||||
def media_image_url(self):
|
||||
""" Image url of current playing media. """
|
||||
"""Image url of current playing media."""
|
||||
return self._child_attr(ATTR_ENTITY_PICTURE)
|
||||
|
||||
@property
|
||||
def media_title(self):
|
||||
""" Title of current playing media. """
|
||||
"""Title of current playing media."""
|
||||
return self._child_attr(ATTR_MEDIA_TITLE)
|
||||
|
||||
@property
|
||||
def media_artist(self):
|
||||
""" Artist of current playing media. (Music track only) """
|
||||
"""Artist of current playing media (Music track only)."""
|
||||
return self._child_attr(ATTR_MEDIA_ARTIST)
|
||||
|
||||
@property
|
||||
def media_album_name(self):
|
||||
""" Album name of current playing media. (Music track only) """
|
||||
"""Album name of current playing media (Music track only)."""
|
||||
return self._child_attr(ATTR_MEDIA_ALBUM_NAME)
|
||||
|
||||
@property
|
||||
def media_album_artist(self):
|
||||
""" Album arist of current playing media. (Music track only) """
|
||||
"""Album artist of current playing media (Music track only)."""
|
||||
return self._child_attr(ATTR_MEDIA_ALBUM_ARTIST)
|
||||
|
||||
@property
|
||||
def media_track(self):
|
||||
""" Track number of current playing media. (Music track only) """
|
||||
"""Track number of current playing media (Music track only)."""
|
||||
return self._child_attr(ATTR_MEDIA_TRACK)
|
||||
|
||||
@property
|
||||
def media_series_title(self):
|
||||
""" Series title of current playing media. (TV Show only)"""
|
||||
"""The title of the series of current playing media (TV Show only)."""
|
||||
return self._child_attr(ATTR_MEDIA_SERIES_TITLE)
|
||||
|
||||
@property
|
||||
def media_season(self):
|
||||
""" Season of current playing media. (TV Show only) """
|
||||
"""Season of current playing media (TV Show only)."""
|
||||
return self._child_attr(ATTR_MEDIA_SEASON)
|
||||
|
||||
@property
|
||||
def media_episode(self):
|
||||
""" Episode of current playing media. (TV Show only) """
|
||||
"""Episode of current playing media (TV Show only)."""
|
||||
return self._child_attr(ATTR_MEDIA_EPISODE)
|
||||
|
||||
@property
|
||||
def media_channel(self):
|
||||
""" Channel currently playing. """
|
||||
"""Channel currently playing."""
|
||||
return self._child_attr(ATTR_MEDIA_CHANNEL)
|
||||
|
||||
@property
|
||||
def media_playlist(self):
|
||||
""" Title of Playlist currently playing. """
|
||||
"""Title of Playlist currently playing."""
|
||||
return self._child_attr(ATTR_MEDIA_PLAYLIST)
|
||||
|
||||
@property
|
||||
def app_id(self):
|
||||
""" ID of the current running app. """
|
||||
"""ID of the current running app."""
|
||||
return self._child_attr(ATTR_APP_ID)
|
||||
|
||||
@property
|
||||
def app_name(self):
|
||||
""" Name of the current running app. """
|
||||
"""Name of the current running app."""
|
||||
return self._child_attr(ATTR_APP_NAME)
|
||||
|
||||
@property
|
||||
def supported_media_commands(self):
|
||||
""" Flags of media commands that are supported. """
|
||||
"""Flag of media commands that are supported."""
|
||||
flags = self._child_attr(ATTR_SUPPORTED_MEDIA_COMMANDS) or 0
|
||||
|
||||
if SERVICE_TURN_ON in self._cmds:
|
||||
@@ -347,69 +345,69 @@ class UniversalMediaPlayer(MediaPlayerDevice):
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
""" Extra attributes a device wants to expose. """
|
||||
"""Extra attributes a device wants to expose."""
|
||||
active_child = self._child_state
|
||||
return {ATTR_ACTIVE_CHILD: active_child.entity_id} \
|
||||
if active_child else {}
|
||||
|
||||
def turn_on(self):
|
||||
""" turn the media player on. """
|
||||
"""Turn the media player on."""
|
||||
self._call_service(SERVICE_TURN_ON, allow_override=True)
|
||||
|
||||
def turn_off(self):
|
||||
""" turn the media player off. """
|
||||
"""Turn the media player off."""
|
||||
self._call_service(SERVICE_TURN_OFF, allow_override=True)
|
||||
|
||||
def mute_volume(self, is_volume_muted):
|
||||
""" mute the volume. """
|
||||
"""Mute the volume."""
|
||||
data = {ATTR_MEDIA_VOLUME_MUTED: is_volume_muted}
|
||||
self._call_service(SERVICE_VOLUME_MUTE, data, allow_override=True)
|
||||
|
||||
def set_volume_level(self, volume_level):
|
||||
""" set volume level, range 0..1. """
|
||||
"""Set volume level, range 0..1."""
|
||||
data = {ATTR_MEDIA_VOLUME_LEVEL: volume_level}
|
||||
self._call_service(SERVICE_VOLUME_SET, data)
|
||||
|
||||
def media_play(self):
|
||||
""" Send play commmand. """
|
||||
"""Send play commmand."""
|
||||
self._call_service(SERVICE_MEDIA_PLAY)
|
||||
|
||||
def media_pause(self):
|
||||
""" Send pause command. """
|
||||
"""Send pause command."""
|
||||
self._call_service(SERVICE_MEDIA_PAUSE)
|
||||
|
||||
def media_previous_track(self):
|
||||
""" Send previous track command. """
|
||||
"""Send previous track command."""
|
||||
self._call_service(SERVICE_MEDIA_PREVIOUS_TRACK)
|
||||
|
||||
def media_next_track(self):
|
||||
""" Send next track command. """
|
||||
"""Send next track command."""
|
||||
self._call_service(SERVICE_MEDIA_NEXT_TRACK)
|
||||
|
||||
def media_seek(self, position):
|
||||
""" Send seek command. """
|
||||
"""Send seek command."""
|
||||
data = {ATTR_MEDIA_SEEK_POSITION: position}
|
||||
self._call_service(SERVICE_MEDIA_SEEK, data)
|
||||
|
||||
def play_media(self, media_type, media_id):
|
||||
""" Plays a piece of media. """
|
||||
"""Play a piece of media."""
|
||||
data = {'media_type': media_type, 'media_id': media_id}
|
||||
self._call_service(SERVICE_PLAY_MEDIA, data)
|
||||
|
||||
def volume_up(self):
|
||||
""" volume_up media player. """
|
||||
"""Volume up media player."""
|
||||
self._call_service(SERVICE_VOLUME_UP, allow_override=True)
|
||||
|
||||
def volume_down(self):
|
||||
""" volume_down media player. """
|
||||
"""Volume down media player."""
|
||||
self._call_service(SERVICE_VOLUME_DOWN, allow_override=True)
|
||||
|
||||
def media_play_pause(self):
|
||||
""" media_play_pause media player. """
|
||||
"""Send play/pause command media player."""
|
||||
self._call_service(SERVICE_MEDIA_PLAY_PAUSE)
|
||||
|
||||
def update(self):
|
||||
""" event to trigger a state update in HA """
|
||||
"""Event to trigger a state update."""
|
||||
for child_name in self._children:
|
||||
child_state = self.hass.states.get(child_name)
|
||||
if child_state and child_state.state not in OFF_STATES:
|
||||
|
||||
Reference in new issue
Block a user