Fix PEP257 issues

This commit is contained in:
Fabian Affolter 2016-03-08 10:34:33 +01:00
parent 7f1e181c9b
commit cf7c2c492a
14 changed files with 460 additions and 473 deletions

View file

@ -1,7 +1,5 @@
"""
homeassistant.components.media_player.chromecast
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Provides functionality to interact with Cast devices on the network.
Provide functionality to interact with Cast devices on the network.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/media_player.cast/
@ -31,7 +29,7 @@ DEFAULT_PORT = 8009
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up the cast platform. """
"""Setup the cast platform."""
import pychromecast
logger = logging.getLogger(__name__)
@ -70,12 +68,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class CastDevice(MediaPlayerDevice):
""" Represents a Cast device on the network. """
"""Representation of a Cast device on the network."""
# pylint: disable=abstract-method
# pylint: disable=too-many-public-methods
def __init__(self, host, port):
"""Initialize the Cast device."""
import pychromecast
self.cast = pychromecast.Chromecast(host, port)
@ -86,22 +84,20 @@ class CastDevice(MediaPlayerDevice):
self.cast_status = self.cast.status
self.media_status = self.cast.media_controller.status
# Entity properties and methods
@property
def should_poll(self):
"""No polling needed."""
return False
@property
def name(self):
""" Returns the name of the device. """
"""Return the name of the device."""
return self.cast.device.friendly_name
# MediaPlayerDevice properties and methods
@property
def state(self):
""" State of the player. """
"""Return the state of the player."""
if self.media_status is None:
return STATE_UNKNOWN
elif self.media_status.player_is_playing:
@ -117,22 +113,22 @@ class CastDevice(MediaPlayerDevice):
@property
def volume_level(self):
""" Volume level of the media player (0..1). """
"""Volume level of the media player (0..1)."""
return self.cast_status.volume_level if self.cast_status else None
@property
def is_volume_muted(self):
""" Boolean if volume is currently muted. """
"""Boolean if volume is currently muted."""
return self.cast_status.volume_muted if self.cast_status else None
@property
def media_content_id(self):
""" Content ID of current playing media. """
"""Content ID of current playing media."""
return self.media_status.content_id if self.media_status else None
@property
def media_content_type(self):
""" Content type of current playing media. """
"""Content type of current playing media."""
if self.media_status is None:
return None
elif self.media_status.media_is_tvshow:
@ -145,12 +141,12 @@ class CastDevice(MediaPlayerDevice):
@property
def media_duration(self):
""" Duration of current playing media in seconds. """
"""Duration of current playing media in seconds."""
return self.media_status.duration if self.media_status else None
@property
def media_image_url(self):
""" Image url of current playing media. """
"""Image url of current playing media."""
if self.media_status is None:
return None
@ -160,61 +156,61 @@ class CastDevice(MediaPlayerDevice):
@property
def media_title(self):
""" Title of current playing media. """
"""Title of current playing media."""
return self.media_status.title if self.media_status else None
@property
def media_artist(self):
""" Artist of current playing media. (Music track only) """
"""Artist of current playing media (Music track only)."""
return self.media_status.artist if self.media_status else None
@property
def media_album(self):
""" Album of current playing media. (Music track only) """
"""Album of current playing media (Music track only)."""
return self.media_status.album_name if self.media_status else None
@property
def media_album_artist(self):
""" Album arist of current playing media. (Music track only) """
"""Album arist of current playing media (Music track only)."""
return self.media_status.album_artist if self.media_status else None
@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.media_status.track if self.media_status else None
@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.media_status.series_title if self.media_status else None
@property
def media_season(self):
""" Season of current playing media. (TV Show only) """
"""Season of current playing media (TV Show only)."""
return self.media_status.season if self.media_status else None
@property
def media_episode(self):
""" Episode of current playing media. (TV Show only) """
"""Episode of current playing media (TV Show only)."""
return self.media_status.episode if self.media_status else None
@property
def app_id(self):
""" ID of the current running app. """
"""Return the ID of the current running app."""
return self.cast.app_id
@property
def app_name(self):
""" Name of the current running app. """
"""Name of the current running app."""
return self.cast.app_display_name
@property
def supported_media_commands(self):
""" Flags of media commands that are supported. """
"""Flag of media commands that are supported."""
return SUPPORT_CAST
def turn_on(self):
""" Turns on the ChromeCast. """
"""Turn on the ChromeCast."""
# The only way we can turn the Chromecast is on is by launching an app
if not self.cast.status or not self.cast.status.is_active_input:
import pychromecast
@ -226,49 +222,48 @@ class CastDevice(MediaPlayerDevice):
CAST_SPLASH, pychromecast.STREAM_TYPE_BUFFERED)
def turn_off(self):
""" Turns Chromecast off. """
"""Turn Chromecast off."""
self.cast.quit_app()
def mute_volume(self, mute):
""" mute the volume. """
"""Mute the volume."""
self.cast.set_volume_muted(mute)
def set_volume_level(self, volume):
""" set volume level, range 0..1. """
"""Set volume level, range 0..1."""
self.cast.set_volume(volume)
def media_play(self):
""" Send play commmand. """
"""Send play commmand."""
self.cast.media_controller.play()
def media_pause(self):
""" Send pause command. """
"""Send pause command."""
self.cast.media_controller.pause()
def media_previous_track(self):
""" Send previous track command. """
"""Send previous track command."""
self.cast.media_controller.rewind()
def media_next_track(self):
""" Send next track command. """
"""Send next track command."""
self.cast.media_controller.skip()
def media_seek(self, position):
""" Seek the media to a specific location. """
"""Seek the media to a specific location."""
self.cast.media_controller.seek(position)
def play_media(self, media_type, media_id):
""" Plays media from a URL """
"""Play media from a URL."""
self.cast.media_controller.play_media(media_id, media_type)
# implementation of chromecast status_listener methods
# Implementation of chromecast status_listener methods
def new_cast_status(self, status):
""" Called when a new cast status is received. """
"""Called when a new cast status is received."""
self.cast_status = status
self.update_ha_state()
def new_media_status(self, status):
""" Called when a new media status is received. """
"""Called when a new media status is received."""
self.media_status = status
self.update_ha_state()