Fix PEP257 issues
This commit is contained in:
parent
f6bc1a4575
commit
7035af6634
15 changed files with 75 additions and 64 deletions
|
@ -1,6 +1,5 @@
|
||||||
"""
|
"""
|
||||||
Component to interface with binary sensors (sensors which only know two states)
|
Component to interface with binary sensors.
|
||||||
that can be monitored.
|
|
||||||
|
|
||||||
For more details about this component, please refer to the documentation at
|
For more details about this component, please refer to the documentation at
|
||||||
https://home-assistant.io/components/binary_sensor/
|
https://home-assistant.io/components/binary_sensor/
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
"""
|
"""
|
||||||
Provides a binary sensor to track online status of a UPS.
|
Support for tracking the online status of a UPS.
|
||||||
|
|
||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/binary_sensor.apcupsd/
|
https://home-assistant.io/components/binary_sensor.apcupsd/
|
||||||
|
@ -17,8 +17,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class OnlineStatus(BinarySensorDevice):
|
class OnlineStatus(BinarySensorDevice):
|
||||||
"""Binary sensor to represent UPS online status."""
|
"""Represent UPS online status."""
|
||||||
|
|
||||||
def __init__(self, config, data):
|
def __init__(self, config, data):
|
||||||
|
"""Initialize the APCUPSd device."""
|
||||||
self._config = config
|
self._config = config
|
||||||
self._data = data
|
self._data = data
|
||||||
self._state = None
|
self._state = None
|
||||||
|
@ -26,17 +28,14 @@ class OnlineStatus(BinarySensorDevice):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
""" The name of the UPS online status sensor. """
|
"""Return the name of the UPS online status sensor."""
|
||||||
return self._config.get("name", DEFAULT_NAME)
|
return self._config.get("name", DEFAULT_NAME)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""True if the UPS is online, else False."""
|
"""Return true if the UPS is online, else false."""
|
||||||
return self._state == apcupsd.VALUE_ONLINE
|
return self._state == apcupsd.VALUE_ONLINE
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""
|
"""Get the status report from APCUPSd and set this entity's state."""
|
||||||
Get the status report from APCUPSd (or cache) and set this entity's
|
|
||||||
state.
|
|
||||||
"""
|
|
||||||
self._state = self._data.status[apcupsd.KEY_STATUS]
|
self._state = self._data.status[apcupsd.KEY_STATUS]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
"""
|
"""
|
||||||
The arest sensor will consume an exposed aREST API of a device.
|
Support for exposed aREST RESTful API of a device.
|
||||||
|
|
||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/binary_sensor.arest/
|
https://home-assistant.io/components/binary_sensor.arest/
|
||||||
|
@ -22,7 +22,7 @@ CONF_PIN = 'pin'
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Get the aREST binary sensor."""
|
"""Setup the aREST binary sensor."""
|
||||||
resource = config.get(CONF_RESOURCE)
|
resource = config.get(CONF_RESOURCE)
|
||||||
pin = config.get(CONF_PIN)
|
pin = config.get(CONF_PIN)
|
||||||
|
|
||||||
|
@ -53,9 +53,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
# pylint: disable=too-many-instance-attributes, too-many-arguments
|
# pylint: disable=too-many-instance-attributes, too-many-arguments
|
||||||
class ArestBinarySensor(BinarySensorDevice):
|
class ArestBinarySensor(BinarySensorDevice):
|
||||||
"""Implements an aREST binary sensor for a pin."""
|
"""Implement an aREST binary sensor for a pin."""
|
||||||
|
|
||||||
def __init__(self, arest, resource, name, pin):
|
def __init__(self, arest, resource, name, pin):
|
||||||
|
"""Initialize the aREST device."""
|
||||||
self.arest = arest
|
self.arest = arest
|
||||||
self._resource = resource
|
self._resource = resource
|
||||||
self._name = name
|
self._name = name
|
||||||
|
@ -70,30 +71,32 @@ class ArestBinarySensor(BinarySensorDevice):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""The name of the binary sensor."""
|
"""Return the name of the binary sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""True if the binary sensor is on."""
|
"""Return true if the binary sensor is on."""
|
||||||
return bool(self.arest.data.get('state'))
|
return bool(self.arest.data.get('state'))
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data from aREST API."""
|
"""Get the latest data from aREST API."""
|
||||||
self.arest.update()
|
self.arest.update()
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
class ArestData(object):
|
class ArestData(object):
|
||||||
"""Class for handling the data retrieval for pins."""
|
"""Class for handling the data retrieval for pins."""
|
||||||
|
|
||||||
def __init__(self, resource, pin):
|
def __init__(self, resource, pin):
|
||||||
|
"""Initialize the aREST data object."""
|
||||||
self._resource = resource
|
self._resource = resource
|
||||||
self._pin = pin
|
self._pin = pin
|
||||||
self.data = {}
|
self.data = {}
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data from aREST device."""
|
"""Get the latest data from aREST device."""
|
||||||
try:
|
try:
|
||||||
response = requests.get('{}/digital/{}'.format(
|
response = requests.get('{}/digital/{}'.format(
|
||||||
self._resource, self._pin), timeout=10)
|
self._resource, self._pin), timeout=10)
|
||||||
|
|
|
@ -35,7 +35,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class BloomSkySensor(BinarySensorDevice):
|
class BloomSkySensor(BinarySensorDevice):
|
||||||
""" Represents a single binary sensor in a BloomSky device. """
|
"""Represent a single binary sensor in a BloomSky device."""
|
||||||
|
|
||||||
def __init__(self, bs, device, sensor_name):
|
def __init__(self, bs, device, sensor_name):
|
||||||
"""Initialize a BloomSky binary sensor."""
|
"""Initialize a BloomSky binary sensor."""
|
||||||
|
@ -53,7 +53,7 @@ class BloomSkySensor(BinarySensorDevice):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Unique ID for this sensor."""
|
"""Return the unique ID for this sensor."""
|
||||||
return self._unique_id
|
return self._unique_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -63,7 +63,7 @@ class BloomSkySensor(BinarySensorDevice):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""If binary sensor is on."""
|
"""Return true if binary sensor is on."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"""
|
"""
|
||||||
Allows to configure custom shell commands to turn a value into a logical value
|
Support for custom shell commands to to retrieve values.
|
||||||
for a binary sensor.
|
|
||||||
|
|
||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/binary_sensor.command/
|
https://home-assistant.io/components/binary_sensor.command/
|
||||||
|
@ -25,7 +24,7 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Add the Command Sensor."""
|
"""Setup the Command Sensor."""
|
||||||
if config.get('command') is None:
|
if config.get('command') is None:
|
||||||
_LOGGER.error('Missing required variable: "command"')
|
_LOGGER.error('Missing required variable: "command"')
|
||||||
return False
|
return False
|
||||||
|
@ -44,11 +43,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments
|
||||||
class CommandBinarySensor(BinarySensorDevice):
|
class CommandBinarySensor(BinarySensorDevice):
|
||||||
"""
|
"""Represent a command line binary sensor."""
|
||||||
Represents a binary sensor that is returning a value of a shell commands.
|
|
||||||
"""
|
|
||||||
def __init__(self, hass, data, name, payload_on,
|
def __init__(self, hass, data, name, payload_on,
|
||||||
payload_off, value_template):
|
payload_off, value_template):
|
||||||
|
"""Initialize the Command line binary sensor."""
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
self.data = data
|
self.data = data
|
||||||
self._name = name
|
self._name = name
|
||||||
|
@ -60,16 +58,16 @@ class CommandBinarySensor(BinarySensorDevice):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""The name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""True if the binary sensor is on."""
|
"""Return true if the binary sensor is on."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Gets the latest data and updates the state."""
|
"""Get the latest data and updates the state."""
|
||||||
self.data.update()
|
self.data.update()
|
||||||
value = self.data.value
|
value = self.data.value
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
class DemoBinarySensor(BinarySensorDevice):
|
class DemoBinarySensor(BinarySensorDevice):
|
||||||
"""A Demo binary sensor."""
|
"""A Demo binary sensor."""
|
||||||
|
|
||||||
def __init__(self, name, state, sensor_class):
|
def __init__(self, name, state, sensor_class):
|
||||||
|
"""Initialize the demo sensor."""
|
||||||
self._name = name
|
self._name = name
|
||||||
self._state = state
|
self._state = state
|
||||||
self._sensor_type = sensor_class
|
self._sensor_type = sensor_class
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
"""
|
"""
|
||||||
Allows to configure a MQTT binary sensor.
|
Support for MQTT binary sensors.
|
||||||
|
|
||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/binary_sensor.mqtt/
|
https://home-assistant.io/components/binary_sensor.mqtt/
|
||||||
|
@ -24,7 +24,6 @@ DEPENDENCIES = ['mqtt']
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Add MQTT binary sensor."""
|
"""Add MQTT binary sensor."""
|
||||||
|
|
||||||
if config.get('state_topic') is None:
|
if config.get('state_topic') is None:
|
||||||
_LOGGER.error('Missing required variable: state_topic')
|
_LOGGER.error('Missing required variable: state_topic')
|
||||||
return False
|
return False
|
||||||
|
@ -41,9 +40,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
||||||
class MqttBinarySensor(BinarySensorDevice):
|
class MqttBinarySensor(BinarySensorDevice):
|
||||||
"""Represents a binary sensor that is updated by MQTT."""
|
"""Represent a binary sensor that is updated by MQTT."""
|
||||||
|
|
||||||
def __init__(self, hass, name, state_topic, qos, payload_on, payload_off,
|
def __init__(self, hass, name, state_topic, qos, payload_on, payload_off,
|
||||||
value_template):
|
value_template):
|
||||||
|
"""Initialize the MQTT binary sensor."""
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
self._name = name
|
self._name = name
|
||||||
self._state = False
|
self._state = False
|
||||||
|
@ -73,10 +74,10 @@ class MqttBinarySensor(BinarySensorDevice):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""The name of the binary sensor."""
|
"""Return the name of the binary sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""True if the binary sensor is on."""
|
"""Return true if the binary sensor is on."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
|
@ -26,7 +26,6 @@ BINARY_TYPES = ['fan',
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup Nest binary sensors."""
|
"""Setup Nest binary sensors."""
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
try:
|
try:
|
||||||
for structure in nest.NEST.structures:
|
for structure in nest.NEST.structures:
|
||||||
|
|
|
@ -66,6 +66,7 @@ class NX584ZoneSensor(BinarySensorDevice):
|
||||||
"""Represents a NX584 zone as a sensor."""
|
"""Represents a NX584 zone as a sensor."""
|
||||||
|
|
||||||
def __init__(self, zone, zone_type):
|
def __init__(self, zone, zone_type):
|
||||||
|
"""Initialize the nx594 binary sensor."""
|
||||||
self._zone = zone
|
self._zone = zone
|
||||||
self._zone_type = zone_type
|
self._zone_type = zone_type
|
||||||
|
|
||||||
|
@ -81,7 +82,7 @@ class NX584ZoneSensor(BinarySensorDevice):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Name of the binary sensor."""
|
"""Return the name of the binary sensor."""
|
||||||
return self._zone['name']
|
return self._zone['name']
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -95,6 +96,7 @@ class NX584Watcher(threading.Thread):
|
||||||
"""Event listener thread to process NX584 events."""
|
"""Event listener thread to process NX584 events."""
|
||||||
|
|
||||||
def __init__(self, client, zone_sensors):
|
def __init__(self, client, zone_sensors):
|
||||||
|
"""Initialize nx584 watcher thread."""
|
||||||
super(NX584Watcher, self).__init__()
|
super(NX584Watcher, self).__init__()
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
self._client = client
|
self._client = client
|
||||||
|
@ -115,7 +117,7 @@ class NX584Watcher(threading.Thread):
|
||||||
self._process_zone_event(event)
|
self._process_zone_event(event)
|
||||||
|
|
||||||
def _run(self):
|
def _run(self):
|
||||||
# Throw away any existing events so we don't replay history
|
"""Throw away any existing events so we don't replay history."""
|
||||||
self._client.get_events()
|
self._client.get_events()
|
||||||
while True:
|
while True:
|
||||||
events = self._client.get_events()
|
events = self._client.get_events()
|
||||||
|
@ -123,6 +125,7 @@ class NX584Watcher(threading.Thread):
|
||||||
self._process_events(events)
|
self._process_events(events)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
"""Run the watcher."""
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
self._run()
|
self._run()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
"""
|
"""
|
||||||
The rest binary sensor will consume responses sent by an exposed REST API.
|
Support for RESTful binary sensors.
|
||||||
|
|
||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/binary_sensor.rest/
|
https://home-assistant.io/components/binary_sensor.rest/
|
||||||
|
@ -52,7 +52,7 @@ class RestBinarySensor(BinarySensorDevice):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Name of the binary sensor."""
|
"""Return the name of the binary sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
"""
|
"""
|
||||||
Allows to configure a binary sensor using RPi GPIO.
|
Support for binary sensor using RPi GPIO.
|
||||||
|
|
||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/binary_sensor.rpi_gpio/
|
https://home-assistant.io/components/binary_sensor.rpi_gpio/
|
||||||
|
@ -20,8 +20,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Sets up the Raspberry PI GPIO devices."""
|
"""Setup the Raspberry PI GPIO devices."""
|
||||||
|
|
||||||
pull_mode = config.get('pull_mode', DEFAULT_PULL_MODE)
|
pull_mode = config.get('pull_mode', DEFAULT_PULL_MODE)
|
||||||
bouncetime = config.get('bouncetime', DEFAULT_BOUNCETIME)
|
bouncetime = config.get('bouncetime', DEFAULT_BOUNCETIME)
|
||||||
invert_logic = config.get('invert_logic', DEFAULT_INVERT_LOGIC)
|
invert_logic = config.get('invert_logic', DEFAULT_INVERT_LOGIC)
|
||||||
|
@ -36,10 +35,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
||||||
class RPiGPIOBinarySensor(BinarySensorDevice):
|
class RPiGPIOBinarySensor(BinarySensorDevice):
|
||||||
"""Represents a binary sensor that uses Raspberry Pi GPIO."""
|
"""Represent a binary sensor that uses Raspberry Pi GPIO."""
|
||||||
def __init__(self, name, port, pull_mode, bouncetime, invert_logic):
|
|
||||||
# pylint: disable=no-member
|
|
||||||
|
|
||||||
|
def __init__(self, name, port, pull_mode, bouncetime, invert_logic):
|
||||||
|
"""Initialize the RPi binary sensor."""
|
||||||
|
# pylint: disable=no-member
|
||||||
self._name = name or DEVICE_DEFAULT_NAME
|
self._name = name or DEVICE_DEFAULT_NAME
|
||||||
self._port = port
|
self._port = port
|
||||||
self._pull_mode = pull_mode
|
self._pull_mode = pull_mode
|
||||||
|
@ -50,9 +50,10 @@ class RPiGPIOBinarySensor(BinarySensorDevice):
|
||||||
self._state = rpi_gpio.read_input(self._port)
|
self._state = rpi_gpio.read_input(self._port)
|
||||||
|
|
||||||
def read_gpio(port):
|
def read_gpio(port):
|
||||||
"""Reads state from GPIO."""
|
"""Read state from GPIO."""
|
||||||
self._state = rpi_gpio.read_input(self._port)
|
self._state = rpi_gpio.read_input(self._port)
|
||||||
self.update_ha_state()
|
self.update_ha_state()
|
||||||
|
|
||||||
rpi_gpio.edge_detect(self._port, read_gpio, self._bouncetime)
|
rpi_gpio.edge_detect(self._port, read_gpio, self._bouncetime)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -62,10 +63,10 @@ class RPiGPIOBinarySensor(BinarySensorDevice):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""The name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Returns the state of the entity."""
|
"""Return the state of the entity."""
|
||||||
return self._state != self._invert_logic
|
return self._state != self._invert_logic
|
||||||
|
|
|
@ -23,6 +23,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
|
|
||||||
class BinarySensor(BinarySensorDevice, Sensor):
|
class BinarySensor(BinarySensorDevice, Sensor):
|
||||||
"""A binary sensor which is on when its state == CONF_VALUE_ON."""
|
"""A binary sensor which is on when its state == CONF_VALUE_ON."""
|
||||||
|
|
||||||
required = (CONF_VALUE_ON,)
|
required = (CONF_VALUE_ON,)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
"""
|
"""
|
||||||
homeassistant.components.binary_sensor.template
|
Support for exposing a templated binary sensor.
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
Support for exposing a templated binary_sensor
|
For more details about this platform, please refer to the documentation at
|
||||||
|
https://home-assistant.io/components/binary_sensor.template/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -22,7 +23,6 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup template binary sensors."""
|
"""Setup template binary sensors."""
|
||||||
|
|
||||||
sensors = []
|
sensors = []
|
||||||
if config.get(CONF_SENSORS) is None:
|
if config.get(CONF_SENSORS) is None:
|
||||||
_LOGGER.error('Missing configuration data for binary_sensor platform')
|
_LOGGER.error('Missing configuration data for binary_sensor platform')
|
||||||
|
@ -70,11 +70,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class BinarySensorTemplate(BinarySensorDevice):
|
class BinarySensorTemplate(BinarySensorDevice):
|
||||||
"""A virtual binary_sensor that triggers from another sensor."""
|
"""A virtual binary sensor that triggers from another sensor."""
|
||||||
|
|
||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments
|
||||||
def __init__(self, hass, device, friendly_name, sensor_class,
|
def __init__(self, hass, device, friendly_name, sensor_class,
|
||||||
value_template):
|
value_template):
|
||||||
|
"""Initialize the Template binary sensor."""
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
self._device = device
|
self._device = device
|
||||||
self._name = friendly_name
|
self._name = friendly_name
|
||||||
|
@ -96,21 +97,26 @@ class BinarySensorTemplate(BinarySensorDevice):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
|
"""No polling needed."""
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sensor_class(self):
|
def sensor_class(self):
|
||||||
|
"""Return the sensor class of the sensor."""
|
||||||
return self._sensor_class
|
return self._sensor_class
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
|
"""Return true if sensor is on."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
"""Get the latest data and update the state."""
|
||||||
try:
|
try:
|
||||||
value = template.render(self._hass, self._template)
|
value = template.render(self._hass, self._template)
|
||||||
except TemplateError as ex:
|
except TemplateError as ex:
|
||||||
|
|
|
@ -22,7 +22,7 @@ SENSOR_TYPES = {
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Sets up the Wink platform."""
|
"""Setup the Wink platform."""
|
||||||
import pywink
|
import pywink
|
||||||
|
|
||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
|
@ -42,16 +42,17 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class WinkBinarySensorDevice(BinarySensorDevice, Entity):
|
class WinkBinarySensorDevice(BinarySensorDevice, Entity):
|
||||||
"""Represents a Wink sensor."""
|
"""Representation of a Wink sensor."""
|
||||||
|
|
||||||
def __init__(self, wink):
|
def __init__(self, wink):
|
||||||
|
"""Initialize the Wink binary sensor."""
|
||||||
self.wink = wink
|
self.wink = wink
|
||||||
self._unit_of_measurement = self.wink.UNIT
|
self._unit_of_measurement = self.wink.UNIT
|
||||||
self.capability = self.wink.capability()
|
self.capability = self.wink.capability()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return True if the binary sensor is on."""
|
"""Return true if the binary sensor is on."""
|
||||||
if self.capability == "loudness":
|
if self.capability == "loudness":
|
||||||
return self.wink.loudness_boolean()
|
return self.wink.loudness_boolean()
|
||||||
elif self.capability == "vibration":
|
elif self.capability == "vibration":
|
||||||
|
@ -68,12 +69,12 @@ class WinkBinarySensorDevice(BinarySensorDevice, Entity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
""" Returns the id of this wink sensor """
|
"""Return the ID of this wink sensor."""
|
||||||
return "{}.{}".format(self.__class__, self.wink.device_id())
|
return "{}.{}".format(self.__class__, self.wink.device_id())
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
""" Returns the name of the sensor if any. """
|
"""Return the name of the sensor if any."""
|
||||||
return self.wink.name()
|
return self.wink.name()
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
|
|
@ -19,8 +19,6 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class ZigBeeBinarySensor(ZigBeeDigitalIn, BinarySensorDevice):
|
class ZigBeeBinarySensor(ZigBeeDigitalIn, BinarySensorDevice):
|
||||||
"""
|
"""Use ZigBeeDigitalIn as binary sensor."""
|
||||||
Use multiple inheritance to turn a ZigBeeDigitalIn into a
|
|
||||||
BinarySensorDevice.
|
|
||||||
"""
|
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue