Remove superfluous comments and update ordering (#7227)

* Remove superfluous comments and update ordering

* Fix pylint issues
This commit is contained in:
Fabian Affolter 2017-04-22 21:13:04 +02:00 committed by GitHub
parent d229787fa6
commit 5bfe5b3f70
3 changed files with 20 additions and 64 deletions

View file

@ -4,7 +4,6 @@ Support for MAX! Window Shutter via MAX! Cube.
For more details about this platform, please refer to the documentation For more details about this platform, please refer to the documentation
https://home-assistant.io/components/maxcube/ https://home-assistant.io/components/maxcube/
""" """
import logging import logging
from homeassistant.components.binary_sensor import BinarySensorDevice from homeassistant.components.binary_sensor import BinarySensorDevice
@ -15,27 +14,24 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Iterate through all MAX! Devices and add window shutters to HASS.""" """Iterate through all MAX! Devices and add window shutters."""
cube = hass.data[MAXCUBE_HANDLE].cube cube = hass.data[MAXCUBE_HANDLE].cube
# List of devices
devices = [] devices = []
for device in cube.devices: for device in cube.devices:
# Create device name by concatenating room name + device name name = "{} {}".format(
name = "%s %s" % (cube.room_by_id(device.room_id).name, device.name) cube.room_by_id(device.room_id).name, device.name)
# Only add Window Shutters # Only add Window Shutters
if cube.is_windowshutter(device): if cube.is_windowshutter(device):
# add device to HASS
devices.append(MaxCubeShutter(hass, name, device.rf_address)) devices.append(MaxCubeShutter(hass, name, device.rf_address))
if len(devices) > 0: if len(devices):
add_devices(devices) add_devices(devices)
class MaxCubeShutter(BinarySensorDevice): class MaxCubeShutter(BinarySensorDevice):
"""MAX! Cube BinarySensor device.""" """Representation of a MAX! Cube Binary Sensor device."""
def __init__(self, hass, name, rf_address): def __init__(self, hass, name, rf_address):
"""Initialize MAX! Cube BinarySensorDevice.""" """Initialize MAX! Cube BinarySensorDevice."""
@ -68,9 +64,5 @@ class MaxCubeShutter(BinarySensorDevice):
def update(self): def update(self):
"""Get latest data from MAX! Cube.""" """Get latest data from MAX! Cube."""
self._cubehandle.update() self._cubehandle.update()
# Get the device we want to update
device = self._cubehandle.cube.device_by_rf(self._rf_address) device = self._cubehandle.cube.device_by_rf(self._rf_address)
# Update our internal state
self._state = device.is_open self._state = device.is_open

View file

@ -4,7 +4,6 @@ Support for MAX! Thermostats via MAX! Cube.
For more details about this platform, please refer to the documentation For more details about this platform, please refer to the documentation
https://home-assistant.io/components/maxcube/ https://home-assistant.io/components/maxcube/
""" """
import socket import socket
import logging import logging
@ -15,29 +14,27 @@ from homeassistant.const import STATE_UNKNOWN
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
STATE_MANUAL = "manual" STATE_MANUAL = 'manual'
STATE_BOOST = "boost" STATE_BOOST = 'boost'
STATE_VACATION = "vacation" STATE_VACATION = 'vacation'
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Iterate through all MAX! Devices and add thermostats to HASS.""" """Iterate through all MAX! Devices and add thermostats to HASS."""
cube = hass.data[MAXCUBE_HANDLE].cube cube = hass.data[MAXCUBE_HANDLE].cube
# List of devices
devices = [] devices = []
for device in cube.devices: for device in cube.devices:
# Create device name by concatenating room name + device name name = '{} {}'.format(
name = "%s %s" % (cube.room_by_id(device.room_id).name, device.name) cube.room_by_id(device.room_id).name, device.name)
# Only add thermostats and wallthermostats # Only add thermostats and wallthermostats
if cube.is_thermostat(device) or cube.is_wallthermostat(device): if cube.is_thermostat(device) or cube.is_wallthermostat(device):
# Add device to HASS # Add device to HASS
devices.append(MaxCubeClimate(hass, name, device.rf_address)) devices.append(MaxCubeClimate(hass, name, device.rf_address))
# Add all devices at once if len(devices):
if len(devices) > 0:
add_devices(devices) add_devices(devices)
@ -66,19 +63,13 @@ class MaxCubeClimate(ClimateDevice):
@property @property
def min_temp(self): def min_temp(self):
"""Return the minimum temperature.""" """Return the minimum temperature."""
# Get the device we want (does not do any IO, just reads from memory)
device = self._cubehandle.cube.device_by_rf(self._rf_address) device = self._cubehandle.cube.device_by_rf(self._rf_address)
# Map and return minimum temperature
return self.map_temperature_max_hass(device.min_temperature) return self.map_temperature_max_hass(device.min_temperature)
@property @property
def max_temp(self): def max_temp(self):
"""Return the maximum temperature.""" """Return the maximum temperature."""
# Get the device we want (does not do any IO, just reads from memory)
device = self._cubehandle.cube.device_by_rf(self._rf_address) device = self._cubehandle.cube.device_by_rf(self._rf_address)
# Map and return maximum temperature
return self.map_temperature_max_hass(device.max_temperature) return self.map_temperature_max_hass(device.max_temperature)
@property @property
@ -89,7 +80,6 @@ class MaxCubeClimate(ClimateDevice):
@property @property
def current_temperature(self): def current_temperature(self):
"""Return the current temperature.""" """Return the current temperature."""
# Get the device we want (does not do any IO, just reads from memory)
device = self._cubehandle.cube.device_by_rf(self._rf_address) device = self._cubehandle.cube.device_by_rf(self._rf_address)
# Map and return current temperature # Map and return current temperature
@ -98,10 +88,7 @@ class MaxCubeClimate(ClimateDevice):
@property @property
def current_operation(self): def current_operation(self):
"""Return current operation (auto, manual, boost, vacation).""" """Return current operation (auto, manual, boost, vacation)."""
# Get the device we want (does not do any IO, just reads from memory)
device = self._cubehandle.cube.device_by_rf(self._rf_address) device = self._cubehandle.cube.device_by_rf(self._rf_address)
# Mode Mapping
return self.map_mode_max_hass(device.mode) return self.map_mode_max_hass(device.mode)
@property @property
@ -112,22 +99,15 @@ class MaxCubeClimate(ClimateDevice):
@property @property
def target_temperature(self): def target_temperature(self):
"""Return the temperature we try to reach.""" """Return the temperature we try to reach."""
# Get the device we want (does not do any IO, just reads from memory)
device = self._cubehandle.cube.device_by_rf(self._rf_address) device = self._cubehandle.cube.device_by_rf(self._rf_address)
# Map and return target temperature
return self.map_temperature_max_hass(device.target_temperature) return self.map_temperature_max_hass(device.target_temperature)
def set_temperature(self, **kwargs): def set_temperature(self, **kwargs):
"""Set new target temperatures.""" """Set new target temperatures."""
# Fail is target temperature has not been supplied as argument
if kwargs.get(ATTR_TEMPERATURE) is None: if kwargs.get(ATTR_TEMPERATURE) is None:
return False return False
# Determine the new target temperature
target_temperature = kwargs.get(ATTR_TEMPERATURE) target_temperature = kwargs.get(ATTR_TEMPERATURE)
# Write the target temperature to the MAX! Cube.
device = self._cubehandle.cube.device_by_rf(self._rf_address) device = self._cubehandle.cube.device_by_rf(self._rf_address)
cube = self._cubehandle.cube cube = self._cubehandle.cube
@ -141,13 +121,9 @@ class MaxCubeClimate(ClimateDevice):
def set_operation_mode(self, operation_mode): def set_operation_mode(self, operation_mode):
"""Set new operation mode.""" """Set new operation mode."""
# Get the device we want to update
device = self._cubehandle.cube.device_by_rf(self._rf_address) device = self._cubehandle.cube.device_by_rf(self._rf_address)
# Mode Mapping
mode = self.map_mode_hass_max(operation_mode) mode = self.map_mode_hass_max(operation_mode)
# Write new mode to thermostat
if mode is None: if mode is None:
return False return False
@ -160,7 +136,6 @@ class MaxCubeClimate(ClimateDevice):
def update(self): def update(self):
"""Get latest data from MAX! Cube.""" """Get latest data from MAX! Cube."""
# Update the CubeHandle
self._cubehandle.update() self._cubehandle.update()
@staticmethod @staticmethod

View file

@ -4,25 +4,25 @@ Platform for the MAX! Cube LAN Gateway.
For more details about this component, please refer to the documentation For more details about this component, please refer to the documentation
https://home-assistant.io/components/maxcube/ https://home-assistant.io/components/maxcube/
""" """
from socket import timeout
import logging import logging
import time import time
from socket import timeout
from threading import Lock from threading import Lock
import voluptuous as vol
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.discovery import load_platform from homeassistant.helpers.discovery import load_platform
from homeassistant.const import CONF_HOST, CONF_PORT from homeassistant.const import CONF_HOST, CONF_PORT
import homeassistant.helpers.config_validation as cv
import voluptuous as vol
REQUIREMENTS = ['maxcube-api==0.1.0'] REQUIREMENTS = ['maxcube-api==0.1.0']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
DOMAIN = 'maxcube'
MAXCUBE_HANDLE = 'maxcube'
DEFAULT_PORT = 62910 DEFAULT_PORT = 62910
DOMAIN = 'maxcube'
MAXCUBE_HANDLE = 'maxcube'
CONFIG_SCHEMA = vol.Schema({ CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({ DOMAIN: vol.Schema({
@ -37,11 +37,9 @@ def setup(hass, config):
from maxcube.connection import MaxCubeConnection from maxcube.connection import MaxCubeConnection
from maxcube.cube import MaxCube from maxcube.cube import MaxCube
# Read Config
host = config.get(DOMAIN).get(CONF_HOST) host = config.get(DOMAIN).get(CONF_HOST)
port = config.get(DOMAIN).get(CONF_PORT) port = config.get(DOMAIN).get(CONF_PORT)
# Assign Cube Handle to global variable
try: try:
cube = MaxCube(MaxCubeConnection(host, port)) cube = MaxCube(MaxCubeConnection(host, port))
except timeout: except timeout:
@ -51,13 +49,9 @@ def setup(hass, config):
hass.data[MAXCUBE_HANDLE] = MaxCubeHandle(cube) hass.data[MAXCUBE_HANDLE] = MaxCubeHandle(cube)
# Load Climate (for Thermostats)
load_platform(hass, 'climate', DOMAIN) load_platform(hass, 'climate', DOMAIN)
# Load BinarySensor (for Window Shutter)
load_platform(hass, 'binary_sensor', DOMAIN) load_platform(hass, 'binary_sensor', DOMAIN)
# Initialization successfull
return True return True
@ -66,13 +60,8 @@ class MaxCubeHandle(object):
def __init__(self, cube): def __init__(self, cube):
"""Initialize the Cube Handle.""" """Initialize the Cube Handle."""
# Cube handle
self.cube = cube self.cube = cube
# Instantiate Mutex
self.mutex = Lock() self.mutex = Lock()
# Update Timestamp
self._updatets = time.time() self._updatets = time.time()
def update(self): def update(self):
@ -81,7 +70,7 @@ class MaxCubeHandle(object):
with self.mutex: with self.mutex:
# Only update every 60s # Only update every 60s
if (time.time() - self._updatets) >= 60: if (time.time() - self._updatets) >= 60:
_LOGGER.debug("UPDATE: Updating") _LOGGER.debug("Updating")
try: try:
self.cube.update() self.cube.update()
@ -91,4 +80,4 @@ class MaxCubeHandle(object):
self._updatets = time.time() self._updatets = time.time()
else: else:
_LOGGER.debug("UPDATE: Skipping") _LOGGER.debug("Skipping update")