desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Return the unit the value is expressed in.'
@property def unit_of_measurement(self):
return self._unit
'Return the state of the sensor.'
@property def state(self):
return self._state
'Retrieve latest state.'
@asyncio.coroutine def async_update(self):
if (self._sensor in ('audio_connections', 'video_connections')): if (not self._ipcam.status_data): return self._state = self._ipcam.status_data.get(self._sensor) self._unit = 'Connections' else: (self._state, self._unit) = self._ipcam.export_sensor(self._sensor)
'Return the icon for the sensor.'
@property def icon(self):
if ((self._sensor == 'battery_level') and (self._state is not None)): rounded_level = round(int(self._state), (-1)) returning_icon = 'mdi:battery' if (rounded_level < 10): returning_icon = 'mdi:battery-outline' elif (self._state == 100): returning_icon = 'mdi:...
'Initialize a Pi-Hole sensor.'
def __init__(self, hass, api, name, variable):
self._hass = hass self._api = api self._name = name self._var_id = variable variable_info = MONITORED_CONDITIONS[variable] self._var_name = variable_info[0] self._var_units = variable_info[1] self._var_icon = variable_info[2]
'Return the name of the sensor.'
@property def name(self):
return '{} {}'.format(self._name, 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):
return self._var_units
'Return the state of the device.'
@property def state(self):
try: return round(self._api.data[self._var_id], 2) except TypeError: return self._api.data[self._var_id]
'Return the state attributes of the Pi-Hole.'
@property def device_state_attributes(self):
return {ATTR_BLOCKED_DOMAINS: self._api.data['domains_being_blocked']}
'Could the device be accessed during the last update call.'
@property def available(self):
return self._api.available
'Get the latest data from the Pi-Hole API.'
def update(self):
self._api.update()
'Initialize the data object.'
def __init__(self, host, use_ssl, verify_ssl):
from homeassistant.components.sensor.rest import RestData uri_scheme = ('https://' if use_ssl else 'http://') resource = '{}{}{}'.format(uri_scheme, host, _ENDPOINT) self._rest = RestData('GET', resource, None, None, None, verify_ssl) self.data = None self.available = True self.update()
'Get the latest data from the Pi-Hole.'
def update(self):
try: self._rest.update() self.data = json.loads(self._rest.data) self.available = True except TypeError: _LOGGER.error('Unable to fetch data from Pi-Hole') self.available = False
'Initialize the sensor.'
def __init__(self, sensor_type, transmission_client, client_name):
self._name = SENSOR_TYPES[sensor_type][0] self.transmission_client = transmission_client self.type = sensor_type self.client_name = client_name self._state = None self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
'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
'Call the throttled Transmission refresh method.'
def refresh_transmission_data(self):
from transmissionrpc.error import TransmissionError if (_THROTTLED_REFRESH is not None): try: _THROTTLED_REFRESH() except TransmissionError: _LOGGER.error('Connection to Transmission API failed')
'Get the latest data from Transmission and updates the state.'
def update(self):
self.refresh_transmission_data() if (self.type == 'current_status'): if self.transmission_client.session: upload = self.transmission_client.session.uploadSpeed download = self.transmission_client.session.downloadSpeed if ((upload > 0) and (download > 0)): ...
'Initialize a Google Wifi sensor.'
def __init__(self, api, name, variable):
self._api = api self._name = name self._state = STATE_UNKNOWN variable_info = MONITORED_CONDITIONS[variable] self._var_name = variable self._var_units = variable_info[1] self._var_icon = variable_info[2]
'Return the name of the sensor.'
@property def name(self):
return '{}_{}'.format(self._name, 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):
return self._var_units
'Return availability of Google Wifi API.'
@property def available(self):
return self._api.available
'Return the state of the device.'
@property def state(self):
return self._state
'Get the latest data from the Google Wifi API.'
def update(self):
self._api.update() if self.available: self._state = self._api.data[self._var_name] else: self._state = STATE_UNKNOWN
'Initialize the data object.'
def __init__(self, host, conditions):
uri = 'http://' resource = '{}{}{}'.format(uri, host, ENDPOINT) self._request = requests.Request('GET', resource).prepare() self.raw_data = None self.conditions = conditions self.data = {ATTR_CURRENT_VERSION: STATE_UNKNOWN, ATTR_NEW_VERSION: STATE_UNKNOWN, ATTR_UPTIME: STATE_UNKNOWN, ATTR_LAST_R...
'Get the latest data from the router.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
try: with requests.Session() as sess: response = sess.send(self._request, timeout=10) self.raw_data = response.json() self.data_format() self.available = True except (ValueError, requests.exceptions.ConnectionError): _LOGGER.warning('Unable to fetch d...
'Format raw data into easily accessible dict.'
def data_format(self):
for attr_key in self.conditions: value = MONITORED_CONDITIONS[attr_key] try: primary_key = value[0][0] sensor_key = value[0][1] if (primary_key in self.raw_data): sensor_value = self.raw_data[primary_key][sensor_key] if ((attr_key =...
'Initialize the sensor.'
def __init__(self, name, weather_data, sensor_type, temp_unit):
self.client_name = name self._name = SENSOR_TYPES[sensor_type][0] self.owa_client = weather_data self.temp_unit = temp_unit self.type = sensor_type self._state = None self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
'Return the name of the sensor.'
@property def name(self):
return '{} {}'.format(self.client_name, self._name)
'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
'Return the state attributes.'
@property def device_state_attributes(self):
return {ATTR_ATTRIBUTION: CONF_ATTRIBUTION}
'Get the latest data from OWM and updates the states.'
def update(self):
self.owa_client.update() data = self.owa_client.data fc_data = self.owa_client.fc_data if ((data is None) or (fc_data is None)): return if (self.type == 'weather'): self._state = data.get_detailed_status() elif (self.type == 'temperature'): if (self.temp_unit == TEMP_CELS...
'Initialize the data object.'
def __init__(self, owm, forecast, latitude, longitude):
self.owm = owm self.forecast = forecast self.latitude = latitude self.longitude = longitude self.data = None self.fc_data = None
'Get the latest data from OpenWeatherMap.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
try: obs = self.owm.weather_at_coords(self.latitude, self.longitude) except TypeError: obs = None if (obs is None): _LOGGER.warning('Failed to fetch data') return self.data = obs.get_weather() if (self.forecast == 1): try: obs = self.owm.t...
'Initialize the sensor.'
def __init__(self, data, stop, route, name):
self.data = data self._name = name self._stop = stop self._route = route self._times = 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
'Return the state attributes.'
@property def device_state_attributes(self):
if (self._times is not None): next_up = 'None' if self._times: next_up = (self._times[1][ATTR_ROUTE] + ' in ') next_up += self._times[1][ATTR_DUE_IN] return {ATTR_DUE_IN: self._times[0][ATTR_DUE_IN], ATTR_DUE_AT: self._times[0][ATTR_DUE_AT], ATTR_STOP_ID: self._...
'Return the unit this state is expressed in.'
@property def unit_of_measurement(self):
return 'min'
'Icon to use in the frontend, if any.'
@property def icon(self):
return ICON
'Get the latest data from opendata.ch and update the states.'
def update(self):
self.data.update() self._times = self.data.info try: self._state = self._times[0][ATTR_DUE_IN] except TypeError: pass
'Initialize the data object.'
def __init__(self, stop, route):
self.stop = stop self.route = route self.info = [{ATTR_DUE_AT: 'n/a', ATTR_ROUTE: self.route, ATTR_DUE_IN: 'n/a'}]
'Get the latest data from opendata.ch.'
def update(self):
params = {} params['stopid'] = self.stop if self.route: params['routeid'] = self.route params['maxresults'] = 2 params['format'] = 'json' response = requests.get(_RESOURCE, params, timeout=10) if (response.status_code != 200): self.info = [{ATTR_DUE_AT: 'n/a', ATTR_ROUTE: sel...
'Initialize the sensor.'
def __init__(self, name, description, product_id, domain, regex):
self._name = name self.description = description self.data = GeizParser(product_id, domain, regex) self._state = 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 best price of the selected product.'
@property def state(self):
return self._state
'Return the state attributes.'
@property def device_state_attributes(self):
attrs = {'device_name': self.data.device_name, 'description': self.description, 'unit_of_measurement': self.data.unit_of_measurement, 'product_id': self.data.product_id, 'price1': self.data.prices[0], 'price2': self.data.prices[1], 'price3': self.data.prices[2], 'price4': self.data.prices[3]} return attrs
'Get the latest price from geizhals and updates the state.'
def update(self):
self.data.update() self._state = self.data.prices[0]
'Initialize the sensor.'
def __init__(self, product_id, domain, regex):
self.product_id = product_id self.domain = domain self.regex = regex self.device_name = '' self.prices = [None, None, None, None] self.unit_of_measurement = ''
'Update the device prices.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
import bs4 import requests import re sess = requests.session() request = sess.get('https://{}/{}'.format(self.domain, self.product_id), allow_redirects=True, timeout=1) soup = bs4.BeautifulSoup(request.text, 'html.parser') raw = soup.find_all('span', attrs={'itemprop': 'name'}) self.devi...
'Initialize a new OctoPrint sensor.'
def __init__(self, api, condition, sensor_type, sensor_name, unit, endpoint, group, tool=None):
self.sensor_name = sensor_name if (tool is None): self._name = '{} {}'.format(sensor_name, condition) else: self._name = '{} {} {} {}'.format(sensor_name, condition, tool, 'temp') self.sensor_type = sensor_type self.api = api self._state = None self._unit_of_measu...
'Return the name of the sensor.'
@property def name(self):
return self._name
'Return the state of the sensor.'
@property def state(self):
sensor_unit = self.unit_of_measurement if ((sensor_unit == TEMP_CELSIUS) or (sensor_unit == '%')): if (self._state is None): self._state = 0 return round(self._state, 2) else: 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 state of sensor.'
def update(self):
try: self._state = self.api.update(self.sensor_type, self.api_endpoint, self.api_group, self.api_tool) except requests.exceptions.ConnectionError: return
'Initialize the sensor.'
def __init__(self, name, tellcore_sensor, datatype, sensor_info):
self._datatype = datatype self._tellcore_sensor = tellcore_sensor self._unit_of_measurement = (sensor_info.unit or None) self._value = None self._name = '{} {}'.format(name, sensor_info.name)
'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._value
'Return the unit of measurement of this entity, if any.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Update tellstick sensor.'
def update(self):
self._value = self._tellcore_sensor.value(self._datatype).value
'Initialize a PVOutput sensor.'
def __init__(self, rest, name):
self.rest = rest self._name = name self.pvcoutput = None self.status = namedtuple('status', [ATTR_DATE, ATTR_TIME, ATTR_ENERGY_GENERATION, ATTR_POWER_GENERATION, ATTR_ENERGY_CONSUMPTION, ATTR_POWER_CONSUMPTION, ATTR_EFFICIENCY, ATTR_TEMPERATURE, ATTR_VOLTAGE])
'Return the name of the sensor.'
@property def name(self):
return self._name
'Return the state of the device.'
@property def state(self):
if (self.pvcoutput is not None): return self.pvcoutput.energy_generation return None
'Return the state attributes of the monitored installation.'
@property def device_state_attributes(self):
if (self.pvcoutput is not None): return {ATTR_ENERGY_GENERATION: self.pvcoutput.energy_generation, ATTR_POWER_GENERATION: self.pvcoutput.power_generation, ATTR_ENERGY_CONSUMPTION: self.pvcoutput.energy_consumption, ATTR_POWER_CONSUMPTION: self.pvcoutput.power_consumption, ATTR_EFFICIENCY: self.pvcoutput.eff...
'Get the latest data from the PVOutput API and updates the state.'
def update(self):
try: self.rest.update() self.pvcoutput = self.status._make(self.rest.data.split(',')) except TypeError: self.pvcoutput = None _LOGGER.error('Unable to fetch data from PVOutput. %s', self.rest.data)
'Initialize the sensor.'
def __init__(self, probe, variable, name):
self.probe = probe self.client_name = name self.variable = variable
'Return the name of the sensor.'
@property def name(self):
return '{} {}'.format(self.client_name, self.variable)
'Return the state of the sensor.'
@property def state(self):
return self.probe.get_data(self.variable)
'Return the unit of measurement of this entity, if any.'
@property def unit_of_measurement(self):
return SENSOR_TYPES[self.variable][1]
'Return the state attributes.'
@property def device_state_attributes(self):
return {ATTR_WEATHER_ATTRIBUTION: ATTRIBUTION, ATTR_STATION: self.probe.get_data('station_name'), ATTR_UPDATED: self.probe.last_update.isoformat()}
'Delegate update to probe.'
def update(self):
self.probe.update()
'Initialize the probe.'
def __init__(self, station_id):
self._station_id = station_id self.data = {}
'Return the timestamp of the most recent data.'
@property def last_update(self):
(date, time) = (self.data.get('update_date'), self.data.get('update_time')) if ((date is not None) and (time is not None)): return datetime.strptime((date + time), '%d-%m-%Y%H:%M').replace(tzinfo=pytz.timezone('Europe/Vienna'))
'Fetch the latest CSV data.'
@classmethod def current_observations(cls):
try: response = requests.get(cls.API_URL, headers=cls.API_HEADERS, timeout=15) response.raise_for_status() response.encoding = 'UTF8' return csv.DictReader(response.text.splitlines(), delimiter=';', quotechar='"') except requests.exceptions.HTTPError: _LOGGER.error('While...
'Get the latest data from ZAMG.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
if (self.last_update and ((self.last_update + timedelta(hours=1)) > datetime.utcnow().replace(tzinfo=pytz.utc))): return for row in self.current_observations(): if (row.get('Station') == self._station_id): api_fields = {col_heading: (standard_name, dtype) for (standard_name, (_, _, c...
'Get the data.'
def get_data(self, variable):
return self.data.get(variable)
'Initialize the sensor.'
def __init__(self, name, state_topic, qos, unit_of_measurement, force_update, expire_after, value_template):
self._state = STATE_UNKNOWN self._name = name self._state_topic = state_topic self._qos = qos self._unit_of_measurement = unit_of_measurement self._force_update = force_update self._template = value_template self._expire_after = expire_after self._expiration_trigger = None
'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 message_received(topic, payload, qos): 'Handle new MQTT messages.' if ((self._expire_after is not None) and (self._expire_after > 0)): if self._expiration_trigger: self._expiration_trigger() self._expiration_trigger = None ...
'Triggered when value is expired.'
@callback def value_is_expired(self, *_):
self._expiration_trigger = None self._state = STATE_UNKNOWN self.hass.async_add_job(self.async_update_ha_state())
'No polling needed.'
@property def should_poll(self):
return False
'Return the name of the sensor.'
@property def name(self):
return self._name
'Return the unit this state is expressed in.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Force update.'
@property def force_update(self):
return self._force_update
'Return the state of the entity.'
@property def state(self):
return self._state
'Initialize the sensor.'
def __init__(self, vera_device, controller):
self.current_value = None self._temperature_units = None self.last_changed_time = None VeraDevice.__init__(self, vera_device, controller) self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
'Return the name of the sensor.'
@property def state(self):
return self.current_value
'Return the unit of measurement of this entity, if any.'
@property def unit_of_measurement(self):
if (self.vera_device.category == 'Temperature Sensor'): return self._temperature_units elif (self.vera_device.category == 'Light Sensor'): return 'lux' elif (self.vera_device.category == 'Humidity Sensor'): return '%' elif (self.vera_device.category == 'Power meter'):...
'Update the state.'
def update(self):
if (self.vera_device.category == 'Temperature Sensor'): self.current_value = self.vera_device.temperature vera_temp_units = self.vera_device.vera_controller.temperature_units if (vera_temp_units == 'F'): self._temperature_units = TEMP_FAHRENHEIT else: self....
'Initialize the GPSD sensor.'
def __init__(self, hass, name, host, port):
from gps3.agps3threaded import AGPS3mechanism self.hass = hass self._name = name self._host = host self._port = port self.agps_thread = AGPS3mechanism() self.agps_thread.stream_data(host=self._host, port=self._port) self.agps_thread.run_thread()
'Return the name.'
@property def name(self):
return self._name
'Return the state of GPSD.'
@property def state(self):
if (self.agps_thread.data_stream.mode == 3): return '3D Fix' elif (self.agps_thread.data_stream.mode == 2): return '2D Fix' return STATE_UNKNOWN
'Return the state attributes of the GPS.'
@property def device_state_attributes(self):
return {ATTR_LATITUDE: self.agps_thread.data_stream.lat, ATTR_LONGITUDE: self.agps_thread.data_stream.lon, ATTR_ELEVATION: self.agps_thread.data_stream.alt, ATTR_GPS_TIME: self.agps_thread.data_stream.time, ATTR_SPEED: self.agps_thread.data_stream.speed, ATTR_CLIMB: self.agps_thread.data_stream.climb, ATTR_MODE: se...
'Initialize a new PM sensor.'
def __init__(self, mhz_client, sensor_type, temp_unit, name):
self._mhz_client = mhz_client self._sensor_type = sensor_type self._temp_unit = temp_unit self._name = name self._unit_of_measurement = SENSOR_TYPES[sensor_type][1] self._ppm = None self._temperature = None
'Return the name of the sensor.'
@property def name(self):
return '{}: {}'.format(self._name, SENSOR_TYPES[self._sensor_type][0])
'Return the state of the sensor.'
@property def state(self):
return (self._ppm if (self._sensor_type == SENSOR_CO2) else self._temperature)