desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Return the state attributes.'
@property def device_state_attributes(self):
attrs = {} attrs[ATTR_ATTRIBUTION] = CONF_ATTRIBUTION attrs['brand'] = DEFAULT_BRAND if ((self._sensor_type == 'last_capture') or (self._sensor_type == 'captured_today')): attrs['model'] = self._data.model_id return attrs
'Initialize the sensor.'
def __init__(self, name, broadlink_data, sensor_type):
self._name = '{} {}'.format(name, SENSOR_TYPES[sensor_type][0]) self._state = None self._type = sensor_type self._broadlink_data = broadlink_data self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
'Return the name of the sensor.'
@property def name(self):
return self._name
'Return the state of the sensor.'
@property def state(self):
return self._state
'Return the unit this state is expressed in.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Get the latest data from the sensor.'
def update(self):
self._broadlink_data.update() if (self._broadlink_data.data is None): return self._state = self._broadlink_data.data[self._type]
'Initialize the data object.'
def __init__(self, interval, ip_addr, mac_addr, timeout):
import broadlink self.data = None self._device = broadlink.a1((ip_addr, 80), mac_addr) self._device.timeout = timeout self._schema = vol.Schema({vol.Optional('temperature'): vol.Range(min=(-50), max=150), vol.Optional('humidity'): vol.Range(min=0, max=100), vol.Optional('light'): vol.Any(0, 1, 2, 3)...
'Initialize the sensor.'
def __init__(self, ebox_data, sensor_type, name):
self.client_name = name self.type = sensor_type self._name = SENSOR_TYPES[sensor_type][0] self._unit_of_measurement = SENSOR_TYPES[sensor_type][1] self._icon = SENSOR_TYPES[sensor_type][2] self.ebox_data = ebox_data self._state = None
'Return the name of the sensor.'
@property def name(self):
return '{} {}'.format(self.client_name, self._name)
'Return the state of the sensor.'
@property def state(self):
return self._state
'Return the unit of measurement of this entity, if any.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Icon to use in the frontend, if any.'
@property def icon(self):
return self._icon
'Get the latest data from EBox and update the state.'
def update(self):
self.ebox_data.update() if (self.type in self.ebox_data.data): self._state = round(self.ebox_data.data[self.type], 2)
'Initialize the data object.'
def __init__(self, username, password):
from pyebox import EboxClient self.client = EboxClient(username, password, REQUESTS_TIMEOUT) self.data = {}
'Get the latest data from Ebox.'
def update(self):
from pyebox.client import PyEboxError try: self.client.fetch_data() except PyEboxError as exp: _LOGGER.error('Error on receive last EBox data: %s', exp) return self.data = self.client.get_data()
'Construct a LIRC interface object.'
def __init__(self, hass):
threading.Thread.__init__(self) self.daemon = True self.stopped = threading.Event() self.hass = hass
'Run the loop of the LIRC interface thread.'
def run(self):
import lirc _LOGGER.debug('LIRC interface thread started') while (not self.stopped.isSet()): try: code = lirc.nextcode() except lirc.NextCodeError: _LOGGER.warning('Error reading next code from LIRC') code = None if code: ...
'Initialize the vlc device.'
def __init__(self, name, arguments):
import vlc self._instance = vlc.Instance(arguments) self._vlc = self._instance.media_player_new() self._name = name self._volume = None self._muted = None self._state = None self._media_position_updated_at = None self._media_position = None self._media_duration = None
'Get the latest details from the device.'
def update(self):
import vlc status = self._vlc.get_state() if (status == vlc.State.Playing): self._state = STATE_PLAYING elif (status == vlc.State.Paused): self._state = STATE_PAUSED else: self._state = STATE_IDLE self._media_duration = (self._vlc.get_length() / 1000) position = (self...
'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
'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_VLC
'Content type of current playing media.'
@property def media_content_type(self):
return MEDIA_TYPE_MUSIC
'Duration of current playing media in seconds.'
@property def media_duration(self):
return self._media_duration
'Position of current playing media in seconds.'
@property def media_position(self):
return self._media_position
'When was the position of the current playing media valid.'
@property def media_position_updated_at(self):
return self._media_position_updated_at
'Seek the media to a specific location.'
def media_seek(self, position):
track_length = (self._vlc.get_length() / 1000) self._vlc.set_position((position / track_length))
'Mute the volume.'
def mute_volume(self, mute):
self._vlc.audio_set_mute(mute) self._muted = mute
'Set volume level, range 0..1.'
def set_volume_level(self, volume):
self._vlc.audio_set_volume(int((volume * 100))) self._volume = volume
'Send play commmand.'
def media_play(self):
self._vlc.play() self._state = STATE_PLAYING
'Send pause command.'
def media_pause(self):
self._vlc.pause() self._state = STATE_PAUSED
'Play media from a URL or file.'
def play_media(self, media_type, media_id, **kwargs):
if (not (media_type == MEDIA_TYPE_MUSIC)): _LOGGER.error('Invalid media type %s. Only %s is supported', media_type, MEDIA_TYPE_MUSIC) return self._vlc.set_media(self._instance.media_new(media_id)) self._vlc.play() self._state = STATE_PLAYING
'Initialize the device.'
def __init__(self, name, host, port, device):
from DirectPy import DIRECTV self.dtv = DIRECTV(host, port, device) self._name = name self._is_standby = True self._current = None
'Retrieve latest state.'
def update(self):
self._is_standby = self.dtv.get_standby() if self._is_standby: self._current = None else: self._current = self.dtv.get_tuned()
'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._is_standby: return STATE_OFF return STATE_PLAYING
'Return the content ID of current playing media.'
@property def media_content_id(self):
if self._is_standby: return None return self._current['programId']
'Return the duration of current playing media in seconds.'
@property def media_duration(self):
if self._is_standby: return None return self._current['duration']
'Return the title of current playing media.'
@property def media_title(self):
if self._is_standby: return None return self._current['title']
'Return the title of current episode of TV show.'
@property def media_series_title(self):
if self._is_standby: return None elif ('episodeTitle' in self._current): return self._current['episodeTitle'] return None
'Flag media player features that are supported.'
@property def supported_features(self):
return SUPPORT_DTV
'Return the content type of current playing media.'
@property def media_content_type(self):
if ('episodeTitle' in self._current): return MEDIA_TYPE_TVSHOW return MEDIA_TYPE_VIDEO
'Return the channel current playing media.'
@property def media_channel(self):
if self._is_standby: return None return '{} ({})'.format(self._current['callsign'], self._current['major'])
'Turn on the receiver.'
def turn_on(self):
self.dtv.key_press('poweron')
'Turn off the receiver.'
def turn_off(self):
self.dtv.key_press('poweroff')
'Send play command.'
def media_play(self):
self.dtv.key_press('play')
'Send pause command.'
def media_pause(self):
self.dtv.key_press('pause')
'Send stop command.'
def media_stop(self):
self.dtv.key_press('stop')
'Send rewind command.'
def media_previous_track(self):
self.dtv.key_press('rew')
'Send fast forward command.'
def media_next_track(self):
self.dtv.key_press('ffwd')
'Initialize the NAD Receiver device.'
def __init__(self, name, nad_receiver, min_volume, max_volume, source_dict):
self._name = name self._nad_receiver = nad_receiver self._min_volume = min_volume self._max_volume = max_volume self._source_dict = source_dict self._reverse_mapping = {value: key for (key, value) in self._source_dict.items()} self._volume = self._state = self._mute = self._source = None
'Calculate the volume given the decibel. Return the volume (0..1).'
def calc_volume(self, decibel):
return (abs((self._min_volume - decibel)) / abs((self._min_volume - self._max_volume)))
'Calculate the decibel given the volume. Return the dB.'
def calc_db(self, volume):
return (self._min_volume + round((abs((self._min_volume - self._max_volume)) * volume)))
'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
'Retrieve latest state.'
def update(self):
if (self._nad_receiver.main_power('?') == 'Off'): self._state = STATE_OFF else: self._state = STATE_ON if (self._nad_receiver.main_mute('?') == 'Off'): self._mute = False else: self._mute = True self._volume = self.calc_volume(self._nad_receiver.main_volume('?')) ...
'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._mute
'Flag media player features that are supported.'
@property def supported_features(self):
return SUPPORT_NAD
'Turn the media player off.'
def turn_off(self):
self._nad_receiver.main_power('=', 'Off')
'Turn the media player on.'
def turn_on(self):
self._nad_receiver.main_power('=', 'On')
'Volume up the media player.'
def volume_up(self):
self._nad_receiver.main_volume('+')
'Volume down the media player.'
def volume_down(self):
self._nad_receiver.main_volume('-')
'Set volume level, range 0..1.'
def set_volume_level(self, volume):
self._nad_receiver.main_volume('=', self.calc_db(volume))
'Select input source.'
def select_source(self, source):
self._nad_receiver.main_source('=', self._reverse_mapping.get(source))
'Name of the current input source.'
@property def source(self):
return self._source
'List of available input sources.'
@property def source_list(self):
return sorted(list(self._reverse_mapping.keys()))
'Mute (true) or unmute (false) media player.'
def mute_volume(self, mute):
if mute: self._nad_receiver.main_mute('=', 'On') else: self._nad_receiver.main_mute('=', 'Off')
'Initialize the CMUS device.'
def __init__(self, server, password, port, name):
from pycmus import remote if server: self.cmus = remote.PyCmus(server=server, password=password, port=port) auto_name = 'cmus-{}'.format(server) else: self.cmus = remote.PyCmus() auto_name = 'cmus-local' self._name = (name or auto_name) self.status = {}
'Get the latest data and update the state.'
def update(self):
status = self.cmus.get_status_dict() if (not status): _LOGGER.warning('Recieved no status from cmus') else: self.status = status
'Return the name of the device.'
@property def name(self):
return self._name
'Return the media state.'
@property def state(self):
if (self.status.get('status') == 'playing'): return STATE_PLAYING elif (self.status.get('status') == 'paused'): return STATE_PAUSED return STATE_OFF
'Content ID of current playing media.'
@property def media_content_id(self):
return self.status.get('file')
'Content type of the current playing media.'
@property def content_type(self):
return MEDIA_TYPE_MUSIC
'Duration of current playing media in seconds.'
@property def media_duration(self):
return self.status.get('duration')
'Title of current playing media.'
@property def media_title(self):
return self.status['tag'].get('title')
'Artist of current playing media, music track only.'
@property def media_artist(self):
return self.status['tag'].get('artist')
'Track number of current playing media, music track only.'
@property def media_track(self):
return self.status['tag'].get('tracknumber')
'Album name of current playing media, music track only.'
@property def media_album_name(self):
return self.status['tag'].get('album')
'Album artist of current playing media, music track only.'
@property def media_album_artist(self):
return self.status['tag'].get('albumartist')
'Return the volume level.'
@property def volume_level(self):
left = self.status['set'].get('vol_left')[0] right = self.status['set'].get('vol_right')[0] if (left != right): volume = (float((left + right)) / 2) else: volume = left return (int(volume) / 100)
'Flag media player features that are supported.'
@property def supported_features(self):
return SUPPORT_CMUS
'Service to send the CMUS the command to stop playing.'
def turn_off(self):
self.cmus.player_stop()
'Service to send the CMUS the command to start playing.'
def turn_on(self):
self.cmus.player_play()
'Set volume level, range 0..1.'
def set_volume_level(self, volume):
self.cmus.set_volume(int((volume * 100)))
'Set the volume up.'
def volume_up(self):
left = self.status['set'].get('vol_left') right = self.status['set'].get('vol_right') if (left != right): current_volume = (float((left + right)) / 2) else: current_volume = left if (current_volume <= 100): self.cmus.set_volume((int(current_volume) + 5))
'Set the volume down.'
def volume_down(self):
left = self.status['set'].get('vol_left') right = self.status['set'].get('vol_right') if (left != right): current_volume = (float((left + right)) / 2) else: current_volume = left if (current_volume <= 100): self.cmus.set_volume((int(current_volume) - 5))
'Send the play command.'
def play_media(self, media_type, media_id, **kwargs):
if (media_type in [MEDIA_TYPE_MUSIC, MEDIA_TYPE_PLAYLIST]): self.cmus.player_play_file(media_id) else: _LOGGER.error('Invalid media type %s. Only %s and %s are supported', media_type, MEDIA_TYPE_MUSIC, MEDIA_TYPE_PLAYLIST)
'Send the pause command.'
def media_pause(self):
self.cmus.player_pause()
'Send next track command.'
def media_next_track(self):
self.cmus.player_next()
'Send next track command.'
def media_previous_track(self):
self.cmus.player_prev()
'Send seek command.'
def media_seek(self, position):
self.cmus.seek(position)
'Send the play command.'
def media_play(self):
self.cmus.player_play()
'Send the stop command.'
def media_stop(self):
self.cmus.stop()
'Initialize the media player.'
def __init__(self, name, url, code):
from websocket import create_connection self._connection = create_connection self._url = url self._authorization_code = code self._name = name self._status = STATE_OFF self._ws = None self._title = None self._artist = None self._albumart = None self._seek_position = None ...
'Check if the websocket is setup and connected.'
def get_ws(self):
if (self._ws is None): try: self._ws = self._connection(self._url, timeout=1) msg = json.dumps({'namespace': 'connect', 'method': 'connect', 'arguments': ['Home Assistant', self._authorization_code]}) self._ws.send(msg) except (socket.timeout, ConnectionRefused...
'Send ws messages to GPMDP and verify request id in response.'
def send_gpmdp_msg(self, namespace, method, with_id=True):
from websocket import _exceptions try: websocket = self.get_ws() if (websocket is None): self._status = STATE_OFF return self._request_id += 1 websocket.send(json.dumps({'namespace': namespace, 'method': method, 'requestID': self._request_id})) if ...
'Get the latest details from the player.'
def update(self):
time.sleep(1) playstate = self.send_gpmdp_msg('playback', 'getPlaybackState') if (playstate is None): return self._status = PLAYBACK_DICT[str(playstate['value'])] time_data = self.send_gpmdp_msg('playback', 'getCurrentTime') if (time_data is not None): self._seek_position = int((...