desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Get the latest data from NetAtmo API and updates the states.'
def update(self):
self.netatmo_data.update() data = self.netatmo_data.data.get(self.module_name) if (data is None): _LOGGER.warning('No data found for %s', self.module_name) self._state = STATE_UNKNOWN return if (self.type == 'temperature'): self._state = round(data['Temperatur...
'Initialize the data object.'
def __init__(self, auth, station):
self.auth = auth self.data = None self.station_data = None self.station = station
'Return all module available on the API as a list.'
def get_module_names(self):
self.update() return self.data.keys()
'Call the Netatmo API to update the data.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
import lnetatmo self.station_data = lnetatmo.WeatherStationData(self.auth) if (self.station is not None): self.data = self.station_data.lastData(station=self.station, exclude=3600) else: self.data = self.station_data.lastData(exclude=3600)
'Initialize the sensor.'
def __init__(self, hass, dweet, name, value_template, unit_of_measurement):
self.hass = hass self.dweet = dweet self._name = name self._value_template = value_template self._state = STATE_UNKNOWN self._unit_of_measurement = unit_of_measurement
'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.'
@property def state(self):
return self._state
'Get the latest data from REST API.'
def update(self):
self.dweet.update() if (self.dweet.data is None): self._state = STATE_UNKNOWN else: values = json.dumps(self.dweet.data[0]['content']) self._state = self._value_template.render_with_possible_json_value(values, STATE_UNKNOWN)
'Initialize the sensor.'
def __init__(self, device):
self._device = device self.data = None
'Get the latest data from Dweet.io.'
def update(self):
import dweepy try: self.data = dweepy.get_latest_dweet_for(self._device) except dweepy.DweepyError: _LOGGER.warning("Device %s doesn't contain any data", self._device) self.data = None
'Initialize the sensor.'
def __init__(self, user, lastfm):
self._user = lastfm.get_user(user) self._name = user self._lastfm = lastfm self._state = 'Not Scrobbling' self._playcount = None self._lastplayed = None self._topplayed = None self._cover = None
'Return the name of the sensor.'
@property def name(self):
return self._name
'Return the entity ID.'
@property def entity_id(self):
return 'sensor.lastfm_{}'.format(self._name)
'Return the state of the sensor.'
@property def state(self):
return self._state
'Update device state.'
def update(self):
self._cover = self._user.get_image() self._playcount = self._user.get_playcount() last = self._user.get_recent_tracks(limit=2)[0] self._lastplayed = '{} - {}'.format(last.track.artist, last.track.title) top = self._user.get_top_tracks(limit=1)[0] toptitle = re.search("', '(.+?)',", str(...
'Return the state attributes.'
@property def device_state_attributes(self):
return {ATTR_LAST_PLAYED: self._lastplayed, ATTR_PLAY_COUNT: self._playcount, ATTR_TOP_PLAYED: self._topplayed}
'Avatar of the user.'
@property def entity_picture(self):
return self._cover
'Return the icon to use in the frontend.'
@property def icon(self):
return ICON
'Initialize the data.'
def __init__(self, api_key, api_secret, sensor_id):
import neurio self.api_key = api_key self.api_secret = api_secret self.sensor_id = sensor_id self._daily_usage = None self._active_power = None self._state = None neurio_tp = neurio.TokenProvider(key=api_key, secret=api_secret) self.neurio_client = neurio.Client(token_provider=neurio...
'Return latest daily usage value.'
@property def daily_usage(self):
return self._daily_usage
'Return latest active power value.'
@property def active_power(self):
return self._active_power
'Return current power value.'
def get_active_power(self):
try: sample = self.neurio_client.get_samples_live_last(self.sensor_id) self._active_power = sample['consumptionPower'] except (requests.exceptions.RequestException, ValueError, KeyError): _LOGGER.warning('Could not update current power usage') return None
'Return current daily power usage.'
def get_daily_usage(self):
kwh = 0 start_time = dt_util.start_of_local_day().astimezone(dt_util.UTC).isoformat() end_time = dt_util.utcnow().isoformat() _LOGGER.debug('Start: %s, End: %s', start_time, end_time) try: history = self.neurio_client.get_samples_stats(self.sensor_id, start_time, 'days', end_time) ...
'Initialize the sensor.'
def __init__(self, data, name, sensor_type, update_call):
self._name = name self._data = data self._sensor_type = sensor_type self.update_sensor = update_call self._state = None if (sensor_type == ACTIVE_TYPE): self._unit_of_measurement = 'W' elif (sensor_type == DAILY_TYPE): self._unit_of_measurement = 'kWh'
'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):
return ICON
'Get the latest data, update state.'
def update(self):
self.update_sensor() if (self._sensor_type == ACTIVE_TYPE): self._state = self._data.active_power elif (self._sensor_type == DAILY_TYPE): self._state = self._data.daily_usage
'Initialize sensors from Blink camera.'
def __init__(self, name, sensor_type, index, data):
self._name = ((('blink_' + name) + '_') + SENSOR_TYPES[sensor_type][0]) self._camera_name = name self._type = sensor_type self.data = data self.index = index self._state = None self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
'Return the name of the camera.'
@property def name(self):
return self._name
'Return the camera\'s current state.'
@property def state(self):
return self._state
'Return the unique camera sensor identifier.'
@property def unique_id(self):
return 'sensor_{}_{}'.format(self._name, self.index)
'Return the unit of measurement.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Retrieve sensor data from the camera.'
def update(self):
camera = self.data.cameras[self._camera_name] if (self._type == 'temperature'): self._state = camera.temperature elif (self._type == 'battery'): self._state = camera.battery_string elif (self._type == 'notifications'): self._state = camera.notifications else: self._st...
'Initialize the sensor.'
def __init__(self, data, name, unit_of_measurement):
self.data = data self._name = name self._state = None self._unit_of_measurement = 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._state
'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() self._state = self.data.value
'Initialize the data object.'
def __init__(self, host, port, community, baseoid, version):
self._host = host self._port = port self._community = community self._baseoid = baseoid self._version = SNMP_VERSIONS[version] self.value = None
'Get the latest data from the remote SNMP capable host.'
def update(self):
from pysnmp.hlapi import getCmd, CommunityData, SnmpEngine, UdpTransportTarget, ContextData, ObjectType, ObjectIdentity (errindication, errstatus, errindex, restable) = next(getCmd(SnmpEngine(), CommunityData(self._community, mpModel=self._version), UdpTransportTarget((self._host, self._port)), ContextData(), O...
'Initialize a KNX Float Sensor.'
def __init__(self, hass, config):
KNXGroupAddress.__init__(self, hass, config) device_type = config.config.get(CONF_TYPE) sensor_config = FIXED_SETTINGS_MAP.get(device_type) if (not sensor_config): raise NotImplementedError() address_type = sensor_config.get('address_type') if (address_type == KNXAddressType.FLOAT): ...
'Return the Value of the KNX Sensor.'
@property def state(self):
return self._value
'Return the defined Unit of Measurement for the KNX Sensor.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Update KNX sensor.'
def update(self):
super().update() self._value = None if self._data: if (self._data == 0): value = 0 else: value = self.convert(self._data) if (self._minimum_value <= value <= self._maximum_value): self._value = value
'We don\'t want to cache any Sensor Value.'
@property def cache(self):
return False
'Initialize the sensor.'
def __init__(self, session, name, interval):
self._session = session self._name = name self._attributes = None self._state = None self.update = Throttle(interval)(self._update)
'Return the name of the sensor.'
@property def name(self):
return (self._name or DOMAIN)
'Return the state of the sensor.'
@property def state(self):
return self._state
'Update device state.'
def _update(self):
import upsmychoice status_counts = defaultdict(int) for package in upsmychoice.get_packages(self._session): status = slugify(package['status']) skip = ((status == STATUS_DELIVERED) and (parse_date(package['delivery_date']) < now().date())) if skip: continue status...
'Return the state attributes.'
@property def device_state_attributes(self):
return self._attributes
'Icon to use in the frontend.'
@property def icon(self):
return ICON
'Initialize the Netdata sensor.'
def __init__(self, rest, name, sensor_type):
self.rest = rest self.type = sensor_type self._name = '{} {}'.format(name, SENSOR_TYPES[self.type][0]) self._precision = SENSOR_TYPES[self.type][4] self._unit_of_measurement = SENSOR_TYPES[self.type][1]
'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 resources.'
@property def state(self):
value = self.rest.data if (value is not None): netdata_id = SENSOR_TYPES[self.type][3] if (netdata_id in value): return '{0:.{1}f}'.format(value[netdata_id], self._precision) return None
'Could the resource be accessed during the last update call.'
@property def available(self):
return self.rest.available
'Get the latest data from Netdata REST API.'
def update(self):
self.rest.update()
'Initialize the data object.'
def __init__(self, resource):
self._resource = resource self.data = None self.available = True
'Get the latest data from the Netdata REST API.'
def update(self):
try: response = requests.get(self._resource, timeout=5) det = response.json() self.data = {k: v for (k, v) in zip(det['labels'], det['data'][0])} self.available = True except requests.exceptions.ConnectionError: _LOGGER.error('Connection error: %s', urlsplit(self._r...
'Initialize the sensor.'
def __init__(self, hass, option_type):
self._name = OPTION_TYPES[option_type] self.type = option_type self._state = None self.hass = hass self._update_internal_state(dt_util.utcnow())
'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):
if (('date' in self.type) and ('time' in self.type)): return 'mdi:calendar-clock' elif ('date' in self.type): return 'mdi:calendar' return 'mdi:clock'
'Compute next time an update should occur.'
def get_next_interval(self, now=None):
if (now is None): now = dt_util.utcnow() if (self.type == 'date'): now = dt_util.start_of_local_day(now) return (now + timedelta(seconds=86400)) elif (self.type == 'beat'): interval = 86.4 else: interval = 60 timestamp = int(dt_util.as_timestamp(now)) delt...
'Get the latest data and update state.'
@callback def point_in_time_listener(self, time_date):
self._update_internal_state(time_date) self.hass.async_add_job(self.async_update_ha_state()) async_track_point_in_utc_time(self.hass, self.point_in_time_listener, self.get_next_interval())
'Initialize the file sensor.'
def __init__(self, name, file_path, unit_of_measurement, value_template):
self._name = name self._file_path = file_path self._unit_of_measurement = unit_of_measurement self._val_tpl = value_template self._state = None
'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 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
'Get the latest entry from a file and updates the state.'
def update(self):
try: with open(self._file_path, 'r', encoding='utf-8') as file_data: for line in file_data: data = line data = data.strip() except (IndexError, FileNotFoundError, IsADirectoryError, UnboundLocalError): _LOGGER.warning('File or data not present ...
'Initialize the sensor.'
def __init__(self, hass, name, variable, payload, unit_of_measurement):
self._state = STATE_UNKNOWN self._hass = hass self._name = name self._variable = variable self._payload = payload self._unit_of_measurement = unit_of_measurement hass.bus.listen(pilight.EVENT, self._handle_code)
'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
'Return the state of the entity.'
@property def state(self):
return self._state
'Handle received code by the pilight-daemon. If the code matches the defined playload of this sensor the sensor state is changed accordingly.'
def _handle_code(self, call):
if (self._payload.items() <= call.data.items()): try: value = call.data[self._variable] self._state = value self.schedule_update_ha_state() except KeyError: _LOGGER.error('No variable %s in received code data %s', str(self._variabl...
'Initialize the sensor.'
def __init__(self, hass, hp_ilo_data, sensor_type, sensor_name, sensor_value_template, unit_of_measurement):
self._hass = hass self._name = sensor_name self._unit_of_measurement = unit_of_measurement self._ilo_function = SENSOR_TYPES[sensor_type][1] self.hp_ilo_data = hp_ilo_data if (sensor_value_template is not None): sensor_value_template.hass = hass self._sensor_value_template = sensor_v...
'Return the name of the sensor.'
@property def name(self):
return self._name
'Return the unit of measurement of the sensor.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'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._state_attributes
'Get the latest data from HP ILO and updates the states.'
def update(self):
self.hp_ilo_data.update() ilo_data = getattr(self.hp_ilo_data.data, self._ilo_function)() if (self._sensor_value_template is not None): ilo_data = self._sensor_value_template.render(ilo_data=ilo_data) self._state = ilo_data
'Initialize the data object.'
def __init__(self, host, port, login, password):
self._host = host self._port = port self._login = login self._password = password self.data = None self.update()
'Get the latest data from HP ILO.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
import hpilo try: self.data = hpilo.Ilo(hostname=self._host, login=self._login, password=self._password, port=self._port) except (hpilo.IloError, hpilo.IloCommunicationError, hpilo.IloLoginFailed) as error: raise ValueError('Unable to init HP ILO, %s', error)
'Initialize the sensor.'
def __init__(self, gateway, name, mtu, unit):
units = {'W': 'power', 'V': 'voltage'} self._gateway = gateway self._name = '{} mtu{} {}'.format(name, mtu, units[unit]) self._mtu = mtu self._unit = unit self.update()
'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
'Return the state of the resources.'
@property def state(self):
try: return self._gateway.data[self._mtu][self._unit] except KeyError: pass
'Get the latest data from REST API.'
def update(self):
self._gateway.update()
'Initialize the data object.'
def __init__(self, url):
self.url = url self.data = dict()
'Get the latest data from the Ted5000 XML API.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
import xmltodict try: request = requests.get(self.url, timeout=10) except requests.exceptions.RequestException as err: _LOGGER.error('No connection to endpoint: %s', err) else: doc = xmltodict.parse(request.text) mtus = int(doc['LiveData']['System']['NumberMTU...
'Initialize the sensor.'
def __init__(self, name, device_file):
self._name = name self._device_file = device_file self._state = None
'Read the temperature as it is returned by the sensor.'
def _read_temp_raw(self):
ds_device_file = open(self._device_file, 'r') lines = ds_device_file.readlines() ds_device_file.close() return lines
'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 the value is expressed in.'
@property def unit_of_measurement(self):
return TEMP_CELSIUS