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):
| if (not self._unit):
return self._inferred_unit
return self._unit
|
'Get the latest status and use it to update our sensor state.'
| def update(self):
| if (self.type.upper() not in self._data.status):
self._state = None
self._inferred_unit = None
else:
(self._state, self._inferred_unit) = infer_unit(self._data.status[self.type.upper()])
|
'Initialize the sensor.'
| def __init__(self, data, sensor_types):
| self.data = data
self._name = SENSOR_TYPES[sensor_types][0]
self._unit_of_measurement = SENSOR_TYPES[sensor_types][1]
self.type = sensor_types
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
|
'Get the latest data and updates the states.'
| def update(self):
| self.data.update()
if (not self.data.humidity):
_LOGGER.error("Don't receive data")
return
if (self.type == 'temperature'):
self._state = self.data.temperature
if (self.type == 'humidity'):
self._state = self.data.humidity
if (self.type == 'pressure'):
s... |
'Initialize the data object.'
| def __init__(self, is_hat_attached):
| self.temperature = None
self.humidity = None
self.pressure = None
self.is_hat_attached = is_hat_attached
|
'Get the latest data from Sense HAT.'
| @Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
| from sense_hat import SenseHat
sense = SenseHat()
temp_from_h = sense.get_temperature_from_humidity()
temp_from_p = sense.get_temperature_from_pressure()
t_total = ((temp_from_h + temp_from_p) / 2)
if self.is_hat_attached:
t_cpu = get_cpu_temp()
t_correct = (t_total - ((t_cpu - t... |
'Initialize the API wrapper.'
| def __init__(self, config):
| from qnapstats import QNAPStats
protocol = ('https' if config.get(CONF_SSL) else 'http')
self._api = QNAPStats(((protocol + '://') + config.get(CONF_HOST)), config.get(CONF_PORT), config.get(CONF_USERNAME), config.get(CONF_PASSWORD), verify_ssl=config.get(CONF_VERIFY_SSL), timeout=config.get(CONF_TIMEOUT))
... |
'Update API information and store locally.'
| @Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
| try:
self.data['system_stats'] = self._api.get_system_stats()
self.data['system_health'] = self._api.get_system_health()
self.data['smart_drive_health'] = self._api.get_smart_disk_health()
self.data['volumes'] = self._api.get_volumes()
self.data['bandwidth'] = self._api.get_b... |
'Initialize the sensor.'
| def __init__(self, api, variable, variable_info, monitor_device=None):
| self.var_id = variable
self.var_name = variable_info[0]
self.var_units = variable_info[1]
self.var_icon = variable_info[2]
self.monitor_device = monitor_device
self._api = api
|
'Return the name of the sensor, if any.'
| @property
def name(self):
| server_name = self._api.data['system_stats']['system']['name']
if (self.monitor_device is not None):
return '{} {} ({})'.format(server_name, self.var_name, self.monitor_device)
return '{} {}'.format(server_name, self.var_name)
|
'Return the 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
|
'Get the latest data for the states.'
| def update(self):
| self._api.update()
|
'Return the state of the sensor.'
| @property
def state(self):
| if (self.var_id == 'cpu_temp'):
return self._api.data['system_stats']['cpu']['temp_c']
elif (self.var_id == 'cpu_usage'):
return self._api.data['system_stats']['cpu']['usage_percent']
|
'Return the state of the sensor.'
| @property
def state(self):
| free = (float(self._api.data['system_stats']['memory']['free']) / 1024)
if (self.var_id == 'memory_free'):
return round_nicely(free)
total = (float(self._api.data['system_stats']['memory']['total']) / 1024)
used = (total - free)
if (self.var_id == 'memory_used'):
return round_nicely(... |
'Return the state attributes.'
| @property
def device_state_attributes(self):
| if self._api.data:
data = self._api.data['system_stats']['memory']
size = round_nicely((float(data['total']) / 1024))
return {ATTR_MEMORY_SIZE: '{} GB'.format(size)}
|
'Return the state of the sensor.'
| @property
def state(self):
| if (self.var_id == 'network_link_status'):
nic = self._api.data['system_stats']['nics'][self.monitor_device]
return nic['link_status']
data = self._api.data['bandwidth'][self.monitor_device]
if (self.var_id == 'network_tx'):
return round_nicely(((data['tx'] / 1024) / 1024))
if (s... |
'Return the state attributes.'
| @property
def device_state_attributes(self):
| if self._api.data:
data = self._api.data['system_stats']['nics'][self.monitor_device]
return {ATTR_IP: data['ip'], ATTR_MASK: data['mask'], ATTR_MAC: data['mac'], ATTR_MAX_SPEED: data['max_speed'], ATTR_PACKETS_TX: data['tx_packets'], ATTR_PACKETS_RX: data['rx_packets'], ATTR_PACKETS_ERR: data['err_... |
'Return the state of the sensor.'
| @property
def state(self):
| if (self.var_id == 'status'):
return self._api.data['system_health']
if (self.var_id == 'system_temp'):
return int(self._api.data['system_stats']['system']['temp_c'])
|
'Return the state attributes.'
| @property
def device_state_attributes(self):
| if self._api.data:
data = self._api.data['system_stats']
days = int(data['uptime']['days'])
hours = int(data['uptime']['hours'])
minutes = int(data['uptime']['minutes'])
return {ATTR_NAME: data['system']['name'], ATTR_MODEL: data['system']['model'], ATTR_SERIAL: data['system'... |
'Return the state of the sensor.'
| @property
def state(self):
| data = self._api.data['smart_drive_health'][self.monitor_device]
if (self.var_id == 'drive_smart_status'):
return data['health']
if (self.var_id == 'drive_temp'):
return int(data['temp_c'])
|
'Return the name of the sensor, if any.'
| @property
def name(self):
| server_name = self._api.data['system_stats']['system']['name']
return '{} {} (Drive {})'.format(server_name, self.var_name, self.monitor_device)
|
'Return the state attributes.'
| @property
def device_state_attributes(self):
| if self._api.data:
data = self._api.data['smart_drive_health'][self.monitor_device]
return {ATTR_DRIVE: data['drive_number'], ATTR_MODEL: data['model'], ATTR_SERIAL: data['serial'], ATTR_TYPE: data['type']}
|
'Return the state of the sensor.'
| @property
def state(self):
| data = self._api.data['volumes'][self.monitor_device]
free_gb = (((int(data['free_size']) / 1024) / 1024) / 1024)
if (self.var_id == 'volume_size_free'):
return round_nicely(free_gb)
total_gb = (((int(data['total_size']) / 1024) / 1024) / 1024)
used_gb = (total_gb - free_gb)
if (self.var... |
'Return the state attributes.'
| @property
def device_state_attributes(self):
| if self._api.data:
data = self._api.data['volumes'][self.monitor_device]
total_gb = (((int(data['total_size']) / 1024) / 1024) / 1024)
return {ATTR_VOLUME_SIZE: '{} GB'.format(round_nicely(total_gb))}
|
'Initialize the sensor.'
| def __init__(self, rest, name, quote):
| self.rest = rest
self._name = name
self._quote = quote
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 other attributes of the sensor.'
| @property
def device_state_attributes(self):
| attr = self.rest.data
attr[ATTR_ATTRIBUTION] = CONF_ATTRIBUTION
return attr
|
'Update current conditions.'
| def update(self):
| self.rest.update()
value = self.rest.data
self._state = round(value[str(self._quote)], 4)
|
'Initialize the data object.'
| def __init__(self, resource, parameters, quote):
| self._resource = resource
self._parameters = parameters
self._quote = quote
self.data = None
|
'Get the latest data from openexchangerates.org.'
| @Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
| try:
result = requests.get(self._resource, params=self._parameters, timeout=10)
self.data = result.json()['rates']
except requests.exceptions.HTTPError:
_LOGGER.error('Check the Openexchangerates API key')
self.data = None
return False
|
'Initialize an OpenHardwareMonitor sensor.'
| def __init__(self, data, name, path, unit_of_measurement):
| self._name = name
self._data = data
self.path = path
self.attributes = {}
self._unit_of_measurement = unit_of_measurement
self.value = None
|
'Return the name of the device.'
| @property
def name(self):
| return self._name
|
'Return the unit of measurement.'
| @property
def unit_of_measurement(self):
| return self._unit_of_measurement
|
'Return the state of the device.'
| @property
def state(self):
| return self.value
|
'Return the state attributes of the sun.'
| @property
def state_attributes(self):
| return self.attributes
|
'Update the device from a new JSON object.'
| def update(self):
| self._data.update()
array = self._data.data[OHM_CHILDREN]
_attributes = {}
for path_index in range(0, len(self.path)):
path_number = self.path[path_index]
values = array[path_number]
if (path_index == (len(self.path) - 1)):
self.value = values[OHM_VALUE].split(' ')... |
'Initialize the Open Hardware Monitor data-handler.'
| def __init__(self, config, hass):
| self.data = None
self._config = config
self._hass = hass
self.devices = []
self.initialize(utcnow())
|
'Hit by the timer with the configured interval.'
| @Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
| if (self.data is None):
self.initialize(utcnow())
else:
self.refresh()
|
'Download and parse JSON from OHM.'
| def refresh(self):
| data_url = ('http://%s:%d/data.json' % (self._config.get(CONF_HOST), self._config.get(CONF_PORT)))
try:
response = requests.get(data_url, timeout=30)
self.data = response.json()
except requests.exceptions.ConnectionError:
_LOGGER.error('ConnectionError: Is OpenHardwareMonitor ... |
'Initial parsing of the sensors and adding of devices.'
| def initialize(self, now):
| self.refresh()
if (self.data is None):
return
self.devices = self.parse_children(self.data, [], [], [])
|
'Recursively loop through child objects, finding the values.'
| def parse_children(self, json, devices, path, names):
| result = devices.copy()
if json[OHM_CHILDREN]:
for child_index in range(0, len(json[OHM_CHILDREN])):
child_path = path.copy()
child_path.append(child_index)
child_names = names.copy()
if path:
child_names.append(json[OHM_NAME])
... |
'Initialize the sensor.'
| def __init__(self, fido_data, sensor_type, name, number):
| self.client_name = name
self._number = number
self.type = sensor_type
self._name = SENSOR_TYPES[sensor_type][0]
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
self._icon = SENSOR_TYPES[sensor_type][2]
self.fido_data = fido_data
self._state = None
|
'Return the name of the sensor.'
| @property
def name(self):
| return '{} {} {}'.format(self.client_name, self._number, 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 self._icon
|
'Return the state attributes of the sensor.'
| @property
def device_state_attributes(self):
| return {'number': self._number}
|
'Get the latest data from Fido and update the state.'
| def update(self):
| self.fido_data.update()
if (self.type == 'balance'):
if (self.fido_data.data.get(self.type) is not None):
self._state = round(self.fido_data.data[self.type], 2)
elif (self.fido_data.data.get(self._number, {}).get(self.type) is not None):
self._state = self.fido_data.data[self._nu... |
'Initialize the data object.'
| def __init__(self, username, password):
| from pyfido import FidoClient
self.client = FidoClient(username, password, REQUESTS_TIMEOUT)
self.data = {}
|
'Get the latest data from Fido.'
| @Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
| from pyfido.client import PyFidoError
try:
self.client.fetch_data()
except PyFidoError as err:
_LOGGER.error('Error on receive last Fido data: %s', err)
return
self.data = self.client.get_data()
|
'Initialize the sensor.'
| def __init__(self, name, api_app_id, api_app_key, url):
| self._data = {}
self._api_app_id = api_app_id
self._api_app_key = api_app_key
self._url = (self.TRANSPORT_API_URL_BASE + url)
self._name = name
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 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 self.ICON
|
'Perform an API request.'
| def _do_api_request(self, params):
| request_params = dict({'app_id': self._api_app_id, 'app_key': self._api_app_key}, **params)
response = requests.get(self._url, params=request_params)
if (response.status_code != 200):
_LOGGER.warning('Invalid response from API')
elif ('error' in response.json()):
if ('exceeded' ... |
'Construct a live bus time sensor.'
| def __init__(self, api_app_id, api_app_key, stop_atcocode, bus_direction, interval):
| self._stop_atcocode = stop_atcocode
self._bus_direction = bus_direction
self._next_buses = []
self._destination_re = re.compile('{}'.format(bus_direction), re.IGNORECASE)
sensor_name = 'Next bus to {}'.format(bus_direction)
stop_url = 'bus/stop/{}/live.json'.format(stop_atcocode)
Uk... |
'Get the latest live departure data for the specified stop.'
| def _update(self):
| params = {'group': 'route', 'nextbuses': 'no'}
self._do_api_request(params)
if (self._data != {}):
self._next_buses = []
for (route, departures) in self._data['departures'].items():
for departure in departures:
if self._destination_re.search(departure['direction']... |
'Return other details about the sensor state.'
| @property
def device_state_attributes(self):
| attrs = {}
if (self._data is not None):
for key in [ATTR_ATCOCODE, ATTR_LOCALITY, ATTR_STOP_NAME, ATTR_REQUEST_TIME]:
attrs[key] = self._data.get(key)
attrs[ATTR_NEXT_BUSES] = self._next_buses
return attrs
|
'Construct a live bus time sensor.'
| def __init__(self, api_app_id, api_app_key, station_code, calling_at, interval):
| self._station_code = station_code
self._calling_at = calling_at
self._next_trains = []
sensor_name = 'Next train to {}'.format(calling_at)
query_url = 'train/station/{}/live.json'.format(station_code)
UkTransportSensor.__init__(self, sensor_name, api_app_id, api_app_key, query_url)
... |
'Get the latest live departure data for the specified stop.'
| def _update(self):
| params = {'darwin': 'false', 'calling_at': self._calling_at, 'train_status': 'passenger'}
self._do_api_request(params)
self._next_trains = []
if (self._data != {}):
if (self._data['departures']['all'] == []):
self._state = 'No departures'
else:
for departure in... |
'Return other details about the sensor state.'
| @property
def device_state_attributes(self):
| attrs = {}
if (self._data is not None):
attrs[ATTR_STATION_CODE] = self._station_code
attrs[ATTR_CALLING_AT] = self._calling_at
if self._next_trains:
attrs[ATTR_NEXT_TRAINS] = self._next_trains
return attrs
|
'Initialize the sensor.'
| def __init__(self, sensor_type, sabnzb_client, client_name):
| self._name = SENSOR_TYPES[sensor_type][0]
self.sabnzb_client = sabnzb_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 SABnzbd refresh method.'
| def refresh_sabnzbd_data(self):
| if (_THROTTLED_REFRESH is not None):
from pysabnzbd import SabnzbdApiException
try:
_THROTTLED_REFRESH()
except SabnzbdApiException:
_LOGGER.exception('Connection to SABnzbd API failed')
|
'Get the latest data and updates the states.'
| def update(self):
| self.refresh_sabnzbd_data()
if self.sabnzb_client.queue:
if (self.type == 'current_status'):
self._state = self.sabnzb_client.queue.get('status')
elif (self.type == 'speed'):
mb_spd = (float(self.sabnzb_client.queue.get('kbpersec')) / 1024)
self._state = round... |
'Initialize the HaveIBeenPwnedSensor sensor.'
| def __init__(self, data, hass, email):
| self._state = STATE_UNKNOWN
self._data = data
self._hass = hass
self._email = email
self._unit_of_measurement = 'Breaches'
|
'Return the name of the sensor.'
| @property
def name(self):
| return 'Breaches {}'.format(self._email)
|
'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
|
'Return the atrributes of the sensor.'
| @property
def device_state_attributes(self):
| val = {}
if (self._email not in self._data.data):
return val
for (idx, value) in enumerate(self._data.data[self._email]):
tmpname = 'breach {}'.format((idx + 1))
tmpvalue = '{} {}'.format(value['Title'], dt_util.as_local(dt_util.parse_datetime(value['AddedDate'])).strftime(DATE... |
'Update sensor without throttle.'
| def update_nothrottle(self, dummy=None):
| self._data.update_no_throttle()
if (self._email not in self._data.data):
track_point_in_time(self._hass, self.update_nothrottle, (dt_util.now() + MIN_TIME_BETWEEN_FORCED_UPDATES))
return
if (self._email in self._data.data):
self._state = len(self._data.data[self._email])
self... |
'Update data and see if it contains data for our email.'
| def update(self):
| self._data.update()
if (self._email in self._data.data):
self._state = len(self._data.data[self._email])
|
'Initialize the data object.'
| def __init__(self, emails):
| self._email_count = len(emails)
self._current_index = 0
self.data = {}
self._email = emails[0]
self._emails = emails
|
'Set the next email to be looked up.'
| def set_next_email(self):
| self._current_index = ((self._current_index + 1) % self._email_count)
self._email = self._emails[self._current_index]
|
'Get the data for a specific email.'
| def update_no_throttle(self):
| self.update(no_throttle=True)
|
'Get the latest data for current email from REST service.'
| @Throttle(MIN_TIME_BETWEEN_UPDATES, MIN_TIME_BETWEEN_FORCED_UPDATES)
def update(self, **kwargs):
| try:
url = 'https://haveibeenpwned.com/api/v2/breachedaccount/{}'.format(self._email)
_LOGGER.info('Checking for breaches for email %s', self._email)
req = requests.get(url, headers={'User-agent': USER_AGENT}, allow_redirects=True, timeout=5)
except requests.exceptions.Req... |
'Initialize the sensor.'
| def __init__(self, event, name, data_type, should_fire_event=False):
| self.event = event
self._name = name
self.should_fire_event = should_fire_event
self.data_type = data_type
self._unit_of_measurement = DATA_TYPES.get(data_type, '')
|
'Return the name of the sensor.'
| def __str__(self):
| return self._name
|
'Return the state of the sensor.'
| @property
def state(self):
| if (not self.event):
return None
return self.event.values.get(self.data_type)
|
'Get the name of the sensor.'
| @property
def name(self):
| return '{} {}'.format(self._name, self.data_type)
|
'Return the state attributes.'
| @property
def device_state_attributes(self):
| if (not self.event):
return None
return self.event.values
|
'Return the unit this state is expressed in.'
| @property
def unit_of_measurement(self):
| return self._unit_of_measurement
|
'Initialize the sensor.'
| def __init__(self, data, symbol):
| self._name = symbol
self.data = data
self._symbol = symbol
self._state = None
self._unit_of_measurement = 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):
| return self._symbol
|
'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._state is not None):
return {ATTR_ATTRIBUTION: CONF_ATTRIBUTION, ATTR_CHANGE: self.data.price_change, ATTR_OPEN: self.data.price_open, ATTR_PREV_CLOSE: self.data.prev_close}
|
'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):
| _LOGGER.debug('Updating sensor %s - %s', self._name, self._state)
self.data.update()
self._state = self.data.state
|
'Initialize the data object.'
| def __init__(self, symbol):
| from yahoo_finance import Share
self._symbol = symbol
self.state = None
self.price_change = None
self.price_open = None
self.prev_close = None
self.stock = Share(self._symbol)
|
'Get the latest data and updates the states.'
| def update(self):
| self.stock.refresh()
self.state = self.stock.get_price()
self.price_change = self.stock.get_change()
self.price_open = self.stock.get_open()
self.prev_close = self.stock.get_prev_close()
|
'Initialize monitor sensor.'
| def __init__(self, monitor_id, monitor_name):
| self._monitor_id = monitor_id
self._monitor_name = monitor_name
self._state = None
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.