Fix PEP257 issues

This commit is contained in:
Fabian Affolter 2016-03-07 20:21:08 +01:00
parent f6bc1a4575
commit 7035af6634
15 changed files with 75 additions and 64 deletions

View file

@ -1,6 +1,5 @@
"""
Component to interface with binary sensors (sensors which only know two states)
that can be monitored.
Component to interface with binary sensors.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/binary_sensor/

View file

@ -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
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):
"""Binary sensor to represent UPS online status."""
"""Represent UPS online status."""
def __init__(self, config, data):
"""Initialize the APCUPSd device."""
self._config = config
self._data = data
self._state = None
@ -26,17 +28,14 @@ class OnlineStatus(BinarySensorDevice):
@property
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)
@property
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
def update(self):
"""
Get the status report from APCUPSd (or cache) and set this entity's
state.
"""
"""Get the status report from APCUPSd and set this entity's state."""
self._state = self._data.status[apcupsd.KEY_STATUS]

View file

@ -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
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):
"""Get the aREST binary sensor."""
"""Setup the aREST binary sensor."""
resource = config.get(CONF_RESOURCE)
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
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):
"""Initialize the aREST device."""
self.arest = arest
self._resource = resource
self._name = name
@ -70,30 +71,32 @@ class ArestBinarySensor(BinarySensorDevice):
@property
def name(self):
"""The name of the binary sensor."""
"""Return the name of the binary sensor."""
return self._name
@property
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'))
def update(self):
"""Gets the latest data from aREST API."""
"""Get 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."""
def __init__(self, resource, pin):
"""Initialize the aREST data object."""
self._resource = resource
self._pin = pin
self.data = {}
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
"""Gets the latest data from aREST device."""
"""Get the latest data from aREST device."""
try:
response = requests.get('{}/digital/{}'.format(
self._resource, self._pin), timeout=10)

View file

@ -35,7 +35,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
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):
"""Initialize a BloomSky binary sensor."""
@ -53,7 +53,7 @@ class BloomSkySensor(BinarySensorDevice):
@property
def unique_id(self):
"""Unique ID for this sensor."""
"""Return the unique ID for this sensor."""
return self._unique_id
@property
@ -63,7 +63,7 @@ class BloomSkySensor(BinarySensorDevice):
@property
def is_on(self):
"""If binary sensor is on."""
"""Return true if binary sensor is on."""
return self._state
def update(self):

View file

@ -1,6 +1,5 @@
"""
Allows to configure custom shell commands to turn a value into a logical value
for a binary sensor.
Support for custom shell commands to to retrieve values.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/binary_sensor.command/
@ -25,7 +24,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."""
"""Setup the Command Sensor."""
if config.get('command') is None:
_LOGGER.error('Missing required variable: "command"')
return False
@ -44,11 +43,10 @@ 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.
"""
"""Represent a command line binary sensor."""
def __init__(self, hass, data, name, payload_on,
payload_off, value_template):
"""Initialize the Command line binary sensor."""
self._hass = hass
self.data = data
self._name = name
@ -60,16 +58,16 @@ class CommandBinarySensor(BinarySensorDevice):
@property
def name(self):
"""The name of the sensor."""
"""Return the name of the sensor."""
return self._name
@property
def is_on(self):
"""True if the binary sensor is on."""
"""Return true if the binary sensor is on."""
return self._state
def update(self):
"""Gets the latest data and updates the state."""
"""Get the latest data and updates the state."""
self.data.update()
value = self.data.value

View file

@ -17,7 +17,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class DemoBinarySensor(BinarySensorDevice):
"""A Demo binary sensor."""
def __init__(self, name, state, sensor_class):
"""Initialize the demo sensor."""
self._name = name
self._state = state
self._sensor_type = sensor_class

View file

@ -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
https://home-assistant.io/components/binary_sensor.mqtt/
@ -24,7 +24,6 @@ DEPENDENCIES = ['mqtt']
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Add MQTT binary sensor."""
if config.get('state_topic') is None:
_LOGGER.error('Missing required variable: state_topic')
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
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,
value_template):
"""Initialize the MQTT binary sensor."""
self._hass = hass
self._name = name
self._state = False
@ -73,10 +74,10 @@ class MqttBinarySensor(BinarySensorDevice):
@property
def name(self):
"""The name of the binary sensor."""
"""Return the name of the binary sensor."""
return self._name
@property
def is_on(self):
"""True if the binary sensor is on."""
"""Return true if the binary sensor is on."""
return self._state

View file

@ -26,7 +26,6 @@ BINARY_TYPES = ['fan',
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup Nest binary sensors."""
logger = logging.getLogger(__name__)
try:
for structure in nest.NEST.structures:

View file

@ -66,6 +66,7 @@ class NX584ZoneSensor(BinarySensorDevice):
"""Represents a NX584 zone as a sensor."""
def __init__(self, zone, zone_type):
"""Initialize the nx594 binary sensor."""
self._zone = zone
self._zone_type = zone_type
@ -81,7 +82,7 @@ class NX584ZoneSensor(BinarySensorDevice):
@property
def name(self):
"""Name of the binary sensor."""
"""Return the name of the binary sensor."""
return self._zone['name']
@property
@ -95,6 +96,7 @@ class NX584Watcher(threading.Thread):
"""Event listener thread to process NX584 events."""
def __init__(self, client, zone_sensors):
"""Initialize nx584 watcher thread."""
super(NX584Watcher, self).__init__()
self.daemon = True
self._client = client
@ -115,7 +117,7 @@ class NX584Watcher(threading.Thread):
self._process_zone_event(event)
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()
while True:
events = self._client.get_events()
@ -123,6 +125,7 @@ class NX584Watcher(threading.Thread):
self._process_events(events)
def run(self):
"""Run the watcher."""
while True:
try:
self._run()

View file

@ -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
https://home-assistant.io/components/binary_sensor.rest/
@ -52,7 +52,7 @@ class RestBinarySensor(BinarySensorDevice):
@property
def name(self):
"""Name of the binary sensor."""
"""Return the name of the binary sensor."""
return self._name
@property

View file

@ -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
https://home-assistant.io/components/binary_sensor.rpi_gpio/
@ -20,8 +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."""
"""Setup the Raspberry PI GPIO devices."""
pull_mode = config.get('pull_mode', DEFAULT_PULL_MODE)
bouncetime = config.get('bouncetime', DEFAULT_BOUNCETIME)
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
class RPiGPIOBinarySensor(BinarySensorDevice):
"""Represents a binary sensor that uses Raspberry Pi GPIO."""
def __init__(self, name, port, pull_mode, bouncetime, invert_logic):
# pylint: disable=no-member
"""Represent a binary sensor that uses Raspberry Pi GPIO."""
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._port = port
self._pull_mode = pull_mode
@ -50,9 +50,10 @@ class RPiGPIOBinarySensor(BinarySensorDevice):
self._state = rpi_gpio.read_input(self._port)
def read_gpio(port):
"""Reads state from GPIO."""
"""Read 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
@ -62,10 +63,10 @@ class RPiGPIOBinarySensor(BinarySensorDevice):
@property
def name(self):
"""The name of the sensor."""
"""Return the name of the sensor."""
return self._name
@property
def is_on(self):
"""Returns the state of the entity."""
"""Return the state of the entity."""
return self._state != self._invert_logic

View file

@ -23,6 +23,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
class BinarySensor(BinarySensorDevice, Sensor):
"""A binary sensor which is on when its state == CONF_VALUE_ON."""
required = (CONF_VALUE_ON,)
@property

View file

@ -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
@ -22,7 +23,6 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup template binary sensors."""
sensors = []
if config.get(CONF_SENSORS) is None:
_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):
"""A virtual binary_sensor that triggers from another sensor."""
"""A virtual binary sensor that triggers from another sensor."""
# pylint: disable=too-many-arguments
def __init__(self, hass, device, friendly_name, sensor_class,
value_template):
"""Initialize the Template binary sensor."""
self._hass = hass
self._device = device
self._name = friendly_name
@ -96,21 +97,26 @@ class BinarySensorTemplate(BinarySensorDevice):
@property
def should_poll(self):
"""No polling needed."""
return False
@property
def sensor_class(self):
"""Return the sensor class of the sensor."""
return self._sensor_class
@property
def name(self):
"""Return the name of the sensor."""
return self._name
@property
def is_on(self):
"""Return true if sensor is on."""
return self._state
def update(self):
"""Get the latest data and update the state."""
try:
value = template.render(self._hass, self._template)
except TemplateError as ex:

View file

@ -22,7 +22,7 @@ SENSOR_TYPES = {
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Sets up the Wink platform."""
"""Setup the Wink platform."""
import pywink
if discovery_info is None:
@ -42,16 +42,17 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class WinkBinarySensorDevice(BinarySensorDevice, Entity):
"""Represents a Wink sensor."""
"""Representation of a Wink sensor."""
def __init__(self, wink):
"""Initialize the Wink binary sensor."""
self.wink = wink
self._unit_of_measurement = self.wink.UNIT
self.capability = self.wink.capability()
@property
def is_on(self):
"""Return True if the binary sensor is on."""
"""Return true if the binary sensor is on."""
if self.capability == "loudness":
return self.wink.loudness_boolean()
elif self.capability == "vibration":
@ -68,12 +69,12 @@ class WinkBinarySensorDevice(BinarySensorDevice, Entity):
@property
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())
@property
def name(self):
""" Returns the name of the sensor if any. """
"""Return the name of the sensor if any."""
return self.wink.name()
def update(self):

View file

@ -19,8 +19,6 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
class ZigBeeBinarySensor(ZigBeeDigitalIn, BinarySensorDevice):
"""
Use multiple inheritance to turn a ZigBeeDigitalIn into a
BinarySensorDevice.
"""
"""Use ZigBeeDigitalIn as binary sensor."""
pass