desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Return the state of the sensor.'
@property def state(self):
return (self.mean if (not self.is_binary) else self.count)
'Return the unit the value is expressed in.'
@property def unit_of_measurement(self):
return (self._unit_of_measurement if (not self.is_binary) else None)
'No polling needed.'
@property def should_poll(self):
return False
'Return the state attributes of the sensor.'
@property def device_state_attributes(self):
if (not self.is_binary): return {ATTR_MEAN: self.mean, ATTR_COUNT: self.count, ATTR_MAX_VALUE: self.max, ATTR_MEDIAN: self.median, ATTR_MIN_VALUE: self.min, ATTR_SAMPLING_SIZE: ('unlimited' if (self._sampling_size is 0) else self._sampling_size), ATTR_STANDARD_DEVIATION: self.stdev, ATTR_TOTAL: self.total, ...
'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):
if (not self.is_binary): try: self.mean = round(statistics.mean(self.states), 2) self.median = round(statistics.median(self.states), 2) self.stdev = round(statistics.stdev(self.states), 2) self.variance = round(statistics.variance(self.states), 2) exce...
'Create a new Dyson filter life sensor.'
def __init__(self, hass, device):
self.hass = hass self._device = device self._old_value = None self._name = None
'Callback when entity is added to hass.'
@asyncio.coroutine def async_added_to_hass(self):
self.hass.async_add_job(self._device.add_message_listener, self.on_message)
'Called when new messages received from the fan.'
def on_message(self, message):
if ((self._old_value is None) or (self._old_value != self.state)): _LOGGER.debug('Message received for %s device: %s', self.name, message) self._old_value = self.state self.schedule_update_ha_state()
'No polling needed.'
@property def should_poll(self):
return False
'Return the name of the dyson sensor name.'
@property def name(self):
return self._name
'Create a new Dyson filter life sensor.'
def __init__(self, hass, device):
DysonSensor.__init__(self, hass, device) self._name = '{} filter life'.format(self._device.name)
'Return filter life in hours.'
@property def state(self):
if self._device.state: return int(self._device.state.filter_life) return None
'Return the unit the value is expressed in.'
@property def unit_of_measurement(self):
return SENSOR_UNITS['filter_life']
'Create a new Dyson Dust sensor.'
def __init__(self, hass, device):
DysonSensor.__init__(self, hass, device) self._name = '{} dust'.format(self._device.name)
'Return Dust value.'
@property def state(self):
if self._device.environmental_state: return self._device.environmental_state.dust return None
'Return the unit the value is expressed in.'
@property def unit_of_measurement(self):
return SENSOR_UNITS['dust']
'Create a new Dyson Humidity sensor.'
def __init__(self, hass, device):
DysonSensor.__init__(self, hass, device) self._name = '{} humidity'.format(self._device.name)
'Return Dust value.'
@property def state(self):
if self._device.environmental_state: if (self._device.environmental_state.humidity == 0): return STATE_OFF return self._device.environmental_state.humidity return None
'Return the unit the value is expressed in.'
@property def unit_of_measurement(self):
return SENSOR_UNITS['humidity']
'Create a new Dyson Temperature sensor.'
def __init__(self, hass, device, unit):
DysonSensor.__init__(self, hass, device) self._name = '{} temperature'.format(self._device.name) self._unit = unit
'Return Dust value.'
@property def state(self):
if self._device.environmental_state: temperature_kelvin = self._device.environmental_state.temperature if (temperature_kelvin == 0): return STATE_OFF if (self._unit == TEMP_CELSIUS): return float('{0:.1f}'.format((temperature_kelvin - 273.15))) return float('{...
'Return the unit the value is expressed in.'
@property def unit_of_measurement(self):
return self._unit
'Create a new Dyson Air Quality sensor.'
def __init__(self, hass, device):
DysonSensor.__init__(self, hass, device) self._name = '{} air quality'.format(self._device.name)
'Return Air Quality value.'
@property def state(self):
if self._device.environmental_state: return self._device.environmental_state.volatil_organic_compounds return None
'Return the unit the value is expressed in.'
@property def unit_of_measurement(self):
return SENSOR_UNITS['air_quality']
'Initialize the sensor.'
def __init__(self, hass, name, api_key, origin, destination, options):
self._hass = hass self._name = name self._options = options self._unit_of_measurement = 'min' self._matrix = None self.valid_api_connection = True if (origin.split('.', 1)[0] in TRACKABLE_DOMAINS): self._origin_entity_id = origin else: self._origin = origin if (destin...
'Return the state of the sensor.'
@property def state(self):
if (self._matrix is None): return None _data = self._matrix['rows'][0]['elements'][0] if ('duration_in_traffic' in _data): return round((_data['duration_in_traffic']['value'] / 60)) if ('duration' in _data): return round((_data['duration']['value'] / 60)) return None
'Get the name of the sensor.'
@property def name(self):
return self._name
'Return the state attributes.'
@property def device_state_attributes(self):
if (self._matrix is None): return None res = self._matrix.copy() res.update(self._options) del res['rows'] _data = self._matrix['rows'][0]['elements'][0] if ('duration_in_traffic' in _data): res['duration_in_traffic'] = _data['duration_in_traffic']['text'] if ('duration' in _...
'Return the unit this state is expressed in.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Get the latest data from Google.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
options_copy = self._options.copy() dtime = options_copy.get('departure_time') atime = options_copy.get('arrival_time') if ((dtime is not None) and (':' in dtime)): options_copy['departure_time'] = convert_time_to_utc(dtime) elif (dtime is not None): options_copy['departure_time'] = ...
'Get the location from the entity state or attributes.'
def _get_location_from_entity(self, entity_id):
entity = self._hass.states.get(entity_id) if (entity is None): _LOGGER.error('Unable to find entity %s', entity_id) self.valid_api_connection = False return None if location.has_location(entity): return self._get_location_from_attributes(entity) zone_entity = ...
'Get the lat/long string from an entities attributes.'
@staticmethod def _get_location_from_attributes(entity):
attr = entity.attributes return ('%s,%s' % (attr.get(ATTR_LATITUDE), attr.get(ATTR_LONGITUDE)))
'Initialize the alarm panel.'
def __init__(self, hass):
self._display = '' self._state = STATE_UNKNOWN self._icon = 'mdi:alarm-check' self._name = 'Alarm Panel Display' _LOGGER.debug('Setting up panel')
'Register callbacks.'
@asyncio.coroutine def async_added_to_hass(self):
async_dispatcher_connect(self.hass, SIGNAL_PANEL_MESSAGE, self._message_callback)
'Return the icon if any.'
@property def icon(self):
return self._icon
'Return the overall state.'
@property def state(self):
return self._display
'Return the name of the device.'
@property def name(self):
return self._name
'No polling needed.'
@property def should_poll(self):
return False
'Initialize the sensor.'
def __init__(self, arest, resource, location, name, variable=None, pin=None, unit_of_measurement=None, renderer=None):
self.arest = arest self._resource = resource self._name = '{} {}'.format(location.title(), name.title()) self._variable = variable self._pin = pin self._state = STATE_UNKNOWN self._unit_of_measurement = unit_of_measurement self._renderer = renderer if (self._pin is not 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 state of the sensor.'
@property def state(self):
values = self.arest.data if ('error' in values): return values['error'] value = self._renderer(values.get('value', values.get(self._variable, STATE_UNKNOWN))) return value
'Get the latest data from aREST API.'
def update(self):
self.arest.update()
'Could the device be accessed during the last update call.'
@property def available(self):
return self.arest.available
'Initialize the data object.'
def __init__(self, resource, pin=None):
self._resource = resource self._pin = pin self.data = {} self.available = True
'Get the latest data from aREST device.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
try: if (self._pin is None): response = requests.get(self._resource, timeout=10) self.data = response.json()['variables'] else: try: if (str(self._pin[0]) == 'A'): response = requests.get('{}/analog/{}'.format(self._resource, se...
'Initialize the sensor.'
def __init__(self, station, destinations, directions, lines, products, timeoffset, name):
self._station = station self._name = name self.data = MVGLiveData(station, destinations, directions, lines, products, timeoffset) self._state = STATE_UNKNOWN self._icon = ICONS['-']
'Return the name of the sensor.'
@property def name(self):
if self._name: return self._name return self._station
'Return the next departure time.'
@property def state(self):
return self._state
'Return the state attributes.'
@property def state_attributes(self):
return self.data.departures
'Icon to use in the frontend, if any.'
@property def icon(self):
return self._icon
'Return the unit this state is expressed in.'
@property def unit_of_measurement(self):
return 'min'
'Get the latest data and update the state.'
def update(self):
self.data.update() if (not self.data.departures): self._state = '-' self._icon = ICONS['-'] else: self._state = self.data.departures.get('time', '-') self._icon = ICONS[self.data.departures.get('product', '-')]
'Initialize the sensor.'
def __init__(self, station, destinations, directions, lines, products, timeoffset):
import MVGLive self._station = station self._destinations = destinations self._directions = directions self._lines = lines self._products = products self._timeoffset = timeoffset self._include_ubahn = (True if ('U-Bahn' in self._products) else False) self._include_tram = (True if ('T...
'Update the connection data.'
def update(self):
try: _departures = self.mvg.getlivedata(station=self._station, ubahn=self._include_ubahn, tram=self._include_tram, bus=self._include_bus, sbahn=self._include_sbahn) except ValueError: self.departures = {} _LOGGER.warning('Returned data not understood') return for _de...
'Initialize the sensor.'
def __init__(self, name, phonebook):
self._state = VALUE_DEFAULT self._attributes = {} self._name = name self.phonebook = phonebook
'Set the state.'
def set_state(self, state):
self._state = state
'Set the state attributes.'
def set_attributes(self, attributes):
self._attributes = attributes
'Only poll to update phonebook, if defined.'
@property def should_poll(self):
return (self.phonebook is not None)
'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
'Return a name for a given phone number.'
def number_to_name(self, number):
if (self.phonebook is None): return 'unknown' return self.phonebook.get_name(number)
'Update the phonebook if it is defined.'
def update(self):
if (self.phonebook is not None): self.phonebook.update_phonebook()
'Initialize Fritz!Box monitor instance.'
def __init__(self, host, port, sensor):
self.host = host self.port = port self.sock = None self._sensor = sensor self.stopped = threading.Event()
'Connect to the Fritz!Box.'
def connect(self):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.settimeout(10) try: self.sock.connect((self.host, self.port)) threading.Thread(target=self._listen).start() except socket.error as err: self.sock = None _LOGGER.error('Cannot connect to %s ...
'Listen to incoming or outgoing calls.'
def _listen(self):
while (not self.stopped.isSet()): try: response = self.sock.recv(2048) except socket.timeout: continue response = str(response, 'utf-8') if (not response): self.sock = None while (self.sock is None): self.connect() ...
'Parse the call information and set the sensor states.'
def _parse(self, line):
line = line.split(';') df_in = '%d.%m.%y %H:%M:%S' df_out = '%Y-%m-%dT%H:%M:%S' isotime = datetime.datetime.strptime(line[0], df_in).strftime(df_out) if (line[1] == 'RING'): self._sensor.set_state(VALUE_RING) att = {'type': 'incoming', 'from': line[3], 'to': line[4], 'device': lin...
'Initialize the class.'
def __init__(self, host, port, username, password, phonebook_id=0, prefixes=None):
self.host = host self.username = username self.password = password self.port = port self.phonebook_id = phonebook_id self.phonebook_dict = None self.number_dict = None self.prefixes = (prefixes or []) import fritzconnection as fc self.fph = fc.FritzPhonebook(address=self.host, us...
'Update the phone book dictionary.'
@Throttle(MIN_TIME_PHONEBOOK_UPDATE) def update_phonebook(self):
self.phonebook_dict = self.fph.get_all_names(self.phonebook_id) self.number_dict = {re.sub('[^\\d\\+]', '', nr): name for (name, nrs) in self.phonebook_dict.items() for nr in nrs} _LOGGER.info('Fritz!Box phone book successfully updated')
'Return a name for a given phone number.'
def get_name(self, number):
number = re.sub('[^\\d\\+]', '', str(number)) if (self.number_dict is None): return 'unknown' try: return self.number_dict[number] except KeyError: pass if self.prefixes: for prefix in self.prefixes: try: return self.number_dict[(prefix + n...
'Initialize the sensor.'
def __init__(self, name, data):
self.data = data self._name = name self._unit_of_measurement = TEMP_CELSIUS self._state = None
'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):
if (self._state is not STATE_UNKNOWN): return self._unit_of_measurement return None
'Return the state of the sensor.'
@property def state(self):
try: return round(float(self._state), 1) except ValueError: return STATE_UNKNOWN
'Return the state attributes.'
@property def device_state_attributes(self):
attributes = {} if (self.data.measurings is not None): if ('02' in self.data.measurings): attributes[ATTR_WATERLEVEL] = self.data.measurings['02']['current'] attributes[ATTR_WATERLEVEL_MEAN] = self.data.measurings['02']['mean'] attributes[ATTR_WATERLEVEL_MAX] = self.d...
'Icon to use in the frontend, if any.'
@property def icon(self):
return ICON
'Get the latest data and update the states.'
def update(self):
self.data.update() if (self.data.measurings is not None): if ('03' not in self.data.measurings): self._state = STATE_UNKNOWN else: self._state = self.data.measurings['03']['current']
'Initialize the data object.'
def __init__(self, station):
self.station = station self.measurings = None
'Get the latest data from hydrodata.ch.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
import xmltodict details = {} try: response = requests.get(_RESOURCE, timeout=5) except requests.exceptions.ConnectionError: _LOGGER.error('Unable to retrieve data from %s', _RESOURCE) try: stations = xmltodict.parse(response.text)['AKT_Data']['MesPar'] ...
'Initialize the sensor.'
def __init__(self, start, goal):
self._name = '{} to {}'.format(start, goal) self.data = SchieneData(start, goal) 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 departure time of the next train.'
@property def state(self):
return self._state
'Return the state attributes.'
@property def device_state_attributes(self):
connections = self.data.connections[0] connections['next'] = self.data.connections[1]['departure'] connections['next_on'] = self.data.connections[2]['departure'] return connections
'Get the latest delay from bahn.de and updates the state.'
def update(self):
self.data.update() self._state = self.data.connections[0].get('departure', 'Unknown') if (self.data.connections[0]['delay'] != 0): self._state += ' + {}'.format(self.data.connections[0]['delay'])
'Initialize the sensor.'
def __init__(self, start, goal):
import schiene self.start = start self.goal = goal self.schiene = schiene.Schiene() self.connections = [{}]
'Update the connection data.'
def update(self):
self.connections = self.schiene.connections(self.start, self.goal, dt_util.as_local(dt_util.utcnow())) for con in self.connections: if ('details' in con): con.pop('details') delay = con.get('delay', {'delay_departure': 0, 'delay_arrival': 0}) con['delay'] = delay['del...
'Initialize handler.'
def __init__(self, entity):
super().__init__() self.entity = entity self.count = 0
'Handle a log message.'
def handle(self, record):
if (record.name == NAME_STREAM): if (not record.msg.startswith('STREAM')): return if record.msg.endswith('ATTACHED'): self.entity.count += 1 elif record.msg.endswith('RESPONSE CLOSED'): self.entity.count -= 1 elif (not record.msg.startswith('WS')): ...
'Initialize the API count.'
def __init__(self):
self.count = 0
'Return name of entity.'
@property def name(self):
return 'Connected clients'
'Return current API count.'
@property def state(self):
return self.count
'Return the unit of measurement.'
@property def unit_of_measurement(self):
return 'clients'
'Initialize the sensor.'
def __init__(self, data, sensor_type):
self._data = data self.type = sensor_type self._name = (SENSOR_PREFIX + SENSOR_TYPES[sensor_type][0]) self._unit = SENSOR_TYPES[sensor_type][1] self._inferred_unit = None self._state = None
'Return the name of the UPS sensor.'
@property def name(self):
return self._name
'Icon to use in the frontend, if any.'
@property def icon(self):
return SENSOR_TYPES[self.type][2]
'Return true if the UPS is online, else False.'
@property def state(self):
return self._state