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):
if (self._units == 'C'): return TEMP_CELSIUS elif (self._units == 'F'): return TEMP_FAHRENHEIT return self._units
'Initialize the sensor.'
def __init__(self, weather_data, name, forecast, sensor_type):
self._client = name self._name = SENSOR_TYPES[sensor_type][0] self._type = sensor_type self._state = STATE_UNKNOWN self._unit = SENSOR_TYPES[sensor_type][1] self._data = weather_data self._forecast = forecast self._code = None
'Return the name of the sensor.'
@property def name(self):
return '{} {}'.format(self._client, 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._data.yahoo.Units.get(self._unit, self._unit)
'Return the entity picture to use in the frontend, if any.'
@property def entity_picture(self):
if ((self._code is None) or ('weather' not in self._type)): return None return self._data.yahoo.getWeatherImage(self._code)
'Return the state attributes.'
@property def device_state_attributes(self):
return {ATTR_ATTRIBUTION: CONF_ATTRIBUTION}
'Get the latest data from Yahoo! and updates the states.'
def update(self):
self._data.update() if (not self._data.yahoo.RawData): _LOGGER.info("Don't receive weather data from Yahoo!") return self._code = self._data.yahoo.Now['code'] if (self._type == 'weather_current'): self._state = self._data.yahoo.Now['text'] elif (self._type == '...
'Initialize the data object.'
def __init__(self, woeid, temp_unit):
from yahooweather import YahooWeather self._yahoo = YahooWeather(woeid, temp_unit)
'Return Yahoo! API object.'
@property def yahoo(self):
return self._yahoo
'Get the latest data from Yahoo!.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
return self._yahoo.updateWeather()
'Initialize a web scrape sensor.'
def __init__(self, hass, rest, name, select, value_template, unit):
self.rest = rest self._name = name self._state = STATE_UNKNOWN self._select = select self._value_template = value_template self._unit_of_measurement = unit
'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 device.'
@property def state(self):
return self._state
'Get the latest data from the source and updates the state.'
def update(self):
self.rest.update() from bs4 import BeautifulSoup raw_data = BeautifulSoup(self.rest.data, 'html.parser') _LOGGER.debug(raw_data) value = raw_data.select(self._select)[0].text _LOGGER.debug(value) if (self._value_template is not None): self._state = self._value_template.render_with_po...
'Initialize the sensor.'
def __init__(self, name, addresses):
self._name = name self.addresses = addresses self._state = None self._unit_of_measurement = 'BTC'
'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 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_ATTRIBUTION: CONF_ATTRIBUTION}
'Get the latest state of the sensor.'
def update(self):
from pyblockchain import get_balance self._state = get_balance(self.addresses)
'Initialize a HDDTemp sensor.'
def __init__(self, name, hddtemp):
self.hddtemp = hddtemp self._name = name self._state = False self._details = None
'Return the name of the sensor.'
@property def name(self):
return self._name
'Return the state of the device.'
@property def state(self):
return self._state
'Return the unit the value is expressed in.'
@property def unit_of_measurement(self):
if (self._details[4] == 'C'): return TEMP_CELSIUS return TEMP_FAHRENHEIT
'Return the state attributes of the sensor.'
@property def device_state_attributes(self):
return {ATTR_DEVICE: self._details[1], ATTR_MODEL: self._details[2]}
'Get the latest data from HDDTemp daemon and updates the state.'
def update(self):
self.hddtemp.update() if (self.hddtemp.data is not None): self._details = self.hddtemp.data.split('|') self._state = self._details[3] else: self._state = STATE_UNKNOWN
'Initialize the data object.'
def __init__(self, host, port):
self.host = host self.port = port self.data = None
'Get the latest data from HDDTemp running as daemon.'
def update(self):
try: connection = Telnet(host=self.host, port=self.port, timeout=DEFAULT_TIMEOUT) self.data = connection.read_all().decode('ascii') except ConnectionRefusedError: _LOGGER.error('HDDTemp is not available at %s:%s', self.host, self.port) self.data = None
'Initialize the sensor.'
def __init__(self, pygtfs, name, origin, destination, offset):
self._pygtfs = pygtfs self.origin = origin self.destination = destination self._offset = offset self._custom_name = name self._name = '' self._unit_of_measurement = 'min' self._state = 0 self._attributes = {} self.lock = threading.Lock() self.update()
'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
'Return the state attributes.'
@property def device_state_attributes(self):
return self._attributes
'Icon to use in the frontend, if any.'
@property def icon(self):
return ICON
'Get the latest data from GTFS and update the states.'
def update(self):
with self.lock: self._departure = get_next_departure(self._pygtfs, self.origin, self.destination, self._offset) if (not self._departure): self._state = 0 self._attributes = {'Info': 'No more departures today'} if (self._name == ''): self._...
'Initialize the sensor.'
def __init__(self, name, plex_url, plex_user, plex_password, plex_server):
from plexapi.utils import NA from plexapi.myplex import MyPlexAccount from plexapi.server import PlexServer self._na_type = NA self._name = name self._state = 0 self._now_playing = [] if (plex_user and plex_password): user = MyPlexAccount.signin(plex_user, plex_password) ...
'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 'Watching'
'Return the state attributes.'
@property def device_state_attributes(self):
return {content[0]: content[1] for content in self._now_playing}
'Update method for Plex sensor.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
sessions = self._server.sessions() now_playing = [] for sess in sessions: user = (sess.username if (sess.username is not self._na_type) else '') title = (sess.title if (sess.title is not self._na_type) else '') year = (sess.year if (sess.year is not self._na_type) else '') no...
'Initialize the REST sensor.'
def __init__(self, hass, rest, name, unit_of_measurement, value_template):
self._hass = hass self.rest = rest self._name = name self._state = STATE_UNKNOWN self._unit_of_measurement = unit_of_measurement self._value_template = value_template
'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 device.'
@property def state(self):
return self._state
'Get the latest data from REST API and update the state.'
def update(self):
self.rest.update() value = self.rest.data if (value is None): value = STATE_UNKNOWN elif (self._value_template is not None): value = self._value_template.render_with_possible_json_value(value, STATE_UNKNOWN) self._state = value
'Initialize the data object.'
def __init__(self, method, resource, auth, headers, data, verify_ssl):
self._request = requests.Request(method, resource, headers=headers, auth=auth, data=data).prepare() self._verify_ssl = verify_ssl self.data = None
'Get the latest data from REST service with provided method.'
def update(self):
try: with requests.Session() as sess: response = sess.send(self._request, timeout=10, verify=self._verify_ssl) self.data = response.text except requests.exceptions.RequestException: _LOGGER.error('Error fetching data: %s', self._request) self.data = None
'Initialize the sensor.'
def __init__(self, fstatus):
self._name = 'fritz_netmonitor' self._fstatus = fstatus self._state = STATE_UNAVAILABLE self._is_linked = self._is_connected = self._wan_access_type = None self._external_ip = self._uptime = None self._bytes_sent = self._bytes_received = None self._max_byte_rate_up = self._max_byte_rate_down...
'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 ICON
'Return the state of the device.'
@property def state(self):
return self._state
'Return the device state attributes.'
@property def state_attributes(self):
if (self._state == STATE_UNAVAILABLE): return {} attr = {ATTR_IS_LINKED: self._is_linked, ATTR_IS_CONNECTED: self._is_connected, ATTR_WAN_ACCESS_TYPE: self._wan_access_type, ATTR_EXTERNAL_IP: self._external_ip, ATTR_UPTIME: self._uptime, ATTR_BYTES_SENT: self._bytes_sent, ATTR_BYTES_RECEIVED: self._byte...
'Retrieve information from the FritzBox.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
try: self._is_linked = self._fstatus.is_linked self._is_connected = self._fstatus.is_connected self._wan_access_type = self._fstatus.wan_access_type self._external_ip = self._fstatus.external_ip self._uptime = self._fstatus.uptime self._bytes_sent = self._fstatus.byte...
'Initialize the HistoryStats sensor.'
def __init__(self, hass, entity_id, entity_state, start, end, duration, sensor_type, name):
self._hass = hass self._entity_id = entity_id self._entity_state = entity_state self._duration = duration self._start = start self._end = end self._type = sensor_type self._name = name self._unit_of_measurement = UNITS[sensor_type] self._period = (datetime.datetime.now(), datetim...
'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._type == CONF_TYPE_TIME): return round(self.value, 2) if (self._type == CONF_TYPE_RATIO): return HistoryStatsHelper.pretty_ratio(self.value, self._period) if (self._type == CONF_TYPE_COUNT): return self.count
'Return the unit the value is expressed in.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Return the polling state.'
@property def should_poll(self):
return True
'Return the state attributes of the sensor.'
@property def device_state_attributes(self):
hsh = HistoryStatsHelper return {ATTR_VALUE: hsh.pretty_duration(self.value)}
'Return the icon to use in the frontend, if any.'
@property def icon(self):
return ICON
'Get the latest data and updates the states.'
def update(self):
(p_start, p_end) = self._period self.update_period() (start, end) = self._period start = dt_util.as_utc(start) end = dt_util.as_utc(end) p_start = dt_util.as_utc(p_start) p_end = dt_util.as_utc(p_end) now = datetime.datetime.now() start_timestamp = math.floor(dt_util.as_timestamp(sta...
'Parse the templates and store a datetime tuple in _period.'
def update_period(self):
start = None end = None if (self._start is not None): try: start_rendered = self._start.render() except (TemplateError, TypeError) as ex: HistoryStatsHelper.handle_template_exception(ex, 'start') return start = dt_util.parse_datetime(start_rendered...
'Format a duration in days, hours, minutes, seconds.'
@staticmethod def pretty_duration(hours):
seconds = int((3600 * hours)) (days, seconds) = divmod(seconds, 86400) (hours, seconds) = divmod(seconds, 3600) (minutes, seconds) = divmod(seconds, 60) if (days > 0): return ('%dd %dh %dm' % (days, hours, minutes)) elif (hours > 0): return ('%dh %dm' % (hours, minutes))...
'Format the ratio of value / period duration.'
@staticmethod def pretty_ratio(value, period):
if ((len(period) != 2) or (period[0] == period[1])): return 0.0 ratio = (((100 * 3600) * value) / (period[1] - period[0]).total_seconds()) return round(ratio, 1)
'Log an error nicely if the template cannot be interpreted.'
@staticmethod def handle_template_exception(ex, field):
if (ex.args and ex.args[0].startswith("UndefinedError: 'None' has no attribute")): _LOGGER.warning(ex) return _LOGGER.error('Error parsing template for field %s', field) _LOGGER.error(ex)
'Initialize the modbus register sensor.'
def __init__(self, name, slave, register, register_type, unit_of_measurement, count, scale, offset, data_type, precision):
self._name = name self._slave = (int(slave) if slave else None) self._register = int(register) self._register_type = register_type self._unit_of_measurement = unit_of_measurement self._count = int(count) self._scale = scale self._offset = offset self._precision = precision self._...
'Return the state of the sensor.'
@property def state(self):
return self._value
'Return the name of the sensor.'
@property def name(self):
return self._name
'Return the unit of measurement.'
@property def unit_of_measurement(self):
return self._unit_of_measurement
'Update the state of the sensor.'
def update(self):
if (self._register_type == REGISTER_TYPE_INPUT): result = modbus.HUB.read_input_registers(self._slave, self._register, self._count) else: result = modbus.HUB.read_holding_registers(self._slave, self._register, self._count) val = 0 try: registers = result.registers except Attr...
'Initialize the sensor.'
def __init__(self, data, option_type, currency):
self.data = data self._name = OPTION_TYPES[option_type][0] self._unit_of_measurement = OPTION_TYPES[option_type][1] self._currency = currency self.type = option_type 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 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_ATTRIBUTION: CONF_ATTRIBUTION}
'Get the latest data and updates the states.'
def update(self):
self.data.update() stats = self.data.stats ticker = self.data.ticker if (self.type == 'exchangerate'): self._state = ticker[self._currency].p15min self._unit_of_measurement = self._currency elif (self.type == 'trade_volume_btc'): self._state = '{0:.1f}'.format(stats.trade_vol...
'Initialize the data object.'
def __init__(self):
self.stats = None self.ticker = None
'Get the latest data from blockchain.info.'
def update(self):
from blockchain import statistics, exchangerates self.stats = statistics.get() self.ticker = exchangerates.get_ticker()
'Initialize the sensor.'
def __init__(self, data, room, name, username):
self._name = name self._data = data self._room = room self._username = username self._state = None self._mention = 0 self._unit_of_measurement = 'Msg'
'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
'Return the state attributes.'
@property def device_state_attributes(self):
return {ATTR_USERNAME: self._username, ATTR_ROOM: self._room, ATTR_MENTION: self._mention}
'Return the icon to use in the frontend, if any.'
@property def icon(self):
return ICON
'Get the latest data and updates the state.'
def update(self):
data = self._data.user.unread_items(self._room) self._mention = len(data['mention']) self._state = len(data['chat'])
'Initialize the sensor.'
def __init__(self, name, data, sensor_type):
self._data = data self.type = sensor_type self._name = '{} {}'.format(name, SENSOR_TYPES[sensor_type][0]) self._unit = SENSOR_TYPES[sensor_type][1] 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 entity state from ups.'
@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
'Return the sensor attributes.'
@property def device_state_attributes(self):
attr = dict() attr[ATTR_STATE] = self.opp_state() return attr
'Return UPS operating state.'
def opp_state(self):
if (self._data.status is None): return STATE_TYPES['OFF'] else: try: return ' '.join((STATE_TYPES[state] for state in self._data.status[KEY_STATUS].split())) except KeyError: return STATE_UNKNOWN
'Get the latest status and use it to update our sensor state.'
def update(self):
if (self._data.status is None): self._state = None return if (self.type not in self._data.status): self._state = None else: self._state = self._data.status[self.type]
'Initialize the data oject.'
def __init__(self, host, port, alias, username, password):
from pynut2.nut2 import PyNUTClient, PyNUTError self._host = host self._port = port self._alias = alias self._username = username self._password = password self.pynuterror = PyNUTError self._client = PyNUTClient(self._host, self._port, self._username, self._password, 5, False) self._...
'Get latest update if throttle allows. Return status.'
@property def status(self):
self.update() return self._status