desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Return the masked device id (isolated address bits).'
@property def masked_id(self):
return self._masked_id
'Return the number of data bits.'
@property def data_bits(self):
return self._data_bits
'Return the value of the \'On\' command.'
@property def cmd_on(self):
return self._cmd_on
'Return the value of the \'Off\' command.'
@property def cmd_off(self):
return self._cmd_off
'No polling needed.'
@property def should_poll(self):
return False
'Return is the device must fire event.'
@property def should_fire_event(self):
return self._should_fire_event
'Return the sensor class.'
@property def device_class(self):
return self._device_class
'Return the off_delay attribute value.'
@property def off_delay(self):
return self._off_delay
'Return true if the sensor state is True.'
@property def is_on(self):
return self._state
'Apply a command for updating the state.'
def apply_cmd(self, cmd):
if (cmd == self.cmd_on): self.update_state(True) elif (cmd == self.cmd_off): self.update_state(False)
'Update the state of the device.'
def update_state(self, state):
self._state = state self.schedule_update_ha_state()
'Initialize the sensor.'
def __init__(self, sensor_name, sensor_index):
self._name = (sensor_name + ' Occupancy') self.sensor_name = sensor_name self.index = sensor_index self._state = None self._device_class = 'occupancy'
'Return the name of the Ecobee sensor.'
@property def name(self):
return self._name.rstrip()
'Return the status of the sensor.'
@property def is_on(self):
return (self._state == 'true')
'Return the unique ID of this sensor.'
@property def unique_id(self):
return 'binary_sensor_ecobee_{}_{}'.format(self._name, self.index)
'Return the class of this sensor, from DEVICE_CLASSES.'
@property def device_class(self):
return self._device_class
'Get the latest state of the sensor.'
def update(self):
data = ecobee.NETWORK data.update() for sensor in data.ecobee.get_remote_sensors(self.index): for item in sensor['capability']: if ((item['type'] == 'occupancy') and (self.sensor_name == sensor['name'])): self._state = item['value']
'Return true if switch is on.'
@property def is_on(self):
if (not self.available): return False return bool(self._hm_get_state())
'Return the class of this sensor from DEVICE_CLASSES.'
@property def device_class(self):
if (self._state == 'MOTION'): return 'motion' return SENSOR_TYPES_CLASS.get(self._hmdevice.__class__.__name__, None)
'Generate the data dictionary (self._data) from metadata.'
def _init_data_struct(self):
if self._state: self._data.update({self._state: STATE_UNKNOWN})
'Initialize the RPi binary sensor.'
def __init__(self, name, port, pull_mode, bouncetime, invert_logic):
self._name = (name or DEVICE_DEFAULT_NAME) self._port = port self._pull_mode = pull_mode self._bouncetime = bouncetime self._invert_logic = invert_logic self._state = None rpi_gpio.setup_input(self._port, self._pull_mode) def read_gpio(port): 'Read state from GPIO.' ...
'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)
'Update the GPIO state.'
def update(self):
self._state = rpi_gpio.read_input(self._port)
'Return True if the binary sensor is on.'
@property def is_on(self):
if (self.value_type in self._values): return (self._values[self.value_type] == STATE_ON) return False
'Return the class of this sensor, from DEVICE_CLASSES.'
@property def device_class(self):
pres = self.gateway.const.Presentation class_map = {pres.S_DOOR: 'opening', pres.S_MOTION: 'motion', pres.S_SMOKE: 'smoke'} if (float(self.gateway.protocol_version) >= 1.5): class_map.update({pres.S_SPRINKLER: 'sprinkler', pres.S_WATER_LEAK: 'leak', pres.S_SOUND: 'sound', pres.S_VIBRATION: 'vibratio...
'Initialize the sensor.'
def __init__(self, sleepiq_data, bed_id, side):
sleepiq.SleepIQSensor.__init__(self, sleepiq_data, bed_id, side) self.type = sleepiq.IS_IN_BED self._state = None self._name = sleepiq.SENSOR_TYPES[self.type] self.update()
'Return the status of the sensor.'
@property def is_on(self):
return (self._state is True)
'Return the class of this sensor.'
@property def device_class(self):
return 'occupancy'
'Get the latest data from SleepIQ and updates the states.'
def update(self):
sleepiq.SleepIQSensor.update(self) self._state = self.side.is_in_bed
'Initialize the RPi binary sensor.'
def __init__(self, hass, port, name, settle_time, invert_logic):
self._port = port self._name = (name or DEVICE_DEFAULT_NAME) self._invert_logic = invert_logic self._state = None def read_pfio(port): 'Read state from PFIO.' self._state = rpi_pfio.read_input(self._port) self.schedule_update_ha_state() rpi_pfio.edge_detect(hass,...
'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)
'Update the PFIO state.'
def update(self):
self._state = rpi_pfio.read_input(self._port)
'Initialize the nx594 binary sensor.'
def __init__(self, zone, zone_type):
self._zone = zone self._zone_type = zone_type
'Return the class of this sensor, from DEVICE_CLASSES.'
@property def device_class(self):
return self._zone_type
'No polling needed.'
@property def should_poll(self):
return False
'Return the name of the binary sensor.'
@property def name(self):
return self._zone['name']
'Return true if the binary sensor is on.'
@property def is_on(self):
return self._zone['state']
'Initialize NX584 watcher thread.'
def __init__(self, client, zone_sensors):
super(NX584Watcher, self).__init__() self.daemon = True self._client = client self._zone_sensors = zone_sensors
'Throw away any existing events so we don\'t replay history.'
def _run(self):
self._client.get_events() while True: events = self._client.get_events() if events: self._process_events(events)
'Run the watcher.'
def run(self):
while True: try: self._run() except requests.exceptions.ConnectionError: _LOGGER.error('Failed to reach NX584 server') time.sleep(10)
'Initialize the sensor.'
def __init__(self, values, device_class):
zwave.ZWaveDeviceEntity.__init__(self, values, DOMAIN) self._sensor_type = device_class self._state = self.values.primary.data
'Handle data changes for node values.'
def update_properties(self):
self._state = self.values.primary.data
'Return true if the binary sensor is on.'
@property def is_on(self):
return self._state
'Return the class of this sensor, from DEVICE_CLASSES.'
@property def device_class(self):
return self._sensor_type
'Initialize the sensor.'
def __init__(self, values, device_class):
super(ZWaveTriggerSensor, self).__init__(values, device_class) self.re_arm_sec = 60 self.invalidate_after = None
'Handle value changes for this entity\'s node.'
def update_properties(self):
self._state = self.values.primary.data _LOGGER.debug('off_delay=%s', self.values.off_delay) if self.values.off_delay: _LOGGER.debug('off_delay.data=%s', self.values.off_delay.data) self.re_arm_sec = (self.values.off_delay.data * 8) if (not self.hass): return self.invalidate_a...
'Return true if movement has happened within the rearm time.'
@property def is_on(self):
return (self._state and ((self.invalidate_after is None) or (self.invalidate_after > dt_util.utcnow())))
'Initialize the Taps Aff sensor.'
def __init__(self, taps_aff_data, name):
self.data = taps_aff_data self._name = name
'Return the name of the sensor.'
@property def name(self):
return '{}'.format(self._name)
'Return true if taps aff.'
@property def is_on(self):
return self.data.is_taps_aff
'Get the latest data.'
def update(self):
self.data.update()
'Initialize the sensor.'
def __init__(self, location):
from tapsaff import TapsAff self._is_taps_aff = None self.taps_aff = TapsAff(location)
'Return true if taps aff.'
@property def is_taps_aff(self):
return self._is_taps_aff
'Get the latest data from the Taps Aff API and updates the states.'
def update(self):
try: self._is_taps_aff = self.taps_aff.is_taps_aff except RuntimeError: _LOGGER.error('Update failed. Check configured location')
'Initialize a REST binary sensor.'
def __init__(self, hass, rest, name, device_class, value_template):
self._hass = hass self.rest = rest self._name = name self._device_class = device_class self._state = False self._previous_data = None self._value_template = value_template
'Return the name of the binary sensor.'
@property def name(self):
return self._name
'Return the class of this sensor.'
@property def device_class(self):
return self._device_class
'Return true if the binary sensor is on.'
@property def is_on(self):
if (self.rest.data is None): return False response = self.rest.data if (self._value_template is not None): response = self._value_template.async_render_with_possible_json_value(self.rest.data, False) try: return bool(int(response)) except ValueError: return {'true': T...
'Get the latest data from REST API and updates the state.'
def update(self):
self.rest.update()
'Initialize the modbus coil sensor.'
def __init__(self, name, slave, coil):
self._name = name self._slave = (int(slave) if slave else None) self._coil = int(coil) self._value = None
'Return the name of the sensor.'
@property def name(self):
return self._name
'Return the state of the sensor.'
@property def is_on(self):
return self._value
'Update the state of the sensor.'
def update(self):
result = modbus.HUB.read_coils(self._slave, self._coil, 1) try: self._value = result.bits[0] except AttributeError: _LOGGER.error('No response from modbus slave %s coil %s', self._slave, self._coil)
'Initialize a BloomSky binary sensor.'
def __init__(self, bs, device, sensor_name):
self._bloomsky = bs self._device_id = device['DeviceID'] self._sensor_name = sensor_name self._name = '{} {}'.format(device['DeviceName'], sensor_name) self._unique_id = 'bloomsky_binary_sensor {}'.format(self._name) self._state = None
'Return the name of the BloomSky device and this sensor.'
@property def name(self):
return self._name
'Return the unique ID for this sensor.'
@property def unique_id(self):
return self._unique_id
'Return the class of this sensor, from DEVICE_CLASSES.'
@property def device_class(self):
return SENSOR_TYPES.get(self._sensor_name)
'Return true if binary sensor is on.'
@property def is_on(self):
return self._state
'Request an update from the BloomSky API.'
def update(self):
self._bloomsky.refresh_devices() self._state = self._bloomsky.devices[self._device_id]['Data'][self._sensor_name]
'Return true if the binary sensor is on.'
@property def is_on(self):
return (self._state == self._config[CONF_VALUE_ON])
'Initialize the sensor.'
def __init__(self, iss_data, name, show):
self.iss_data = iss_data self._state = None self._name = name self._show_on_map = show
'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.iss_data.is_above if self.iss_data else False)
'Return the class of this sensor.'
@property def device_class(self):
return DEFAULT_DEVICE_CLASS
'Return the state attributes.'
@property def device_state_attributes(self):
if self.iss_data: attrs = {ATTR_ISS_NUMBER_PEOPLE_SPACE: self.iss_data.number_of_people_in_space, ATTR_ISS_NEXT_RISE: self.iss_data.next_rise} if self._show_on_map: attrs[ATTR_LONGITUDE] = self.iss_data.position.get('longitude') attrs[ATTR_LATITUDE] = self.iss_data.position.g...
'Get the latest data from ISS API and updates the states.'
def update(self):
self.iss_data.update()
'Initialize the data object.'
def __init__(self, latitude, longitude):
self.is_above = None self.next_rise = None self.number_of_people_in_space = None self.position = None self.latitude = latitude self.longitude = longitude
'Get the latest data from the ISS API.'
@Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self):
import pyiss try: iss = pyiss.ISS() self.is_above = iss.is_ISS_above(self.latitude, self.longitude) self.next_rise = iss.next_rise(self.latitude, self.longitude) self.number_of_people_in_space = iss.number_of_people_in_space() self.position = iss.current_location() ex...
'Initialize the EnOcean binary sensor.'
def __init__(self, dev_id, devname, device_class):
enocean.EnOceanDevice.__init__(self) self.stype = 'listener' self.dev_id = dev_id self.which = (-1) self.onoff = (-1) self.devname = devname self._device_class = device_class
'Return the default name for the binary sensor.'
@property def name(self):
return self.devname
'Return the class of this sensor.'
@property def device_class(self):
return self._device_class
'Fire an event with the data that have changed. This method is called when there is an incoming packet associated with this platform.'
def value_changed(self, value, value2):
self.schedule_update_ha_state() if (value2 == 112): self.which = 0 self.onoff = 0 elif (value2 == 80): self.which = 0 self.onoff = 1 elif (value2 == 48): self.which = 1 self.onoff = 0 elif (value2 == 16): self.which = 1 self.onoff = 1 ...
'Initialize a new Digital Ocean sensor.'
def __init__(self, do, droplet_id):
self._digital_ocean = do self._droplet_id = droplet_id self._state = None self.data = None
'Return the name of the sensor.'
@property def name(self):
return self.data.name
'Return true if the binary sensor is on.'
@property def is_on(self):
return (self.data.status == 'active')
'Return the class of this sensor.'
@property def device_class(self):
return DEFAULT_DEVICE_CLASS
'Return the state attributes of the Digital Ocean droplet.'
@property def device_state_attributes(self):
return {ATTR_CREATED_AT: self.data.created_at, ATTR_DROPLET_ID: self.data.id, ATTR_DROPLET_NAME: self.data.name, ATTR_FEATURES: self.data.features, ATTR_IPV4_ADDRESS: self.data.ip_address, ATTR_IPV6_ADDRESS: self.data.ip_v6_address, ATTR_MEMORY: self.data.memory, ATTR_REGION: self.data.region['name'], ATTR_VCPUS: s...
'Update state of sensor.'
def update(self):
self._digital_ocean.update() for droplet in self._digital_ocean.data: if (droplet.id == self._droplet_id): self.data = droplet
'Initialize the Ping Binary sensor.'
def __init__(self, name, ping):
self._name = name self.ping = ping
'Return the name of the device.'
@property def name(self):
return self._name
'Return the class of this sensor.'
@property def device_class(self):
return DEFAULT_DEVICE_CLASS
'Return true if the binary sensor is on.'
@property def is_on(self):
return self.ping.available
'Return the state attributes of the ICMP checo request.'
@property def device_state_attributes(self):
if (self.ping.data is not False): return {ATTR_ROUND_TRIP_TIME_AVG: self.ping.data['avg'], ATTR_ROUND_TRIP_TIME_MAX: self.ping.data['max'], ATTR_ROUND_TRIP_TIME_MDEV: self.ping.data['mdev'], ATTR_ROUND_TRIP_TIME_MIN: self.ping.data['min']}
'Get the latest data.'
def update(self):
self.ping.update()
'Initialize the data object.'
def __init__(self, host, count):
self._ip_address = host self._count = count self.data = {} self.available = False if (sys.platform == 'win32'): self._ping_cmd = ['ping', '-n', str(self._count), '-w', '1000', self._ip_address] else: self._ping_cmd = ['ping', '-n', '-q', '-c', str(self._count), '-W1', self._ip_ad...
'Send ICMP echo request and return details if success.'
def ping(self):
pinger = subprocess.Popen(self._ping_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) try: out = pinger.communicate() _LOGGER.debug('Output is %s', str(out)) if (sys.platform == 'win32'): match = WIN32_PING_MATCHER.search(str(out).split('\n')[(-1)]) (rtt...