desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Return the unit of measurement of this entity, if any.'
| @property
def unit_of_measurement(self):
| return self._unit_of_measurement
|
'Read from sensor and update the state.'
| def update(self):
| self._mhz_client.update()
data = self._mhz_client.data
self._temperature = data.get(SENSOR_TEMPERATURE)
if ((self._temperature is not None) and (self._temp_unit == TEMP_FAHRENHEIT)):
self._temperature = round(celsius_to_fahrenheit(self._temperature), 1)
self._ppm = data.get(SENSOR_CO2)
|
'Return the state attributes.'
| @property
def device_state_attributes(self):
| result = {}
if ((self._sensor_type == SENSOR_TEMPERATURE) and (self._ppm is not None)):
result[ATTR_CO2_CONCENTRATION] = self._ppm
if ((self._sensor_type == SENSOR_CO2) and (self._temperature is not None)):
result[ATTR_TEMPERATURE] = self._temperature
return result
|
'Initialize the sensor.'
| def __init__(self, co2sensor, serial):
| self.co2sensor = co2sensor
self._serial = serial
self.data = dict()
|
'Get the latest data the MH-Z19 sensor.'
| @Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
| self.data = {}
try:
result = self.co2sensor.read_mh_z19_with_temperature(self._serial)
if (result is None):
return
(co2, temperature) = result
except OSError as err:
_LOGGER.error('Could not open serial connection to %s (%s)', self._serial, er... |
'Initialize the sensor.'
| def __init__(self, time_zone, name):
| self._name = name
self._time_zone = time_zone
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):
| return self._state
|
'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):
| self._state = dt_util.now(time_zone=self._time_zone).strftime(TIME_STR_FORMAT)
|
'Initialize the sensor.'
| def __init__(self, hass, name, port, modem):
| self._attributes = {'cid_time': 0, 'cid_number': '', 'cid_name': ''}
self._name = name
self.port = port
self.modem = modem
self._state = STATE_IDLE
modem.registercallback(self._incomingcallcallback)
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, self._stop_modem)
|
'Set the state.'
| def set_state(self, state):
| self._state = state
|
'Set the state attributes.'
| def set_attributes(self, attributes):
| self._attributes = attributes
|
'No polling needed.'
| @property
def should_poll(self):
| return False
|
'Return icon.'
| @property
def icon(self):
| return ICON
|
'Return the state of the device.'
| @property
def state(self):
| return self._state
|
'Return the name of the sensor.'
| @property
def name(self):
| return self._name
|
'Return the state attributes.'
| @property
def device_state_attributes(self):
| return self._attributes
|
'HA is shutting down, close modem port.'
| def _stop_modem(self, event):
| if self.modem:
self.modem.close()
self.modem = None
return
|
'Handle new states.'
| def _incomingcallcallback(self, newstate):
| if (newstate == self.modem.STATE_RING):
if (self.state == self.modem.STATE_IDLE):
att = {'cid_time': self.modem.get_cidtime, 'cid_number': '', 'cid_name': ''}
self.set_attributes(att)
self._state = STATE_RING
self.schedule_update_ha_state()
elif (newstate == self.... |
'Initialize a sensor for Ring device.'
| def __init__(self, hass, data, sensor_type):
| super(RingSensor, self).__init__()
self._sensor_type = sensor_type
self._data = data
self._extra = None
self._icon = 'mdi:{}'.format(SENSOR_TYPES.get(self._sensor_type)[3])
self._kind = SENSOR_TYPES.get(self._sensor_type)[4]
self._name = '{0} {1}'.format(self._data.name, SENSOR_TYPES.get(... |
'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):
| attrs = {}
attrs[ATTR_ATTRIBUTION] = CONF_ATTRIBUTION
attrs['device_id'] = self._data.id
attrs['firmware'] = self._data.firmware
attrs['kind'] = self._data.kind
attrs['timezone'] = self._data.timezone
attrs['type'] = self._data.family
if (self._extra and self._sensor_type.startswith('las... |
'Icon to use in the frontend, if any.'
| @property
def icon(self):
| return self._icon
|
'Return the units of measurement.'
| @property
def unit_of_measurement(self):
| return SENSOR_TYPES.get(self._sensor_type)[2]
|
'Get the latest data and updates the state.'
| def update(self):
| _LOGGER.debug('Pulling data from %s sensor', self._name)
self._data.update()
if (self._sensor_type == 'volume'):
self._state = self._data.volume
if (self._sensor_type == 'battery'):
self._state = self._data.battery_life
if self._sensor_type.startswith('last_'):
hi... |
'Initialize the XiaomiSensor.'
| def __init__(self, device, name, data_key, xiaomi_hub):
| self._data_key = data_key
XiaomiDevice.__init__(self, device, name, xiaomi_hub)
|
'Return the unit of measurement of this entity, if any.'
| @property
def unit_of_measurement(self):
| if (self._data_key == 'temperature'):
return TEMP_CELSIUS
elif (self._data_key == 'humidity'):
return '%'
elif (self._data_key == 'illumination'):
return 'lm'
elif (self._data_key == 'lux'):
return 'lx'
elif (self._data_key == 'pressure'):
return 'hPa'
|
'Return the state of the sensor.'
| @property
def state(self):
| return self._state
|
'Parse data sent by gateway.'
| def parse_data(self, data):
| value = data.get(self._data_key)
if (value is None):
return False
value = float(value)
if ((self._data_key == 'temperature') and (value == 10000)):
return False
elif ((self._data_key == 'humidity') and (value == 0)):
return False
elif ((self._data_key == 'illumination') a... |
'Initialize the sensor.'
| def __init__(self, name, minimum, maximum, unit_of_measurement):
| self._name = name
self._minimum = minimum
self._maximum = maximum
self._unit_of_measurement = unit_of_measurement
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):
| return self._state
|
'Return the icon to use in the frontend, if any.'
| @property
def icon(self):
| return ICON
|
'Return the unit this state is expressed in.'
| @property
def unit_of_measurement(self):
| return self._unit_of_measurement
|
'Get a new number and updates the states.'
| @asyncio.coroutine
def async_update(self):
| from random import randrange
self._state = randrange(self._minimum, (self._maximum + 1))
|
'Initialize the sensor.'
| def __init__(self, port, hass):
| self._port = port
self._hass = hass
|
'Return the name of th sensor.'
| @property
def name(self):
| return self._port.label
|
'Return the state of the sensor.'
| @property
def state(self):
| try:
tag = self._port.tag
except ValueError:
tag = None
if (tag is None):
return STATE_OFF
elif (self._port.model == 'Input Digital'):
return (STATE_ON if (self._port.value > 0) else STATE_OFF)
digits = DIGITS.get(self._port.tag, 0)
return round(self._port.valu... |
'Return the unit of measurement of this entity, if any.'
| @property
def unit_of_measurement(self):
| try:
tag = self._port.tag
except ValueError:
return 'State'
if (tag == 'temperature'):
return TEMP_CELSIUS
elif (tag == 'active_pwr'):
return 'Watts'
elif (self._port.model == 'Input Digital'):
return 'State'
return tag
|
'Get the latest data.'
| def update(self):
| self._port.refresh()
|
'Initialize the sensor.'
| def __init__(self, name, state, unit_of_measurement, battery):
| self._name = name
self._state = state
self._unit_of_measurement = unit_of_measurement
self._battery = battery
|
'No polling needed for a demo sensor.'
| @property
def should_poll(self):
| return False
|
'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 this state is expressed in.'
| @property
def unit_of_measurement(self):
| return self._unit_of_measurement
|
'Return the state attributes.'
| @property
def device_state_attributes(self):
| if self._battery:
return {ATTR_BATTERY_LEVEL: self._battery}
|
'Constructor.
Args:
friendly_name (string|func): Friendly name
feature (string): WU feature. See:
https://www.wunderground.com/weather/api/d/docs?d=data/index
value (function(WUndergroundData)): callback that
extracts desired value from WUndergroundData object
unit_of_measurement (string): unit of meassurement
entity_p... | def __init__(self, friendly_name, feature, value, unit_of_measurement=None, entity_picture=None, icon='mdi:gauge', device_state_attributes=None):
| self.friendly_name = friendly_name
self.unit_of_measurement = unit_of_measurement
self.feature = feature
self.value = value
self.entity_picture = entity_picture
self.icon = icon
self.device_state_attributes = (device_state_attributes or {})
|
'Constructor.
Args:
friendly_name (string|func): Friendly name of sensor
field (string): Field name in the "current_observation"
dictionary.
icon (string): icon name or URL, if None sensor
will use current weather symbol
unit_of_measurement (string): unit of meassurement'
| def __init__(self, friendly_name, field, icon='mdi:gauge', unit_of_measurement=None):
| super().__init__(friendly_name, 'conditions', value=(lambda wu: wu.data['current_observation'][field]), icon=icon, unit_of_measurement=unit_of_measurement, entity_picture=(lambda wu: (wu.data['current_observation']['icon_url'] if (icon is None) else None)), device_state_attributes={'date': (lambda wu: wu.data['curr... |
'Constructor.
Args:
period (int): forecast period number
field (string): field name to use as value
unit_of_measurement(string): unit of measurement'
| def __init__(self, period, field, unit_of_measurement=None):
| super().__init__(friendly_name=(lambda wu: wu.data['forecast']['txt_forecast']['forecastday'][period]['title']), feature='forecast', value=(lambda wu: wu.data['forecast']['txt_forecast']['forecastday'][period][field]), entity_picture=(lambda wu: wu.data['forecast']['txt_forecast']['forecastday'][period]['icon_url']... |
'Constructor.
Args:
period (int): forecast period number
field (string): field name to use as value
wu_unit (string): "fahrenheit", "celsius", "degrees" etc.
see the example json at:
https://www.wunderground.com/weather/api/d/docs?d=data/forecast&MR=1
ha_unit (string): coresponding unit in home assistant
title (string)... | def __init__(self, friendly_name, period, field, wu_unit=None, ha_unit=None, icon=None):
| super().__init__(friendly_name=friendly_name, feature='forecast', value=((lambda wu: wu.data['forecast']['simpleforecast']['forecastday'][period][field][wu_unit]) if wu_unit else (lambda wu: wu.data['forecast']['simpleforecast']['forecastday'][period][field])), unit_of_measurement=ha_unit, entity_picture=(lambda wu... |
'Constructor.
Args:
period (int): forecast period number
field (int): field name to use as value'
| def __init__(self, period, field):
| super().__init__(friendly_name=(lambda wu: '{} {}'.format(wu.data['hourly_forecast'][period]['FCTTIME']['weekday_name_abbrev'], wu.data['hourly_forecast'][period]['FCTTIME']['civil'])), feature='hourly', value=(lambda wu: wu.data['hourly_forecast'][period][field]), entity_picture=(lambda wu: wu.data['hourly_fore... |
'Constructor.
Args:
friendly_name (string|func): Friendly name
field (string): value name returned in \'almanac\' dict
as returned by the WU API
value_type (string): "record" or "normal"
wu_unit (string): unit name in WU API
icon (string): icon name or URL
unit_of_measurement (string): unit of meassurement'
| def __init__(self, friendly_name, field, value_type, wu_unit, unit_of_measurement, icon):
| super().__init__(friendly_name=friendly_name, feature='almanac', value=(lambda wu: wu.data['almanac'][field][value_type][wu_unit]), unit_of_measurement=unit_of_measurement, icon=icon)
|
'Constructor.
Args:
friendly_name (string|func): Friendly name'
| def __init__(self, friendly_name):
| super().__init__(friendly_name=friendly_name, feature='alerts', value=(lambda wu: len(wu.data['alerts'])), icon=(lambda wu: ('mdi:alert-circle-outline' if wu.data['alerts'] else 'mdi:check-circle-outline')), device_state_attributes=self._get_attributes)
|
'Initialize the sensor.'
| def __init__(self, rest, condition):
| self.rest = rest
self._condition = condition
self.rest.request_feature(SENSOR_TYPES[condition].feature)
|
'Return the name of the sensor.'
| @property
def name(self):
| return ('PWS_' + self._condition)
|
'Return the state of the sensor.'
| @property
def state(self):
| return self._cfg_expand('value', STATE_UNKNOWN)
|
'Return the state attributes.'
| @property
def device_state_attributes(self):
| attrs = self._cfg_expand('device_state_attributes', {})
for (attr, callback) in attrs.items():
try:
attrs[attr] = callback(self.rest)
except TypeError:
attrs[attr] = callback
except (KeyError, IndexError) as err:
_LOGGER.warning('Failed to parse ... |
'Return icon.'
| @property
def icon(self):
| return self._cfg_expand('icon', super().icon)
|
'Return the entity picture.'
| @property
def entity_picture(self):
| url = self._cfg_expand('entity_picture')
if (url is not None):
return re.sub('^http://', 'https://', url, flags=re.IGNORECASE)
|
'Return the units of measurement.'
| @property
def unit_of_measurement(self):
| return self._cfg_expand('unit_of_measurement')
|
'Update current conditions.'
| def update(self):
| self.rest.update()
|
'Initialize the data object.'
| def __init__(self, hass, api_key, pws_id, lang, latitude, longitude):
| self._hass = hass
self._api_key = api_key
self._pws_id = pws_id
self._lang = 'lang:{}'.format(lang)
self._latitude = latitude
self._longitude = longitude
self._features = set()
self.data = None
|
'Register feature to be fetched from WU API.'
| def request_feature(self, feature):
| self._features.add(feature)
|
'Get the latest data from WUnderground.'
| @Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
| try:
result = requests.get(self._build_url(), timeout=10).json()
if ('error' in result['response']):
raise ValueError(result['response']['error']['description'])
else:
self.data = result
except ValueError as err:
_LOGGER.error('Check WUnderground API... |
'Initialize the CUPS sensor.'
| def __init__(self, data, printer):
| self.data = data
self._name = printer
self._printer = None
|
'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._printer is not None):
try:
return next((v for (k, v) in PRINTER_STATES.items() if (self._printer['printer-state'] == k)))
except StopIteration:
return self._printer['printer-state']
|
'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):
| if (self._printer is not None):
return {ATTR_DEVICE_URI: self._printer['device-uri'], ATTR_PRINTER_INFO: self._printer['printer-info'], ATTR_PRINTER_IS_SHARED: self._printer['printer-is-shared'], ATTR_PRINTER_LOCATION: self._printer['printer-location'], ATTR_PRINTER_MODEL: self._printer['printer-make-and-mo... |
'Get the latest data and updates the states.'
| def update(self):
| self.data.update()
self._printer = self.data.printers.get(self._name)
|
'Initialize the data object.'
| def __init__(self, host, port):
| self._host = host
self._port = port
self.printers = None
|
'Get the latest data from CUPS.'
| def update(self):
| from cups import Connection
conn = Connection(host=self._host, port=self._port)
self.printers = conn.getPrinters()
|
'Initialize the sensor.'
| def __init__(self, temper_device, temp_unit, name, scaling):
| self.temp_unit = temp_unit
self.scale = scaling['scale']
self.offset = scaling['offset']
self.current_value = None
self._name = name
self.set_temper_device(temper_device)
|
'Return the name of the temperature sensor.'
| @property
def name(self):
| return self._name
|
'Return the state of the entity.'
| @property
def state(self):
| return self.current_value
|
'Return the unit of measurement of this entity, if any.'
| @property
def unit_of_measurement(self):
| return self.temp_unit
|
'Assign the underlying device for this sensor.'
| def set_temper_device(self, temper_device):
| self.temper_device = temper_device
self.temper_device.set_calibration_data(scale=self.scale, offset=self.offset)
|
'Retrieve latest state.'
| def update(self):
| try:
format_str = ('fahrenheit' if (self.temp_unit == TEMP_FAHRENHEIT) else 'celsius')
sensor_value = self.temper_device.get_temperature(format_str)
self.current_value = round(sensor_value, 1)
except IOError:
_LOGGER.error('Failed to get temperature. The device ... |
'Initialize the sensor.'
| def __init__(self, sensor_type, argument=''):
| self._name = '{} {}'.format(SENSOR_TYPES[sensor_type][0], argument)
self.argument = argument
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 self._name.rstrip()
|
'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
|
'Get the latest system information.'
| def update(self):
| import psutil
if (self.type == 'disk_use_percent'):
self._state = psutil.disk_usage(self.argument).percent
elif (self.type == 'disk_use'):
self._state = round((psutil.disk_usage(self.argument).used / (1024 ** 3)), 1)
elif (self.type == 'disk_free'):
self._state = round((psutil.di... |
'Initialize Zabbix sensor.'
| def __init__(self, zApi, name='Zabbix'):
| self._name = name
self._zapi = zApi
self._state = None
self._attributes = {}
|
'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 'issues'
|
'Update the sensor.'
| def update(self):
| _LOGGER.debug('Updating ZabbixTriggerCountSensor: %s', str(self._name))
triggers = self._call_zabbix_api()
self._state = len(triggers)
|
'Return the state attributes of the device.'
| @property
def device_state_attributes(self):
| return self._attributes
|
'Initialize Zabbix sensor.'
| def __init__(self, zApi, hostid, name=None):
| super().__init__(zApi, name)
self._hostid = hostid
if (not name):
self._name = self._zapi.host.get(hostids=self._hostid, output='extend')[0]['name']
self._attributes['Host ID'] = self._hostid
|
'Initialize Zabbix sensor.'
| def __init__(self, zApi, hostids, name=None):
| super().__init__(zApi, name)
self._hostids = hostids
if (not name):
host_names = self._zapi.host.get(hostids=self._hostids, output='extend')
self._name = ' '.join((name['name'] for name in host_names))
self._attributes['Host IDs'] = self._hostids
|
'Initialize an Arlo sensor.'
| def __init__(self, hass, name, device, sensor_type):
| super().__init__()
self._name = name
self._hass = hass
self._data = device
self._sensor_type = sensor_type
self._state = None
self._icon = 'mdi:{}'.format(SENSOR_TYPES.get(self._sensor_type)[2])
|
'Return the name of this camera.'
| @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 the units of measurement.'
| @property
def unit_of_measurement(self):
| return SENSOR_TYPES.get(self._sensor_type)[1]
|
'Get the latest data and updates the state.'
| def update(self):
| self._data.update()
if (self._sensor_type == 'total_cameras'):
self._state = len(self._data.cameras)
elif (self._sensor_type == 'captured_today'):
self._state = len(self._data.captured_today)
elif (self._sensor_type == 'last_capture'):
try:
video = self._data.videos()... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.