Fixes for PEP257 (#11810)

* Fixes for PEP257

* More updates
This commit is contained in:
Fabian Affolter 2018-01-21 07:35:38 +01:00 committed by Paulus Schoutsen
parent 0100f87ff2
commit 47e31dc9ee
143 changed files with 1584 additions and 1761 deletions

View file

@ -1,20 +1,27 @@
"""Integration with the Rachio Iro sprinkler system controller."""
import logging
"""
Integration with the Rachio Iro sprinkler system controller.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.rachio/
"""
from datetime import timedelta
import logging
import voluptuous as vol
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchDevice
from homeassistant.const import CONF_ACCESS_TOKEN
import homeassistant.helpers.config_validation as cv
import homeassistant.util as util
from homeassistant.components.switch import SwitchDevice, PLATFORM_SCHEMA
from homeassistant.const import CONF_ACCESS_TOKEN
REQUIREMENTS = ['rachiopy==0.1.2']
_LOGGER = logging.getLogger(__name__)
CONF_MANUAL_RUN_MINS = 'manual_run_mins'
DATA_RACHIO = 'rachio'
CONF_MANUAL_RUN_MINS = 'manual_run_mins'
DEFAULT_MANUAL_RUN_MINS = 10
MIN_UPDATE_INTERVAL = timedelta(seconds=30)
@ -23,50 +30,49 @@ MIN_FORCED_UPDATE_INTERVAL = timedelta(seconds=1)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_ACCESS_TOKEN): cv.string,
vol.Optional(CONF_MANUAL_RUN_MINS, default=DEFAULT_MANUAL_RUN_MINS):
cv.positive_int
cv.positive_int,
})
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the component."""
"""Set up the Rachio switches."""
from rachiopy import Rachio
# Get options
manual_run_mins = config.get(CONF_MANUAL_RUN_MINS)
_LOGGER.debug("Rachio run time is %d min", manual_run_mins)
# Get access token
_LOGGER.debug("Getting Rachio access token...")
access_token = config.get(CONF_ACCESS_TOKEN)
# Configure API
_LOGGER.debug("Configuring Rachio API...")
from rachiopy import Rachio
_LOGGER.debug("Configuring Rachio API")
rachio = Rachio(access_token)
person = None
try:
person = _get_person(rachio)
except KeyError:
_LOGGER.error("Could not reach the Rachio API. "
"Is your access token valid?")
return False
_LOGGER.error(
"Could not reach the Rachio API. Is your access token valid?")
return
# Get and persist devices
devices = _list_devices(rachio, manual_run_mins)
if not devices:
_LOGGER.error("No Rachio devices found in account " +
person['username'])
return False
_LOGGER.error(
"No Rachio devices found in account %s", person['username'])
return
hass.data[DATA_RACHIO] = devices[0]
if len(devices) > 1:
_LOGGER.warning("Multiple Rachio devices found in account, "
"using " + hass.data[DATA_RACHIO].device_id)
"using %s", hass.data[DATA_RACHIO].device_id)
else:
_LOGGER.info("Found Rachio device")
_LOGGER.debug("Found Rachio device")
hass.data[DATA_RACHIO].update()
add_devices(hass.data[DATA_RACHIO].list_zones())
return True
def _get_person(rachio):
@ -82,10 +88,10 @@ def _list_devices(rachio, manual_run_mins):
class RachioIro(object):
"""Represents one Rachio Iro."""
"""Representation of a Rachio Iro."""
def __init__(self, rachio, device_id, manual_run_mins):
"""Initialize a new device."""
"""Initialize a Rachio device."""
self.rachio = rachio
self._device_id = device_id
self.manual_run_mins = manual_run_mins
@ -95,40 +101,40 @@ class RachioIro(object):
def __str__(self):
"""Display the device as a string."""
return "Rachio Iro " + self.serial_number
return "Rachio Iro {}".format(self.serial_number)
@property
def device_id(self):
"""How the Rachio API refers to the device."""
"""Return the Rachio API device ID."""
return self._device['id']
@property
def status(self):
"""The current status of the device."""
"""Return the current status of the device."""
return self._device['status']
@property
def serial_number(self):
"""The serial number of the device."""
"""Return the serial number of the device."""
return self._device['serialNumber']
@property
def is_paused(self):
"""Whether the device is temporarily disabled."""
"""Return whether the device is temporarily disabled."""
return self._device['paused']
@property
def is_on(self):
"""Whether the device is powered on and connected."""
"""Return whether the device is powered on and connected."""
return self._device['on']
@property
def current_schedule(self):
"""The schedule that the device is running right now."""
"""Return the schedule that the device is running right now."""
return self._running
def list_zones(self, include_disabled=False):
"""A list of the zones connected to the device and their data."""
"""Return alist of the zones connected to the device, incl. data."""
if not self._zones:
self._zones = [RachioZone(self.rachio, self, zone['id'],
self.manual_run_mins)
@ -155,7 +161,7 @@ class RachioIro(object):
class RachioZone(SwitchDevice):
"""Represents one zone of sprinklers connected to the Rachio Iro."""
"""Representation of one zone of sprinklers connected to the Rachio Iro."""
def __init__(self, rachio, device, zone_id, manual_run_mins):
"""Initialize a new Rachio Zone."""
@ -167,7 +173,7 @@ class RachioZone(SwitchDevice):
def __str__(self):
"""Display the zone as a string."""
return "Rachio Zone " + self.name
return "Rachio Zone {}".format(self.name)
@property
def zone_id(self):
@ -176,29 +182,28 @@ class RachioZone(SwitchDevice):
@property
def unique_id(self):
"""Generate a unique string ID for the zone."""
"""Return the unique string ID for the zone."""
return '{iro}-{zone}'.format(
iro=self._device.device_id,
zone=self.zone_id)
iro=self._device.device_id, zone=self.zone_id)
@property
def number(self):
"""The physical connection of the zone pump."""
"""Return the physical connection of the zone pump."""
return self._zone['zoneNumber']
@property
def name(self):
"""The friendly name of the zone."""
"""Return the friendly name of the zone."""
return self._zone['name']
@property
def is_enabled(self):
"""Whether the zone is allowed to run."""
"""Return whether the zone is allowed to run."""
return self._zone['enabled']
@property
def is_on(self):
"""Whether the zone is currently running."""
"""Return whether the zone is currently running."""
schedule = self._device.current_schedule
return self.zone_id == schedule.get('zoneId')