desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Get the latest data from the smart plug and updates the states.'
def update(self):
self.data.update()
'Initialize the data object.'
def __init__(self, smartplug):
self.smartplug = smartplug self.state = None self.temperature = None self.current_consumption = None self.total_consumption = None
'Get the latest data from the smart plug.'
def update(self):
self.state = self.smartplug.state self.temperature = self.smartplug.temperature self.current_consumption = self.smartplug.current_consumption self.total_consumption = self.smartplug.total_consumption
'Initialize the alarm panel.'
def __init__(self, name, hass):
self._display = '' self._name = name self._state = STATE_UNKNOWN _LOGGER.debug('Setting up panel')
'Register callbacks.'
@asyncio.coroutine def async_added_to_hass(self):
async_dispatcher_connect(self.hass, SIGNAL_PANEL_MESSAGE, self._message_callback)
'Return the name of the device.'
@property def name(self):
return self._name
'Return the polling state.'
@property def should_poll(self):
return False
'Return the regex for code format or None if no code is required.'
@property def code_format(self):
return '^\\d{4,6}$'
'Return the state of the device.'
@property def state(self):
return self._state
'Send disarm command.'
@asyncio.coroutine def async_alarm_disarm(self, code=None):
_LOGGER.debug('alarm_disarm: %s', code) if code: _LOGGER.debug('alarm_disarm: sending %s1', str(code)) self.hass.data[DATA_AD].send('{!s}1'.format(code))
'Send arm away command.'
@asyncio.coroutine def async_alarm_arm_away(self, code=None):
_LOGGER.debug('alarm_arm_away: %s', code) if code: _LOGGER.debug('alarm_arm_away: sending %s2', str(code)) self.hass.data[DATA_AD].send('{!s}2'.format(code))
'Send arm home command.'
@asyncio.coroutine def async_alarm_arm_home(self, code=None):
_LOGGER.debug('alarm_arm_home: %s', code) if code: _LOGGER.debug('alarm_arm_home: sending %s3', str(code)) self.hass.data[DATA_AD].send('{!s}3'.format(code))
'Initialize object.'
def __init__(self, name, egardiasystem, hass, rs_enabled=False, rs_port=None, rs_codes=None):
self._name = name self._egardiasystem = egardiasystem self._status = STATE_UNKNOWN self._rs_enabled = rs_enabled self._rs_port = rs_port self._hass = hass if (rs_codes is not None): self._rs_codes = rs_codes[0] else: self._rs_codes = rs_codes if self._rs_enabled: ...
'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._status
'Handle egardia_system_status_event.'
def handle_system_status_event(self, event):
if (event.data.get('status') is not None): statuscode = event.data.get('status') status = self.lookupstatusfromcode(statuscode) self.parsestatus(status)
'Subscribe to egardia_system_status event.'
def listen_to_system_status(self):
self._hass.bus.listen('egardia_system_status', self.handle_system_status_event)
'Look at the rs_codes and returns the status from the code.'
def lookupstatusfromcode(self, statuscode):
status = 'UNKNOWN' if (self._rs_codes is not None): statuscode = str(statuscode).strip() for i in self._rs_codes: val = str(self._rs_codes[i]).strip() if (',' in val): splitted = val.split(',') for code in splitted: code...
'Parse the status.'
def parsestatus(self, status):
newstatus = [v for (k, v) in STATES.items() if (status.upper() == k)][0] self._status = newstatus
'Update the alarm status.'
def update(self):
status = self._egardiasystem.getstate() self.parsestatus(status)
'Send disarm command.'
def alarm_disarm(self, code=None):
try: self._egardiasystem.alarm_disarm() except requests.exceptions.RequestException as err: _LOGGER.error('Egardia device exception occurred when sending disarm command: %s', err)
'Send arm home command.'
def alarm_arm_home(self, code=None):
try: self._egardiasystem.alarm_arm_home() except requests.exceptions.RequestException as err: _LOGGER.error('Egardia device exception occurred when sending arm home command: %s', err)
'Send arm away command.'
def alarm_arm_away(self, code=None):
try: self._egardiasystem.alarm_arm_away() except requests.exceptions.RequestException as err: _LOGGER.error('Egardia device exception occurred when sending arm away command: %s', err)
'Initialize the SimpliSafe alarm.'
def __init__(self, simplisafe, name, code):
self.simplisafe = simplisafe self._name = name self._code = (str(code) if code else None)
'Return the name of the device.'
@property def name(self):
if (self._name is not None): return self._name return 'Alarm {}'.format(self.simplisafe.location_id())
'One or more characters if code is defined.'
@property def code_format(self):
return (None if (self._code is None) else '.+')
'Return the state of the device.'
@property def state(self):
status = self.simplisafe.state() if (status == 'Off'): state = STATE_ALARM_DISARMED elif (status == 'Home'): state = STATE_ALARM_ARMED_HOME elif (status == 'Away'): state = STATE_ALARM_ARMED_AWAY else: state = STATE_UNKNOWN return state
'Return the state attributes.'
@property def device_state_attributes(self):
return {'temperature': self.simplisafe.temperature(), 'co': self.simplisafe.carbon_monoxide(), 'fire': self.simplisafe.fire(), 'alarm': self.simplisafe.alarm(), 'last_event': self.simplisafe.last_event(), 'flood': self.simplisafe.flood()}
'Update alarm status.'
def update(self):
self.simplisafe.update()
'Send disarm command.'
def alarm_disarm(self, code=None):
if (not self._validate_code(code, 'disarming')): return self.simplisafe.set_state('off') _LOGGER.info('SimpliSafe alarm disarming')
'Send arm home command.'
def alarm_arm_home(self, code=None):
if (not self._validate_code(code, 'arming home')): return self.simplisafe.set_state('home') _LOGGER.info('SimpliSafe alarm arming home')
'Send arm away command.'
def alarm_arm_away(self, code=None):
if (not self._validate_code(code, 'arming away')): return self.simplisafe.set_state('away') _LOGGER.info('SimpliSafe alarm arming away')
'Validate given code.'
def _validate_code(self, code, state):
check = ((self._code is None) or (code == self._code)) if (not check): _LOGGER.warning('Wrong code entered for %s', state) return check
'Init the manual MQTT alarm panel.'
def __init__(self, hass, name, code, pending_time, trigger_time, disarm_after_trigger, state_topic, command_topic, qos, payload_disarm, payload_arm_home, payload_arm_away):
self._state = STATE_ALARM_DISARMED self._hass = hass self._name = name self._code = (str(code) if code else None) self._pending_time = datetime.timedelta(seconds=pending_time) self._trigger_time = datetime.timedelta(seconds=trigger_time) self._disarm_after_trigger = disarm_after_trigger ...
'Return the polling state.'
@property def should_poll(self):
return False
'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._state in (STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_AWAY)) and self._pending_time and ((self._state_ts + self._pending_time) > dt_util.utcnow())): return STATE_ALARM_PENDING if ((self._state == STATE_ALARM_TRIGGERED) and self._trigger_time): if ((self._state_ts + self._pending_time) >...
'One or more characters.'
@property def code_format(self):
return (None if (self._code is None) else '.+')
'Send disarm command.'
def alarm_disarm(self, code=None):
if (not self._validate_code(code, STATE_ALARM_DISARMED)): return self._state = STATE_ALARM_DISARMED self._state_ts = dt_util.utcnow() self.schedule_update_ha_state()
'Send arm home command.'
def alarm_arm_home(self, code=None):
if (not self._validate_code(code, STATE_ALARM_ARMED_HOME)): return self._state = STATE_ALARM_ARMED_HOME self._state_ts = dt_util.utcnow() self.schedule_update_ha_state() if self._pending_time: track_point_in_time(self._hass, self.async_update_ha_state, (self._state_ts + self._pending...
'Send arm away command.'
def alarm_arm_away(self, code=None):
if (not self._validate_code(code, STATE_ALARM_ARMED_AWAY)): return self._state = STATE_ALARM_ARMED_AWAY self._state_ts = dt_util.utcnow() self.schedule_update_ha_state() if self._pending_time: track_point_in_time(self._hass, self.async_update_ha_state, (self._state_ts + self._pending...
'Send alarm trigger command. No code needed.'
def alarm_trigger(self, code=None):
self._pre_trigger_state = self._state self._state = STATE_ALARM_TRIGGERED self._state_ts = dt_util.utcnow() self.schedule_update_ha_state() if self._trigger_time: track_point_in_time(self._hass, self.async_update_ha_state, (self._state_ts + self._pending_time)) track_point_in_time(se...
'Validate given code.'
def _validate_code(self, code, state):
check = ((self._code is None) or (code == self._code)) if (not check): _LOGGER.warning('Invalid code given for %s', state) return check
'Subscribe mqtt events. This method must be run in the event loop and returns a coroutine.'
def async_added_to_hass(self):
async_track_state_change(self.hass, self.entity_id, self._async_state_changed_listener) @callback def message_received(topic, payload, qos): 'Run when new MQTT message has been received.' if (payload == self._payload_disarm): self.async_alarm_disarm(self._cod...
'Publish state change to MQTT.'
@asyncio.coroutine def _async_state_changed_listener(self, entity_id, old_state, new_state):
mqtt.async_publish(self.hass, self._state_topic, new_state.state, self._qos, True)
'Init the nx584 alarm panel.'
def __init__(self, hass, url, name):
from nx584 import client self._hass = hass self._name = name self._url = url self._alarm = client.Client(self._url) self._alarm.list_zones() self._state = STATE_UNKNOWN
'Return the name of the device.'
@property def name(self):
return self._name
'Return che characters if code is defined.'
@property def code_format(self):
return '[0-9]{4}([0-9]{2})?'
'Return the state of the device.'
@property def state(self):
return self._state
'Process new events from panel.'
def update(self):
try: part = self._alarm.list_partitions()[0] zones = self._alarm.list_zones() except requests.exceptions.ConnectionError as ex: _LOGGER.error('Unable to connect to %(host)s: %(reason)s', dict(host=self._url, reason=ex)) self._state = STATE_UNKNOWN zones = [...
'Send disarm command.'
def alarm_disarm(self, code=None):
self._alarm.disarm(code)
'Send arm home command.'
def alarm_arm_home(self, code=None):
self._alarm.arm('stay')
'Send arm away command.'
def alarm_arm_away(self, code=None):
self._alarm.arm('exit')
'Initalize the Verisure alarm panel.'
def __init__(self):
self._state = STATE_UNKNOWN self._digits = hub.config.get(CONF_CODE_DIGITS) self._changed_by = None
'Return the name of the device.'
@property def name(self):
return '{} alarm'.format(hub.session.installations[0]['alias'])
'Return the state of the device.'
@property def state(self):
return self._state
'Return the code format as regex.'
@property def code_format(self):
return ('^\\d{%s}$' % self._digits)
'Return the last change triggered by.'
@property def changed_by(self):
return self._changed_by
'Update alarm status.'
def update(self):
hub.update_overview() status = hub.get_first('$.armState.statusType') if (status == 'DISARMED'): self._state = STATE_ALARM_DISARMED elif (status == 'ARMED_HOME'): self._state = STATE_ALARM_ARMED_HOME elif (status == 'ARMED_AWAY'): self._state = STATE_ALARM_ARMED_AWAY elif...
'Send disarm command.'
def alarm_disarm(self, code=None):
set_arm_state('DISARMED', code)
'Send arm home command.'
def alarm_arm_home(self, code=None):
set_arm_state('ARMED_HOME', code)
'Send arm away command.'
def alarm_arm_away(self, code=None):
set_arm_state('ARMED_AWAY', code)
'Initialize the Concord232 alarm panel.'
def __init__(self, hass, url, name):
from concord232 import client as concord232_client self._state = STATE_UNKNOWN self._hass = hass self._name = name self._url = url try: client = concord232_client.Client(self._url) except requests.exceptions.ConnectionError as ex: _LOGGER.error('Unable to connect to ...
'Return the name of the device.'
@property def name(self):
return self._name
'Return the characters if code is defined.'
@property def code_format(self):
return '[0-9]{4}([0-9]{2})?'
'Return the state of the device.'
@property def state(self):
return self._state
'Update values from API.'
def update(self):
try: part = self._alarm.list_partitions()[0] except requests.exceptions.ConnectionError as ex: _LOGGER.error('Unable to connect to %(host)s: %(reason)s', dict(host=self._url, reason=ex)) newstate = STATE_UNKNOWN except IndexError: _LOGGER.error('Concord232 r...
'Send disarm command.'
def alarm_disarm(self, code=None):
self._alarm.disarm(code)
'Send arm home command.'
def alarm_arm_home(self, code=None):
self._alarm.arm('stay')
'Send arm away command.'
def alarm_arm_away(self, code=None):
self._alarm.arm('auto')
'Callback when entity is added to hass.'
@asyncio.coroutine def async_added_to_hass(self):
self.hass.data[DOMAIN]['entities']['alarm_control_panel'].append(self)
'Return the state of the device.'
@property def state(self):
wink_state = self.wink.state() if (wink_state == 'away'): state = STATE_ALARM_ARMED_AWAY elif (wink_state == 'home'): state = STATE_ALARM_DISARMED elif (wink_state == 'night'): state = STATE_ALARM_ARMED_HOME else: state = STATE_UNKNOWN return state
'Send disarm command.'
def alarm_disarm(self, code=None):
self.wink.set_mode('home')
'Send arm home command.'
def alarm_arm_home(self, code=None):
self.wink.set_mode('night')
'Send arm away command.'
def alarm_arm_away(self, code=None):
self.wink.set_mode('away')
'Return the state attributes.'
@property def device_state_attributes(self):
return {'private': self.wink.private()}
'Init the MQTT Alarm Control Panel.'
def __init__(self, name, state_topic, command_topic, qos, payload_disarm, payload_arm_home, payload_arm_away, code):
self._state = STATE_UNKNOWN self._name = name self._state_topic = state_topic self._command_topic = command_topic self._qos = qos self._payload_disarm = payload_disarm self._payload_arm_home = payload_arm_home self._payload_arm_away = payload_arm_away self._code = code
'Subscribe mqtt events. This method must be run in the event loop and returns a coroutine.'
def async_added_to_hass(self):
@callback def message_received(topic, payload, qos): 'Run when new MQTT message has been received.' if (payload not in (STATE_ALARM_DISARMED, STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_AWAY, STATE_ALARM_PENDING, STATE_ALARM_TRIGGERED)): _LOGGER.warning('Received ...
'No polling needed.'
@property def should_poll(self):
return False
'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
'One or more characters if code is defined.'
@property def code_format(self):
return (None if (self._code is None) else '.+')
'Send disarm command. This method is a coroutine.'
@asyncio.coroutine def async_alarm_disarm(self, code=None):
if (not self._validate_code(code, 'disarming')): return mqtt.async_publish(self.hass, self._command_topic, self._payload_disarm, self._qos)
'Send arm home command. This method is a coroutine.'
@asyncio.coroutine def async_alarm_arm_home(self, code=None):
if (not self._validate_code(code, 'arming home')): return mqtt.async_publish(self.hass, self._command_topic, self._payload_arm_home, self._qos)
'Send arm away command. This method is a coroutine.'
@asyncio.coroutine def async_alarm_arm_away(self, code=None):
if (not self._validate_code(code, 'arming away')): return mqtt.async_publish(self.hass, self._command_topic, self._payload_arm_away, self._qos)
'Validate given code.'
def _validate_code(self, code, state):
check = ((self._code is None) or (code == self._code)) if (not check): _LOGGER.warning('Wrong code entered for %s', state) return check
'Initialize the TotalConnect status.'
def __init__(self, name, username, password):
from total_connect_client import TotalConnectClient _LOGGER.debug('Setting up TotalConnect...') self._name = name self._username = username self._password = password self._state = STATE_UNKNOWN self._client = TotalConnectClient.TotalConnectClient(username, password)
'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 the state of the device.'
def update(self):
status = self._client.get_armed_status() if (status == self._client.DISARMED): state = STATE_ALARM_DISARMED elif (status == self._client.ARMED_STAY): state = STATE_ALARM_ARMED_HOME elif (status == self._client.ARMED_AWAY): state = STATE_ALARM_ARMED_AWAY else: state = ...
'Send disarm command.'
def alarm_disarm(self, code=None):
self._client.disarm()
'Send arm home command.'
def alarm_arm_home(self, code=None):
self._client.arm_stay()
'Send arm away command.'
def alarm_arm_away(self, code=None):
self._client.arm_away()
'Init the manual alarm panel.'
def __init__(self, hass, name, code, pending_time, trigger_time, disarm_after_trigger):
self._state = STATE_ALARM_DISARMED self._hass = hass self._name = name self._code = (str(code) if code else None) self._pending_time = datetime.timedelta(seconds=pending_time) self._trigger_time = datetime.timedelta(seconds=trigger_time) self._disarm_after_trigger = disarm_after_trigger ...
'Return the plling state.'
@property def should_poll(self):
return False
'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._state in (STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_AWAY)) and self._pending_time and ((self._state_ts + self._pending_time) > dt_util.utcnow())): return STATE_ALARM_PENDING if ((self._state == STATE_ALARM_TRIGGERED) and self._trigger_time): if ((self._state_ts + self._pending_time) >...
'One or more characters.'
@property def code_format(self):
return (None if (self._code is None) else '.+')
'Send disarm command.'
def alarm_disarm(self, code=None):
if (not self._validate_code(code, STATE_ALARM_DISARMED)): return self._state = STATE_ALARM_DISARMED self._state_ts = dt_util.utcnow() self.schedule_update_ha_state()
'Send arm home command.'
def alarm_arm_home(self, code=None):
if (not self._validate_code(code, STATE_ALARM_ARMED_HOME)): return self._state = STATE_ALARM_ARMED_HOME self._state_ts = dt_util.utcnow() self.schedule_update_ha_state() if self._pending_time: track_point_in_time(self._hass, self.async_update_ha_state, (self._state_ts + self._pending...