desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'When was the position of the current playing media valid. Returns value from homeassistant.util.dt.utcnow().'
@property def media_position_updated_at(self):
return self.media_status_received
'Turn on the ChromeCast.'
def turn_on(self):
if ((not self.cast.status) or (not self.cast.status.is_active_input)): import pychromecast if self.cast.app_id: self.cast.quit_app() self.cast.play_media(CAST_SPLASH, pychromecast.STREAM_TYPE_BUFFERED)
'Turn Chromecast off.'
def turn_off(self):
self.cast.quit_app()
'Mute the volume.'
def mute_volume(self, mute):
self.cast.set_volume_muted(mute)
'Set volume level, range 0..1.'
def set_volume_level(self, volume):
self.cast.set_volume(volume)
'Send play commmand.'
def media_play(self):
self.cast.media_controller.play()
'Send pause command.'
def media_pause(self):
self.cast.media_controller.pause()
'Send stop command.'
def media_stop(self):
self.cast.media_controller.stop()
'Send previous track command.'
def media_previous_track(self):
self.cast.media_controller.rewind()
'Send next track command.'
def media_next_track(self):
self.cast.media_controller.skip()
'Seek the media to a specific location.'
def media_seek(self, position):
self.cast.media_controller.seek(position)
'Play media from a URL.'
def play_media(self, media_type, media_id, **kwargs):
self.cast.media_controller.play_media(media_id, media_type)
'Handle updates of the cast status.'
def new_cast_status(self, status):
self.cast_status = status self.schedule_update_ha_state()
'Handle updates of the media status.'
def new_media_status(self, status):
self.media_status = status self.media_status_received = dt_util.utcnow() self.schedule_update_ha_state()
'Initialize entity to control Dune HD.'
def __init__(self, player, name, sources):
self._player = player self._name = name self._sources = sources self._media_title = None self._state = None
'Update internal status of the entity.'
def update(self):
self._state = self._player.update_state() self.__update_title() return True
'Return player state.'
@property def state(self):
state = STATE_OFF if ('playback_position' in self._state): state = STATE_PLAYING if (self._state['player_state'] in ('playing', 'buffering')): state = STATE_PLAYING if (int(self._state.get('playback_speed', 1234)) == 0): state = STATE_PAUSED if (self._state['player_state'] ==...
'Return the name of the device.'
@property def name(self):
return self._name
'Return the volume level of the media player (0..1).'
@property def volume_level(self):
return (int(self._state.get('playback_volume', 0)) / 100)
'Return a boolean if volume is currently muted.'
@property def is_volume_muted(self):
return (int(self._state.get('playback_mute', 0)) == 1)
'Return a list of available input sources.'
@property def source_list(self):
return list(self._sources.keys())
'Flag media player features that are supported.'
@property def supported_features(self):
return DUNEHD_PLAYER_SUPPORT
'Volume up media player.'
def volume_up(self):
self._state = self._player.volume_up()
'Volume down media player.'
def volume_down(self):
self._state = self._player.volume_down()
'Mute/unmute player volume.'
def mute_volume(self, mute):
self._state = self._player.mute(mute)
'Turn off media player.'
def turn_off(self):
self._media_title = None self._state = self._player.turn_off() self.schedule_update_ha_state()
'Turn off media player.'
def turn_on(self):
self._state = self._player.turn_on() self.schedule_update_ha_state()
'Play media media player.'
def media_play(self):
self._state = self._player.play() self.schedule_update_ha_state()
'Pause media player.'
def media_pause(self):
self._state = self._player.pause() self.schedule_update_ha_state()
'Return the current media source.'
@property def media_title(self):
self.__update_title() if self._media_title: return self._media_title return self._state.get('playback_url', 'Not playing')
'Select input source.'
def select_source(self, source):
self._media_title = source self._state = self._player.launch_media_url(self._sources.get(source)) self.schedule_update_ha_state()
'Send previous track command.'
def media_previous_track(self):
self._state = self._player.previous_track() self.schedule_update_ha_state()
'Send next track command.'
def media_next_track(self):
self._state = self._player.next_track() self.schedule_update_ha_state()
'Initialize Vizio device.'
def __init__(self, host, token, name, volume_step):
import pyvizio self._device = pyvizio.Vizio(DEVICE_ID, host, DEFAULT_NAME, token) self._name = name self._state = STATE_UNKNOWN self._volume_level = None self._volume_step = volume_step self._current_input = None self._available_inputs = None
'Retrieve latest state of the TV.'
@util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS) def update(self):
is_on = self._device.get_power_state() if (is_on is None): self._state = STATE_UNKNOWN return elif (is_on is False): self._state = STATE_OFF else: self._state = STATE_ON self._volume_level = self._device.get_current_volume() input_ = self._device.get_current_input...
'Return the state of the TV.'
@property def state(self):
return self._state
'Return the name of the TV.'
@property def name(self):
return self._name
'Return the volume level of the TV.'
@property def volume_level(self):
return self._volume_level
'Return current input of the TV.'
@property def source(self):
return self._current_input
'Return list of available inputs of the TV.'
@property def source_list(self):
return self._available_inputs
'Flag TV features that are supported.'
@property def supported_features(self):
return SUPPORTED_COMMANDS
'Turn the TV player on.'
def turn_on(self):
self._device.pow_on()
'Turn the TV player off.'
def turn_off(self):
self._device.pow_off()
'Mute the volume.'
def mute_volume(self, mute):
if mute: self._device.mute_on() else: self._device.mute_off()
'Send previous channel command.'
def media_previous_track(self):
self._device.ch_down()
'Send next channel command.'
def media_next_track(self):
self._device.ch_up()
'Select input source.'
def select_source(self, source):
self._device.input_switch(source)
'Increasing volume of the TV.'
def volume_up(self):
self._device.vol_up(num=self._volume_step)
'Decreasing volume of the TV.'
def volume_down(self):
self._device.vol_down(num=self._volume_step)
'Validating if host is available and key is correct.'
def validate_setup(self):
return (self._device.get_current_volume() is not None)
'Initialize the FireTV server.'
def __init__(self, proto, host, port, device_id):
self.proto = proto self.host = host self.port = port self.device_id = device_id
'Get the device state. An exception means UNKNOWN state.'
@property def state(self):
try: response = requests.get(DEVICE_STATE_URL.format(self.proto, self.host, self.port, self.device_id), timeout=10).json() return response.get('state', STATE_UNKNOWN) except requests.exceptions.RequestException: _LOGGER.error('Could not retrieve device state for %s', se...
'Perform an action on the device.'
def action(self, action_id):
try: requests.get(DEVICE_ACTION_URL.format(self.proto, self.host, self.port, self.device_id, action_id), timeout=10) except requests.exceptions.RequestException: _LOGGER.error('Action request for %s was not accepted for device %s', action_id, self.device_id)
'Initialize the FireTV device.'
def __init__(self, proto, host, port, device, name):
self._firetv = FireTV(proto, host, port, device) self._name = name self._state = STATE_UNKNOWN
'Return the device name.'
@property def name(self):
return self._name
'Device should be polled.'
@property def should_poll(self):
return True
'Flag media player features that are supported.'
@property def supported_features(self):
return SUPPORT_FIRETV
'Return the state of the player.'
@property def state(self):
return self._state
'Get the latest date and update device state.'
def update(self):
self._state = {'idle': STATE_IDLE, 'off': STATE_OFF, 'play': STATE_PLAYING, 'pause': STATE_PAUSED, 'standby': STATE_STANDBY, 'disconnected': STATE_UNKNOWN}.get(self._firetv.state, STATE_UNKNOWN)
'Turn on the device.'
def turn_on(self):
self._firetv.action('turn_on')
'Turn off the device.'
def turn_off(self):
self._firetv.action('turn_off')
'Send play command.'
def media_play(self):
self._firetv.action('media_play')
'Send pause command.'
def media_pause(self):
self._firetv.action('media_pause')
'Send play/pause command.'
def media_play_pause(self):
self._firetv.action('media_play_pause')
'Send volume up command.'
def volume_up(self):
self._firetv.action('volume_up')
'Send volume down command.'
def volume_down(self):
self._firetv.action('volume_down')
'Send previous track command (results in rewind).'
def media_previous_track(self):
self._firetv.action('media_previous')
'Send next track command (results in fast-forward).'
def media_next_track(self):
self._firetv.action('media_next')
'Initialize the iTunes device.'
def __init__(self, host, port, use_ssl):
self.host = host self.port = port self.use_ssl = use_ssl
'Return the base url for endpoints.'
@property def _base_url(self):
if self.use_ssl: uri_scheme = 'https://' else: uri_scheme = 'http://' if self.port: return '{}{}:{}'.format(uri_scheme, self.host, self.port) return '{}{}'.format(uri_scheme, self.host)
'Make the actual request and return the parsed response.'
def _request(self, method, path, params=None):
url = '{}{}'.format(self._base_url, path) try: if (method == 'GET'): response = requests.get(url, timeout=DEFAULT_TIMEOUT) elif (method == 'POST'): response = requests.put(url, params, timeout=DEFAULT_TIMEOUT) elif (method == 'PUT'): response = request...
'Make a request for a controlling command.'
def _command(self, named_command):
return self._request('PUT', ('/' + named_command))
'Return the current state.'
def now_playing(self):
return self._request('GET', '/now_playing')
'Set the volume and returns the current state, level 0-100.'
def set_volume(self, level):
return self._request('PUT', '/volume', {'level': level})
'Mute and returns the current state, muted True or False.'
def set_muted(self, muted):
return self._request('PUT', '/mute', {'muted': muted})
'Set playback to play and returns the current state.'
def play(self):
return self._command('play')
'Set playback to paused and returns the current state.'
def pause(self):
return self._command('pause')
'Skip to the next track and returns the current state.'
def next(self):
return self._command('next')
'Skip back and returns the current state.'
def previous(self):
return self._command('previous')
'Set a playlist to be current and returns the current state.'
def play_playlist(self, playlist_id_or_name):
response = self._request('GET', '/playlists') playlists = response.get('playlists', []) found_playlists = [playlist for playlist in playlists if (playlist_id_or_name in [playlist['name'], playlist['id']])] if found_playlists: playlist = found_playlists[0] path = (('/playlists/' + playlis...
'Return a URL of the current track\'s album art.'
def artwork_url(self):
return (self._base_url + '/artwork')
'Return a list of AirPlay devices.'
def airplay_devices(self):
return self._request('GET', '/airplay_devices')
'Return an AirPlay device.'
def airplay_device(self, device_id):
return self._request('GET', ('/airplay_devices/' + device_id))
'Toggle airplay device on or off, id, toggle True or False.'
def toggle_airplay_device(self, device_id, toggle):
command = ('on' if toggle else 'off') path = ((('/airplay_devices/' + device_id) + '/') + command) return self._request('PUT', path)
'Set volume, returns current state of device, id,level 0-100.'
def set_volume_airplay_device(self, device_id, level):
path = (('/airplay_devices/' + device_id) + '/volume') return self._request('PUT', path, {'level': level})
'Initialize the iTunes device.'
def __init__(self, name, host, port, use_ssl, add_devices):
self._name = name self._host = host self._port = port self._use_ssl = use_ssl self._add_devices = add_devices self.client = Itunes(self._host, self._port, self._use_ssl) self.current_volume = None self.muted = None self.current_title = None self.current_album = None self.curr...
'Update all the state properties with the passed in dictionary.'
def update_state(self, state_hash):
self.player_state = state_hash.get('player_state', None) self.current_volume = state_hash.get('volume', 0) self.muted = state_hash.get('muted', None) self.current_title = state_hash.get('name', None) self.current_album = state_hash.get('album', None) self.current_artist = state_hash.get('artist'...
'Return the name of the device.'
@property def name(self):
return self._name
'Return the state of the device.'
@property def state(self):
if ((self.player_state == 'offline') or (self.player_state is None)): return 'offline' if (self.player_state == 'error'): return 'error' if (self.player_state == 'stopped'): return STATE_IDLE if (self.player_state == 'paused'): return STATE_PAUSED return STATE_PLAYING...
'Retrieve latest state.'
def update(self):
now_playing = self.client.now_playing() self.update_state(now_playing) found_devices = self.client.airplay_devices() found_devices = found_devices.get('airplay_devices', []) new_devices = [] for device_data in found_devices: device_id = device_data.get('id') if self.airplay_devic...
'Boolean if volume is currently muted.'
@property def is_volume_muted(self):
return self.muted
'Volume level of the media player (0..1).'
@property def volume_level(self):
return (self.current_volume / 100.0)
'Content ID of current playing media.'
@property def media_content_id(self):
return self.content_id
'Content type of current playing media.'
@property def media_content_type(self):
return MEDIA_TYPE_MUSIC
'Image url of current playing media.'
@property def media_image_url(self):
if ((self.player_state in (STATE_PLAYING, STATE_IDLE, STATE_PAUSED)) and (self.current_title is not None)): return self.client.artwork_url() return 'https://cloud.githubusercontent.com/assets/260/9829355/33fab972-58cf-11e5-8ea2-2ca74bdaae40.png'
'Title of current playing media.'
@property def media_title(self):
return self.current_title
'Artist of current playing media (Music track only).'
@property def media_artist(self):
return self.current_artist
'Album of current playing media (Music track only).'
@property def media_album_name(self):
return self.current_album
'Title of the currently playing playlist.'
@property def media_playlist(self):
return self.current_playlist
'Flag media player features that are supported.'
@property def supported_features(self):
return SUPPORT_ITUNES