desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Update function for updating api information.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
self._api.update()
'Initialize the sensor.'
def __init__(self, api, variable, variable_info, monitor_device=None):
self.var_id = variable self.var_name = variable_info[0] self.var_units = variable_info[1] self.var_icon = variable_info[2] self.monitor_device = monitor_device self._api = api
'Return the name of the sensor, if any.'
@property def name(self):
if (self.monitor_device is not None): return '{} ({})'.format(self.var_name, self.monitor_device) return self.var_name
'Icon to use in the frontend, if any.'
@property def icon(self):
return self.var_icon
'Return the unit the value is expressed in.'
@property def unit_of_measurement(self):
if (self.var_id in ['volume_disk_temp_avg', 'volume_disk_temp_max', 'disk_temp']): return self._api.temp_unit return self.var_units
'Get the latest data for the states.'
def update(self):
if (self._api is not None): self._api.update()
'Return the state of the sensor.'
@property def state(self):
network_sensors = ['network_up', 'network_down'] memory_sensors = ['memory_size', 'memory_cached', 'memory_available_swap', 'memory_available_real', 'memory_total_swap', 'memory_total_real'] if ((self.var_id in network_sensors) or (self.var_id in memory_sensors)): attr = getattr(self._api.utilisatio...
'Return the state of the sensor.'
@property def state(self):
temp_sensors = ['volume_disk_temp_avg', 'volume_disk_temp_max', 'disk_temp'] if (self.monitor_device is not None): if (self.var_id in temp_sensors): attr = getattr(self._api.storage, self.var_id)(self.monitor_device) if (self._api.temp_unit == TEMP_CELSIUS): retur...
'Initialize the sensor.'
def __init__(self, name, state_topic, device_id, timeout, consider_home):
self._state = STATE_AWAY self._name = name self._state_topic = '{}{}'.format(state_topic, '/+') self._device_id = slugify(device_id).upper() self._timeout = timeout self._consider_home = (timedelta(seconds=consider_home) if consider_home else None) self._distance = None self._updated = N...
'Subscribe to MQTT events. This method must be run in the event loop and returns a coroutine.'
def async_added_to_hass(self):
@callback def update_state(device_id, room, distance): 'Update the sensor state.' self._state = room self._distance = distance self._updated = dt.utcnow() self.hass.async_add_job(self.async_update_ha_state()) @callback def message_received(topic, payload,...
'Return the name of the sensor.'
@property def name(self):
return self._name
'Return the state attributes.'
@property def device_state_attributes(self):
return {ATTR_DISTANCE: self._distance}
'Return the current room of the entity.'
@property def state(self):
return self._state
'Update the state for absent devices.'
def update(self):
if (self._updated and self._consider_home and ((dt.utcnow() - self._updated) > self._consider_home)): self._state = STATE_AWAY
'Initialize the sensor.'
def __init__(self, name, data):
self._name = name self._data = data self._state = None self._description = None
'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
'Icon to use in the frontend, if any.'
@property def icon(self):
return self.ICON
'Return other details about the sensor state.'
@property def device_state_attributes(self):
attrs = {} attrs['Description'] = self._description return attrs
'Update the sensor.'
def update(self):
self._data.update() self._state = self._data.data[self.name]['State'] self._description = self._data.data[self.name]['Description']
'Initialize the TubeData object.'
def __init__(self):
self.data = None
'Get the latest data from TFL.'
@Throttle(SCAN_INTERVAL) def update(self):
response = requests.get(URL) if (response.status_code != 200): _LOGGER.warning('Invalid response from API') else: self.data = parse_api_response(response.json())
'Return the state of the sensor.'
@property def state(self):
val = getattr(self.vehicle, self._attribute) if (self._attribute == 'odometer'): return round((val / 1000)) return val
'Return the unit of measurement.'
@property def unit_of_measurement(self):
return RESOURCES[self._attribute][3]
'Return the icon.'
@property def icon(self):
return RESOURCES[self._attribute][2]
'Initialize the sensor.'
def __init__(self, poller, parameter, name, unit, force_update, median):
self.poller = poller self.parameter = parameter self._unit = unit self._name = name self._state = None self.data = [] self._force_update = force_update self.median_count = median
'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 units of measurement.'
@property def unit_of_measurement(self):
return self._unit
'Force update.'
@property def force_update(self):
return self._force_update
'Update current conditions. This uses a rolling median over 3 values to filter out outliers.'
def update(self):
try: _LOGGER.debug('Polling data for %s', self.name) data = self.poller.parameter_value(self.parameter) except IOError as ioerr: _LOGGER.info('Polling error %s', ioerr) data = None return if (data is not None): _LOGGER.debug('%s = %s', sel...
'Initialize the sensor.'
def __init__(self, data, sensor_types):
self.data = data self._name = SENSOR_TYPES[sensor_types][0] self._unit_of_measurement = SENSOR_TYPES[sensor_types][1] self.type = sensor_types self._state = None
'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
'Icon to use in the frontend, if any.'
@property def icon(self):
return SENSOR_TYPES[self.type][2]
'Return the unit the value is expressed in.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Get the latest data and updates the states.'
def update(self):
self.data.update() if (self.type == 'light'): self._state = self.data.light if (self.type == 'light_red'): self._state = self.data.light_red if (self.type == 'light_green'): self._state = self.data.light_green if (self.type == 'light_blue'): self._state = self.data.li...
'Initialize the data object.'
def __init__(self, envirophat, use_leds):
self.envirophat = envirophat self.use_leds = use_leds self.light = None self.light_red = None self.light_green = None self.light_blue = None self.accelerometer_x = None self.accelerometer_y = None self.accelerometer_z = None self.magnetometer_x = None self.magnetometer_y = No...
'Get the latest data from Enviro pHAT.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
self.light = self.envirophat.light.light() if self.use_leds: self.envirophat.leds.on() (self.light_red, self.light_green, self.light_blue) = self.envirophat.light.rgb() if self.use_leds: self.envirophat.leds.off() (self.accelerometer_x, self.accelerometer_y, self.accelerometer_z) = s...
'Initialize the sensor.'
def __init__(self, hass, data, name, unit_of_measurement, value_template):
self._hass = hass self.data = data self._name = name self._state = None self._unit_of_measurement = unit_of_measurement self._value_template = value_template
'Return the name of the sensor.'
@property def name(self):
return self._name
'Return the unit the value is expressed in.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Return the state of the device.'
@property def state(self):
return self._state
'Get the latest data and updates the state.'
def update(self):
self.data.update() value = self.data.value if (value is None): value = STATE_UNKNOWN elif (self._value_template is not None): self._state = self._value_template.render_with_possible_json_value(value, STATE_UNKNOWN) else: self._state = value
'Initialize the data object.'
def __init__(self, command):
self.command = command self.value = None
'Get the latest data with a shell command.'
def update(self):
_LOGGER.info('Running command: %s', self.command) try: return_value = subprocess.check_output(self.command, shell=True, timeout=15) self.value = return_value.strip().decode('utf-8') except subprocess.CalledProcessError: _LOGGER.error('Command failed: %s', self.command) ...
'Initialize the sensor.'
def __init__(self, hass, partition_name, partition_number, info, controller):
self._icon = 'mdi:alarm' self._partition_number = partition_number _LOGGER.debug('Setting up sensor for partition: %s', partition_name) super().__init__((partition_name + ' Keypad'), info, controller)
'Register callbacks.'
@asyncio.coroutine def async_added_to_hass(self):
async_dispatcher_connect(self.hass, SIGNAL_KEYPAD_UPDATE, self._update_callback) async_dispatcher_connect(self.hass, SIGNAL_PARTITION_UPDATE, self._update_callback)
'Return the icon if any.'
@property def icon(self):
return self._icon
'Return the overall state.'
@property def state(self):
return self._info['status']['alpha']
'Return the state attributes.'
@property def device_state_attributes(self):
return self._info['status']
'Update the partition state in HA, if needed.'
@callback def _update_callback(self, partition):
if ((partition is None) or (int(partition) == self._partition_number)): self.hass.async_add_job(self.async_update_ha_state())
'Initialize a sensor.'
def __init__(self, name, namespace, instance):
self._name = name self.namespace = namespace self.instance = instance self.bt_addr = None self.temperature = STATE_UNKNOWN
'Return the name of the sensor.'
@property def name(self):
return self._name
'Return the state of the device.'
@property def state(self):
return self.temperature
'Return the unit the value is expressed in.'
@property def unit_of_measurement(self):
return TEMP_CELSIUS
'Return the polling state.'
@property def should_poll(self):
return False
'Construct interface object.'
def __init__(self, hass, devices, bt_device_id):
self.hass = hass self.devices = devices self.bt_device_id = bt_device_id def callback(bt_addr, _, packet, additional_info): 'Handle new packets.' self.process_packet(additional_info['namespace'], additional_info['instance'], packet.temperature) from beacontools import BeaconSca...
'Continously scan for BLE advertisements.'
def start(self):
if (not self.scanning): self.scanner.start() self.scanning = True else: _LOGGER.debug('start() called, but scanner is already running')
'Assign temperature to device.'
def process_packet(self, namespace, instance, temperature):
_LOGGER.debug('Received temperature for <%s,%s>: %d', namespace, instance, temperature) for dev in self.devices: if ((dev.namespace == namespace) and (dev.instance == instance)): if (dev.temperature != temperature): dev.temperature = temperature de...
'Signal runner to stop and join thread.'
def stop(self):
if self.scanning: _LOGGER.debug('Stopping...') self.scanner.stop() _LOGGER.debug('Stopped') self.scanning = False else: _LOGGER.debug('stop() called but scanner was not running')
'Initialize the sensor.'
def __init__(self, name, user, password, server, port):
self._name = (name or user) self._user = user self._password = password self._server = server self._port = port self._unread_count = 0 self.connection = self._login()
'Login and return an IMAP connection.'
def _login(self):
import imaplib try: connection = imaplib.IMAP4_SSL(self._server, self._port) connection.login(self._user, self._password) return connection except imaplib.IMAP4.error: _LOGGER.error('Failed to login to %s.', self._server) return False
'Return the name of the sensor.'
@property def name(self):
return self._name
'Return the number of unread emails.'
@property def state(self):
return self._unread_count
'Check the number of unread emails.'
def update(self):
import imaplib try: self.connection.select() self._unread_count = len(self.connection.search(None, 'UnSeen UnDeleted')[1][0].split()) except imaplib.IMAP4.error: _LOGGER.info('Connection to %s lost, attempting to reconnect', self._server) try: ...
'Return the icon to use in the frontend.'
@property def icon(self):
return ICON
'Initialize the sensor.'
def __init__(self, channel):
self._channel = channel self._state = STATE_OFFLINE self._preview = None self._game = None self._title = None
'Device should be polled.'
@property def should_poll(self):
return True
'Return the name of the sensor.'
@property def name(self):
return self._channel
'Return the state of the sensor.'
@property def state(self):
return self._state
'Return preview of current game.'
@property def entity_picture(self):
return self._preview
'Update device state.'
def update(self):
from twitch.api import v3 as twitch stream = twitch.streams.by_channel(self._channel).get('stream') if stream: self._game = stream.get('channel').get('game') self._title = stream.get('channel').get('status') self._preview = stream.get('preview').get('small') self._state = STA...
'Return the state attributes.'
@property def device_state_attributes(self):
if (self._state == STATE_STREAMING): return {ATTR_GAME: self._game, ATTR_TITLE: self._title}
'Icon to use in the frontend, if any.'
@property def icon(self):
return ICON
'Initialize the ThinkingCleaner.'
def __init__(self, tc_object, sensor_type, update_devices):
self.type = sensor_type self._tc_object = tc_object self._update_devices = update_devices self._unit_of_measurement = SENSOR_TYPES[sensor_type][1] self._state = None
'Return the name of the sensor.'
@property def name(self):
return '{} {}'.format(self._tc_object.name, SENSOR_TYPES[self.type][0])
'Icon to use in the frontend, if any.'
@property def icon(self):
return SENSOR_TYPES[self.type][2]
'Return the state of the device.'
@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
'Update the sensor.'
def update(self):
self._update_devices() if (self.type == 'battery'): self._state = self._tc_object.battery elif (self.type == 'state'): self._state = STATES[self._tc_object.status] elif (self.type == 'capacity'): self._state = self._tc_object.capacity
'Initialize the sensor.'
def __init__(self, device_label):
self._device_label = device_label
'Return the name of the device.'
@property def name(self):
return (hub.get_first("$.climateValues[?(@.deviceLabel=='%s')].deviceArea", self._device_label) + ' temperature')
'Return the state of the device.'
@property def state(self):
return hub.get_first("$.climateValues[?(@.deviceLabel=='%s')].temperature", self._device_label)
'Return True if entity is available.'
@property def available(self):
return (hub.get_first("$.climateValues[?(@.deviceLabel=='%s')].temperature", self._device_label) is not None)
'Return the unit of measurement of this entity.'
@property def unit_of_measurement(self):
return TEMP_CELSIUS
'Update the sensor.'
def update(self):
hub.update_overview()
'Initialize the sensor.'
def __init__(self, device_label):
self._device_label = device_label
'Return the name of the device.'
@property def name(self):
return (hub.get_first("$.climateValues[?(@.deviceLabel=='%s')].deviceArea", self._device_label) + ' humidity')
'Return the state of the device.'
@property def state(self):
return hub.get_first("$.climateValues[?(@.deviceLabel=='%s')].humidity", self._device_label)
'Return True if entity is available.'
@property def available(self):
return (hub.get_first("$.climateValues[?(@.deviceLabel=='%s')].humidity", self._device_label) is not None)
'Return the unit of measurement of this entity.'
@property def unit_of_measurement(self):
return '%'
'Update the sensor.'
def update(self):
hub.update_overview()
'Initialize the sensor.'
def __init__(self, device_label):
self._device_label = device_label
'Return the name of the device.'
@property def name(self):
return (hub.get_first("$.eventCounts[?(@.deviceLabel=='%s')].area", self._device_label) + ' mouse')
'Return the state of the device.'
@property def state(self):
return hub.get_first("$.eventCounts[?(@.deviceLabel=='%s')].detections", self._device_label)
'Return True if entity is available.'
@property def available(self):
return (hub.get_first("$.eventCounts[?(@.deviceLabel=='%s')]", self._device_label) is not None)
'Return the unit of measurement of this entity.'
@property def unit_of_measurement(self):
return 'Mice'
'Update the sensor.'
def update(self):
hub.update_overview()
'Initialize the sensor.'
def __init__(self, sensor_type, charger):
self._name = SENSOR_TYPES[sensor_type][0] self.type = sensor_type self._state = None self.charger = charger self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]