desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Send arm away command.'
| def alarm_arm_away(self, code=None):
| if (not self._validate_code(code, STATE_ALARM_ARMED_AWAY)):
return
self._state = STATE_ALARM_ARMED_AWAY
self._state_ts = dt_util.utcnow()
self.schedule_update_ha_state()
if self._pending_time:
track_point_in_time(self._hass, self.async_update_ha_state, (self._state_ts + self._pending... |
'Send alarm trigger command. No code needed.'
| def alarm_trigger(self, code=None):
| self._pre_trigger_state = self._state
self._state = STATE_ALARM_TRIGGERED
self._state_ts = dt_util.utcnow()
self.schedule_update_ha_state()
if self._trigger_time:
track_point_in_time(self._hass, self.async_update_ha_state, (self._state_ts + self._pending_time))
track_point_in_time(se... |
'Validate given code.'
| def _validate_code(self, code, state):
| check = ((self._code is None) or (code == self._code))
if (not check):
_LOGGER.warning('Invalid code given for %s', state)
return check
|
'Initialize seven segments processing.'
| def __init__(self, hass, camera_entity, config, name):
| self.hass = hass
self._camera_entity = camera_entity
if name:
self._name = name
else:
self._name = 'SevenSegement OCR {0}'.format(split_entity_id(camera_entity)[1])
self._state = None
self.filepath = os.path.join(self.hass.config.config_dir, 'ocr.png')
crop = ['crop', s... |
'Return the class of this device, from component DEVICE_CLASSES.'
| @property
def device_class(self):
| return 'ocr'
|
'Return camera entity id from process pictures.'
| @property
def camera_entity(self):
| return self._camera_entity
|
'Return the name of the image processor.'
| @property
def name(self):
| return self._name
|
'Return the state of the entity.'
| @property
def state(self):
| return self._state
|
'Process the image.'
| def process_image(self, image):
| from PIL import Image
import subprocess
stream = io.BytesIO(image)
img = Image.open(stream)
img.save(self.filepath, 'png')
ocr = subprocess.Popen(self._command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out = ocr.communicate()
if (out[0] != ''):
self._state = out[0].strip()... |
'Initialize Dlib face entity.'
| def __init__(self, camera_entity, name=None):
| super().__init__()
self._camera = camera_entity
if name:
self._name = name
else:
self._name = 'Dlib Face {0}'.format(split_entity_id(camera_entity)[1])
|
'Return camera entity id from process pictures.'
| @property
def camera_entity(self):
| return self._camera
|
'Return the name of the entity.'
| @property
def name(self):
| return self._name
|
'Process image.'
| def process_image(self, image):
| import face_recognition
fak_file = io.BytesIO(image)
fak_file.name = 'snapshot.jpg'
fak_file.seek(0)
image = face_recognition.load_image_file(fak_file)
face_locations = face_recognition.face_locations(image)
face_locations = [{ATTR_LOCATION: location} for location in face_locations]
self... |
'Initialize the OpenCV entity.'
| def __init__(self, hass, camera_entity, name, classifiers):
| self.hass = hass
self._camera_entity = camera_entity
if name:
self._name = name
else:
self._name = 'OpenCV {0}'.format(split_entity_id(camera_entity)[1])
self._classifiers = classifiers
self._matches = {}
self._total_matches = 0
self._last_image = None
|
'Return camera entity id from process pictures.'
| @property
def camera_entity(self):
| return self._camera_entity
|
'Return the name of the image processor.'
| @property
def name(self):
| return self._name
|
'Return the state of the entity.'
| @property
def state(self):
| return self._total_matches
|
'Return device specific state attributes.'
| @property
def state_attributes(self):
| return {ATTR_MATCHES: self._matches, ATTR_TOTAL_MATCHES: self._total_matches}
|
'Process the image.'
| def process_image(self, image):
| import cv2
import numpy
cv_image = cv2.imdecode(numpy.asarray(bytearray(image)), cv2.IMREAD_UNCHANGED)
for (name, classifier) in self._classifiers.items():
scale = DEFAULT_SCALE
neighbors = DEFAULT_NEIGHBORS
min_size = DEFAULT_MIN_SIZE
if isinstance(classifier, dict):
... |
'Initialize Dlib face identify entry.'
| def __init__(self, camera_entity, faces, name=None):
| import face_recognition
super().__init__()
self._camera = camera_entity
if name:
self._name = name
else:
self._name = 'Dlib Face {0}'.format(split_entity_id(camera_entity)[1])
self._faces = {}
for (face_name, face_file) in faces.items():
try:
image =... |
'Return camera entity id from process pictures.'
| @property
def camera_entity(self):
| return self._camera
|
'Return the name of the entity.'
| @property
def name(self):
| return self._name
|
'Process image.'
| def process_image(self, image):
| import face_recognition
fak_file = io.BytesIO(image)
fak_file.name = 'snapshot.jpg'
fak_file.seek(0)
image = face_recognition.load_image_file(fak_file)
unknowns = face_recognition.face_encodings(image)
found = []
for unknown_face in unknowns:
for (name, face) in self._faces.items... |
'Initialize demo ALPR image processing entity.'
| def __init__(self, camera_entity, name):
| super().__init__()
self._name = name
self._camera = camera_entity
|
'Return camera entity id from process pictures.'
| @property
def camera_entity(self):
| return self._camera
|
'Return minimum confidence for send events.'
| @property
def confidence(self):
| return 80
|
'Return the name of the entity.'
| @property
def name(self):
| return self._name
|
'Process image.'
| def process_image(self, image):
| demo_data = {'AC3829': 98.3, 'BE392034': 95.5, 'CD02394': 93.4, 'DF923043': 90.8}
self.process_plates(demo_data, 1)
|
'Initialize demo face image processing entity.'
| def __init__(self, camera_entity, name):
| super().__init__()
self._name = name
self._camera = camera_entity
|
'Return camera entity id from process pictures.'
| @property
def camera_entity(self):
| return self._camera
|
'Return minimum confidence for send events.'
| @property
def confidence(self):
| return 80
|
'Return the name of the entity.'
| @property
def name(self):
| return self._name
|
'Process image.'
| def process_image(self, image):
| demo_data = [{ATTR_CONFIDENCE: 98.34, ATTR_NAME: 'Hans', ATTR_AGE: 16.0, ATTR_GENDER: 'male'}, {ATTR_NAME: 'Helena', ATTR_AGE: 28.0, ATTR_GENDER: 'female'}, {ATTR_CONFIDENCE: 62.53, ATTR_NAME: 'Luna'}]
self.process_faces(demo_data, 4)
|
'Initialize the sensor.'
| def __init__(self, data):
| self.data = data
self._ticker = None
self._unit_of_measurement = 'USD'
|
'Return the name of the sensor.'
| @property
def name(self):
| return self._ticker.get('name')
|
'Return the state of the sensor.'
| @property
def state(self):
| return round(float(self._ticker.get('price_usd')), 2)
|
'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_24H_VOLUME_USD: self._ticker.get('24h_volume_usd'), ATTR_ATTRIBUTION: CONF_ATTRIBUTION, ATTR_AVAILABLE_SUPPLY: self._ticker.get('available_supply'), ATTR_MARKET_CAP: self._ticker.get('market_cap_usd'), ATTR_PERCENT_CHANGE_24H: self._ticker.get('percent_change_24h'), ATTR_PERCENT_CHANGE_7D: self._ticker... |
'Get the latest data and updates the states.'
| def update(self):
| self.data.update()
self._ticker = self.data.ticker[0]
|
'Initialize the data object.'
| def __init__(self, currency):
| self.currency = currency
self.ticker = None
|
'Get the latest data from blockchain.info.'
| def update(self):
| from coinmarketcap import Market
self.ticker = Market().ticker(self.currency, limit=1)
|
'Initialize the sensor.'
| def __init__(self, account, steamod):
| self._steamod = steamod
self._account = account
self._profile = None
self._game = self._state = self._name = self._avatar = 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.steam_{}'.format(self._account)
|
'Return the state of the sensor.'
| @property
def state(self):
| return self._state
|
'Update device state.'
| def update(self):
| try:
self._profile = self._steamod.user.profile(self._account)
if (self._profile.current_game[2] is None):
self._game = 'None'
else:
self._game = self._profile.current_game[2]
self._state = {1: STATE_ONLINE, 2: STATE_BUSY, 3: STATE_AWAY, 4: STATE_SNOOZE, 5: ST... |
'Return the state attributes.'
| @property
def device_state_attributes(self):
| return {'Game': self._game}
|
'Avatar of the account.'
| @property
def entity_picture(self):
| return self._avatar
|
'Return the icon to use in the frontend.'
| @property
def icon(self):
| return ICON
|
'Initialize a new PM sensor.'
| def __init__(self, pmDataCollector, name, pmname):
| self._name = name
self._pmname = pmname
self._state = None
self._collector = pmDataCollector
|
'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 '\xc2\xb5g/m\xc2\xb3'
|
'Read from sensor and update the state.'
| def update(self):
| _LOGGER.debug('Reading data from PM sensor')
try:
self._state = self._collector.read_data()[self._pmname]
except KeyError:
_LOGGER.error('Could not read PM%s value', self._pmname)
|
'Sensor needs polling.'
| def should_poll(self):
| return True
|
'Initialize.'
| def __init__(self):
| self.state = {}
self._dovado = None
|
'Set up the connection.'
| def setup(self, hass, config, add_devices):
| import dovado
self._dovado = dovado.Dovado(config.get(CONF_USERNAME), config.get(CONF_PASSWORD), config.get(CONF_HOST), config.get(CONF_PORT))
if (not self.update()):
return False
def send_sms(service):
'Send SMS through the router.'
number = (service.data.get('number... |
'Name of the router.'
| @property
def name(self):
| return self.state.get('product name', DEVICE_DEFAULT_NAME)
|
'Update device state.'
| @Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
| _LOGGER.info('Updating')
try:
self.state = (self._dovado.state or {})
if (not self.state):
return False
self.state.update(connected=(self.state.get('modem status') == 'CONNECTED'))
_LOGGER.debug('Received: %s', self.state)
return True
except OSError ... |
'Initialize the sensor.'
| def __init__(self, dovado, sensor):
| self._dovado = dovado
self._sensor = sensor
self._state = self._compute_state()
|
'Update sensor values.'
| def update(self):
| self._dovado.update()
self._state = self._compute_state()
|
'Return the name of the sensor.'
| @property
def name(self):
| return '{} {}'.format(self._dovado.name, SENSORS[self._sensor][1])
|
'Return the sensor state.'
| @property
def state(self):
| return self._state
|
'Return the icon for the sensor.'
| @property
def icon(self):
| return SENSORS[self._sensor][3]
|
'Return the unit of measurement.'
| @property
def unit_of_measurement(self):
| return SENSORS[self._sensor][2]
|
'Return the state attributes.'
| @property
def device_state_attributes(self):
| return {k: v for (k, v) in self._dovado.state.items() if (k not in ['date', 'time'])}
|
'Initialize a sensor.'
| def __init__(self, name, mon):
| self.mon = mon
self._name = name
|
'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.mon.data['humid']
|
'Return the unit the value is expressed in.'
| @property
def unit_of_measurement(self):
| return '%'
|
'Return the state attributes of the sensor.'
| @property
def device_state_attributes(self):
| return {ATTR_DEVICE: 'SKYBEACON', ATTR_MODEL: 1}
|
'Initialize a sensor.'
| def __init__(self, name, mon):
| self.mon = mon
self._name = name
|
'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.mon.data['temp']
|
'Return the unit the value is expressed in.'
| @property
def unit_of_measurement(self):
| return TEMP_CELSIUS
|
'Return the state attributes of the sensor.'
| @property
def device_state_attributes(self):
| return {ATTR_DEVICE: 'SKYBEACON', ATTR_MODEL: 1}
|
'Construct interface object.'
| def __init__(self, hass, mac, name):
| threading.Thread.__init__(self)
self.daemon = False
self.hass = hass
self.mac = mac
self.name = name
self.data = {'temp': STATE_UNKNOWN, 'humid': STATE_UNKNOWN}
self.keep_going = True
self.event = threading.Event()
|
'Thread that keeps connection alive.'
| def run(self):
| import pygatt
from pygatt.backends import Characteristic
from pygatt.exceptions import BLEError, NotConnectedError, NotificationTimeout
cached_char = Characteristic(BLE_TEMP_UUID, BLE_TEMP_HANDLE)
adapter = pygatt.backends.GATTToolBackend()
while True:
try:
_LOGGER.info('Conn... |
'Notification callback from pygatt.'
| def _update(self, handle, value):
| _LOGGER.debug('%s: %15s temperature = %-2d.%-2d, humidity = %3d', handle, self.name, value[0], value[2], value[1])
self.data['temp'] = float(('%d.%d' % (value[0], value[2])))
self.data['humid'] = value[1]
|
'Signal runner to stop and join thread.'
| def terminate(self):
| self.keep_going = False
self.event.set()
self.join()
|
'Create Sonarr entity.'
| def __init__(self, hass, conf, sensor_type):
| from pytz import timezone
self.conf = conf
self.host = conf.get(CONF_HOST)
self.port = conf.get(CONF_PORT)
self.urlbase = conf.get(CONF_URLBASE)
if self.urlbase:
self.urlbase = '{}/'.format(self.urlbase.strip('/'))
self.apikey = conf.get(CONF_API_KEY)
self.included = conf.get(CON... |
'Return the name of the sensor.'
| @property
def name(self):
| return '{} {}'.format('Sonarr', self._name)
|
'Return sensor state.'
| @property
def state(self):
| return self._state
|
'Return sensor availability.'
| @property
def available(self):
| return self._available
|
'Return the unit of the sensor.'
| @property
def unit_of_measurement(self):
| return self._unit
|
'Return the state attributes of the sensor.'
| @property
def device_state_attributes(self):
| attributes = {}
if (self.type == 'upcoming'):
for show in self.data:
attributes[show['series']['title']] = 'S{:02d}E{:02d}'.format(show['seasonNumber'], show['episodeNumber'])
elif (self.type == 'queue'):
for show in self.data:
attributes[(show['series']['title'] + ' ... |
'Return the icon of the sensor.'
| @property
def icon(self):
| return self._icon
|
'Update the data for the sensor.'
| def update(self):
| start = get_date(self._tz)
end = get_date(self._tz, self.days)
try:
res = requests.get(ENDPOINTS[self.type].format(self.ssl, self.host, self.port, self.urlbase, self.apikey, start, end), timeout=5)
except OSError:
_LOGGER.error('Host %s is not available', self.host)
s... |
'Initialize the sensor.'
| def __init__(self, structure, device, variable):
| self.structure = structure
self.device = device
self.variable = variable
self._location = self.device.where
self._name = '{} {}'.format(self.device.name_long, self.variable.replace('_', ' '))
self._state = None
self._unit = None
|
'Return the name of the nest, if any.'
| @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 sensor.'
| @property
def state(self):
| return self._state
|
'Retrieve latest state.'
| def update(self):
| self._unit = SENSOR_UNITS.get(self.variable, None)
if (self.variable == 'operation_mode'):
self._state = getattr(self.device, 'mode')
else:
self._state = getattr(self.device, self.variable)
|
'Return the state of the sensor.'
| @property
def state(self):
| return self._state
|
'Retrieve latest state.'
| def update(self):
| if (self.device.temperature_scale == 'C'):
self._unit = TEMP_CELSIUS
else:
self._unit = TEMP_FAHRENHEIT
temp = getattr(self.device, self.variable)
if (temp is None):
self._state = None
if isinstance(temp, tuple):
(low, high) = temp
self._state = ('%s-%s' % (in... |
'Return the state of the sensor.'
| @property
def state(self):
| return self._state
|
'Retrieve latest state.'
| def update(self):
| self._state = getattr(self.device, self.variable).capitalize()
|
'Initialize the Statistics sensor.'
| def __init__(self, hass, entity_id, name, sampling_size):
| self._hass = hass
self._entity_id = entity_id
self.is_binary = (True if (self._entity_id.split('.')[0] == 'binary_sensor') else False)
if (not self.is_binary):
self._name = '{} {}'.format(name, ATTR_MEAN)
else:
self._name = '{} {}'.format(name, ATTR_COUNT)
self._sampling_si... |
'Return the name of the sensor.'
| @property
def name(self):
| return self._name
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.