Fix PEEP257 issues

This commit is contained in:
Fabian Affolter committed 2016-03-08 17:55:57 +01:00
1 parent d784610c52
commit b534244e40
42 files changed
+335 -308

No files matched your search

+54 -56
View File
@@ -34,10 +34,7 @@ _LOGGER = logging.getLogger(__name__)
def setup(hass, config):
"""
Set up the connection to the ZigBee device and instantiate the helper
class for it.
"""
"""Setup the connection to the ZigBee device."""
global DEVICE
global GPIO_DIGITAL_OUTPUT_LOW
global GPIO_DIGITAL_OUTPUT_HIGH
@@ -69,27 +66,27 @@ def setup(hass, config):
def close_serial_port(*args):
""" Close the serial port we're using to communicate with the ZigBee. """
"""Close the serial port we're using to communicate with the ZigBee."""
DEVICE.zb.serial.close()
class ZigBeeConfig(object):
"""
Handles the fetching of configuration from the config file for any ZigBee
entity.
"""
"""Handle the fetching of configuration from the config file."""
def __init__(self, config):
"""Initialize the configuration."""
self._config = config
self._should_poll = config.get("poll", True)
@property
def name(self):
""" The name given to the entity. """
"""The name given to the entity."""
return self._config["name"]
@property
def address(self):
"""
"""The address of the device.
If an address has been provided, unhexlify it, otherwise return None
as we're talking to our local ZigBee device.
"""
@@ -100,38 +97,33 @@ class ZigBeeConfig(object):
@property
def should_poll(self):
"""
A bool depicting whether HA should repeatedly poll this device for its
value.
"""
"""No polling needed."""
return self._should_poll
class ZigBeePinConfig(ZigBeeConfig):
"""
Handles the fetching of configuration from the config file for a ZigBee
GPIO pin.
"""
"""Handle the fetching of configuration from the config file."""
@property
def pin(self):
""" The GPIO pin number. """
"""The GPIO pin number."""
return self._config["pin"]
class ZigBeeDigitalPinConfig(ZigBeePinConfig):
"""
Handles the fetching of configuration from the config file for a ZigBee
GPIO pin set to digital in or out.
"""
"""Handle the fetching of configuration from the config file."""
def __init__(self, config):
"""Initialize the configuration."""
super(ZigBeeDigitalPinConfig, self).__init__(config)
self._bool2state, self._state2bool = self.boolean_maps
@property
def boolean_maps(self):
"""
Create dicts to map booleans to pin high/low and vice versa. Depends on
the config item "on_state" which should be set to "low" or "high".
"""Create dicts to map booleans to pin high/low and vice versa.
Depends on the config item "on_state" which should be set to "low"
or "high".
"""
if self._config.get("on_state", "").lower() == "low":
bool2state = {
@@ -148,17 +140,17 @@ class ZigBeeDigitalPinConfig(ZigBeePinConfig):
@property
def bool2state(self):
"""
A dictionary mapping booleans to GPIOSetting objects to translate
on/off as being pin high or low.
"""A dictionary mapping booleans to GPIOSetting objects.
For the translation of on/off as being pin high or low.
"""
return self._bool2state
@property
def state2bool(self):
"""
A dictionary mapping GPIOSetting objects to booleans to translate
pin high/low as being on or off.
"""A dictionary mapping GPIOSetting objects to booleans.
For the translation of pin high/low as being on or off.
"""
return self._state2bool
@@ -167,30 +159,32 @@ ZigBeeDigitalInConfig = ZigBeeDigitalPinConfig
class ZigBeeDigitalOutConfig(ZigBeeDigitalPinConfig):
"""A subclass of ZigBeeDigitalPinConfig.
Set _should_poll to default as False instead of True. The value will
still be overridden by the presence of a 'poll' config entry.
"""
A subclass of ZigBeeDigitalPinConfig which sets _should_poll to default as
False instead of True. The value will still be overridden by the presence
of a 'poll' config entry.
"""
def __init__(self, config):
"""Initialize the ZigBee Digital out."""
super(ZigBeeDigitalOutConfig, self).__init__(config)
self._should_poll = config.get("poll", False)
class ZigBeeAnalogInConfig(ZigBeePinConfig):
"""
Handles the fetching of configuration from the config file for a ZigBee
GPIO pin set to analog in.
"""
"""Representation of a ZigBee GPIO pin set to analog in."""
@property
def max_voltage(self):
""" The voltage at which the ADC will report its highest value. """
"""The voltage at which the ADC will report its highest value."""
return float(self._config.get("max_volts", DEFAULT_ADC_MAX_VOLTS))
class ZigBeeDigitalIn(Entity):
""" Represents a GPIO pin configured as a digital input. """
"""Representation of a GPIO pin configured as a digital input."""
def __init__(self, hass, config):
"""Initialize the device."""
self._config = config
self._state = False
# Get initial state
@@ -199,21 +193,21 @@ class ZigBeeDigitalIn(Entity):
@property
def name(self):
""" The name of the input. """
"""Return the name of the input."""
return self._config.name
@property
def should_poll(self):
""" State of the polling, if needed. """
"""Return the state of the polling, if needed."""
return self._config.should_poll
@property
def is_on(self):
""" Returns True if the Entity is on, else False. """
"""Return True if the Entity is on, else False."""
return self._state
def update(self):
""" Ask the ZigBee device what its output is set to. """
"""Ask the ZigBee device what its output is set to."""
try:
pin_state = DEVICE.get_gpio_pin(
self._config.pin,
@@ -231,8 +225,10 @@ class ZigBeeDigitalIn(Entity):
class ZigBeeDigitalOut(ZigBeeDigitalIn):
""" Adds functionality to ZigBeeDigitalIn to control an output. """
"""Representation of a GPIO pin configured as a digital input."""
def _set_state(self, state):
"""Initialize the ZigBee digital out device."""
try:
DEVICE.set_gpio_pin(
self._config.pin,
@@ -252,17 +248,19 @@ class ZigBeeDigitalOut(ZigBeeDigitalIn):
self.update_ha_state()
def turn_on(self, **kwargs):
""" Set the digital output to its 'on' state. """
"""Set the digital output to its 'on' state."""
self._set_state(True)
def turn_off(self, **kwargs):
""" Set the digital output to its 'off' state. """
"""Set the digital output to its 'off' state."""
self._set_state(False)
class ZigBeeAnalogIn(Entity):
""" Represents a GPIO pin configured as an analog input. """
"""Representation of a GPIO pin configured as an analog input."""
def __init__(self, hass, config):
"""Initialize the ZigBee analog in device."""
self._config = config
self._value = None
# Get initial state
@@ -271,26 +269,26 @@ class ZigBeeAnalogIn(Entity):
@property
def name(self):
""" The name of the input. """
"""The name of the input."""
return self._config.name
@property
def should_poll(self):
""" State of the polling, if needed. """
"""The state of the polling, if needed."""
return self._config.should_poll
@property
def state(self):
""" Returns the state of the entity. """
"""Return the state of the entity."""
return self._value
@property
def unit_of_measurement(self):
""" Unit this state is expressed in. """
"""Return the unit this state is expressed in."""
return "%"
def update(self):
""" Get the latest reading from the ADC. """
"""Get the latest reading from the ADC."""
try:
self._value = DEVICE.read_analog_pin(
self._config.pin,