desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Initialize the binary sensor.'
def __init__(self, name, host, ipcam, sensor):
super().__init__(host, ipcam) self._sensor = sensor self._mapped_name = KEY_MAP.get(self._sensor, self._sensor) self._name = '{} {}'.format(name, self._mapped_name) self._state = None self._unit = None
'Return the name of the binary sensor, if any.'
@property def name(self):
return self._name
'Return true if the binary sensor is on.'
@property def is_on(self):
return self._state
'Retrieve latest state.'
@asyncio.coroutine def async_update(self):
(state, _) = self._ipcam.export_sensor(self._sensor) self._state = (state == 1.0)
'Return the class of this device, from component DEVICE_CLASSES.'
@property def device_class(self):
return 'motion'
'Initialize the binary sensor.'
def __init__(self, axis_event, hass):
self.hass = hass self._state = False self._delay = axis_event.device_config(CONF_TRIGGER_TIME) self._timer = None AxisDeviceEvent.__init__(self, axis_event)
'Return true if event is active.'
@property def is_on(self):
return self._state
'Get the latest data and update the state.'
def update(self):
self._state = self.axis_event.is_tripped
'Update the sensor\'s state, if needed.'
def _update_callback(self):
self.update() if (self._timer is not None): self._timer() self._timer = None if ((self._delay > 0) and (not self.is_on)): def _delay_update(now): 'Timer callback for sensor update.' _LOGGER.debug('%s Called delayed (%s sec) update.',...
'Initialize the data oject.'
def __init__(self, hass, url, port, name, username, password):
from pyhik.hikvision import HikCamera self._url = url self._port = port self._name = name self._username = username self._password = password self.camdata = HikCamera(self._url, self._port, self._username, self._password) if (self._name is None): self._name = self.camdata.get_nam...
'Shutdown Hikvision subscriptions and subscription thread on exit.'
def stop_hik(self, event):
self.camdata.disconnect()
'Start Hikvision event stream thread.'
def start_hik(self, event):
self.camdata.start_stream()
'Return list of available sensors and their states.'
@property def sensors(self):
return self.camdata.current_event_states
'Return device id.'
@property def cam_id(self):
return self.camdata.get_id
'Return device name.'
@property def name(self):
return self._name
'Return device type.'
@property def type(self):
return self.camdata.get_type
'Return attribute list for sensor/channel.'
def get_attributes(self, sensor, channel):
return self.camdata.fetch_attributes(sensor, channel)
'Initialize the binary_sensor.'
def __init__(self, hass, sensor, channel, cam, delay):
self._hass = hass self._cam = cam self._sensor = sensor self._channel = channel if (self._cam.type == 'NVR'): self._name = '{} {} {}'.format(self._cam.name, sensor, channel) else: self._name = '{} {}'.format(self._cam.name, sensor) self._id = '{}.{}.{}'.format(self._...
'Extract sensor state.'
def _sensor_state(self):
return self._cam.get_attributes(self._sensor, self._channel)[0]
'Extract sensor last update time.'
def _sensor_last_update(self):
return self._cam.get_attributes(self._sensor, self._channel)[3]
'Return the name of the Hikvision sensor.'
@property def name(self):
return self._name
'Return an unique ID.'
@property def unique_id(self):
return '{}.{}'.format(self.__class__, self._id)
'Return true if sensor is on.'
@property def is_on(self):
return self._sensor_state()
'Return the class of this sensor, from DEVICE_CLASSES.'
@property def device_class(self):
try: return DEVICE_CLASS_MAP[self._sensor] except KeyError: return None
'No polling needed.'
@property def should_poll(self):
return False
'Return the state attributes.'
@property def device_state_attributes(self):
attr = {} attr[ATTR_LAST_TRIP_TIME] = self._sensor_last_update() if (self._delay != 0): attr[ATTR_DELAY] = self._delay return attr
'Update the sensor\'s state, if needed.'
def _update_callback(self, msg):
_LOGGER.debug('Callback signal from: %s', msg) if ((self._delay > 0) and (not self.is_on)): def _delay_update(now): 'Timer callback for sensor update.' _LOGGER.debug('%s Called delayed (%ssec) update', self._name, self._delay) self.sch...
'Initialize the Beaglebone Black binary sensor.'
def __init__(self, pin, params):
self._pin = pin self._name = (params.get(CONF_NAME) or DEVICE_DEFAULT_NAME) self._bouncetime = params.get(CONF_BOUNCETIME) self._pull_mode = params.get(CONF_PULL_MODE) self._invert_logic = params.get(CONF_INVERT_LOGIC) bbb_gpio.setup_input(self._pin, self._pull_mode) self._state = bbb_gpio.r...
'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 state of the entity.'
@property def is_on(self):
return (self._state != self._invert_logic)
'Initialize a new OctoPrint sensor.'
def __init__(self, api, condition, sensor_type, sensor_name, unit, endpoint, group, tool=None):
self.sensor_name = sensor_name if (tool is None): self._name = '{} {}'.format(sensor_name, condition) else: self._name = '{} {}'.format(sensor_name, condition) self.sensor_type = sensor_type self.api = api self._state = False self._unit_of_measurement = unit self.ap...
'Return the name of the sensor.'
@property def name(self):
return self._name
'Return true if binary sensor is on.'
@property def is_on(self):
return bool(self._state)
'Return the class of this sensor, from DEVICE_CLASSES.'
@property def device_class(self):
return None
'Update state of sensor.'
def update(self):
try: self._state = self.api.update(self.sensor_type, self.api_endpoint, self.api_group, self.api_tool) except requests.exceptions.ConnectionError: return
'Initialize the MQTT binary sensor.'
def __init__(self, name, state_topic, device_class, qos, payload_on, payload_off, value_template):
self._name = name self._state = False self._state_topic = state_topic self._device_class = device_class self._payload_on = payload_on self._payload_off = payload_off self._qos = qos self._template = value_template
'Subscribe mqtt events. This method must be run in the event loop and returns a coroutine.'
def async_added_to_hass(self):
@callback def message_received(topic, payload, qos): 'Handle a new received MQTT message.' if (self._template is not None): payload = self._template.async_render_with_possible_json_value(payload) if (payload == self._payload_on): self._state = True ...
'Return the polling state.'
@property def should_poll(self):
return False
'Return the name of the binary sensor.'
@property def name(self):
return self._name
'Return true if the binary sensor is on.'
@property def is_on(self):
return self._state
'Return the class of this sensor.'
@property def device_class(self):
return self._device_class
'Initialize the binary_sensor.'
def __init__(self, vera_device, controller):
self._state = False VeraDevice.__init__(self, vera_device, controller) self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
'Return true if sensor is on.'
@property def is_on(self):
return self._state
'Get the latest data and update the state.'
def update(self):
self._state = self.vera_device.is_tripped
'Initialize MAX! Cube BinarySensorDevice.'
def __init__(self, hass, name, rf_address):
self._name = name self._sensor_type = 'opening' self._rf_address = rf_address self._cubehandle = hass.data[MAXCUBE_HANDLE] self._state = STATE_UNKNOWN
'Return the polling state.'
@property def should_poll(self):
return True
'Return the name of the BinarySensorDevice.'
@property def name(self):
return self._name
'Return the class of this sensor.'
@property def device_class(self):
return self._sensor_type
'Return true if the binary sensor is on/open.'
@property def is_on(self):
return self._state
'Get latest data from MAX! Cube.'
def update(self):
self._cubehandle.update() device = self._cubehandle.cube.device_by_rf(self._rf_address) self._state = device.is_open
'Initialize the flic button.'
def __init__(self, hass, client, address, timeout, ignored_click_types):
import pyflic self._hass = hass self._address = address self._timeout = timeout self._is_down = False self._ignored_click_types = (ignored_click_types or []) self._hass_click_types = {pyflic.ClickType.ButtonClick: CLICK_TYPE_SINGLE, pyflic.ClickType.ButtonSingleClick: CLICK_TYPE_SINGLE, pyfl...
'Create a new connection channel to the button.'
def _create_channel(self):
import pyflic channel = pyflic.ButtonConnectionChannel(self._address) channel.on_button_up_or_down = self._on_up_down if (set(self._ignored_click_types) == set(CLICK_TYPES)): return channel if (CLICK_TYPE_DOUBLE in self._ignored_click_types): channel.on_button_click_or_hold = self._o...
'Return the name of the device.'
@property def name(self):
return 'flic_{}'.format(self.address.replace(':', ''))
'Return the bluetooth address of the device.'
@property def address(self):
return self._address
'Return true if sensor is on.'
@property def is_on(self):
return self._is_down
'No polling needed.'
@property def should_poll(self):
return False
'Return device specific state attributes.'
@property def device_state_attributes(self):
return {'address': self.address}
'Generate a log message and returns true if timeout exceeded.'
def _queued_event_check(self, click_type, time_diff):
time_string = '{:d} {}'.format(time_diff, ('second' if (time_diff == 1) else 'seconds')) if (time_diff > self._timeout): _LOGGER.warning('Queued %s dropped for %s. Time in queue was %s', click_type, self.address, time_string) return True _LOGGER.info('Queued ...
'Update device state, if event was not queued.'
def _on_up_down(self, channel, click_type, was_queued, time_diff):
import pyflic if (was_queued and self._queued_event_check(click_type, time_diff)): return self._is_down = (click_type == pyflic.ClickType.ButtonDown) self.schedule_update_ha_state()
'Fire click event, if event was not queued.'
def _on_click(self, channel, click_type, was_queued, time_diff):
if (was_queued and self._queued_event_check(click_type, time_diff)): return hass_click_type = self._hass_click_types[click_type] if (hass_click_type in self._ignored_click_types): return self._hass.bus.fire(EVENT_NAME, {EVENT_DATA_NAME: self.name, EVENT_DATA_ADDRESS: self.address, EVENT_...
'Remove device, if button disconnects.'
def _connection_status_changed(self, channel, connection_status, disconnect_reason):
import pyflic if (connection_status == pyflic.ConnectionStatus.Disconnected): _LOGGER.info('Button (%s) disconnected. Reason: %s', self.address, disconnect_reason) self.remove()
'Initialize a sensor for Ring device.'
def __init__(self, hass, data, sensor_type):
super(RingBinarySensor, self).__init__() self._sensor_type = sensor_type self._data = data self._name = '{0} {1}'.format(self._data.name, SENSOR_TYPES.get(self._sensor_type)[0]) self._device_class = SENSOR_TYPES.get(self._sensor_type)[2] self._state = None
'Return the name of the sensor.'
@property def name(self):
return self._name
'Return True if the binary sensor is on.'
@property def is_on(self):
return self._state
'Return the class of the binary sensor.'
@property def device_class(self):
return self._device_class
'Return the state attributes.'
@property def device_state_attributes(self):
attrs = {} attrs[ATTR_ATTRIBUTION] = CONF_ATTRIBUTION attrs['device_id'] = self._data.id attrs['firmware'] = self._data.firmware attrs['timezone'] = self._data.timezone if (self._data.alert and self._data.alert_expires_at): attrs['expires_at'] = self._data.alert_expires_at attrs[...
'Get the latest data and updates the state.'
def update(self):
self._data.check_alerts() if self._data.alert: self._state = (self._sensor_type == self._data.alert.get('kind')) else: self._state = False
'Initialize the XiaomiSmokeSensor.'
def __init__(self, device, name, xiaomi_hub, data_key, device_class):
self._data_key = data_key self._device_class = device_class self._should_poll = False self._density = 0 XiaomiDevice.__init__(self, device, name, xiaomi_hub)
'Return True if entity has to be polled for state.'
@property def should_poll(self):
return self._should_poll
'Return true if sensor is on.'
@property def is_on(self):
return self._state
'Return the class of binary sensor.'
@property def device_class(self):
return self._device_class
'Update the sensor state.'
def update(self):
_LOGGER.debug('Updating xiaomi sensor by polling') self._get_from_hub(self._sid)
'Initialize the XiaomiSmokeSensor.'
def __init__(self, device, xiaomi_hub):
self._density = None XiaomiBinarySensor.__init__(self, device, 'Natgas Sensor', xiaomi_hub, 'alarm', 'gas')
'Return the state attributes.'
@property def device_state_attributes(self):
attrs = {ATTR_DENSITY: self._density} attrs.update(super().device_state_attributes) return attrs
'Parse data sent by gateway.'
def parse_data(self, data):
if (DENSITY in data): self._density = int(data.get(DENSITY)) value = data.get(self._data_key) if (value is None): return False if (value == '1'): if self._state: return False self._state = True return True elif (value == '0'): if self._stat...
'Initialize the XiaomiMotionSensor.'
def __init__(self, device, hass, xiaomi_hub):
self._hass = hass self._no_motion_since = 0 XiaomiBinarySensor.__init__(self, device, 'Motion Sensor', xiaomi_hub, 'status', 'motion')
'Return the state attributes.'
@property def device_state_attributes(self):
attrs = {ATTR_NO_MOTION_SINCE: self._no_motion_since} attrs.update(super().device_state_attributes) return attrs
'Parse data sent by gateway.'
def parse_data(self, data):
self._should_poll = False if (NO_MOTION in data): self._no_motion_since = data[NO_MOTION] self._state = False return True value = data.get(self._data_key) if (value is None): return False if (value == MOTION): self._should_poll = True if (self.entity_i...
'Initialize the XiaomiDoorSensor.'
def __init__(self, device, xiaomi_hub):
self._open_since = 0 XiaomiBinarySensor.__init__(self, device, 'Door Window Sensor', xiaomi_hub, 'status', 'opening')
'Return the state attributes.'
@property def device_state_attributes(self):
attrs = {ATTR_OPEN_SINCE: self._open_since} attrs.update(super().device_state_attributes) return attrs
'Parse data sent by gateway.'
def parse_data(self, data):
self._should_poll = False if (NO_CLOSE in data): self._open_since = data[NO_CLOSE] return True value = data.get(self._data_key) if (value is None): return False if (value == 'open'): self._should_poll = True if self._state: return False sel...
'Initialize the XiaomiSmokeSensor.'
def __init__(self, device, xiaomi_hub):
self._density = 0 XiaomiBinarySensor.__init__(self, device, 'Smoke Sensor', xiaomi_hub, 'alarm', 'smoke')
'Return the state attributes.'
@property def device_state_attributes(self):
attrs = {ATTR_DENSITY: self._density} attrs.update(super().device_state_attributes) return attrs
'Parse data sent by gateway.'
def parse_data(self, data):
if (DENSITY in data): self._density = int(data.get(DENSITY)) value = data.get(self._data_key) if (value is None): return False if (value == '1'): if self._state: return False self._state = True return True elif (value == '0'): if self._stat...
'Initialize the XiaomiButton.'
def __init__(self, device, name, data_key, hass, xiaomi_hub):
self._hass = hass XiaomiBinarySensor.__init__(self, device, name, xiaomi_hub, data_key, None)
'Parse data sent by gateway.'
def parse_data(self, data):
value = data.get(self._data_key) if (value is None): return False if (value == 'long_click_press'): self._state = True click_type = 'long_click_press' elif (value == 'long_click_release'): self._state = False click_type = 'hold' elif (value == 'click'): ...
'Initialize the Xiaomi Cube.'
def __init__(self, device, hass, xiaomi_hub):
self._hass = hass self._state = False XiaomiBinarySensor.__init__(self, device, 'Cube', xiaomi_hub, None, None)
'Parse data sent by gateway.'
def parse_data(self, data):
if ('status' in data): self._hass.bus.fire('cube_action', {'entity_id': self.entity_id, 'action_type': data['status']}) if ('rotate' in data): self._hass.bus.fire('cube_action', {'entity_id': self.entity_id, 'action_type': 'rotate', 'action_value': float(data['rotate'].replace(',', '.'))}) r...
'Initialize the demo sensor.'
def __init__(self, name, state, device_class):
self._name = name self._state = state self._sensor_type = device_class
'Return the class of this sensor.'
@property def device_class(self):
return self._sensor_type
'No polling needed for a demo binary sensor.'
@property def should_poll(self):
return False
'Return the name of the binary sensor.'
@property def name(self):
return self._name
'Return true if the binary sensor is on.'
@property def is_on(self):
return self._state
'Initialize the sensor.'
def __init__(self, aurora_data, name):
self.aurora_data = aurora_data self._name = name
'Return the name of the sensor.'
@property def name(self):
return '{}'.format(self._name)
'Return true if aurora is visible.'
@property def is_on(self):
return (self.aurora_data.is_visible if self.aurora_data else False)
'Return the class of this device.'
@property def device_class(self):
return DEFAULT_DEVICE_CLASS
'Return the state attributes.'
@property def device_state_attributes(self):
attrs = {} if self.aurora_data: attrs['visibility_level'] = self.aurora_data.visibility_level attrs['message'] = self.aurora_data.is_visible_text return attrs
'Get the latest data from Aurora API and updates the states.'
def update(self):
self.aurora_data.update()