desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Login to My Neato.'
def login(self):
try: _LOGGER.debug('Trying to connect to Neato API') self.my_neato = self._neato(self.config[CONF_USERNAME], self.config[CONF_PASSWORD]) return True except HTTPError: _LOGGER.error('Unable to connect to Neato API') return False
'Update the robot states.'
@Throttle(timedelta(seconds=1)) def update_robots(self):
_LOGGER.debug('Running HUB.update_robots %s', self._hass.data[NEATO_ROBOTS]) self._hass.data[NEATO_ROBOTS] = self.my_neato.robots self._hass.data[NEATO_MAP_DATA] = self.my_neato.maps
'Download a new map image.'
def download_map(self, url):
map_image_data = self.my_neato.get_map_image(url) return map_image_data
'Initialize media extractor.'
def __init__(self, hass, component_config, call_data):
self.hass = hass self.config = component_config self.call_data = call_data
'Return media content url.'
def get_media_url(self):
return self.call_data.get(ATTR_MEDIA_CONTENT_ID)
'Return list of entities.'
def get_entities(self):
return self.call_data.get(ATTR_ENTITY_ID, [])
'Extract exact stream format for each entity_id and play it.'
def extract_and_send(self):
try: stream_selector = self.get_stream_selector() except MEDownloadException: _LOGGER.error('Could not retrieve data for the URL: %s', self.get_media_url()) else: entities = self.get_entities() if (len(entities) == 0): self.call_media_player_s...
'Return format selector for the media URL.'
def get_stream_selector(self):
from youtube_dl import YoutubeDL from youtube_dl.utils import DownloadError, ExtractorError ydl = YoutubeDL({'quiet': True, 'logger': _LOGGER}) try: all_media = ydl.extract_info(self.get_media_url(), process=False) except DownloadError: raise MEDownloadException() if ('entries' i...
'Call media_player.play_media service.'
def call_media_player_service(self, stream_selector, entity_id):
stream_query = self.get_stream_query_for_entity(entity_id) try: stream_url = stream_selector(stream_query) except MEQueryException: _LOGGER.error('Wrong query format: %s', stream_query) return else: data = {k: v for (k, v) in self.call_data.items() if (k != ATTR_...
'Get stream format query for entity.'
def get_stream_query_for_entity(self, entity_id):
default_stream_query = self.config.get(CONF_DEFAULT_STREAM_QUERY, DEFAULT_STREAM_QUERY) if entity_id: media_content_type = self.call_data.get(ATTR_MEDIA_CONTENT_TYPE) return self.config.get(CONF_CUSTOMIZE_ENTITIES, {}).get(entity_id, {}).get(media_content_type, default_stream_query) return d...
'Initialize the link.'
def __init__(self, hass, name, url, icon):
self.hass = hass self._name = name self._url = url self._icon = icon self.entity_id = (DOMAIN + ('.%s' % slugify(name))) self.schedule_update_ha_state()
'Return the icon to use in the frontend, if any.'
@property def icon(self):
return self._icon
'Return the name of the URL.'
@property def name(self):
return self._name
'Return the URL.'
@property def state(self):
return self._url
'Initialize the data object.'
def __init__(self, auth, home=None):
self.auth = auth self.camera_data = None self.camera_names = [] self.module_names = [] self.home = home self.camera_type = None
'Return all camera available on the API as a list.'
def get_camera_names(self):
self.camera_names = [] self.update() if (not self.home): for home in self.camera_data.cameras: for camera in self.camera_data.cameras[home].values(): self.camera_names.append(camera['name']) else: for camera in self.camera_data.cameras[self.home].values(): ...
'Return all module available on the API as a list.'
def get_module_names(self, camera_name):
self.module_names = [] self.update() cam_id = self.camera_data.cameraByName(camera=camera_name, home=self.home)['id'] for module in self.camera_data.modules.values(): if (cam_id == module['cam_id']): self.module_names.append(module['name']) return self.module_names
'Return all module available on the API as a list.'
def get_camera_type(self, camera=None, home=None, cid=None):
for camera_name in self.camera_names: self.camera_type = self.camera_data.cameraType(camera_name) return self.camera_type
'Call the Netatmo API to update the data.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
import lnetatmo self.camera_data = lnetatmo.CameraData(self.auth, size=100)
'Call the Netatmo API to update the events.'
@Throttle(MIN_TIME_BETWEEN_EVENT_UPDATES) def update_event(self):
self.camera_data.updateEvent(home=self.home, cameratype=self.camera_type)
'Initialize KiraRemote class.'
def __init__(self, name, kira):
_LOGGER.debug('KiraRemote device init started for: %s', name) self._name = name self._kira = kira
'Return the Kira device\'s name.'
@property def name(self):
return self._name
'Send a command to one device.'
def send_command(self, command, **kwargs):
for singel_command in command: code_tuple = (singel_command, kwargs.get(remote.ATTR_DEVICE)) _LOGGER.info('Sending Command: %s to %s', *code_tuple) self._kira.sendCode(code_tuple)
'Send a command to a device. This method must be run in the event loop and returns a coroutine.'
def async_send_command(self, command, **kwargs):
return self.hass.async_add_job(ft.partial(self.send_command, command, **kwargs))
'Initialize HarmonyRemote class.'
def __init__(self, name, host, port, activity, out_path, token):
import pyharmony from pathlib import Path _LOGGER.debug('HarmonyRemote device init started for: %s', name) self._name = name self.host = host self._port = port self._state = None self._current_activity = None self._default_activity = activity self._token = token ...
'Return the Harmony device\'s name.'
@property def name(self):
return self._name
'Add platform specific attributes.'
@property def device_state_attributes(self):
return {'current_activity': self._current_activity}
'Return False if PowerOff is the current activity, otherwise True.'
@property def is_on(self):
return (self._current_activity not in [None, 'PowerOff'])
'Return current activity.'
def update(self):
import pyharmony name = self._name _LOGGER.debug('Polling %s for current activity', name) state = pyharmony.ha_get_current_activity(self._token, self._config, self.host, self._port) _LOGGER.debug('%s current activity reported as: %s', name, state) self._current_activit...
'Start an activity from the Harmony device.'
def turn_on(self, **kwargs):
import pyharmony if kwargs[ATTR_ACTIVITY]: activity = kwargs[ATTR_ACTIVITY] else: activity = self._default_activity if activity: pyharmony.ha_start_activity(self._token, self.host, self._port, self._config, activity) self._state = True else: _LOGGER.error('No ...
'Start the PowerOff activity.'
def turn_off(self, **kwargs):
import pyharmony pyharmony.ha_power_off(self._token, self.host, self._port)
'Send a set of commands to one device.'
def send_command(self, command, **kwargs):
import pyharmony device = kwargs.pop(ATTR_DEVICE, None) if (device is None): _LOGGER.error('Missing required argument: device') return num_repeats = kwargs.pop(ATTR_NUM_REPEATS, None) if (num_repeats is not None): kwargs[ATTR_NUM_REPEATS] = num_repeats delay_secs...
'Sync the Harmony device with the web service.'
def sync(self):
import pyharmony _LOGGER.debug('Syncing hub with Harmony servers') pyharmony.ha_sync(self._token, self.host, self._port) self._config = pyharmony.ha_get_config(self._token, self.host, self._port) _LOGGER.debug('Writing hub config to file: %s', self._config_path) pyharm...
'Initialize device.'
def __init__(self, itachip2ir, name):
self.itachip2ir = itachip2ir self._power = False self._name = (name or DEVICE_DEFAULT_NAME)
'Return the name of the device.'
@property def name(self):
return self._name
'Return true if device is on.'
@property def is_on(self):
return self._power
'Turn the device on.'
def turn_on(self, **kwargs):
self._power = True self.itachip2ir.send(self._name, 'ON', 1) self.schedule_update_ha_state()
'Turn the device off.'
def turn_off(self, **kwargs):
self._power = False self.itachip2ir.send(self._name, 'OFF', 1) self.schedule_update_ha_state()
'Send a command to one device.'
def send_command(self, command, **kwargs):
for single_command in command: self.itachip2ir.send(self._name, single_command, 1)
'Update the device.'
def update(self):
self.itachip2ir.update()
'Initialize the Demo Remote.'
def __init__(self, name, state, icon):
self._name = (name or DEVICE_DEFAULT_NAME) self._state = state self._icon = icon self._last_command_sent = None
'No polling needed for a demo remote.'
@property def should_poll(self):
return False
'Return the name of the device if any.'
@property def name(self):
return self._name
'Return the icon to use for device if any.'
@property def icon(self):
return self._icon
'Return true if remote is on.'
@property def is_on(self):
return self._state
'Return device state attributes.'
@property def device_state_attributes(self):
if (self._last_command_sent is not None): return {'last_command_sent': self._last_command_sent}
'Turn the remote on.'
def turn_on(self, **kwargs):
self._state = True self.schedule_update_ha_state()
'Turn the remote off.'
def turn_off(self, **kwargs):
self._state = False self.schedule_update_ha_state()
'Send a command to a device.'
def send_command(self, command, **kwargs):
for com in command: self._last_command_sent = com self.schedule_update_ha_state()
'Initialize the system.'
def __init__(self, config_info):
import blinkpy self.blink = blinkpy.Blink(username=config_info[DOMAIN][CONF_USERNAME], password=config_info[DOMAIN][CONF_PASSWORD]) self.blink.setup_system()
'Initialize the ComfoConnect bridge.'
def __init__(self, hass, bridge, name, token, friendly_name, pin):
from pycomfoconnect import ComfoConnect self.data = {} self.name = name self.hass = hass self.comfoconnect = ComfoConnect(bridge=bridge, local_uuid=bytes.fromhex(token), local_devicename=friendly_name, pin=pin) self.comfoconnect.callback_sensor = self.sensor_callback
'Connect with the bridge.'
def connect(self):
_LOGGER.debug('Connecting with bridge') self.comfoconnect.connect(True)
'Disconnect from the bridge.'
def disconnect(self):
_LOGGER.debug('Disconnecting from bridge') self.comfoconnect.disconnect()
'Callback function for sensor updates.'
def sensor_callback(self, var, value):
_LOGGER.debug('Got value from bridge: %d = %d', var, value) from pycomfoconnect import SENSOR_TEMPERATURE_EXTRACT, SENSOR_TEMPERATURE_OUTDOOR if (var in [SENSOR_TEMPERATURE_EXTRACT, SENSOR_TEMPERATURE_OUTDOOR]): self.data[var] = (value / 10) else: self.data[var] = value...
'Subscribe for the specified sensor.'
def subscribe_sensor(self, sensor_id):
self.comfoconnect.register_sensor(sensor_id)
'Initialize the configuration.'
def __init__(self, config):
from knxip.core import parse_group_address self.config = config self.should_poll = config.get('poll', True) if config.get('address'): self._address = parse_group_address(config.get('address')) else: self._address = None if self.config.get('state_address'): self._state_add...
'Return the name given to the entity.'
@property def name(self):
return self.config['name']
'Return the address of the device as an integer value. 3 types of addresses are supported: integer - 0-65535 2 level - a/b 3 level - a/b/c'
@property def address(self):
return self._address
'Return the group address the device sends its current state to. Some KNX devices can send the current state to a seperate group address. This makes send e.g. when an actuator can be switched but also have a timer functionality.'
@property def state_address(self):
return self._state_address
'Initialize the device.'
def __init__(self, hass, config):
self._config = config self._state = False self._data = None _LOGGER.debug('Initalizing KNX group address for %s (%s)', self.name, self.address) def handle_knx_message(addr, data): 'Handle an incoming KNX frame.\n\n ...
'Return the entity\'s display name.'
@property def name(self):
return self._config.name
'Return the entity\'s configuration.'
@property def config(self):
return self._config
'Return the state of the polling, if needed.'
@property def should_poll(self):
return self._config.should_poll
'Return True if the value is not 0 is on, else False.'
@property def is_on(self):
return (self._state != 0)
'Return the KNX group address.'
@property def address(self):
return self._config.address
'Return the KNX group address.'
@property def state_address(self):
return self._config.state_address
'Return the name given to the entity.'
@property def cache(self):
return self._config.config.get('cache', True)
'Write to the group address.'
def group_write(self, value):
KNXTUNNEL.group_write(self.address, [value])
'Get the state from KNX bus or cache.'
def update(self):
from knxip.core import KNXException try: if self.state_address: res = KNXTUNNEL.group_read(self.state_address, use_cache=self.cache) else: res = KNXTUNNEL.group_read(self.address, use_cache=self.cache) if res: self._state = res[0] self._dat...
'Initialize the device. The namelist argument lists the required addresses. E.g. for a dimming actuators, the namelist might look like: onoff_address: 0/0/1 brightness_address: 0/0/2'
def __init__(self, hass, config, required, optional=None):
from knxip.core import parse_group_address, KNXException self.names = {} self.values = {} self._config = config self._state = False self._data = None _LOGGER.debug('%s: initalizing KNX multi address device', self.name) settings = self._config.config if config.address: ...
'Return the entity\'s display name.'
@property def name(self):
return self._config.name
'Return the entity\'s configuration.'
@property def config(self):
return self._config
'Return the state of the polling, if needed.'
@property def should_poll(self):
return self._config.should_poll
'Return the name given to the entity.'
@property def cache(self):
return self._config.config.get('cache', True)
'Check if the attribute with the given name is defined. This is mostly important for optional addresses.'
def has_attribute(self, name):
for attributename in self.names.values(): if (attributename == name): return True return False
'Set a percentage in knx for a given attribute. DPT_Scaling / DPT 5.001 is a single byte scaled percentage'
def set_percentage(self, name, percentage):
percentage = abs(percentage) scaled_value = ((percentage * 255) / 100) value = min(255, scaled_value) return self.set_int_value(name, value)
'Get a percentage from knx for a given attribute. DPT_Scaling / DPT 5.001 is a single byte scaled percentage'
def get_percentage(self, name):
value = self.get_int_value(name) percentage = round(((value * 100) / 255)) return percentage
'Set an integer value for a given attribute.'
def set_int_value(self, name, value, num_bytes=1):
value = round(value) b_value = value.to_bytes(num_bytes, byteorder='big') return self.set_value(name, list(b_value))
'Get an integer value for a given attribute.'
def get_int_value(self, name):
summed_value = 0 raw_value = self.value(name) try: for val in raw_value: summed_value *= 256 summed_value += val except TypeError: pass return summed_value
'Return the value to a given named attribute.'
def value(self, name):
from knxip.core import KNXException addr = None for (attributeaddress, attributename) in self.names.items(): if (attributename == name): addr = attributeaddress if (addr is None): _LOGGER.error("%s: attribute '%s' undefined", self.name, name) _LOGGER.debug('%...
'Set the value of a given named attribute.'
def set_value(self, name, value):
from knxip.core import KNXException addr = None for (attributeaddress, attributename) in self.names.items(): if (attributename == name): addr = attributeaddress if (addr is None): _LOGGER.error("%s: attribute '%s' undefined", self.name, name) _LOGGER.debug('%...
'Setup I2C-HAT instance for digital inputs scanner.'
def setup(self, i2c_hat):
if hasattr(i2c_hat, self._DIGITAL_INPUTS): digital_inputs = getattr(i2c_hat, self._DIGITAL_INPUTS) old_value = None setattr(digital_inputs, self._OLD_VALUE, old_value) setattr(digital_inputs, self._CALLBACKS, {})
'Register edge callback.'
def register_callback(self, i2c_hat, channel, callback):
if hasattr(i2c_hat, self._DIGITAL_INPUTS): digital_inputs = getattr(i2c_hat, self._DIGITAL_INPUTS) callbacks = getattr(digital_inputs, self._CALLBACKS) callbacks[channel] = callback setattr(digital_inputs, self._CALLBACKS, callbacks)
'Scan I2C-HATs digital inputs and fire callbacks.'
def scan(self, i2c_hat):
if hasattr(i2c_hat, self._DIGITAL_INPUTS): digital_inputs = getattr(i2c_hat, self._DIGITAL_INPUTS) callbacks = getattr(digital_inputs, self._CALLBACKS) old_value = getattr(digital_inputs, self._OLD_VALUE) value = digital_inputs.value if ((old_value is not None) and (value != ...
'Init I2C-HATs Manager.'
def __init__(self):
threading.Thread.__init__(self) self._lock = threading.Lock() self._i2c_hats = {} self._run = False self._di_scanner = I2CHatsDIScanner()
'Register I2C-HAT.'
def register_board(self, board, address):
with self._lock: i2c_hat = self._i2c_hats.get(address) if (i2c_hat is None): import raspihats.i2c_hats as module constructor = getattr(module, board) i2c_hat = constructor(address) setattr(i2c_hat, self._CALLBACKS, {}) setattr(i2c_hat, self...
'Keep alive for I2C-HATs.'
def run(self):
from raspihats.i2c_hats import ResponseException _LOGGER.info(log_message(self, 'starting')) while self._run: with self._lock: for i2c_hat in list(self._i2c_hats.values()): try: self._di_scanner.scan(i2c_hat) self._read_status(i2c_h...
'Read I2C-HATs status.'
def _read_status(self, i2c_hat):
status_word = i2c_hat.status if (status_word.value != 0): _LOGGER.error(log_message(self, i2c_hat, status_word))
'Start keep alive mechanism.'
def start_keep_alive(self):
self._run = True threading.Thread.start(self)
'Stop keep alive mechanism.'
def stop_keep_alive(self):
self._run = False self.join()
'Register I2C-HAT digital input edge callback.'
def register_di_callback(self, address, channel, callback):
with self._lock: i2c_hat = self._i2c_hats[address] self._di_scanner.register_callback(i2c_hat, channel, callback)
'Register I2C-HAT online callback.'
def register_online_callback(self, address, channel, callback):
with self._lock: i2c_hat = self._i2c_hats[address] callbacks = getattr(i2c_hat, self._CALLBACKS) callbacks[channel] = callback setattr(i2c_hat, self._CALLBACKS, callbacks)
'Read a value from a I2C-HAT digital input.'
def read_di(self, address, channel):
from raspihats.i2c_hats import ResponseException with self._lock: i2c_hat = self._i2c_hats[address] try: value = i2c_hat.di.value return ((value >> channel) & 1) except ResponseException as ex: raise I2CHatsException(str(ex))
'Write a value to a I2C-HAT digital output.'
def write_dq(self, address, channel, value):
from raspihats.i2c_hats import ResponseException with self._lock: i2c_hat = self._i2c_hats[address] try: i2c_hat.dq.channels[channel] = value except ResponseException as ex: raise I2CHatsException(str(ex))
'Read a value from a I2C-HAT digital output.'
def read_dq(self, address, channel):
from raspihats.i2c_hats import ResponseException with self._lock: i2c_hat = self._i2c_hats[address] try: return i2c_hat.dq.channels[channel] except ResponseException as ex: raise I2CHatsException(str(ex))
'Initialize the OAuth callback view.'
def __init__(self, config, config_file, request_token):
self.config = config self.config_file = config_file self.request_token = request_token
'Finish OAuth callback request.'
@callback def get(self, request):
from aiohttp import web hass = request.app['hass'] data = request.GET response_message = 'Wink has been successfully authorized!\n You can close this window now! For the best results you should reboot\n ...
'Initialize the Wink device.'
def __init__(self, wink, hass):
self.hass = hass self.wink = wink hass.data[DOMAIN]['pubnub'].add_subscription(self.wink.pubnub_channel, self._pubnub_update) hass.data[DOMAIN]['unique_ids'].append((self.wink.object_id() + self.wink.name()))
'Return the name of the device.'
@property def name(self):
return self.wink.name()
'Return true if connection == True.'
@property def available(self):
return self.wink.available()