Add docstrings, fix typos, and update docsstring for PEP257

This commit is contained in:
Fabian Affolter 2016-02-22 10:11:46 +01:00
parent 7a0c99a1d5
commit fd3ea95b82
15 changed files with 67 additions and 89 deletions

View File

@ -1,6 +1,4 @@
"""
homeassistant.components.binary_sensor
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Component to interface with binary sensors (sensors which only know two states)
that can be monitored.

View File

@ -1,6 +1,4 @@
"""
homeassistant.components.binary_sensor.apcupsd
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Provides a binary sensor to track online status of a UPS.
For more details about this platform, please refer to the documentation at
@ -14,12 +12,12 @@ DEFAULT_NAME = "UPS Online Status"
def setup_platform(hass, config, add_entities, discovery_info=None):
""" Instantiate an OnlineStatus binary sensor entity and add it to HA. """
"""Instantiate an OnlineStatus binary sensor entity."""
add_entities((OnlineStatus(config, apcupsd.DATA),))
class OnlineStatus(BinarySensorDevice):
""" Binary sensor to represent UPS online status. """
"""Binary sensor to represent UPS online status."""
def __init__(self, config, data):
self._config = config
self._data = data
@ -33,7 +31,7 @@ class OnlineStatus(BinarySensorDevice):
@property
def is_on(self):
""" True if the UPS is online, else False. """
"""True if the UPS is online, else False."""
return self._state == apcupsd.VALUE_ONLINE
def update(self):

View File

@ -1,6 +1,4 @@
"""
homeassistant.components.binary_sensor.arest
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The arest sensor will consume an exposed aREST API of a device.
For more details about this platform, please refer to the documentation at
@ -24,8 +22,7 @@ CONF_PIN = 'pin'
def setup_platform(hass, config, add_devices, discovery_info=None):
""" Get the aREST binary sensor. """
"""Get the aREST binary sensor."""
resource = config.get(CONF_RESOURCE)
pin = config.get(CONF_PIN)
@ -56,7 +53,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-many-instance-attributes, too-many-arguments
class ArestBinarySensor(BinarySensorDevice):
""" Implements an aREST binary sensor for a pin. """
"""Implements an aREST binary sensor for a pin."""
def __init__(self, arest, resource, name, pin):
self.arest = arest
@ -73,23 +70,22 @@ class ArestBinarySensor(BinarySensorDevice):
@property
def name(self):
""" The name of the binary sensor. """
"""The name of the binary sensor."""
return self._name
@property
def is_on(self):
""" True if the binary sensor is on. """
"""True if the binary sensor is on."""
return bool(self.arest.data.get('state'))
def update(self):
""" Gets the latest data from aREST API. """
"""Gets the latest data from aREST API."""
self.arest.update()
# pylint: disable=too-few-public-methods
class ArestData(object):
""" Class for handling the data retrieval for pins. """
"""Class for handling the data retrieval for pins."""
def __init__(self, resource, pin):
self._resource = resource
self._pin = pin
@ -97,7 +93,7 @@ class ArestData(object):
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
""" Gets the latest data from aREST device. """
"""Gets the latest data from aREST device."""
try:
response = requests.get('{}/digital/{}'.format(
self._resource, self._pin), timeout=10)

View File

@ -38,7 +38,7 @@ class BloomSkySensor(BinarySensorDevice):
""" Represents a single binary sensor in a BloomSky device. """
def __init__(self, bs, device, sensor_name):
"""Initialize a bloomsky binary sensor."""
"""Initialize a BloomSky binary sensor."""
self._bloomsky = bs
self._device_id = device["DeviceID"]
self._sensor_name = sensor_name

View File

@ -1,8 +1,6 @@
"""
homeassistant.components.binary_sensor.command_sensor
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Allows to configure custom shell commands to turn a value
into a logical value for a binary sensor.
Allows to configure custom shell commands to turn a value into a logical value
for a binary sensor.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/binary_sensor.command/
@ -27,8 +25,7 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
""" Add the Command Sensor. """
"""Add the Command Sensor."""
if config.get('command') is None:
_LOGGER.error('Missing required variable: "command"')
return False
@ -47,8 +44,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-many-arguments
class CommandBinarySensor(BinarySensorDevice):
""" Represents a binary sensor that is returning
a value of a shell commands. """
"""
Represents a binary sensor that is returning a value of a shell commands.
"""
def __init__(self, hass, data, name, payload_on,
payload_off, value_template):
self._hass = hass
@ -62,16 +60,16 @@ class CommandBinarySensor(BinarySensorDevice):
@property
def name(self):
""" The name of the sensor. """
"""The name of the sensor."""
return self._name
@property
def is_on(self):
""" True if the binary sensor is on. """
"""True if the binary sensor is on."""
return self._state
def update(self):
""" Gets the latest data and updates the state. """
"""Gets the latest data and updates the state."""
self.data.update()
value = self.data.value

View File

@ -1,13 +1,11 @@
"""
homeassistant.components.binary_sensor.demo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo platform that has two fake binary sensors.
"""
from homeassistant.components.binary_sensor import BinarySensorDevice
def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up the Demo binary sensors. """
"""Sets up the Demo binary sensors """
add_devices([
DemoBinarySensor('Basement Floor Wet', False, 'moisture'),
DemoBinarySensor('Movement Backyard', True, 'motion'),
@ -15,7 +13,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class DemoBinarySensor(BinarySensorDevice):
""" A Demo binary sensor. """
"""A Demo binary sensor."""
def __init__(self, name, state, sensor_class):
self._name = name
@ -24,20 +22,20 @@ class DemoBinarySensor(BinarySensorDevice):
@property
def sensor_class(self):
""" Return our class. """
"""Return the class of this sensor."""
return self._sensor_type
@property
def should_poll(self):
""" No polling needed for a demo binary sensor. """
"""No polling needed for a demo binary sensor."""
return False
@property
def name(self):
""" Returns the name of the binary sensor. """
"""Returns the name of the binary sensor."""
return self._name
@property
def is_on(self):
""" True if the binary sensor is on. """
"""True if the binary sensor is on."""
return self._state

View File

@ -1,6 +1,4 @@
"""
homeassistant.components.binary_sensor.mqtt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Allows to configure a MQTT binary sensor.
For more details about this platform, please refer to the documentation at
@ -25,7 +23,7 @@ DEPENDENCIES = ['mqtt']
# pylint: disable=unused-argument
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:
_LOGGER.error('Missing required variable: state_topic')
@ -43,7 +41,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-many-arguments, too-many-instance-attributes
class MqttBinarySensor(BinarySensorDevice):
""" Represents a binary sensor that is updated by MQTT. """
"""Represents a binary sensor that is updated by MQTT."""
def __init__(self, hass, name, state_topic, qos, payload_on, payload_off,
value_template):
self._hass = hass
@ -55,7 +53,7 @@ class MqttBinarySensor(BinarySensorDevice):
self._qos = qos
def message_received(topic, payload, qos):
""" A new MQTT message has been received. """
"""A new MQTT message has been received."""
if value_template is not None:
payload = template.render_with_possible_json_value(
hass, value_template, payload)
@ -70,15 +68,15 @@ class MqttBinarySensor(BinarySensorDevice):
@property
def should_poll(self):
""" No polling needed. """
"""No polling needed."""
return False
@property
def name(self):
""" The name of the binary sensor. """
"""The name of the binary sensor."""
return self._name
@property
def is_on(self):
""" True if the binary sensor is on. """
"""True if the binary sensor is on."""
return self._state

View File

@ -54,7 +54,8 @@ class MySensorsBinarySensor(BinarySensorDevice):
def __init__(
self, gateway, node_id, child_id, name, value_type, child_type):
"""Setup class attributes on instantiation.
"""
Setup class attributes on instantiation.
Args:
gateway (GatewayWrapper): Gateway object.
@ -124,7 +125,7 @@ class MySensorsBinarySensor(BinarySensorDevice):
@property
def sensor_class(self):
"""Return the class of this sensor, from SENSOR_CASSES."""
"""Return the class of this sensor, from SENSOR_CLASSES."""
pres = self.gateway.const.Presentation
class_map = {
pres.S_DOOR: 'opening',

View File

@ -1,6 +1,4 @@
"""
homeassistant.components.binary_sensor.nest
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for Nest Thermostat Binary Sensors.
For more details about this platform, please refer to the documentation at
@ -27,7 +25,7 @@ BINARY_TYPES = ['fan',
def setup_platform(hass, config, add_devices, discovery_info=None):
""" Setup Nest binary sensors. """
"""Setup Nest binary sensors."""
logger = logging.getLogger(__name__)
try:
@ -48,9 +46,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class NestBinarySensor(NestSensor, BinarySensorDevice):
""" Represents a Nest binary sensor. """
"""Represents a Nest binary sensor."""
@property
def is_on(self):
""" True if the binary sensor is on. """
"""True if the binary sensor is on."""
return bool(getattr(self.device, self.variable))

View File

@ -1,6 +1,4 @@
"""
homeassistant.components.sensor.nx584
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for exposing nx584 elements as sensors.
For more details about this platform, please refer to the documentation at
@ -73,18 +71,22 @@ class NX584ZoneSensor(BinarySensorDevice):
@property
def sensor_class(self):
"""Return the class of this sensor, from SENSOR_CLASSES."""
return self._zone_type
@property
def should_poll(self):
"""No polling needed."""
return False
@property
def name(self):
"""Name of the binary sensor."""
return self._zone['name']
@property
def is_on(self):
"""Return true if the binary sensor is on."""
# True means "faulted" or "open" or "abnormal state"
return self._zone['state']

View File

@ -1,6 +1,4 @@
"""
homeassistant.components.binary_sensor.rest
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The rest binary sensor will consume responses sent by an exposed REST API.
For more details about this platform, please refer to the documentation at
@ -21,7 +19,7 @@ DEFAULT_METHOD = 'GET'
# pylint: disable=unused-variable
def setup_platform(hass, config, add_devices, discovery_info=None):
""" Setup REST binary sensors. """
"""Setup REST binary sensors."""
resource = config.get('resource', None)
method = config.get('method', DEFAULT_METHOD)
payload = config.get('payload', None)
@ -41,10 +39,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-many-arguments
class RestBinarySensor(BinarySensorDevice):
""" A REST binary sensor. """
"""A REST binary sensor."""
def __init__(self, hass, rest, name, value_template):
""" Initialize a REST binary sensor. """
"""Initialize a REST binary sensor."""
self._hass = hass
self.rest = rest
self._name = name
@ -54,12 +52,12 @@ class RestBinarySensor(BinarySensorDevice):
@property
def name(self):
""" Name of the binary sensor. """
"""Name of the binary sensor."""
return self._name
@property
def is_on(self):
""" Return if the binary sensor is on. """
"""Return true if the binary sensor is on."""
if self.rest.data is None:
return False
@ -69,5 +67,5 @@ class RestBinarySensor(BinarySensorDevice):
return bool(int(self.rest.data))
def update(self):
""" Get the latest data from REST API and updates the state. """
"""Get the latest data from REST API and updates the state."""
self.rest.update()

View File

@ -1,12 +1,9 @@
"""
homeassistant.components.binary_sensor.rpi_gpio
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Allows to configure a binary sensor using RPi GPIO.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/binary_sensor.rpi_gpio/
"""
import logging
import homeassistant.components.rpi_gpio as rpi_gpio
@ -23,7 +20,7 @@ _LOGGER = logging.getLogger(__name__)
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up the Raspberry PI GPIO devices. """
"""Sets up the Raspberry PI GPIO devices."""
pull_mode = config.get('pull_mode', DEFAULT_PULL_MODE)
bouncetime = config.get('bouncetime', DEFAULT_BOUNCETIME)
@ -39,7 +36,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-many-arguments, too-many-instance-attributes
class RPiGPIOBinarySensor(BinarySensorDevice):
""" Represents a binary sensor that uses Raspberry Pi GPIO. """
"""Represents a binary sensor that uses Raspberry Pi GPIO."""
def __init__(self, name, port, pull_mode, bouncetime, invert_logic):
# pylint: disable=no-member
@ -53,22 +50,22 @@ class RPiGPIOBinarySensor(BinarySensorDevice):
self._state = rpi_gpio.read_input(self._port)
def read_gpio(port):
""" Reads state from GPIO. """
"""Reads state from GPIO."""
self._state = rpi_gpio.read_input(self._port)
self.update_ha_state()
rpi_gpio.edge_detect(self._port, read_gpio, self._bouncetime)
@property
def should_poll(self):
""" No polling needed. """
"""No polling needed."""
return False
@property
def name(self):
""" The name of the sensor. """
"""The name of the sensor."""
return self._name
@property
def is_on(self):
""" Returns the state of the entity. """
"""Returns the state of the entity."""
return self._state != self._invert_logic

View File

@ -1,30 +1,31 @@
"""
homeassistant.components.binary_sensor.tcp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Provides a binary_sensor which gets its values from a TCP socket.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/binary_sensor.tcp/
"""
import logging
from homeassistant.components.binary_sensor import BinarySensorDevice
from homeassistant.components.sensor.tcp import Sensor, DOMAIN, CONF_VALUE_ON
DEPENDENCIES = [DOMAIN]
_LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_entities, discovery_info=None):
""" Create the BinarySensor. """
"""Create the binary sensor."""
if not BinarySensor.validate_config(config):
return False
add_entities((BinarySensor(hass, config),))
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,)
@property
def is_on(self):
"""True if the binary sensor is on."""
return self._state == self._config[CONF_VALUE_ON]

View File

@ -1,6 +1,4 @@
"""
homeassistant.components.binary_sensor.zigbee
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Contains functionality to use a ZigBee device as a binary sensor.
For more details about this platform, please refer to the documentation at
@ -14,7 +12,7 @@ DEPENDENCIES = ["zigbee"]
def setup_platform(hass, config, add_entities, discovery_info=None):
""" Create and add an entity based on the configuration. """
"""Create and add an entity based on the configuration."""
add_entities([
ZigBeeBinarySensor(hass, ZigBeeDigitalInConfig(config))
])

View File

@ -1,13 +1,9 @@
"""
homeassistant.components.binary_sensor.zwave
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Interfaces with Z-Wave sensors.
For more details about this platform, please refer to the documentation
at https://home-assistant.io/components/zwave/
https://home-assistant.io/components/binary_sensor.zwave/
"""
import logging
from homeassistant.components.zwave import (
@ -23,7 +19,7 @@ DEPENDENCIES = []
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the mysensors platform for sensors."""
"""Setup the Z-Wave platform for sensors."""
if discovery_info is None or NETWORK is None:
return
@ -37,7 +33,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class ZWaveBinarySensor(BinarySensorDevice, ZWaveDeviceEntity):
""" Represents a binary sensor within Z-Wave. """
"""Represents a binary sensor within Z-Wave."""
def __init__(self, value, sensor_class):
self._sensor_type = sensor_class
@ -62,9 +58,10 @@ class ZWaveBinarySensor(BinarySensorDevice, ZWaveDeviceEntity):
@property
def should_poll(self):
"""No polling needed."""
return False
def value_changed(self, value):
""" Called when a value has changed on the network. """
"""Called when a value has changed on the network."""
if self._value.value_id == value.value_id:
self.update_ha_state()