Support for multiple MAX!Cube LAN gateways added (#13517)
This commit is contained in:
parent
ba7fccba34
commit
674682e88f
3 changed files with 60 additions and 34 deletions
|
@ -7,7 +7,7 @@ https://home-assistant.io/components/maxcube/
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||||
from homeassistant.components.maxcube import MAXCUBE_HANDLE
|
from homeassistant.components.maxcube import DATA_KEY
|
||||||
from homeassistant.const import STATE_UNKNOWN
|
from homeassistant.const import STATE_UNKNOWN
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -15,16 +15,17 @@ _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."""
|
"""Iterate through all MAX! Devices and add window shutters."""
|
||||||
cube = hass.data[MAXCUBE_HANDLE].cube
|
|
||||||
devices = []
|
devices = []
|
||||||
|
for handler in hass.data[DATA_KEY].values():
|
||||||
|
cube = handler.cube
|
||||||
|
for device in cube.devices:
|
||||||
|
name = "{} {}".format(
|
||||||
|
cube.room_by_id(device.room_id).name, device.name)
|
||||||
|
|
||||||
for device in cube.devices:
|
# Only add Window Shutters
|
||||||
name = "{} {}".format(
|
if cube.is_windowshutter(device):
|
||||||
cube.room_by_id(device.room_id).name, device.name)
|
devices.append(
|
||||||
|
MaxCubeShutter(handler, name, device.rf_address))
|
||||||
# Only add Window Shutters
|
|
||||||
if cube.is_windowshutter(device):
|
|
||||||
devices.append(MaxCubeShutter(hass, name, device.rf_address))
|
|
||||||
|
|
||||||
if devices:
|
if devices:
|
||||||
add_devices(devices)
|
add_devices(devices)
|
||||||
|
@ -33,12 +34,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
class MaxCubeShutter(BinarySensorDevice):
|
class MaxCubeShutter(BinarySensorDevice):
|
||||||
"""Representation of a MAX! Cube Binary Sensor device."""
|
"""Representation of a MAX! Cube Binary Sensor device."""
|
||||||
|
|
||||||
def __init__(self, hass, name, rf_address):
|
def __init__(self, handler, name, rf_address):
|
||||||
"""Initialize MAX! Cube BinarySensorDevice."""
|
"""Initialize MAX! Cube BinarySensorDevice."""
|
||||||
self._name = name
|
self._name = name
|
||||||
self._sensor_type = 'window'
|
self._sensor_type = 'window'
|
||||||
self._rf_address = rf_address
|
self._rf_address = rf_address
|
||||||
self._cubehandle = hass.data[MAXCUBE_HANDLE]
|
self._cubehandle = handler
|
||||||
self._state = STATE_UNKNOWN
|
self._state = STATE_UNKNOWN
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -10,7 +10,7 @@ import logging
|
||||||
from homeassistant.components.climate import (
|
from homeassistant.components.climate import (
|
||||||
ClimateDevice, STATE_AUTO, SUPPORT_TARGET_TEMPERATURE,
|
ClimateDevice, STATE_AUTO, SUPPORT_TARGET_TEMPERATURE,
|
||||||
SUPPORT_OPERATION_MODE)
|
SUPPORT_OPERATION_MODE)
|
||||||
from homeassistant.components.maxcube import MAXCUBE_HANDLE
|
from homeassistant.components.maxcube import DATA_KEY
|
||||||
from homeassistant.const import TEMP_CELSIUS, ATTR_TEMPERATURE
|
from homeassistant.const import TEMP_CELSIUS, ATTR_TEMPERATURE
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -24,16 +24,16 @@ SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_OPERATION_MODE
|
||||||
|
|
||||||
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."""
|
"""Iterate through all MAX! Devices and add thermostats."""
|
||||||
cube = hass.data[MAXCUBE_HANDLE].cube
|
|
||||||
|
|
||||||
devices = []
|
devices = []
|
||||||
|
for handler in hass.data[DATA_KEY].values():
|
||||||
|
cube = handler.cube
|
||||||
|
for device in cube.devices:
|
||||||
|
name = '{} {}'.format(
|
||||||
|
cube.room_by_id(device.room_id).name, device.name)
|
||||||
|
|
||||||
for device in cube.devices:
|
if cube.is_thermostat(device) or cube.is_wallthermostat(device):
|
||||||
name = '{} {}'.format(
|
devices.append(
|
||||||
cube.room_by_id(device.room_id).name, device.name)
|
MaxCubeClimate(handler, name, device.rf_address))
|
||||||
|
|
||||||
if cube.is_thermostat(device) or cube.is_wallthermostat(device):
|
|
||||||
devices.append(MaxCubeClimate(hass, name, device.rf_address))
|
|
||||||
|
|
||||||
if devices:
|
if devices:
|
||||||
add_devices(devices)
|
add_devices(devices)
|
||||||
|
@ -42,14 +42,14 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
class MaxCubeClimate(ClimateDevice):
|
class MaxCubeClimate(ClimateDevice):
|
||||||
"""MAX! Cube ClimateDevice."""
|
"""MAX! Cube ClimateDevice."""
|
||||||
|
|
||||||
def __init__(self, hass, name, rf_address):
|
def __init__(self, handler, name, rf_address):
|
||||||
"""Initialize MAX! Cube ClimateDevice."""
|
"""Initialize MAX! Cube ClimateDevice."""
|
||||||
self._name = name
|
self._name = name
|
||||||
self._unit_of_measurement = TEMP_CELSIUS
|
self._unit_of_measurement = TEMP_CELSIUS
|
||||||
self._operation_list = [STATE_AUTO, STATE_MANUAL, STATE_BOOST,
|
self._operation_list = [STATE_AUTO, STATE_MANUAL, STATE_BOOST,
|
||||||
STATE_VACATION]
|
STATE_VACATION]
|
||||||
self._rf_address = rf_address
|
self._rf_address = rf_address
|
||||||
self._cubehandle = hass.data[MAXCUBE_HANDLE]
|
self._cubehandle = handler
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
|
|
|
@ -22,12 +22,22 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
DEFAULT_PORT = 62910
|
DEFAULT_PORT = 62910
|
||||||
DOMAIN = 'maxcube'
|
DOMAIN = 'maxcube'
|
||||||
|
|
||||||
MAXCUBE_HANDLE = 'maxcube'
|
DATA_KEY = 'maxcube'
|
||||||
|
|
||||||
|
NOTIFICATION_ID = 'maxcube_notification'
|
||||||
|
NOTIFICATION_TITLE = 'Max!Cube gateway setup'
|
||||||
|
|
||||||
|
CONF_GATEWAYS = 'gateways'
|
||||||
|
|
||||||
|
CONFIG_GATEWAY = vol.Schema({
|
||||||
|
vol.Required(CONF_HOST): cv.string,
|
||||||
|
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
||||||
|
})
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
DOMAIN: vol.Schema({
|
DOMAIN: vol.Schema({
|
||||||
vol.Required(CONF_HOST): cv.string,
|
vol.Required(CONF_GATEWAYS, default={}):
|
||||||
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
vol.All(cv.ensure_list, [CONFIG_GATEWAY])
|
||||||
}),
|
}),
|
||||||
}, extra=vol.ALLOW_EXTRA)
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
|
@ -36,18 +46,33 @@ def setup(hass, config):
|
||||||
"""Establish connection to MAX! Cube."""
|
"""Establish connection to MAX! Cube."""
|
||||||
from maxcube.connection import MaxCubeConnection
|
from maxcube.connection import MaxCubeConnection
|
||||||
from maxcube.cube import MaxCube
|
from maxcube.cube import MaxCube
|
||||||
|
if DATA_KEY not in hass.data:
|
||||||
|
hass.data[DATA_KEY] = {}
|
||||||
|
|
||||||
host = config.get(DOMAIN).get(CONF_HOST)
|
if DOMAIN not in config:
|
||||||
port = config.get(DOMAIN).get(CONF_PORT)
|
|
||||||
|
|
||||||
try:
|
|
||||||
cube = MaxCube(MaxCubeConnection(host, port))
|
|
||||||
except timeout:
|
|
||||||
_LOGGER.error("Connection to Max!Cube could not be established")
|
|
||||||
cube = None
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
hass.data[MAXCUBE_HANDLE] = MaxCubeHandle(cube)
|
connection_failed = 0
|
||||||
|
gateways = config[DOMAIN][CONF_GATEWAYS]
|
||||||
|
for gateway in gateways:
|
||||||
|
host = gateway[CONF_HOST]
|
||||||
|
port = gateway[CONF_PORT]
|
||||||
|
|
||||||
|
try:
|
||||||
|
cube = MaxCube(MaxCubeConnection(host, port))
|
||||||
|
hass.data[DATA_KEY][host] = MaxCubeHandle(cube)
|
||||||
|
except timeout as ex:
|
||||||
|
_LOGGER.error("Unable to connect to Max!Cube gateway: %s", str(ex))
|
||||||
|
hass.components.persistent_notification.create(
|
||||||
|
'Error: {}<br />'
|
||||||
|
'You will need to restart Home Assistant after fixing.'
|
||||||
|
''.format(ex),
|
||||||
|
title=NOTIFICATION_TITLE,
|
||||||
|
notification_id=NOTIFICATION_ID)
|
||||||
|
connection_failed += 1
|
||||||
|
|
||||||
|
if connection_failed >= len(gateways):
|
||||||
|
return False
|
||||||
|
|
||||||
load_platform(hass, 'climate', DOMAIN)
|
load_platform(hass, 'climate', DOMAIN)
|
||||||
load_platform(hass, 'binary_sensor', DOMAIN)
|
load_platform(hass, 'binary_sensor', DOMAIN)
|
||||||
|
|
Loading…
Add table
Reference in a new issue