2019-02-13 20:21:14 +00:00
|
|
|
"""Support to control a Zehnder ComfoAir Q350/450/600 ventilation unit."""
|
2017-06-28 16:04:54 +00:00
|
|
|
import logging
|
|
|
|
|
2019-10-18 22:01:03 +00:00
|
|
|
from pycomfoconnect import (
|
|
|
|
SENSOR_TEMPERATURE_EXTRACT,
|
|
|
|
SENSOR_TEMPERATURE_OUTDOOR,
|
|
|
|
Bridge,
|
|
|
|
ComfoConnect,
|
|
|
|
)
|
2017-06-28 16:04:54 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
|
|
|
from homeassistant.const import (
|
2019-07-31 19:25:30 +00:00
|
|
|
CONF_HOST,
|
|
|
|
CONF_NAME,
|
|
|
|
CONF_PIN,
|
|
|
|
CONF_TOKEN,
|
|
|
|
EVENT_HOMEASSISTANT_STOP,
|
|
|
|
)
|
2018-01-21 06:35:38 +00:00
|
|
|
from homeassistant.helpers import discovery
|
|
|
|
import homeassistant.helpers.config_validation as cv
|
|
|
|
from homeassistant.helpers.dispatcher import dispatcher_send
|
2017-06-28 16:04:54 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
DOMAIN = "comfoconnect"
|
2017-06-28 16:04:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
SIGNAL_COMFOCONNECT_UPDATE_RECEIVED = "comfoconnect_update_received"
|
2017-06-28 16:04:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_CURRENT_TEMPERATURE = "current_temperature"
|
|
|
|
ATTR_CURRENT_HUMIDITY = "current_humidity"
|
|
|
|
ATTR_OUTSIDE_TEMPERATURE = "outside_temperature"
|
|
|
|
ATTR_OUTSIDE_HUMIDITY = "outside_humidity"
|
|
|
|
ATTR_AIR_FLOW_SUPPLY = "air_flow_supply"
|
|
|
|
ATTR_AIR_FLOW_EXHAUST = "air_flow_exhaust"
|
2017-06-28 16:04:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
CONF_USER_AGENT = "user_agent"
|
2017-06-28 16:04:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
DEFAULT_NAME = "ComfoAirQ"
|
2017-06-28 16:04:54 +00:00
|
|
|
DEFAULT_PIN = 0
|
2019-07-31 19:25:30 +00:00
|
|
|
DEFAULT_TOKEN = "00000000000000000000000000000001"
|
|
|
|
DEFAULT_USER_AGENT = "Home Assistant"
|
2017-06-28 16:04:54 +00:00
|
|
|
|
2017-06-29 09:44:35 +00:00
|
|
|
DEVICE = None
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
CONFIG_SCHEMA = vol.Schema(
|
|
|
|
{
|
|
|
|
DOMAIN: vol.Schema(
|
|
|
|
{
|
|
|
|
vol.Required(CONF_HOST): cv.string,
|
|
|
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
|
|
|
vol.Optional(CONF_TOKEN, default=DEFAULT_TOKEN): vol.Length(
|
|
|
|
min=32, max=32, msg="invalid token"
|
|
|
|
),
|
|
|
|
vol.Optional(CONF_USER_AGENT, default=DEFAULT_USER_AGENT): cv.string,
|
|
|
|
vol.Optional(CONF_PIN, default=DEFAULT_PIN): cv.positive_int,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
extra=vol.ALLOW_EXTRA,
|
|
|
|
)
|
2017-06-28 16:04:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
def setup(hass, config):
|
2017-06-29 09:44:35 +00:00
|
|
|
"""Set up the ComfoConnect bridge."""
|
2017-06-28 16:04:54 +00:00
|
|
|
|
|
|
|
conf = config[DOMAIN]
|
|
|
|
host = conf.get(CONF_HOST)
|
|
|
|
name = conf.get(CONF_NAME)
|
|
|
|
token = conf.get(CONF_TOKEN)
|
|
|
|
user_agent = conf.get(CONF_USER_AGENT)
|
|
|
|
pin = conf.get(CONF_PIN)
|
|
|
|
|
|
|
|
# Run discovery on the configured ip
|
|
|
|
bridges = Bridge.discover(host)
|
|
|
|
if not bridges:
|
2017-06-29 09:44:35 +00:00
|
|
|
_LOGGER.error("Could not connect to ComfoConnect bridge on %s", host)
|
2017-06-28 16:04:54 +00:00
|
|
|
return False
|
|
|
|
bridge = bridges[0]
|
2017-06-29 09:44:35 +00:00
|
|
|
_LOGGER.info("Bridge found: %s (%s)", bridge.uuid.hex(), bridge.host)
|
2017-06-28 16:04:54 +00:00
|
|
|
|
|
|
|
# Setup ComfoConnect Bridge
|
|
|
|
ccb = ComfoConnectBridge(hass, bridge, name, token, user_agent, pin)
|
|
|
|
hass.data[DOMAIN] = ccb
|
|
|
|
|
|
|
|
# Start connection with bridge
|
|
|
|
ccb.connect()
|
|
|
|
|
|
|
|
# Schedule disconnect on shutdown
|
|
|
|
def _shutdown(_event):
|
|
|
|
ccb.disconnect()
|
|
|
|
|
|
|
|
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, _shutdown)
|
|
|
|
|
|
|
|
# Load platforms
|
2019-07-31 19:25:30 +00:00
|
|
|
discovery.load_platform(hass, "fan", DOMAIN, {}, config)
|
2017-06-28 16:04:54 +00:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2018-07-20 08:45:20 +00:00
|
|
|
class ComfoConnectBridge:
|
2017-06-28 16:04:54 +00:00
|
|
|
"""Representation of a ComfoConnect bridge."""
|
|
|
|
|
|
|
|
def __init__(self, hass, bridge, name, token, friendly_name, pin):
|
|
|
|
"""Initialize the ComfoConnect bridge."""
|
|
|
|
self.data = {}
|
|
|
|
self.name = name
|
|
|
|
self.hass = hass
|
|
|
|
|
2017-06-29 09:44:35 +00:00
|
|
|
self.comfoconnect = ComfoConnect(
|
2019-07-31 19:25:30 +00:00
|
|
|
bridge=bridge,
|
|
|
|
local_uuid=bytes.fromhex(token),
|
|
|
|
local_devicename=friendly_name,
|
|
|
|
pin=pin,
|
|
|
|
)
|
2017-06-28 16:04:54 +00:00
|
|
|
self.comfoconnect.callback_sensor = self.sensor_callback
|
|
|
|
|
|
|
|
def connect(self):
|
|
|
|
"""Connect with the bridge."""
|
2017-06-29 09:44:35 +00:00
|
|
|
_LOGGER.debug("Connecting with bridge")
|
2017-06-28 16:04:54 +00:00
|
|
|
self.comfoconnect.connect(True)
|
|
|
|
|
|
|
|
def disconnect(self):
|
|
|
|
"""Disconnect from the bridge."""
|
2017-06-29 09:44:35 +00:00
|
|
|
_LOGGER.debug("Disconnecting from bridge")
|
2017-06-28 16:04:54 +00:00
|
|
|
self.comfoconnect.disconnect()
|
|
|
|
|
|
|
|
def sensor_callback(self, var, value):
|
2018-01-21 06:35:38 +00:00
|
|
|
"""Call function for sensor updates."""
|
2017-06-29 09:44:35 +00:00
|
|
|
_LOGGER.debug("Got value from bridge: %d = %d", var, value)
|
2017-06-28 16:04:54 +00:00
|
|
|
|
|
|
|
if var in [SENSOR_TEMPERATURE_EXTRACT, SENSOR_TEMPERATURE_OUTDOOR]:
|
|
|
|
self.data[var] = value / 10
|
|
|
|
else:
|
|
|
|
self.data[var] = value
|
|
|
|
|
|
|
|
# Notify listeners that we have received an update
|
|
|
|
dispatcher_send(self.hass, SIGNAL_COMFOCONNECT_UPDATE_RECEIVED, var)
|