desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Return the contract list.'
def get_contract_list(self):
self._fetch_data() return self.client.get_contracts()
'Fetch latest data from HydroQuebec.'
def _fetch_data(self):
from pyhydroquebec.client import PyHydroQuebecError try: self.client.fetch_data() except PyHydroQuebecError as exp: _LOGGER.error('Error on receive last Hydroquebec data: %s', exp) return
'Return the latest collected data from HydroQuebec.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
self._fetch_data() self.data = self.client.get_data(self._contract)[self._contract]
'Initialize the sensor.'
def __init__(self, hass, name, latitude, longitude, radius, include, exclude):
import crimereports self._hass = hass self._name = name self._include = include self._exclude = exclude radius_kilometers = convert(radius, LENGTH_METERS, LENGTH_KILOMETERS) self._crimereports = crimereports.CrimeReports((latitude, longitude), radius_kilometers) self._attributes = 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
'Return the state attributes.'
@property def device_state_attributes(self):
return self._attributes
'Update device state.'
def update(self):
import crimereports incident_counts = defaultdict(int) incidents = self._crimereports.get_incidents(now().date(), include=self._include, exclude=self._exclude) fire_events = (len(self._previous_incidents) > 0) if (len(incidents) < len(self._previous_incidents)): self._previous_incidents = se...
'Initialize the sensor.'
def __init__(self, name, address):
self._name = name self.address = address self._state = None self._unit_of_measurement = 'ETH'
'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 this sensor expresses itself in.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Return the state attributes of the sensor.'
@property def device_state_attributes(self):
return {ATTR_ATTRIBUTION: CONF_ATTRIBUTION}
'Get the latest state of the sensor.'
def update(self):
from pyetherscan import get_balance self._state = get_balance(self.address)
'Initialise the sensor.'
def __init__(self, device, sensor_type, hass):
super().__init__(device, sensor_type, hass) self._name = SENSOR_TYPES[sensor_type][0] self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
'Return the name of the device.'
@property def name(self):
return '{} {}'.format(self.device.name(), self._name)
'Return the icon of the sensor.'
@property def icon(self):
icon = None if (self.type == 'status'): status = self.device.getStatus() if (status == 'standby'): icon = 'mdi:power-plug-off' elif (status == 'plugged'): icon = 'mdi:power-plug' elif (status == 'charging'): icon = 'mdi:battery-positive' el...
'Return the unit the value is expressed in.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Return the state.'
@property def state(self):
state = None if (self.type == 'status'): state = self.device.getStatus() elif (self.type == 'temperature'): state = self.device.getTemperature() elif (self.type == 'voltage'): state = self.device.getVoltage() elif (self.type == 'amps'): state = self.device.getAmps() ...
'Return the state attributes.'
@property def device_state_attributes(self):
attributes = {} if (self.type == 'status'): man_dev_id = self.device.id() if man_dev_id: attributes['manufacturer_device_id'] = man_dev_id return attributes
'Initialize the sensor.'
def __init__(self, hass, name, indoor_temp_sensor, outdoor_temp_sensor, indoor_humidity_sensor, calib_factor):
self._state = None self._name = name self._indoor_temp_sensor = indoor_temp_sensor self._indoor_humidity_sensor = indoor_humidity_sensor self._outdoor_temp_sensor = outdoor_temp_sensor self._calib_factor = calib_factor self._is_metric = hass.config.units.is_metric self._dewpoint = None ...
'Parse temperature sensor value.'
@staticmethod def _update_temp_sensor(state):
unit = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) temp = util.convert(state.state, float) if (temp is None): _LOGGER.error('Unable to parse sensor temperature: %s', state.state) return None if (unit == TEMP_FAHRENHEIT): return util.temperature.fahrenheit_to_cel...
'Parse humidity sensor value.'
@staticmethod def _update_hum_sensor(state):
unit = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) hum = util.convert(state.state, float) if (hum is None): _LOGGER.error('Unable to parse sensor humidity: %s', state.state) return None if (unit != '%'): _LOGGER.error('Humidity sensor has unsupported ...
'Calculate latest state.'
def update(self):
if (None in (self._indoor_temp, self._indoor_hum, self._outdoor_temp)): return self._calc_dewpoint() self._calc_moldindicator()
'Handle sensor state changes.'
def _sensor_changed(self, entity_id, old_state, new_state):
if (new_state is None): return if (entity_id == self._indoor_temp_sensor): self._indoor_temp = MoldIndicator._update_temp_sensor(new_state) elif (entity_id == self._outdoor_temp_sensor): self._outdoor_temp = MoldIndicator._update_temp_sensor(new_state) elif (entity_id == self._in...
'Calculate the dewpoint for the indoor air.'
def _calc_dewpoint(self):
alpha = ((MAGNUS_K2 * self._indoor_temp) / (MAGNUS_K3 + self._indoor_temp)) beta = ((MAGNUS_K2 * MAGNUS_K3) / (MAGNUS_K3 + self._indoor_temp)) if (self._indoor_hum == 0): self._dewpoint = (-50) else: self._dewpoint = ((MAGNUS_K3 * (alpha + math.log((self._indoor_hum / 100.0)))) / (beta -...
'Calculate the humidity at the (cold) calibration point.'
def _calc_moldindicator(self):
if ((None in (self._dewpoint, self._calib_factor)) or (self._calib_factor == 0)): _LOGGER.debug('Invalid inputs - dewpoint: %s, calibration-factor: %s', self._dewpoint, self._calib_factor) self._state = None return self._crit_temp = (self._outdoor_temp + ((self._indoor_...
'Return the polling state.'
@property def should_poll(self):
return False
'Return the name.'
@property def name(self):
return self._name
'Return the unit of measurement.'
@property def unit_of_measurement(self):
return '%'
'Return the state of the entity.'
@property def state(self):
return self._state
'Return the state attributes.'
@property def device_state_attributes(self):
if self._is_metric: return {ATTR_DEWPOINT: self._dewpoint, ATTR_CRITICAL_TEMP: self._crit_temp} return {ATTR_DEWPOINT: util.temperature.celsius_to_fahrenheit(self._dewpoint), ATTR_CRITICAL_TEMP: util.temperature.celsius_to_fahrenheit(self._crit_temp)}
'Initialize the sensor.'
def __init__(self, name, address):
self._name = name self.address = address self._state = None self._unit_of_measurement = 'XRP'
'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 this sensor expresses itself in.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Return the state attributes of the sensor.'
@property def device_state_attributes(self):
return {ATTR_ATTRIBUTION: CONF_ATTRIBUTION}
'Get the latest state of the sensor.'
def update(self):
from pyripple import get_balance self._state = get_balance(self.address)
'Initialize the sensor.'
def __init__(self, name):
self._name = name self._state = None
'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 == 0): return 'New moon' elif (self._state < 7): return 'Waxing crescent' elif (self._state == 7): return 'First quarter' elif (self._state < 14): return 'Waxing gibbous' elif (self._state == 14): return 'Full moon' elif (sel...
'Icon to use in the frontend, if any.'
@property def icon(self):
return ICON
'Get the time and updates the states.'
@asyncio.coroutine def async_update(self):
from astral import Astral today = dt_util.as_local(dt_util.utcnow()).date() self._state = Astral().moon_phase(today)
'Initialize the sensor.'
def __init__(self, vasttrafik, planner, name, departure, heading, delay):
self._vasttrafik = vasttrafik self._planner = planner self._name = (name or departure) self._departure = planner.location_name(departure)[0] self._heading = (planner.location_name(heading)[0] if heading else None) self._delay = timedelta(minutes=delay) self._departureboard = None
'Return the name of the sensor.'
@property def name(self):
return self._name
'Return the icon for the frontend.'
@property def icon(self):
return ICON
'Return the state attributes.'
@property def device_state_attributes(self):
if (not self._departureboard): return departure = self._departureboard[0] params = {ATTR_ACCESSIBILITY: departure.get('accessibility', None), ATTR_ATTRIBUTION: CONF_ATTRIBUTION, ATTR_DIRECTION: departure.get('direction', None), ATTR_LINE: departure.get('sname', None), ATTR_TRACK: departure.get('trac...
'Return the next departure time.'
@property def state(self):
if (not self._departureboard): _LOGGER.warning('No departures from %s heading %s', self._departure['name'], (self._heading['name'] if self._heading else 'ANY')) return if ('rtTime' in self._departureboard[0]): return self._departureboard[0]['rtTime'] return self._depar...
'Get the departure board.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
try: self._departureboard = self._planner.departureboard(self._departure['id'], direction=(self._heading['id'] if self._heading else None), date=(datetime.now() + self._delay)) except self._vasttrafik.Error: _LOGGER.warning('Unable to read departure board, updating token') ...
'Initialize the sensor.'
def __init__(self, api, channel_id, name):
self._name = name self._state = STATE_UNKNOWN self._api = api self._channel_id = channel_id
'Return the name of the sensor.'
@property def name(self):
return self._name
'Return icon.'
@property def icon(self):
return ICON
'Return the unit of measurement of this entity, if any.'
@property def unit_of_measurement(self):
return UNIT_OF_MEASUREMENT
'Return the state of the device.'
@property def state(self):
return self._state
'Get the latest data.'
def update(self):
try: response = self._api.get_data_now(channelid=self._channel_id) self._state = int(response.power) _LOGGER.debug('Updated power from server %d W', self._state) except OSError as error: _LOGGER.warning('Could not connect to the ELIQ Online API...
'Initialize the sensor.'
def __init__(self, bbox_data, sensor_type, name):
self.client_name = name self.type = sensor_type self._name = SENSOR_TYPES[sensor_type][0] self._unit_of_measurement = SENSOR_TYPES[sensor_type][1] self._icon = SENSOR_TYPES[sensor_type][2] self.bbox_data = bbox_data self._state = None
'Return the name of the sensor.'
@property def name(self):
return '{} {}'.format(self.client_name, 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):
return self._icon
'Return the state attributes.'
@property def device_state_attributes(self):
return {ATTR_ATTRIBUTION: ATTRIBUTION}
'Get the latest data from Bbox and update the state.'
def update(self):
self.bbox_data.update() if (self.type == 'down_max_bandwidth'): self._state = round((self.bbox_data.data['rx']['maxBandwidth'] / 1000), 2) elif (self.type == 'up_max_bandwidth'): self._state = round((self.bbox_data.data['tx']['maxBandwidth'] / 1000), 2) elif (self.type == 'current_down_b...
'Initialize the data object.'
def __init__(self):
self.data = None
'Get the latest data from the Bbox.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
import pybbox try: box = pybbox.Bbox() self.data = box.get_ip_stats() except requests.exceptions.HTTPError as error: _LOGGER.error(error) self.data = None return False
'Initialize the sensor.'
def __init__(self, hass, data, name, value_template, unit_of_measurement, sensorid, elem):
if (name is None): self._name = 'emoncms{}_feedid_{}'.format(sensorid, elem['id']) else: self._name = name self._identifier = get_id(sensorid, elem['tag'], elem['name'], elem['id'], elem['userid']) self._hass = hass self._data = data self._value_template = value_template self...
'Return the name of the sensor.'
@property def name(self):
return self._name
'Return the unit of measurement of this entity, if any.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Return the state of the device.'
@property def state(self):
return self._state
'Return the atrributes of the sensor.'
@property def device_state_attributes(self):
return {ATTR_FEEDID: self._elem['id'], ATTR_TAG: self._elem['tag'], ATTR_FEEDNAME: self._elem['name'], ATTR_SIZE: self._elem['size'], ATTR_USERID: self._elem['userid'], ATTR_LASTUPDATETIME: self._elem['time'], ATTR_LASTUPDATETIMESTR: template.timestamp_local(float(self._elem['time']))}
'Get the latest data and updates the state.'
def update(self):
self._data.update() if (self._data.data is None): return elem = next((elem for elem in self._data.data if (get_id(self._sensorid, elem['tag'], elem['name'], elem['id'], elem['userid']) == self._identifier)), None) if (elem is None): return self._elem = elem if (self._value_templa...
'Initialize the data object.'
def __init__(self, hass, url, apikey, interval):
self._apikey = apikey self._url = '{}/feed/list.json'.format(url) self._interval = interval self._hass = hass self.data = None
'Get the latest data from Emoncms.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
try: parameters = {'apikey': self._apikey} req = requests.get(self._url, params=parameters, allow_redirects=True, timeout=5) except requests.exceptions.RequestException as exception: _LOGGER.error(exception) return else: if (req.status_code == 200): self.d...
'Initialize the battery sensor.'
def __init__(self, name, battery_id):
import batinfo self._battery = batinfo.Batteries() self._name = name self._battery_stat = None self._battery_id = (battery_id - 1) self._unit_of_measurement = '%'
'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._battery_stat.capacity
'Return the unit the value is expressed in.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Return the icon to use in the frontend, if any.'
@property def icon(self):
return ICON
'Return the state attributes of the sensor.'
@property def device_state_attributes(self):
return {ATTR_NAME: self._battery_stat.name, ATTR_PATH: self._battery_stat.path, ATTR_ALARM: self._battery_stat.alarm, ATTR_CAPACITY_LEVEL: self._battery_stat.capacity_level, ATTR_CYCLE_COUNT: self._battery_stat.cycle_count, ATTR_ENERGY_FULL: self._battery_stat.energy_full, ATTR_ENERGY_FULL_DESIGN: self._battery_sta...
'Get the latest data and updates the states.'
def update(self):
self._battery.update() self._battery_stat = self._battery.stat[self._battery_id]
'Return True if state updates should be forced. If True, a state change will be triggered anytime the state property is updated, not just when the value changes.'
@property def force_update(self):
return True
'Return the state of the device.'
@property def state(self):
return self._values.get(self.value_type)
'Return the unit of measurement of this entity.'
@property def unit_of_measurement(self):
pres = self.gateway.const.Presentation set_req = self.gateway.const.SetReq unit_map = {set_req.V_TEMP: (TEMP_CELSIUS if self.gateway.metric else TEMP_FAHRENHEIT), set_req.V_HUM: '%', set_req.V_DIMMER: '%', set_req.V_LIGHT_LEVEL: '%', set_req.V_DIRECTION: '\xc2\xb0', set_req.V_WEIGHT: 'kg', set_req.V_DISTANC...
'Initialize the sensor.'
def __init__(self, sleepiq_data, bed_id, side):
sleepiq.SleepIQSensor.__init__(self, sleepiq_data, bed_id, side) self._state = None self.type = sleepiq.SLEEP_NUMBER self._name = sleepiq.SENSOR_TYPES[self.type] self.update()
'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 ICON
'Get the latest data from SleepIQ and updates the states.'
def update(self):
sleepiq.SleepIQSensor.update(self) self._state = self.side.sleep_number
'Initialize the sensor.'
def __init__(self, rest, base, quote):
self.rest = rest self._quote = quote self._base = base self._state = None
'Return the name of the sensor.'
@property def name(self):
return '{} {}'.format(self._base, self._quote)
'Return the icon to use in the frontend, if any.'
@property def icon(self):
return ICON
'Return the state of the sensor.'
@property def state(self):
return self._state
'Return the state attributes of the sensor.'
@property def device_state_attributes(self):
return {ATTR_ATTRIBUTION: CONF_ATTRIBUTION}
'Update current date.'
def update(self):
self.rest.update() value = self.rest.data if (value is not None): self._state = round(value['{}{}'.format(self._base, self._quote)], 4)
'Initialize the data object.'
def __init__(self, resource, parameters):
self._resource = resource self._parameters = parameters self.data = None
'Get the latest data from Currencylayer.'
def update(self):
try: result = requests.get(self._resource, params=self._parameters, timeout=10) if ('error' in result.json()): raise ValueError(result.json()['error']['info']) else: self.data = result.json()['quotes'] _LOGGER.debug('Currencylayer data updated: %s...
'Initialize the sensor.'
def __init__(self, values):
zwave.ZWaveDeviceEntity.__init__(self, values, DOMAIN) self.update_properties()
'Handle the data changes for node values.'
def update_properties(self):
self._state = self.values.primary.data self._units = self.values.primary.units
'Return force_update.'
@property def force_update(self):
return True
'Return the state of the sensor.'
@property def state(self):
return self._state
'Return the unit of measurement the value is expressed in.'
@property def unit_of_measurement(self):
return self._units
'Return the state of the sensor.'
@property def state(self):
if (self._units in ('C', 'F')): return round(self._state, 1) elif isinstance(self._state, float): return round(self._state, 2) return self._state