desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Update state of the device.'
| def update(self):
| self.wink.update_state()
|
'Only poll if we are not subscribed to pubnub.'
| @property
def should_poll(self):
| return (self.wink.pubnub_channel is None)
|
'Return the state attributes.'
| @property
def device_state_attributes(self):
| attributes = {}
battery = self._battery_level
if battery:
attributes[ATTR_BATTERY_LEVEL] = battery
man_dev_model = self._manufacturer_device_model
if man_dev_model:
attributes['manufacturer_device_model'] = man_dev_model
man_dev_id = self._manufacturer_device_id
if man_dev_id... |
'Return the battery level.'
| @property
def _battery_level(self):
| if (self.wink.battery_level() is not None):
return (self.wink.battery_level() * 100)
|
'Return the manufacturer device model.'
| @property
def _manufacturer_device_model(self):
| return self.wink.manufacturer_device_model()
|
'Return the manufacturer device id.'
| @property
def _manufacturer_device_id(self):
| return self.wink.manufacturer_device_id()
|
'Return the device manufacturer.'
| @property
def _device_manufacturer(self):
| return self.wink.device_manufacturer()
|
'Return the model name.'
| @property
def _model_name(self):
| return self.wink.model_name()
|
'Return the devices tamper status.'
| @property
def _tamper(self):
| if hasattr(self.wink, 'tamper_detected'):
return self.wink.tamper_detected()
return None
|
'Initialize the instance of the view.'
| def __init__(self, config):
| self.config = config
|
'Handle a GET request.'
| @core.callback
def get(self, request):
| xml_template = '<?xml version="1.0" encoding="UTF-8" ?>\n<root xmlns="urn:schemas-upnp-org:device-1-0">\n<specVersion>\n<major>1</major>\n<minor>0</minor>\n</specVersion>\n<URLBase>http://{0}:{1}/</URLBase>\n<device>\n<deviceType>urn:schemas-upnp-org:device:Basic:1</deviceType>\n<friendlyName>HASS Br... |
'Initialize the class.'
| def __init__(self, host_ip_addr, listen_port, upnp_bind_multicast, advertise_ip, advertise_port):
| threading.Thread.__init__(self)
self.host_ip_addr = host_ip_addr
self.listen_port = listen_port
self.upnp_bind_multicast = upnp_bind_multicast
resp_template = 'HTTP/1.1 200 OK\nCACHE-CONTROL: max-age=60\nEXT:\nLOCATION: http://{0}:{1}/description.xml\nSERVER: FreeRTOS/6.0.5, UPnP/1... |
'Run the server.'
| def run(self):
| ssdp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
ssdp_socket.setblocking(False)
ssdp_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
ssdp_socket.setsockopt(socket.SOL_IP, socket.IP_MULTICAST_IF, socket.inet_aton(self.host_ip_addr))
ssdp_socket.setsockopt(socket.SOL_IP, soc... |
'Stop the server.'
| def stop(self):
| self._interrupted = True
os.write(self._interrupted_write_pipe, bytes([0]))
self.join()
|
'Initialize the board.'
| def __init__(self, port):
| from PyMata.pymata import PyMata
self._port = port
self._board = PyMata(self._port, verbose=False)
|
'Set the mode and the direction of a given pin.'
| def set_mode(self, pin, direction, mode):
| if ((mode == 'analog') and (direction == 'in')):
self._board.set_pin_mode(pin, self._board.INPUT, self._board.ANALOG)
elif ((mode == 'analog') and (direction == 'out')):
self._board.set_pin_mode(pin, self._board.OUTPUT, self._board.ANALOG)
elif ((mode == 'digital') and (direction == 'in')):
... |
'Get the values from the pins.'
| def get_analog_inputs(self):
| self._board.capability_query()
return self._board.get_analog_response_table()
|
'Set a given digital pin to high.'
| def set_digital_out_high(self, pin):
| self._board.digital_write(pin, 1)
|
'Set a given digital pin to low.'
| def set_digital_out_low(self, pin):
| self._board.digital_write(pin, 0)
|
'Get the value from a given digital pin.'
| def get_digital_in(self, pin):
| self._board.digital_read(pin)
|
'Get the value from a given analog pin.'
| def get_analog_in(self, pin):
| self._board.analog_read(pin)
|
'Return the version of the Firmata firmware.'
| def get_firmata(self):
| return self._board.get_firmata_version()
|
'Disconnect the board and close the serial connection.'
| def disconnect(self):
| self._board.reset()
self._board.close()
|
'Initialize the lock.'
| def __init__(self, nuki_lock):
| self._nuki_lock = nuki_lock
self._locked = nuki_lock.is_locked
self._name = nuki_lock.name
self._battery_critical = nuki_lock.battery_critical
|
'Callback when entity is added to hass.'
| @asyncio.coroutine
def async_added_to_hass(self):
| if (NUKI_DATA not in self.hass.data):
self.hass.data[NUKI_DATA] = {}
if (DOMAIN not in self.hass.data[NUKI_DATA]):
self.hass.data[NUKI_DATA][DOMAIN] = []
self.hass.data[NUKI_DATA][DOMAIN].append(self)
|
'Return the name of the lock.'
| @property
def name(self):
| return self._name
|
'Return true if lock is locked.'
| @property
def is_locked(self):
| return self._locked
|
'Return the device specific state attributes.'
| @property
def device_state_attributes(self):
| data = {ATTR_BATTERY_CRITICAL: self._battery_critical, ATTR_NUKI_ID: self._nuki_lock.nuki_id}
return data
|
'Update the nuki lock properties.'
| def update(self):
| self._nuki_lock.update(aggressive=False)
self._name = self._nuki_lock.name
self._locked = self._nuki_lock.is_locked
self._battery_critical = self._nuki_lock.battery_critical
|
'Lock the device.'
| def lock(self, **kwargs):
| self._nuki_lock.lock()
|
'Unlock the device.'
| def unlock(self, **kwargs):
| self._nuki_lock.unlock()
|
'Lock and go.
This will first unlock the door, then wait for 20 seconds (or another
amount of time depending on the lock settings) and relock.'
| def lock_n_go(self, unlatch=False, **kwargs):
| self._nuki_lock.lock_n_go(unlatch, kwargs)
|
'Unlatch door.'
| def unlatch(self, **kwargs):
| self._nuki_lock.unlatch()
|
'Return true if lock is locked.'
| @property
def is_locked(self):
| return self.vehicle.is_locked
|
'Lock the car.'
| def lock(self, **kwargs):
| self.vehicle.lock()
|
'Unlock the car.'
| def unlock(self, **kwargs):
| self.vehicle.unlock()
|
'Initialize the Verisure lock.'
| def __init__(self, device_label):
| self._device_label = device_label
self._state = STATE_UNKNOWN
self._digits = hub.config.get(CONF_CODE_DIGITS)
self._changed_by = None
self._change_timestamp = 0
|
'Return the name of the lock.'
| @property
def name(self):
| return hub.get_first("$.doorLockStatusList[?(@.deviceLabel=='%s')].area", self._device_label)
|
'Return the state of the lock.'
| @property
def state(self):
| return self._state
|
'Return True if entity is available.'
| @property
def available(self):
| return (hub.get_first("$.doorLockStatusList[?(@.deviceLabel=='%s')]", self._device_label) is not None)
|
'Last change triggered by.'
| @property
def changed_by(self):
| return self._changed_by
|
'Return the required six digit code.'
| @property
def code_format(self):
| return ('^\\d{%s}$' % self._digits)
|
'Update lock status.'
| def update(self):
| if ((time() - self._change_timestamp) < 10):
return
hub.update_overview()
status = hub.get_first("$.doorLockStatusList[?(@.deviceLabel=='%s')].lockedState", self._device_label)
if (status == 'UNLOCKED'):
self._state = STATE_UNLOCKED
elif (status == 'LOCKED'):
self._state = ST... |
'Return true if lock is locked.'
| @property
def is_locked(self):
| return (self._state == STATE_LOCKED)
|
'Send unlock command.'
| def unlock(self, **kwargs):
| if (self._state == STATE_UNLOCKED):
return
self.set_lock_state(kwargs[ATTR_CODE], STATE_UNLOCKED)
|
'Send lock command.'
| def lock(self, **kwargs):
| if (self._state == STATE_LOCKED):
return
self.set_lock_state(kwargs[ATTR_CODE], STATE_LOCKED)
|
'Send set lock state command.'
| def set_lock_state(self, code, state):
| lock_state = ('lock' if (state == STATE_LOCKED) else 'unlock')
transaction_id = hub.session.set_lock_state(code, self._device_label, lock_state)['doorLockStateChangeTransactionId']
_LOGGER.debug('Verisure doorlock %s', state)
transaction = {}
while ('result' not in transaction):
sleep(... |
'Initialize the lock.'
| def __init__(self, state, access_token, device_id):
| self._state = state
self.access_token = access_token
self.device_id = device_id
|
'Return the name of the device.'
| @property
def name(self):
| return DOMAIN
|
'Return True if the lock is currently locked, else False.'
| @property
def is_locked(self):
| return (self._state == Lockitron.LOCK_STATE)
|
'Lock the device.'
| def lock(self, **kwargs):
| self._state = self.do_change_request(Lockitron.LOCK_STATE)
|
'Unlock the device.'
| def unlock(self, **kwargs):
| self._state = self.do_change_request(Lockitron.UNLOCK_STATE)
|
'Update the internal state of the device.'
| def update(self):
| response = requests.get(API_STATE_URL.format(self.device_id, self.access_token), timeout=5)
if (response.status_code == 200):
self._state = response.json()['state']
else:
_LOGGER.error('Error retrieving lock status: %s', response.text)
|
'Execute the change request and pull out the new state.'
| def do_change_request(self, requested_state):
| response = requests.put(API_ACTION_URL.format(self.device_id, self.access_token, requested_state), timeout=5)
if (response.status_code == 200):
return response.json()['state']
_LOGGER.error('Error setting lock state: %s\n%s', requested_state, response.text)
return self._state
|
'Callback when entity is added to hass.'
| @asyncio.coroutine
def async_added_to_hass(self):
| self.hass.data[DOMAIN]['entities']['lock'].append(self)
|
'Return true if device is locked.'
| @property
def is_locked(self):
| return self.wink.state()
|
'Lock the device.'
| def lock(self, **kwargs):
| self.wink.set_state(True)
|
'Unlock the device.'
| def unlock(self, **kwargs):
| self.wink.set_state(False)
|
'Set lock\'s alarm state.'
| def set_alarm_state(self, enabled):
| self.wink.set_alarm_state(enabled)
|
'Set lock\'s vacation mode.'
| def set_vacation_mode(self, enabled):
| self.wink.set_vacation_mode(enabled)
|
'Set lock\'s beeper mode.'
| def set_beeper_state(self, enabled):
| self.wink.set_beeper_mode(enabled)
|
'Set lock\'s alarm sensitivity.
Valid sensitivities:
0.2, 0.4, 0.6, 0.8, 1.0'
| def set_alarm_sensitivity(self, sensitivity):
| self.wink.set_alarm_sensitivity(sensitivity)
|
'Set lock\'s alarm mode.
Valid modes:
alert - Beep when lock is locked or unlocked
tamper - 15 sec alarm when lock is disturbed when locked
forced_entry - 3 min alarm when significant force applied
to door when locked.'
| def set_alarm_mode(self, mode):
| self.wink.set_alarm_mode(mode)
|
'Return the state attributes.'
| @property
def device_state_attributes(self):
| super_attrs = super().device_state_attributes
sensitivity = dict_value_to_key(ALARM_SENSITIVITY_MAP, self.wink.alarm_sensitivity())
super_attrs['alarm sensitivity'] = sensitivity
super_attrs['vacation mode'] = self.wink.vacation_mode_enabled()
super_attrs['beeper mode'] = self.wink.beeper_e... |
'Initialize the Vera device.'
| def __init__(self, vera_device, controller):
| self._state = None
VeraDevice.__init__(self, vera_device, controller)
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
'Lock the device.'
| def lock(self, **kwargs):
| self.vera_device.lock()
self._state = STATE_LOCKED
|
'Unlock the device.'
| def unlock(self, **kwargs):
| self.vera_device.unlock()
self._state = STATE_UNLOCKED
|
'Return true if device is on.'
| @property
def is_locked(self):
| return (self._state == STATE_LOCKED)
|
'Update state by the Vera device callback.'
| def update(self):
| self._state = (STATE_LOCKED if self.vera_device.is_locked(True) else STATE_UNLOCKED)
|
'Initialize the lock.'
| def __init__(self, name, state):
| self._name = name
self._state = state
|
'No polling needed for a demo lock.'
| @property
def should_poll(self):
| return False
|
'Return the name of the lock if any.'
| @property
def name(self):
| return self._name
|
'Return true if lock is locked.'
| @property
def is_locked(self):
| return (self._state == STATE_LOCKED)
|
'Lock the device.'
| def lock(self, **kwargs):
| self._state = STATE_LOCKED
self.schedule_update_ha_state()
|
'Unlock the device.'
| def unlock(self, **kwargs):
| self._state = STATE_UNLOCKED
self.schedule_update_ha_state()
|
'Initialize the event.'
| def __init__(self, axis_event):
| self.axis_event = axis_event
self._event_class = convert(self.axis_event.topic, 'topic', 'class')
self._name = '{}_{}_{}'.format(self.axis_event.device_name, convert(self.axis_event.topic, 'topic', 'type'), self.axis_event.id)
self.axis_event.callback = self._update_callback
|
'Update the sensor\'s state, if needed.'
| def _update_callback(self):
| self.update()
self.schedule_update_ha_state()
|
'Return the name of the event.'
| @property
def name(self):
| return self._name
|
'Return the class of the event.'
| @property
def device_class(self):
| return self._event_class
|
'No polling needed.'
| @property
def should_poll(self):
| return False
|
'Return the state attributes of the event.'
| @property
def device_state_attributes(self):
| attr = {}
tripped = self.axis_event.is_tripped
attr[ATTR_TRIPPED] = ('True' if tripped else 'False')
location = self.axis_event.device_config(ATTR_LOCATION)
if location:
attr[ATTR_LOCATION] = location
return attr
|
'Initialize Amazon Polly provider for TTS.'
| def __init__(self, polly_client, config, supported_languages, all_voices):
| self.client = polly_client
self.config = config
self.supported_langs = supported_languages
self.all_voices = all_voices
self.default_voice = self.config.get(CONF_VOICE)
self.name = 'Amazon Polly'
|
'Return a list of supported languages.'
| @property
def supported_languages(self):
| return self.supported_langs
|
'Return the default language.'
| @property
def default_language(self):
| return self.all_voices.get(self.default_voice).get('LanguageCode')
|
'Return dict include default options.'
| @property
def default_options(self):
| return {CONF_VOICE: self.default_voice}
|
'Return a list of supported options.'
| @property
def supported_options(self):
| return [CONF_VOICE]
|
'Request TTS file from Polly.'
| def get_tts_audio(self, message, language=None, options=None):
| voice_id = options.get(CONF_VOICE, self.default_voice)
voice_in_dict = self.all_voices.get(voice_id)
if (language != voice_in_dict.get('LanguageCode')):
_LOGGER.error('%s does not support the %s language', voice_id, language)
return (None, None)
resp = self.client.synth... |
'Initialize Pico TTS provider.'
| def __init__(self, lang):
| self._lang = lang
self.name = 'PicoTTS'
|
'Return the default language.'
| @property
def default_language(self):
| return self._lang
|
'Return list of supported languages.'
| @property
def supported_languages(self):
| return SUPPORT_LANGUAGES
|
'Load TTS using pico2wave.'
| def get_tts_audio(self, message, language, options=None):
| with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as tmpf:
fname = tmpf.name
cmd = ['pico2wave', '--wave', fname, '-l', language, message]
subprocess.call(cmd)
data = None
try:
with open(fname, 'rb') as voice:
data = voice.read()
except OSError:
_L... |
'Initialize demo provider.'
| def __init__(self, lang):
| self._lang = lang
self.name = 'Demo'
|
'Return the default language.'
| @property
def default_language(self):
| return self._lang
|
'Return list of supported languages.'
| @property
def supported_languages(self):
| return SUPPORT_LANGUAGES
|
'Return list of supported options like voice, emotionen.'
| @property
def supported_options(self):
| return ['voice', 'age']
|
'Load TTS from demo.'
| def get_tts_audio(self, message, language, options=None):
| filename = os.path.join(os.path.dirname(__file__), 'demo.mp3')
try:
with open(filename, 'rb') as voice:
data = voice.read()
except OSError:
return (None, None)
return ('mp3', data)
|
'Construct a KeyboardRemote interface object.'
| def __init__(self, hass, config):
| from evdev import InputDevice, list_devices
self.device_descriptor = config.get(DEVICE_DESCRIPTOR)
self.device_name = config.get(DEVICE_NAME)
if self.device_descriptor:
self.device_id = self.device_descriptor
else:
self.device_id = self.device_name
self.dev = self._get_keyboard_d... |
'Get the keyboard device.'
| def _get_keyboard_device(self):
| from evdev import InputDevice, list_devices
if self.device_name:
devices = [InputDevice(file_name) for file_name in list_devices()]
for device in devices:
if (self.device_name == device.name):
return device
elif self.device_descriptor:
try:
dev... |
'Run the loop of the KeyboardRemote.'
| def run(self):
| from evdev import categorize, ecodes
if (self.dev is not None):
self.dev.grab()
_LOGGER.debug('Interface started for %s', self.dev)
while (not self.stopped.isSet()):
time.sleep(0.1)
if (self.dev is None):
self.dev = self._get_keyboard_device()
... |
'Initialize OctoPrint API and set headers needed later.'
| def __init__(self, api_url, key):
| self.api_url = api_url
self.headers = {'content-type': CONTENT_TYPE_JSON, 'X-Api-Key': key}
self.printer_last_reading = [{}, None]
self.job_last_reading = [{}, None]
self.job_available = False
self.printer_available = False
self.available = False
self.printer_error_logged = False
sel... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.