Remove superfluous comments and update ordering (#7227)
* Remove superfluous comments and update ordering * Fix pylint issues
This commit is contained in:
parent
d229787fa6
commit
5bfe5b3f70
3 changed files with 20 additions and 64 deletions
|
@ -4,7 +4,6 @@ Support for MAX! Window Shutter via MAX! Cube.
|
|||
For more details about this platform, please refer to the documentation
|
||||
https://home-assistant.io/components/maxcube/
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
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):
|
||||
"""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
|
||||
|
||||
# List of devices
|
||||
devices = []
|
||||
|
||||
for device in cube.devices:
|
||||
# Create device name by concatenating room name + device name
|
||||
name = "%s %s" % (cube.room_by_id(device.room_id).name, device.name)
|
||||
name = "{} {}".format(
|
||||
cube.room_by_id(device.room_id).name, device.name)
|
||||
|
||||
# Only add Window Shutters
|
||||
if cube.is_windowshutter(device):
|
||||
# add device to HASS
|
||||
devices.append(MaxCubeShutter(hass, name, device.rf_address))
|
||||
|
||||
if len(devices) > 0:
|
||||
if len(devices):
|
||||
add_devices(devices)
|
||||
|
||||
|
||||
class MaxCubeShutter(BinarySensorDevice):
|
||||
"""MAX! Cube BinarySensor device."""
|
||||
"""Representation of a MAX! Cube Binary Sensor device."""
|
||||
|
||||
def __init__(self, hass, name, rf_address):
|
||||
"""Initialize MAX! Cube BinarySensorDevice."""
|
||||
|
@ -68,9 +64,5 @@ class MaxCubeShutter(BinarySensorDevice):
|
|||
def update(self):
|
||||
"""Get latest data from MAX! Cube."""
|
||||
self._cubehandle.update()
|
||||
|
||||
# Get the device we want to update
|
||||
device = self._cubehandle.cube.device_by_rf(self._rf_address)
|
||||
|
||||
# Update our internal state
|
||||
self._state = device.is_open
|
||||
|
|
|
@ -4,7 +4,6 @@ Support for MAX! Thermostats via MAX! Cube.
|
|||
For more details about this platform, please refer to the documentation
|
||||
https://home-assistant.io/components/maxcube/
|
||||
"""
|
||||
|
||||
import socket
|
||||
import logging
|
||||
|
||||
|
@ -15,29 +14,27 @@ from homeassistant.const import STATE_UNKNOWN
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
STATE_MANUAL = "manual"
|
||||
STATE_BOOST = "boost"
|
||||
STATE_VACATION = "vacation"
|
||||
STATE_MANUAL = 'manual'
|
||||
STATE_BOOST = 'boost'
|
||||
STATE_VACATION = 'vacation'
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Iterate through all MAX! Devices and add thermostats to HASS."""
|
||||
cube = hass.data[MAXCUBE_HANDLE].cube
|
||||
|
||||
# List of devices
|
||||
devices = []
|
||||
|
||||
for device in cube.devices:
|
||||
# Create device name by concatenating room name + device name
|
||||
name = "%s %s" % (cube.room_by_id(device.room_id).name, device.name)
|
||||
name = '{} {}'.format(
|
||||
cube.room_by_id(device.room_id).name, device.name)
|
||||
|
||||
# Only add thermostats and wallthermostats
|
||||
if cube.is_thermostat(device) or cube.is_wallthermostat(device):
|
||||
# Add device to HASS
|
||||
devices.append(MaxCubeClimate(hass, name, device.rf_address))
|
||||
|
||||
# Add all devices at once
|
||||
if len(devices) > 0:
|
||||
if len(devices):
|
||||
add_devices(devices)
|
||||
|
||||
|
||||
|
@ -66,19 +63,13 @@ class MaxCubeClimate(ClimateDevice):
|
|||
@property
|
||||
def min_temp(self):
|
||||
"""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)
|
||||
|
||||
# Map and return minimum temperature
|
||||
return self.map_temperature_max_hass(device.min_temperature)
|
||||
|
||||
@property
|
||||
def max_temp(self):
|
||||
"""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)
|
||||
|
||||
# Map and return maximum temperature
|
||||
return self.map_temperature_max_hass(device.max_temperature)
|
||||
|
||||
@property
|
||||
|
@ -89,7 +80,6 @@ class MaxCubeClimate(ClimateDevice):
|
|||
@property
|
||||
def current_temperature(self):
|
||||
"""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)
|
||||
|
||||
# Map and return current temperature
|
||||
|
@ -98,10 +88,7 @@ class MaxCubeClimate(ClimateDevice):
|
|||
@property
|
||||
def current_operation(self):
|
||||
"""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)
|
||||
|
||||
# Mode Mapping
|
||||
return self.map_mode_max_hass(device.mode)
|
||||
|
||||
@property
|
||||
|
@ -112,22 +99,15 @@ class MaxCubeClimate(ClimateDevice):
|
|||
@property
|
||||
def target_temperature(self):
|
||||
"""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)
|
||||
|
||||
# Map and return target temperature
|
||||
return self.map_temperature_max_hass(device.target_temperature)
|
||||
|
||||
def set_temperature(self, **kwargs):
|
||||
"""Set new target temperatures."""
|
||||
# Fail is target temperature has not been supplied as argument
|
||||
if kwargs.get(ATTR_TEMPERATURE) is None:
|
||||
return False
|
||||
|
||||
# Determine the new target 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)
|
||||
|
||||
cube = self._cubehandle.cube
|
||||
|
@ -141,13 +121,9 @@ class MaxCubeClimate(ClimateDevice):
|
|||
|
||||
def set_operation_mode(self, operation_mode):
|
||||
"""Set new operation mode."""
|
||||
# Get the device we want to update
|
||||
device = self._cubehandle.cube.device_by_rf(self._rf_address)
|
||||
|
||||
# Mode Mapping
|
||||
mode = self.map_mode_hass_max(operation_mode)
|
||||
|
||||
# Write new mode to thermostat
|
||||
if mode is None:
|
||||
return False
|
||||
|
||||
|
@ -160,7 +136,6 @@ class MaxCubeClimate(ClimateDevice):
|
|||
|
||||
def update(self):
|
||||
"""Get latest data from MAX! Cube."""
|
||||
# Update the CubeHandle
|
||||
self._cubehandle.update()
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -4,25 +4,25 @@ Platform for the MAX! Cube LAN Gateway.
|
|||
For more details about this component, please refer to the documentation
|
||||
https://home-assistant.io/components/maxcube/
|
||||
"""
|
||||
|
||||
from socket import timeout
|
||||
import logging
|
||||
import time
|
||||
from socket import timeout
|
||||
from threading import Lock
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.discovery import load_platform
|
||||
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']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN = 'maxcube'
|
||||
MAXCUBE_HANDLE = 'maxcube'
|
||||
|
||||
DEFAULT_PORT = 62910
|
||||
DOMAIN = 'maxcube'
|
||||
|
||||
MAXCUBE_HANDLE = 'maxcube'
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
DOMAIN: vol.Schema({
|
||||
|
@ -37,11 +37,9 @@ def setup(hass, config):
|
|||
from maxcube.connection import MaxCubeConnection
|
||||
from maxcube.cube import MaxCube
|
||||
|
||||
# Read Config
|
||||
host = config.get(DOMAIN).get(CONF_HOST)
|
||||
port = config.get(DOMAIN).get(CONF_PORT)
|
||||
|
||||
# Assign Cube Handle to global variable
|
||||
try:
|
||||
cube = MaxCube(MaxCubeConnection(host, port))
|
||||
except timeout:
|
||||
|
@ -51,13 +49,9 @@ def setup(hass, config):
|
|||
|
||||
hass.data[MAXCUBE_HANDLE] = MaxCubeHandle(cube)
|
||||
|
||||
# Load Climate (for Thermostats)
|
||||
load_platform(hass, 'climate', DOMAIN)
|
||||
|
||||
# Load BinarySensor (for Window Shutter)
|
||||
load_platform(hass, 'binary_sensor', DOMAIN)
|
||||
|
||||
# Initialization successfull
|
||||
return True
|
||||
|
||||
|
||||
|
@ -66,13 +60,8 @@ class MaxCubeHandle(object):
|
|||
|
||||
def __init__(self, cube):
|
||||
"""Initialize the Cube Handle."""
|
||||
# Cube handle
|
||||
self.cube = cube
|
||||
|
||||
# Instantiate Mutex
|
||||
self.mutex = Lock()
|
||||
|
||||
# Update Timestamp
|
||||
self._updatets = time.time()
|
||||
|
||||
def update(self):
|
||||
|
@ -81,7 +70,7 @@ class MaxCubeHandle(object):
|
|||
with self.mutex:
|
||||
# Only update every 60s
|
||||
if (time.time() - self._updatets) >= 60:
|
||||
_LOGGER.debug("UPDATE: Updating")
|
||||
_LOGGER.debug("Updating")
|
||||
|
||||
try:
|
||||
self.cube.update()
|
||||
|
@ -91,4 +80,4 @@ class MaxCubeHandle(object):
|
|||
|
||||
self._updatets = time.time()
|
||||
else:
|
||||
_LOGGER.debug("UPDATE: Skipping")
|
||||
_LOGGER.debug("Skipping update")
|
||||
|
|
Loading…
Add table
Reference in a new issue