desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Get the latest data from the device.'
def update(self):
temp = (-99) if self._device_file.startswith(DEFAULT_MOUNT_DIR): lines = self._read_temp_raw() while (lines[0].strip()[(-3):] != 'YES'): time.sleep(0.2) lines = self._read_temp_raw() equals_pos = lines[1].find('t=') if (equals_pos != (-1)): tem...
'Initialize the sensor.'
def __init__(self, sensor_type, device_name, device):
self._device_name = device_name self._name = '{} {}'.format(device_name, SENSOR_TYPES[sensor_type][0]) self._device = device self.type = sensor_type self._state = None self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
'Return the name of the iOS sensor.'
@property def name(self):
device_name = self._device[ios.ATTR_DEVICE][ios.ATTR_DEVICE_NAME] return '{} {}'.format(device_name, SENSOR_TYPES[self.type][0])
'Return the state of the sensor.'
@property def state(self):
return self._state
'Return the unique ID of this sensor.'
@property def unique_id(self):
device_id = self._device[ios.ATTR_DEVICE_ID] return 'sensor_ios_battery_{}_{}'.format(self.type, device_id)
'Return the unit of measurement this sensor expresses itself in.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Return the device state attributes.'
@property def device_state_attributes(self):
device = self._device[ios.ATTR_DEVICE] device_battery = self._device[ios.ATTR_BATTERY] return {'Battery State': device_battery[ios.ATTR_BATTERY_STATE], 'Battery Level': device_battery[ios.ATTR_BATTERY_LEVEL], 'Device Type': device[ios.ATTR_DEVICE_TYPE], 'Device Name': device[ios.ATTR_DEVICE_NAME...
'Return the icon to use in the frontend, if any.'
@property def icon(self):
device_battery = self._device[ios.ATTR_BATTERY] battery_state = device_battery[ios.ATTR_BATTERY_STATE] battery_level = device_battery[ios.ATTR_BATTERY_LEVEL] rounded_level = round(battery_level, (-1)) returning_icon_level = DEFAULT_ICON_LEVEL if (battery_state == ios.ATTR_BATTERY_STATE_FULL): ...
'Get the latest state of the sensor.'
def update(self):
self._device = ios.devices().get(self._device_name) self._state = self._device[ios.ATTR_BATTERY][self.type]
'Initialize the sensor.'
def __init__(self, site, data, condition):
self.site = site self.data = data self._condition = condition
'Return the name of the sensor.'
@property def name(self):
return 'Met Office {}'.format(SENSOR_TYPES[self._condition][0])
'Return the state of the sensor.'
@property def state(self):
if ((self._condition == 'visibility_distance') and ('visibility' in self.data.data.__dict__.keys())): return VISIBILTY_CLASSES.get(self.data.data.visibility.value) if (self._condition in self.data.data.__dict__.keys()): variable = getattr(self.data.data, self._condition) if (self._condit...
'Return the unit of measurement.'
@property def unit_of_measurement(self):
return SENSOR_TYPES[self._condition][1]
'Return the state attributes of the device.'
@property def device_state_attributes(self):
attr = {} attr['Sensor Id'] = self._condition attr['Site Id'] = self.site.id attr['Site Name'] = self.site.name attr['Last Update'] = self.data.data.date attr[ATTR_ATTRIBUTION] = CONF_ATTRIBUTION return attr
'Update current conditions.'
def update(self):
self.data.update()
'Initialize the data object.'
def __init__(self, hass, datapoint, site):
self._hass = hass self._datapoint = datapoint self._site = site self.data = None
'Get the latest data from Datapoint.'
@Throttle(SCAN_INTERVAL) def update(self):
import datapoint as dp try: forecast = self._datapoint.get_forecast_for_site(self._site.id, '3hourly') self.data = forecast.now() except (ValueError, dp.exceptions.APIException) as err: _LOGGER.error('Check Met Office %s', err.args) self.data = None raise
'Initialize the sensor.'
def __init__(self, sensor_type, offset, name):
if name: self._name = name else: self._name = SENSOR_TYPES[sensor_type][0] self.type = sensor_type self.offset = offset self._state = None self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
'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 unit of measurement of this entity, if any.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Return the state attributes.'
@property def device_state_attributes(self):
attrs = {ATTR_ATTRIBUTION: CONF_ATTRIBUTION} return attrs
'Get the ComEd Hourly Pricing data from the web service.'
def update(self):
try: if (self.type == CONF_FIVE_MINUTE): url_string = (_RESOURCE + '?type=5minutefeed') response = get(url_string, timeout=10) self._state = round((float(response.json()[0]['price']) + self.offset), 2) elif (self.type == CONF_CURRENT_HOUR_AVERAGE): url...
'Initialize the sensor.'
def __init__(self, rest, name, sensor_type):
self.rest = rest self._name = name self.type = sensor_type self._state = STATE_UNKNOWN self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
'Return the name of the sensor.'
@property def name(self):
if (self._name is None): return SENSOR_TYPES[self.type][0] return '{} {}'.format(self._name, SENSOR_TYPES[self.type][0])
'Return the unit the value is expressed in.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Could the device be accessed during the last update call.'
@property def available(self):
return (self.rest.data is not None)
'Return the state of the resources.'
@property def state(self):
return self._state
'Get the latest data from REST API.'
def update(self):
self.rest.update() value = self.rest.data if (value is not None): if (self.type == 'disk_use_percent'): self._state = value['fs'][0]['percent'] elif (self.type == 'disk_use'): self._state = round((value['fs'][0]['used'] / (1024 ** 3)), 1) elif (self.type == 'd...
'Initialize the data object.'
def __init__(self, resource):
self._resource = resource self.data = dict()
'Get the latest data from the Glances REST API.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
try: response = requests.get(self._resource, timeout=10) self.data = response.json() except requests.exceptions.ConnectionError: _LOGGER.error('Connection error: %s', self._resource) self.data = None
'Initialize the Wink device.'
def __init__(self, wink, hass):
super().__init__(wink, hass) self.capability = self.wink.capability() if (self.wink.unit() == '\xc2\xb0'): self._unit_of_measurement = TEMP_CELSIUS else: self._unit_of_measurement = self.wink.unit()
'Callback when entity is added to hass.'
@asyncio.coroutine def async_added_to_hass(self):
self.hass.data[DOMAIN]['entities']['sensor'].append(self)
'Return the state.'
@property def state(self):
state = None if (self.capability == 'humidity'): if (self.wink.state() is not None): state = round(self.wink.state()) elif (self.capability == 'temperature'): if (self.wink.state() is not None): state = round(self.wink.state(), 1) elif (self.capability == 'balance...
'Return the unit of measurement of this entity, if any.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Initialize the sensor.'
def __init__(self, controller):
self._state = None self._unit_of_measurement = DEFAULT_UNIT self._controller = controller self._name = 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
'No polling needed.'
@property def should_poll(self):
return False
'Return the unit of measurement of this entity, if any.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Initialize the sensor.'
def __init__(self, controller):
super(LoopEnergyElec, self).__init__(controller) self._name = 'Power Usage' self._controller.subscribe_elecricity(self._callback)
'Get the cached Loop energy.'
def update(self):
self._state = round(self._controller.electricity_useage, 2)
'Initialize the sensor.'
def __init__(self, controller):
super(LoopEnergyGas, self).__init__(controller) self._name = 'Gas Usage' self._controller.subscribe_gas(self._callback)
'Get the cached Loop energy.'
def update(self):
self._state = round(self._controller.gas_useage, 2)
'Create Radarr entity.'
def __init__(self, hass, conf, sensor_type):
from pytz import timezone self.conf = conf self.host = conf.get(CONF_HOST) self.port = conf.get(CONF_PORT) self.urlbase = conf.get(CONF_URLBASE) if self.urlbase: self.urlbase = '{}/'.format(self.urlbase.strip('/')) self.apikey = conf.get(CONF_API_KEY) self.included = conf.get(CON...
'Return the name of the sensor.'
@property def name(self):
return '{} {}'.format('Radarr', self._name)
'Return sensor state.'
@property def state(self):
return self._state
'Return sensor availability.'
@property def available(self):
return self._available
'Return the unit of the sensor.'
@property def unit_of_measurement(self):
return self._unit
'Return the state attributes of the sensor.'
@property def device_state_attributes(self):
attributes = {} if (self.type == 'upcoming'): for movie in self.data: attributes[to_key(movie)] = get_release_date(movie) elif (self.type == 'commands'): for command in self.data: attributes[command['name']] = command['state'] elif (self.type == 'diskspace'): ...
'Return the icon of the sensor.'
@property def icon(self):
return self._icon
'Update the data for the sensor.'
def update(self):
start = get_date(self._tz) end = get_date(self._tz, self.days) try: res = requests.get(ENDPOINTS[self.type].format(self.ssl, self.host, self.port, self.urlbase, start, end), headers={'X-Api-Key': self.apikey}, timeout=5) except OSError: _LOGGER.error('Host %s is not available...
'Initialize the min/max sensor.'
def __init__(self, hass, entity_ids, name, sensor_type, round_digits):
self._hass = hass self._entity_ids = entity_ids self._sensor_type = sensor_type self._round_digits = round_digits if name: self._name = name else: self._name = '{} sensor'.format(next((v for (k, v) in SENSOR_TYPES.items() if (self._sensor_type == v)))).capitalize() self._u...
'Return the name of the sensor.'
@property def name(self):
return self._name
'Return the state of the sensor.'
@property def state(self):
if self._unit_of_measurement_mismatch: return STATE_UNKNOWN return getattr(self, next((k for (k, v) in SENSOR_TYPES.items() if (self._sensor_type == v))))
'Return the unit the value is expressed in.'
@property def unit_of_measurement(self):
if self._unit_of_measurement_mismatch: return 'ERR' return self._unit_of_measurement
'No polling needed.'
@property def should_poll(self):
return False
'Return the state attributes of the sensor.'
@property def device_state_attributes(self):
state_attr = {attr: getattr(self, attr) for attr in ATTR_TO_PROPERTY if (getattr(self, attr) is not None)} return state_attr
'Return the icon to use in the frontend, if any.'
@property def icon(self):
return ICON
'Get the latest data and updates the states.'
@asyncio.coroutine def async_update(self):
sensor_values = [self.states[k] for k in self._entity_ids if (k in self.states)] self.min_value = calc_min(sensor_values) self.max_value = calc_max(sensor_values) self.mean = calc_mean(sensor_values, self._round_digits)
'Initialize the OAuth callback view.'
def __init__(self, config, add_devices, oauth):
self.config = config self.add_devices = add_devices self.oauth = oauth
'Finish OAuth callback request.'
@callback def get(self, request):
from oauthlib.oauth2.rfc6749.errors import MismatchingStateError from oauthlib.oauth2.rfc6749.errors import MissingTokenError hass = request.app['hass'] data = request.query response_message = 'Fitbit has been successfully authorized!\n You can close ...
'Initialize the Fitbit sensor.'
def __init__(self, client, config_path, resource_type, is_metric, extra=None):
self.client = client self.config_path = config_path self.resource_type = resource_type self.extra = extra pretty_resource = self.resource_type.replace('activities/', '') pretty_resource = pretty_resource.replace('/', ' ') pretty_resource = pretty_resource.title() if (pretty_resource =...
'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 unit of measurement of this entity, if any.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Icon to use in the frontend, if any.'
@property def icon(self):
if (self.resource_type == 'devices/battery'): return 'mdi:battery-50' return 'mdi:walk'
'Return the state attributes.'
@property def device_state_attributes(self):
attrs = {} attrs[ATTR_ATTRIBUTION] = CONF_ATTRIBUTION if self.extra: attrs['model'] = self.extra.get('deviceVersion') attrs['type'] = self.extra.get('type') return attrs
'Get the latest data from the Fitbit API and update the states.'
def update(self):
if ((self.resource_type == 'devices/battery') and self.extra): self._state = self.extra.get('battery') else: container = self.resource_type.replace('/', '-') response = self.client.time_series(self.resource_type, period='7d') self._state = response[container][(-1)].get('value') ...
'Initialize the Lyft sensor.'
def __init__(self, sensorType, products, product_id, product):
self.data = products self._product_id = product_id self._product = product self._sensortype = sensorType self._name = '{} {}'.format(self._product['display_name'], self._sensortype) if ('lyft' not in self._name.lower()): self._name = 'Lyft{}'.format(self._name) if (self._sensortyp...
'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 unit of measurement of this entity, if any.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Return the state attributes.'
@property def device_state_attributes(self):
params = {'Product ID': self._product['ride_type'], 'Product display name': self._product['display_name'], 'Vehicle Capacity': self._product['seats']} if (self._product.get('pricing_details') is not None): pricing_details = self._product['pricing_details'] params['Base price'] = p...
'Icon to use in the frontend, if any.'
@property def icon(self):
return ICON
'Get the latest data from the Lyft API and update the states.'
def update(self):
self.data.update() try: self._product = self.data.products[self._product_id] except KeyError: return self._state = None if (self._sensortype == 'time'): eta = self._product['eta'] if ((eta is not None) and eta.get('is_valid_estimate')): time_estimate = eta...
'Initialize the LyftEstimate object.'
def __init__(self, session, start_latitude, start_longitude, end_latitude=None, end_longitude=None):
self._session = session self.start_latitude = start_latitude self.start_longitude = start_longitude self.end_latitude = end_latitude self.end_longitude = end_longitude self.products = None
'Get the latest product info and estimates from the Lyft API.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
from lyft_rides.errors import APIError try: self.fetch_data() except APIError as exc: _LOGGER.error('Error fetching Lyft data: %s', exc)
'Get the latest product info and estimates from the Lyft API.'
def fetch_data(self):
from lyft_rides.client import LyftRidesClient client = LyftRidesClient(self._session) self.products = {} products_response = client.get_ride_types(self.start_latitude, self.start_longitude) products = products_response.json.get('ride_types') for product in products: self.products[product...
'Initialize the sensor.'
def __init__(self, hass, api, xuid):
self._hass = hass self._state = STATE_UNKNOWN self._presence = {} self._xuid = xuid self._api = api profile = self._api.get_user_profile(self._xuid) if (profile.get('success', True) and (profile.get('code', 0) != 28)): self.success_init = True self._gamertag = profile.get('Ga...
'Return the name of the sensor.'
@property def name(self):
return self._gamertag
'Return the state of the sensor.'
@property def state(self):
return self._state
'Return the state attributes.'
@property def device_state_attributes(self):
attributes = {} for device in self._presence: for title in device.get('titles'): attributes['{} {}'.format(device.get('type'), title.get('placement'))] = title.get('name') return attributes
'Avatar of the account.'
@property def entity_picture(self):
return self._picture
'Return the icon to use in the frontend.'
@property def icon(self):
return ICON
'Update state data from Xbox API.'
def update(self):
presence = self._api.get_user_presence(self._xuid) self._state = presence.get('state', STATE_UNKNOWN) self._presence = presence.get('devices', {})
'Initialize the sensor.'
def __init__(self, name, pin, pin_type):
self._pin = pin self._name = name self.pin_type = pin_type self.direction = 'in' self._value = None arduino.BOARD.set_mode(self._pin, self.direction, self.pin_type)
'Return the state of the sensor.'
@property def state(self):
return self._value
'Get the name of the sensor.'
@property def name(self):
return self._name
'Get the latest value from the pin.'
def update(self):
self._value = arduino.BOARD.get_analog_inputs()[self._pin][1]
'Initialize the sensor.'
def __init__(self, rest, condition, stationname):
self.rest = rest self._condition = condition self.stationname = stationname
'Return the name of the sensor.'
@property def name(self):
if (self.stationname is None): return 'BOM {}'.format(SENSOR_TYPES[self._condition][0]) return 'BOM {} {}'.format(self.stationname, SENSOR_TYPES[self._condition][0])
'Return the state of the sensor.'
@property def state(self):
if (self.rest.data and (self._condition in self.rest.data)): return self.rest.data[self._condition] return STATE_UNKNOWN
'Return the state attributes of the device.'
@property def device_state_attributes(self):
attr = {} attr['Sensor Id'] = self._condition attr['Zone Id'] = self.rest.data['history_product'] attr['Station Id'] = self.rest.data['wmo'] attr['Station Name'] = self.rest.data['name'] attr['Last Update'] = datetime.datetime.strptime(str(self.rest.data['local_date_time_full']), ...
'Return the units of measurement.'
@property def unit_of_measurement(self):
return SENSOR_TYPES[self._condition][1]
'Update current conditions.'
def update(self):
self.rest.update()
'Initialize the data object.'
def __init__(self, hass, station_id):
self._hass = hass (self._zone_id, self._wmo_id) = station_id.split('.') self.data = None self._lastupdate = LAST_UPDATE
'Get the latest data from BOM.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
if ((self._lastupdate != 0) and ((datetime.datetime.now() - self._lastupdate) < datetime.timedelta(minutes=35))): _LOGGER.info('BOM was updated %s minutes ago, skipping update as < 35 minutes', (datetime.datetime.now() - self._lastupdate)) return self._lastupdate ...
'Initialize the sensor.'
def __init__(self, name, host, ipcam, sensor):
super().__init__(host, ipcam) self._sensor = sensor self._mapped_name = KEY_MAP.get(self._sensor, self._sensor) self._name = '{} {}'.format(name, self._mapped_name) self._state = None self._unit = None
'Return the name of the sensor, if any.'
@property def name(self):
return self._name