desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Set volume level, range 0..1.'
def set_volume_level(self, volume):
response = self.client.set_volume(int((volume * 100))) self.update_state(response)
'Mute (true) or unmute (false) media player.'
def mute_volume(self, mute):
response = self.client.set_muted(mute) self.update_state(response)
'Send media_play command to media player.'
def media_play(self):
response = self.client.play() self.update_state(response)
'Send media_pause command to media player.'
def media_pause(self):
response = self.client.pause() self.update_state(response)
'Send media_next command to media player.'
def media_next_track(self):
response = self.client.next() self.update_state(response)
'Send media_previous command media player.'
def media_previous_track(self):
response = self.client.previous() self.update_state(response)
'Send the play_media command to the media player.'
def play_media(self, media_type, media_id, **kwargs):
if (media_type == MEDIA_TYPE_PLAYLIST): response = self.client.play_playlist(media_id) self.update_state(response)
'Initialize the AirPlay device.'
def __init__(self, device_id, client):
self._id = device_id self.client = client self.device_name = 'AirPlay' self.kind = None self.active = False self.selected = False self.volume = 0 self.supports_audio = False self.supports_video = False self.player_state = None
'Update all the state properties with the passed in dictionary.'
def update_state(self, state_hash):
if ('player_state' in state_hash): self.player_state = state_hash.get('player_state', None) if ('name' in state_hash): name = state_hash.get('name', '') self.device_name = (name + ' AirTunes Speaker').strip() if ('kind' in state_hash): self.kind = state_hash.get('kind',...
'Return the name of the device.'
@property def name(self):
return self.device_name
'Return the icon to use in the frontend, if any.'
@property def icon(self):
if (self.selected is True): return 'mdi:volume-high' return 'mdi:volume-off'
'Return the state of the device.'
@property def state(self):
if (self.selected is True): return STATE_ON return STATE_OFF
'Return the volume.'
@property def volume_level(self):
return (float(self.volume) / 100.0)
'Flag of media content that is supported.'
@property def media_content_type(self):
return MEDIA_TYPE_MUSIC
'Flag media player features that are supported.'
@property def supported_features(self):
return SUPPORT_AIRPLAY
'Set volume level, range 0..1.'
def set_volume_level(self, volume):
volume = int((volume * 100)) response = self.client.set_volume_airplay_device(self._id, volume) self.update_state(response)
'Select AirPlay.'
def turn_on(self):
self.update_state({'selected': True}) self.schedule_update_ha_state() response = self.client.toggle_airplay_device(self._id, True) self.update_state(response)
'Deselect AirPlay.'
def turn_off(self):
self.update_state({'selected': False}) self.schedule_update_ha_state() response = self.client.toggle_airplay_device(self._id, False) self.update_state(response)
'Initialize the Frontier Silicon API device.'
def __init__(self, device_url, password):
self._device_url = device_url self._password = password self._state = STATE_UNKNOWN self._name = None self._title = None self._artist = None self._album_name = None self._mute = None self._source = None self._source_list = None self._media_image_url = None
'Create a fresh fsapi session. A new session is created for each request in case someone else connected to the device in between the updates and invalidated the existing session (i.e UNDOK).'
@property def fs_device(self):
from fsapi import FSAPI return FSAPI(self._device_url, self._password)
'Device should be polled.'
@property def should_poll(self):
return True
'Return the device name.'
@property def name(self):
return self._name
'Title of current playing media.'
@property def media_title(self):
return self._title
'Artist of current playing media, music track only.'
@property def media_artist(self):
return self._artist
'Album name of current playing media, music track only.'
@property def media_album_name(self):
return self._album_name
'Content type of current playing media.'
@property def media_content_type(self):
return MEDIA_TYPE_MUSIC
'Flag of media commands that are supported.'
@property def supported_features(self):
return SUPPORT_FRONTIER_SILICON
'Return the state of the player.'
@property def state(self):
return self._state
'List of available input sources.'
@property def source_list(self):
return self._source_list
'Name of the current input source.'
@property def source(self):
return self._source
'Image url of current playing media.'
@property def media_image_url(self):
return self._media_image_url
'Get the latest date and update device state.'
def update(self):
fs_device = self.fs_device if (not self._name): self._name = fs_device.friendly_name if (not self._source_list): self._source_list = fs_device.mode_list status = fs_device.play_status self._state = {'playing': STATE_PLAYING, 'paused': STATE_PAUSED, 'stopped': STATE_OFF, 'unknown': ST...
'Turn on the device.'
def turn_on(self):
self.fs_device.power = True
'Turn off the device.'
def turn_off(self):
self.fs_device.power = False
'Send play command.'
def media_play(self):
self.fs_device.play()
'Send pause command.'
def media_pause(self):
self.fs_device.pause()
'Send play/pause command.'
def media_play_pause(self):
if ('playing' in self._state): self.fs_device.pause() else: self.fs_device.play()
'Send play/pause command.'
def media_stop(self):
self.fs_device.pause()
'Send previous track command (results in rewind).'
def media_previous_track(self):
self.fs_device.prev()
'Send next track command (results in fast-forward).'
def media_next_track(self):
self.fs_device.next()
'Boolean if volume is currently muted.'
@property def is_volume_muted(self):
return self._mute
'Send mute command.'
def mute_volume(self, mute):
self.fs_device.mute = mute
'Send volume up command.'
def volume_up(self):
self.fs_device.volume += 1
'Send volume down command.'
def volume_down(self):
self.fs_device.volume -= 1
'Set volume command.'
def set_volume_level(self, volume):
self.fs_device.volume = volume
'Select input source.'
def select_source(self, source):
self.fs_device.mode = source
'Initialize the Pandora device.'
def __init__(self, name):
MediaPlayerDevice.__init__(self) self._name = name self._player_state = STATE_OFF self._station = '' self._media_title = '' self._media_artist = '' self._media_album = '' self._stations = [] self._time_remaining = 0 self._media_duration = 0 self._pianobar = None
'Return the polling state.'
@property def should_poll(self):
return True
'Return the name of the media player.'
@property def name(self):
return self._name
'Return the state of the player.'
@property def state(self):
return self._player_state
'Turn the media player on.'
def turn_on(self):
import pexpect if (self._player_state != STATE_OFF): return self._pianobar = pexpect.spawn('pianobar') _LOGGER.info('Started pianobar subprocess') mode = self._pianobar.expect(['Receiving new playlist', 'Select station:', 'Email:']) if (mode == 1): self._pianobar.s...
'Turn the media player off.'
def turn_off(self):
import pexpect if (self._pianobar is None): _LOGGER.info('Pianobar subprocess already stopped') return self._pianobar.send('q') try: _LOGGER.debug('Stopped Pianobar subprocess') self._pianobar.terminate() except pexpect.exceptions.TIMEOUT: os.ki...
'Send play command.'
def media_play(self):
self._send_pianobar_command(SERVICE_MEDIA_PLAY_PAUSE) self._player_state = STATE_PLAYING self.schedule_update_ha_state()
'Send pause command.'
def media_pause(self):
self._send_pianobar_command(SERVICE_MEDIA_PLAY_PAUSE) self._player_state = STATE_PAUSED self.schedule_update_ha_state()
'Go to next track.'
def media_next_track(self):
self._send_pianobar_command(SERVICE_MEDIA_NEXT_TRACK) self.schedule_update_ha_state()
'Flag media player features that are supported.'
@property def supported_features(self):
return PANDORA_SUPPORT
'Name of the current input source.'
@property def source(self):
return self._station
'List of available input sources.'
@property def source_list(self):
return self._stations
'Title of current playing media.'
@property def media_title(self):
self.update_playing_status() return self._media_title
'Content type of current playing media.'
@property def media_content_type(self):
return MEDIA_TYPE_MUSIC
'Artist of current playing media, music track only.'
@property def media_artist(self):
return self._media_artist
'Album name of current playing media, music track only.'
@property def media_album_name(self):
return self._media_album
'Duration of current playing media in seconds.'
@property def media_duration(self):
return self._media_duration
'Choose a different Pandora station and play it.'
def select_source(self, source):
try: station_index = self._stations.index(source) except ValueError: _LOGGER.warning('Station %s is not in list', source) return _LOGGER.debug('Setting station %s, %d', source, station_index) self._send_station_list_command() self._pianobar.sendline('{...
'Send a station list command.'
def _send_station_list_command(self):
import pexpect self._pianobar.send('s') try: self._pianobar.expect('Select station:', timeout=1) except pexpect.exceptions.TIMEOUT: self._clear_buffer() self._pianobar.send('s') self._pianobar.expect('Select station:')
'Query pianobar for info about current media_title, station.'
def update_playing_status(self):
response = self._query_for_playing_status() if (not response): return self._update_current_station(response) self._update_current_song(response) self._update_song_position()
'Query system for info about current track.'
def _query_for_playing_status(self):
import pexpect self._clear_buffer() self._pianobar.send('i') try: match_idx = self._pianobar.expect(['(\\d\\d):(\\d\\d)/(\\d\\d):(\\d\\d)', 'No song playing', 'Select station', 'Receiving new playlist']) except pexpect.exceptions.EOF: _LOGGER.info('Pianobar process ...
'Update current station.'
def _update_current_station(self, response):
station_match = re.search(STATION_PATTERN, response) if station_match: self._station = station_match.group(1) _LOGGER.debug('Got station as: %s', self._station) else: _LOGGER.warning('No station match')
'Update info about current song.'
def _update_current_song(self, response):
song_match = re.search(CURRENT_SONG_PATTERN, response) if song_match: (self._media_title, self._media_artist, self._media_album) = song_match.groups() _LOGGER.debug('Got song as: %s', self._media_title) else: _LOGGER.warning('No song match')
'Get the song position and duration. It\'s hard to predict whether or not the music will start during init so we have to detect state by checking the ticker.'
@util.Throttle(MIN_TIME_BETWEEN_UPDATES) def _update_song_position(self):
(cur_minutes, cur_seconds, total_minutes, total_seconds) = self._pianobar.match.groups() time_remaining = ((int(cur_minutes) * 60) + int(cur_seconds)) self._media_duration = ((int(total_minutes) * 60) + int(total_seconds)) if ((time_remaining != self._time_remaining) and (time_remaining != self._media_d...
'Log grabbed values from console.'
def _log_match(self):
_LOGGER.debug('Before: %s\nMatch: %s\nAfter: %s', repr(self._pianobar.before), repr(self._pianobar.match), repr(self._pianobar.after))
'Send a command to Pianobar.'
def _send_pianobar_command(self, service_cmd):
command = CMD_MAP.get(service_cmd) _LOGGER.debug('Sending pinaobar command %s for %s', command, service_cmd) if (command is None): _LOGGER.info('Command %s not supported yet', service_cmd) self._clear_buffer() self._pianobar.sendline(command)
'List defined Pandora stations.'
def _update_stations(self):
self._send_station_list_command() station_lines = self._pianobar.before.decode('utf-8') _LOGGER.debug('Getting stations: %s', station_lines) self._stations = [] for line in station_lines.split('\r\n'): match = re.search('\\d+\\).....(.+)', line) if match: station = ...
'Clear buffer from pexpect. This is necessary because there are a bunch of 00:00 in the buffer'
def _clear_buffer(self):
import pexpect try: while (not self._pianobar.expect('.+', timeout=0.1)): pass except pexpect.exceptions.TIMEOUT: pass except pexpect.exceptions.EOF: pass
'Initialize the Onkyo Receiver.'
def __init__(self, receiver, sources, name=None):
self._receiver = receiver self._muted = False self._volume = 0 self._pwstate = STATE_OFF self._name = (name or '{}_{}'.format(receiver.info['model_name'], receiver.info['identifier'])) self._current_source = None self._source_list = list(sources.values()) self._source_mapping = sources ...
'Run an eiscp command and catch connection errors.'
def command(self, command):
try: result = self._receiver.command(command) except (ValueError, OSError, AttributeError, AssertionError): if self._receiver.command_socket: self._receiver.command_socket = None _LOGGER.info('Resetting connection to %s', self._name) else: _LO...
'Get the latest details from the device.'
def update(self):
status = self.command('system-power query') if (not status): return if (status[1] == 'on'): self._pwstate = STATE_ON else: self._pwstate = STATE_OFF return volume_raw = self.command('volume query') mute_raw = self.command('audio-muting query') current...
'Return the name of the device.'
@property def name(self):
return self._name
'Return the state of the device.'
@property def state(self):
return self._pwstate
'Return the volume level of the media player (0..1).'
@property def volume_level(self):
return self._volume
'Boolean if volume is currently muted.'
@property def is_volume_muted(self):
return self._muted
'Flag media player features that are supported.'
@property def supported_features(self):
return SUPPORT_ONKYO
'Return the current input source of the device.'
@property def source(self):
return self._current_source
'List of available input sources.'
@property def source_list(self):
return self._source_list
'Turn off media player.'
def turn_off(self):
self.command('system-power standby')
'Set volume level, input is range 0..1. Onkyo ranges from 1-80.'
def set_volume_level(self, volume):
self.command('volume {}'.format(int((volume * 80))))
'Mute (true) or unmute (false) media player.'
def mute_volume(self, mute):
if mute: self.command('audio-muting on') else: self.command('audio-muting off')
'Turn the media player on.'
def turn_on(self):
self.command('system-power on')
'Set the input source.'
def select_source(self, source):
if (source in self._source_list): source = self._reverse_mapping[source] self.command('input-selector {}'.format(source))
'Initialize the device.'
def __init__(self, receiver):
self._receiver = receiver self._name = self._receiver.name self._muted = self._receiver.muted self._volume = self._receiver.volume self._current_source = self._receiver.input_func self._source_list = self._receiver.input_func_list self._state = self._receiver.state self._power = self._re...
'Get the latest status information from device.'
def update(self):
self._receiver.update() self._name = self._receiver.name self._muted = self._receiver.muted self._volume = self._receiver.volume self._current_source = self._receiver.input_func self._source_list = self._receiver.input_func_list self._state = self._receiver.state self._power = self._rece...
'Return the name of the device.'
@property def name(self):
return self._name
'Return the state of the device.'
@property def state(self):
return self._state
'Return 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 ((float(self._volume) + 80) / 100)
'Return the current input source.'
@property def source(self):
return self._current_source
'Return a list of available input sources.'
@property def source_list(self):
return self._source_list
'Flag media player features that are supported.'
@property def supported_features(self):
if (self._current_source in self._receiver.netaudio_func_list): return (SUPPORT_DENON | SUPPORT_MEDIA_MODES) return SUPPORT_DENON
'Content ID of current playing media.'
@property def media_content_id(self):
return None
'Content type of current playing media.'
@property def media_content_type(self):
if ((self._state == STATE_PLAYING) or (self._state == STATE_PAUSED)): return MEDIA_TYPE_MUSIC return MEDIA_TYPE_CHANNEL