desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Refresh state in case an alternate process modified this data.'
def update(self):
self._pa_svr.update_module_state() self._module_idx = self._pa_svr.get_module_idx(self._sink_name, self._source_name)
'Initialize the ThinkingCleaner.'
def __init__(self, tc_object, switch_type, update_devices):
self.type = switch_type self._update_devices = update_devices self._tc_object = tc_object self._state = (self._tc_object.is_cleaning if (switch_type == 'clean') else False) self.lock = False self.last_lock_time = None self.graceful_state = False
'Lock the update since TC clean takes some time to update.'
def lock_update(self):
if self.is_update_locked(): return self.lock = True self.last_lock_time = time.time()
'Reset the update lock.'
def reset_update_lock(self):
self.lock = False self.last_lock_time = None
'Set the graceful state.'
def set_graceful_lock(self, state):
self.graceful_state = state self.reset_update_lock() self.lock_update()
'Check if the update method is locked.'
def is_update_locked(self):
if (self.last_lock_time is None): return False if ((time.time() - self.last_lock_time) >= MIN_TIME_TO_LOCK_UPDATE): self.last_lock_time = None return False return True
'Return the name of the sensor.'
@property def name(self):
return ((self._tc_object.name + ' ') + SWITCH_TYPES[self.type][0])
'Return true if device is on.'
@property def is_on(self):
if (self.type == 'clean'): return (self.graceful_state if self.is_update_locked() else self._tc_object.is_cleaning) return False
'Turn the device on.'
def turn_on(self, **kwargs):
if (self.type == 'clean'): self.set_graceful_lock(True) self._tc_object.start_cleaning() elif (self.type == 'dock'): self._tc_object.dock() elif (self.type == 'find'): self._tc_object.find_me()
'Turn the device off.'
def turn_off(self, **kwargs):
if (self.type == 'clean'): self.set_graceful_lock(False) self._tc_object.stop_cleaning()
'Update the switch state (Only for clean).'
def update(self):
if ((self.type == 'clean') and (not self.is_update_locked())): self._tc_object.update() self._state = (STATE_ON if self._tc_object.is_cleaning else STATE_OFF)
'Initialize the Verisure device.'
def __init__(self, device_id):
self._device_label = device_id self._change_timestamp = 0 self._state = False
'Return the name or location of the smartplug.'
@property def name(self):
return hub.get_first("$.smartPlugs[?(@.deviceLabel == '%s')].area", self._device_label)
'Return true if on.'
@property def is_on(self):
if ((time() - self._change_timestamp) < 10): return self._state self._state = (hub.get_first("$.smartPlugs[?(@.deviceLabel == '%s')].currentState", self._device_label) == 'ON') return self._state
'Return True if entity is available.'
@property def available(self):
return (hub.get_first("$.smartPlugs[?(@.deviceLabel == '%s')]", self._device_label) is not None)
'Set smartplug status on.'
def turn_on(self):
hub.session.set_smartplug_state(self._device_label, True) self._state = True self._change_timestamp = time()
'Set smartplug status off.'
def turn_off(self):
hub.session.set_smartplug_state(self._device_label, False) self._state = False self._change_timestamp = time()
'Get the latest date of the smartplug.'
def update(self):
hub.update_overview()
'Initialize the Neato Connected switches.'
def __init__(self, hass, robot, switch_type):
self.type = switch_type self.robot = robot self.neato = hass.data[NEATO_LOGIN] self._robot_name = '{} {}'.format(self.robot.name, SWITCH_TYPES[self.type][0]) try: self._state = self.robot.state except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError) as ex: ...
'Update the states of Neato switches.'
def update(self):
_LOGGER.debug('Running switch update') self.neato.update_robots() try: self._state = self.robot.state except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError) as ex: _LOGGER.warning('Neato connection error: %s', ex) self._state = None ret...
'Return the name of the switch.'
@property def name(self):
return self._robot_name
'Return True if entity is available.'
@property def available(self):
return self._state
'Return true if switch is on.'
@property def is_on(self):
if (self.type == SWITCH_TYPE_CLEAN): if (self._clean_state == STATE_ON): return True return False elif (self.type == SWITCH_TYPE_SCHEDULE): if (self._schedule_state == STATE_ON): return True return False
'Turn the switch on.'
def turn_on(self, **kwargs):
if (self.type == SWITCH_TYPE_CLEAN): self.robot.start_cleaning() elif (self.type == SWITCH_TYPE_SCHEDULE): self.robot.enable_schedule()
'Turn the switch off.'
def turn_off(self, **kwargs):
if (self.type == SWITCH_TYPE_CLEAN): self.robot.pause_cleaning() self.robot.send_to_base() elif (self.type == SWITCH_TYPE_SCHEDULE): self.robot.disable_schedule()
'Initialize the switch.'
def __init__(self, hass, name, rfdevice, protocol, pulselength, signal_repetitions, code_on, code_off):
self._hass = hass self._name = name self._state = False self._rfdevice = rfdevice self._protocol = protocol self._pulselength = pulselength self._code_on = code_on self._code_off = code_off self._rfdevice.tx_repeat = signal_repetitions
'No polling needed.'
@property def should_poll(self):
return False
'Return the name of the switch.'
@property def name(self):
return self._name
'Return true if device is on.'
@property def is_on(self):
return self._state
'Send the code(s) with a specified pulselength.'
def _send_code(self, code_list, protocol, pulselength):
_LOGGER.info('Sending code(s): %s', code_list) for code in code_list: self._rfdevice.tx_code(code, protocol, pulselength) return True
'Turn the switch on.'
def turn_on(self):
if self._send_code(self._code_on, self._protocol, self._pulselength): self._state = True self.schedule_update_ha_state()
'Turn the switch off.'
def turn_off(self):
if self._send_code(self._code_off, self._protocol, self._pulselength): self._state = False self.schedule_update_ha_state()
'Turn the switch on. This sends a value 0 to the group address of the device'
def turn_on(self, **kwargs):
self.group_write(1) self._state = [1] if (not self.should_poll): self.schedule_update_ha_state()
'Turn the switch off. This sends a value 1 to the group address of the device'
def turn_off(self, **kwargs):
self.group_write(0) self._state = [0] if (not self.should_poll): self.schedule_update_ha_state()
'Initialize switch.'
def __init__(self, board, address, channel, name, invert_logic, initial_state):
self._board = board self._address = address self._channel = channel self._name = (name or DEVICE_DEFAULT_NAME) self._invert_logic = invert_logic if (initial_state is not None): if self._invert_logic: state = (not initial_state) else: state = initial_state ...
'Return the name of the switch.'
@property def name(self):
return self._name
'Polling not needed.'
@property def should_poll(self):
return False
'Return true if device is on.'
@property def is_on(self):
try: state = self.I2C_HATS_MANAGER.read_dq(self._address, self._channel) return (state != self._invert_logic) except I2CHatsException as ex: _LOGGER.error(self._log_message(('Is ON check failed, ' + str(ex)))) return False
'Turn the device on.'
def turn_on(self):
try: state = (True if (self._invert_logic is False) else False) self.I2C_HATS_MANAGER.write_dq(self._address, self._channel, state) self.schedule_update_ha_state() except I2CHatsException as ex: _LOGGER.error(self._log_message(('Turn ON failed, ' + str(ex))))
'Turn the device off.'
def turn_off(self):
try: state = (False if (self._invert_logic is False) else True) self.I2C_HATS_MANAGER.write_dq(self._address, self._channel, state) self.schedule_update_ha_state() except I2CHatsException as ex: _LOGGER.error(self._log_message(('Turn OFF failed, ' + str(ex))))
'Initialize a LiteJet switch.'
def __init__(self, hass, lj, i, name):
self._hass = hass self._lj = lj self._index = i self._state = False self._name = name lj.on_switch_pressed(i, self._on_switch_pressed) lj.on_switch_released(i, self._on_switch_released)
'Return the name of the switch.'
@property def name(self):
return self._name
'Return if the switch is pressed.'
@property def is_on(self):
return self._state
'Return that polling is not necessary.'
@property def should_poll(self):
return False
'Return the device-specific state attributes.'
@property def device_state_attributes(self):
return {ATTR_NUMBER: self._index}
'Press the switch.'
def turn_on(self, **kwargs):
self._lj.press_switch(self._index)
'Release the switch.'
def turn_off(self, **kwargs):
self._lj.release_switch(self._index)
'Initialize the handle.'
def __init__(self, config, echo):
self.config_items = config.items() self.echo = echo
'Test if the received code matches the configured values. The received values have to be a subset of the configured options.'
def match(self, code):
return (self.config_items <= code.items())
'Change the state of the switch.'
def run(self, switch, turn_on):
switch.set_state(turn_on=turn_on, send_code=self.echo)
'Initialize the switch.'
def __init__(self, hass, name, code_on, code_off, code_on_receive, code_off_receive):
self._hass = hass self._name = name self._state = False self._code_on = code_on self._code_off = code_off self._code_on_receive = [] self._code_off_receive = [] for (code_list, conf) in ((self._code_on_receive, code_on_receive), (self._code_off_receive, code_off_receive)): for co...
'Get the name of the switch.'
@property def name(self):
return self._name
'No polling needed, state set when correct code is received.'
@property def should_poll(self):
return False
'Return true if switch is on.'
@property def is_on(self):
return self._state
'Check if received code by the pilight-daemon. If the code matches the receive on/off codes of this switch the switch state is changed accordingly.'
def _handle_code(self, call):
if any(self._code_on_receive): for on_code in self._code_on_receive: if on_code.match(call.data): on_code.run(switch=self, turn_on=True) break if any(self._code_off_receive): for off_code in self._code_off_receive: if off_code.match(call.da...
'Set the state of the switch. This sets the state of the switch. If send_code is set to True, then it will call the pilight.send service to actually send the codes to the pilight daemon.'
def set_state(self, turn_on, send_code=True):
if send_code: if turn_on: self._hass.services.call(pilight.DOMAIN, pilight.SERVICE_NAME, self._code_on, blocking=True) else: self._hass.services.call(pilight.DOMAIN, pilight.SERVICE_NAME, self._code_off, blocking=True) self._state = turn_on self.schedule_update_ha_sta...
'Turn the switch on by calling pilight.send service with on code.'
def turn_on(self):
self.set_state(turn_on=True)
'Turn the switch on by calling pilight.send service with off code.'
def turn_off(self):
self.set_state(turn_on=False)
'Request handler.'
@callback def get(self, request, host):
hass = request.app['hass'] data = request.query (states, consumptions, cumulated_consumptions, start_dates) = ([], [], [], []) for i in range(1, 5): out = ('output%d' % i) states.append((data.get(('%s_state' % out)) == STATE_ON)) consumptions.append(float(data.get(('%s_consumptio...
'Initialize the Netio switch.'
def __init__(self, netio, outlet, name):
self._name = name self.outlet = outlet self.netio = netio
'Return the device\'s name.'
@property def name(self):
return self._name
'Return true if entity is available.'
@property def available(self):
return (not hasattr(self, 'telnet'))
'Turn switch on.'
def turn_on(self):
self._set(True)
'Turn switch off.'
def turn_off(self):
self._set(False)
'Return the switch\'s status.'
@property def is_on(self):
return self.netio.states[(self.outlet - 1)]
'Update the state.'
def update(self):
self.netio.update()
'Return optional state attributes.'
@property def state_attributes(self):
return {ATTR_TOTAL_CONSUMPTION_KWH: self.cumulated_consumption_kwh, ATTR_START_DATE: self.start_date.split('|')[0]}
'Return actual power.'
@property def current_power_w(self):
return self.netio.consumptions[(self.outlet - 1)]
'Return the total enerygy consumption since start_date.'
@property def cumulated_consumption_kwh(self):
return self.netio.cumulated_consumptions[(self.outlet - 1)]
'Point in time when the energy accumulation started.'
@property def start_date(self):
return self.netio.start_dates[(self.outlet - 1)]
'Initialize the S20 device.'
def __init__(self, name, s20):
from orvibo.s20 import S20Exception self._name = name self._s20 = s20 self._state = False self._exc = S20Exception
'Return the polling state.'
@property def should_poll(self):
return True
'Return the name of the switch.'
@property def name(self):
return self._name
'Return true if device is on.'
@property def is_on(self):
return self._state
'Update device state.'
def update(self):
try: self._state = self._s20.on except self._exc: _LOGGER.exception('Error while fetching S20 state')
'Turn the device on.'
def turn_on(self, **kwargs):
try: self._s20.on = True except self._exc: _LOGGER.exception('Error while turning on S20')
'Turn the device off.'
def turn_off(self, **kwargs):
try: self._s20.on = False except self._exc: _LOGGER.exception('Error while turning off S20')
'Callback when entity is added to hass.'
@asyncio.coroutine def async_added_to_hass(self):
self.hass.data[DOMAIN]['entities']['switch'].append(self)
'Return true if device is on.'
@property def is_on(self):
return self.wink.state()
'Turn the device on.'
def turn_on(self, **kwargs):
self.wink.set_state(True)
'Turn the device off.'
def turn_off(self):
self.wink.set_state(False)
'Return the state attributes.'
@property def device_state_attributes(self):
attributes = super(WinkToggleDevice, self).device_state_attributes try: event = self.wink.last_event() attributes['last_event'] = event except AttributeError: pass return attributes
'Initialize the WeMo switch.'
def __init__(self, device):
self.wemo = device self.insight_params = None self.maker_params = None self.coffeemaker_mode = None self._state = None self._model_name = self.wemo.model_name wemo = get_component('wemo') wemo.SUBSCRIPTION_REGISTRY.register(self.wemo) wemo.SUBSCRIPTION_REGISTRY.on(self.wemo, None, se...
'Update the state by the Wemo device.'
def _update_callback(self, _device, _type, _params):
_LOGGER.info('Subscription update for %s', _device) updated = self.wemo.subscription_update(_type, _params) self._update(force_update=(not updated)) if (not hasattr(self, 'hass')): return self.schedule_update_ha_state()
'No polling needed with subscriptions.'
@property def should_poll(self):
if (self._model_name == 'Insight'): return True return False
'Return the ID of this WeMo switch.'
@property def unique_id(self):
return '{}.{}'.format(self.__class__, self.wemo.serialnumber)
'Return the name of the switch if any.'
@property def name(self):
return self.wemo.name
'Return the state attributes of the device.'
@property def device_state_attributes(self):
attr = {} if self.maker_params: if self.maker_params['hassensor']: if self.maker_params['sensorstate']: attr[ATTR_SENSOR_STATE] = STATE_OFF else: attr[ATTR_SENSOR_STATE] = STATE_ON if self.maker_params['switchmode']: attr[ATTR_S...
'Format seconds into uptime string in the format: 00d 00h 00m 00s.'
@staticmethod def as_uptime(_seconds):
uptime = (datetime(1, 1, 1) + timedelta(seconds=_seconds)) return '{:0>2d}d {:0>2d}h {:0>2d}m {:0>2d}s'.format((uptime.day - 1), uptime.hour, uptime.minute, uptime.second)
'Return the current power usage in W.'
@property def current_power_w(self):
if self.insight_params: return (convert(self.insight_params['currentpower'], float, 0.0) / 1000.0)
'Return the today total energy usage in kWh.'
@property def today_energy_kwh(self):
if self.insight_params: miliwatts = convert(self.insight_params['todaymw'], float, 0.0) return round((miliwatts / ((1000.0 * 1000.0) * 60)), 2)
'Return the state of the device.'
@property def detail_state(self):
if (self.coffeemaker_mode is not None): return self.wemo.mode_string if self.insight_params: standby_state = int(self.insight_params['state']) if (standby_state == WEMO_ON): return STATE_ON elif (standby_state == WEMO_OFF): return STATE_OFF elif (s...
'Return true if switch is on. Standby is on.'
@property def is_on(self):
return self._state
'Return true if switch is available.'
@property def available(self):
if ((self._model_name == 'Insight') and (self.insight_params is None)): return False if ((self._model_name == 'Maker') and (self.maker_params is None)): return False if ((self._model_name == 'CoffeeMaker') and (self.coffeemaker_mode is None)): return False return True
'Return the icon of device based on its type.'
@property def icon(self):
if (self._model_name == 'CoffeeMaker'): return 'mdi:coffee' return None
'Turn the switch on.'
def turn_on(self, **kwargs):
self._state = WEMO_ON self.wemo.on() self.schedule_update_ha_state()
'Turn the switch off.'
def turn_off(self, **kwargs):
self._state = WEMO_OFF self.wemo.off() self.schedule_update_ha_state()
'Update WeMo state.'
def update(self):
self._update(force_update=True)
'Update the device state.'
def _update(self, force_update=True):
try: self._state = self.wemo.get_state(force_update) if (self._model_name == 'Insight'): self.insight_params = self.wemo.insight_params self.insight_params['standby_state'] = self.wemo.get_standby_state elif (self._model_name == 'Maker'): self.maker_params...
'Initialize the Pin.'
def __init__(self, pin, options):
self._pin = pin self._name = options.get(CONF_NAME) self.pin_type = CONF_TYPE self.direction = 'out' self._state = options.get(CONF_INITIAL) if options.get(CONF_NEGATE): self.turn_on_handler = arduino.BOARD.set_digital_out_low self.turn_off_handler = arduino.BOARD.set_digital_out...