2016-08-19 07:17:28 +00:00
|
|
|
"""
|
|
|
|
Support for KNX thermostats.
|
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation
|
2016-09-14 06:03:30 +00:00
|
|
|
https://home-assistant.io/components/climate.knx/
|
2016-08-19 07:17:28 +00:00
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
|
2016-09-14 06:03:30 +00:00
|
|
|
import voluptuous as vol
|
2016-08-19 07:17:28 +00:00
|
|
|
|
2016-09-14 06:03:30 +00:00
|
|
|
from homeassistant.components.climate import (ClimateDevice, PLATFORM_SCHEMA)
|
|
|
|
from homeassistant.components.knx import (KNXConfig, KNXMultiAddressDevice)
|
|
|
|
from homeassistant.const import (CONF_NAME, TEMP_CELSIUS, ATTR_TEMPERATURE)
|
|
|
|
import homeassistant.helpers.config_validation as cv
|
2016-08-19 07:17:28 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2016-09-14 06:03:30 +00:00
|
|
|
CONF_ADDRESS = 'address'
|
|
|
|
CONF_SETPOINT_ADDRESS = 'setpoint_address'
|
|
|
|
CONF_TEMPERATURE_ADDRESS = 'temperature_address'
|
|
|
|
|
|
|
|
DEFAULT_NAME = 'KNX Thermostat'
|
|
|
|
DEPENDENCIES = ['knx']
|
|
|
|
|
|
|
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|
|
|
vol.Required(CONF_ADDRESS): cv.string,
|
|
|
|
vol.Required(CONF_SETPOINT_ADDRESS): cv.string,
|
|
|
|
vol.Required(CONF_TEMPERATURE_ADDRESS): cv.string,
|
|
|
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
|
|
|
})
|
|
|
|
|
2016-08-19 07:17:28 +00:00
|
|
|
|
2016-09-14 06:03:30 +00:00
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
2016-08-19 07:17:28 +00:00
|
|
|
"""Create and add an entity based on the configuration."""
|
2016-09-14 06:03:30 +00:00
|
|
|
add_devices([KNXThermostat(hass, KNXConfig(config))])
|
2016-08-19 07:17:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
class KNXThermostat(KNXMultiAddressDevice, ClimateDevice):
|
|
|
|
"""Representation of a KNX thermostat.
|
|
|
|
|
|
|
|
A KNX thermostat will has the following parameters:
|
|
|
|
- temperature (current temperature)
|
|
|
|
- setpoint (target temperature in HASS terms)
|
|
|
|
- operation mode selection (comfort/night/frost protection)
|
|
|
|
|
|
|
|
This version supports only polling. Messages from the KNX bus do not
|
|
|
|
automatically update the state of the thermostat (to be implemented
|
|
|
|
in future releases)
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, hass, config):
|
|
|
|
"""Initialize the thermostat based on the given configuration."""
|
2016-09-14 06:03:30 +00:00
|
|
|
KNXMultiAddressDevice.__init__(
|
|
|
|
self, hass, config, ['temperature', 'setpoint'], ['mode'])
|
2016-08-19 07:17:28 +00:00
|
|
|
|
|
|
|
self._unit_of_measurement = TEMP_CELSIUS # KNX always used celsius
|
|
|
|
self._away = False # not yet supported
|
|
|
|
self._is_fan_on = False # not yet supported
|
2016-11-09 05:00:33 +00:00
|
|
|
self._current_temp = None
|
|
|
|
self._target_temp = None
|
2016-08-19 07:17:28 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def should_poll(self):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Return the polling state, is needed for the KNX thermostat."""
|
2016-08-19 07:17:28 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
@property
|
2016-10-11 07:00:29 +00:00
|
|
|
def temperature_unit(self):
|
2016-08-19 07:17:28 +00:00
|
|
|
"""Return the unit of measurement."""
|
|
|
|
return self._unit_of_measurement
|
|
|
|
|
|
|
|
@property
|
|
|
|
def current_temperature(self):
|
|
|
|
"""Return the current temperature."""
|
2016-11-09 05:00:33 +00:00
|
|
|
return self._current_temp
|
2016-08-19 07:17:28 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def target_temperature(self):
|
|
|
|
"""Return the temperature we try to reach."""
|
2016-11-09 05:00:33 +00:00
|
|
|
return self._target_temp
|
2016-08-19 07:17:28 +00:00
|
|
|
|
2016-09-09 17:06:53 +00:00
|
|
|
def set_temperature(self, **kwargs):
|
2016-08-19 07:17:28 +00:00
|
|
|
"""Set new target temperature."""
|
2016-09-09 17:06:53 +00:00
|
|
|
temperature = kwargs.get(ATTR_TEMPERATURE)
|
|
|
|
if temperature is None:
|
|
|
|
return
|
2016-08-19 07:17:28 +00:00
|
|
|
from knxip.conversion import float_to_knx2
|
|
|
|
|
2016-09-14 06:03:30 +00:00
|
|
|
self.set_value('setpoint', float_to_knx2(temperature))
|
2016-08-19 07:17:28 +00:00
|
|
|
_LOGGER.debug("Set target temperature to %s", temperature)
|
|
|
|
|
|
|
|
def set_operation_mode(self, operation_mode):
|
|
|
|
"""Set operation mode."""
|
|
|
|
raise NotImplementedError()
|
2016-11-09 05:00:33 +00:00
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Update KNX climate."""
|
|
|
|
from knxip.conversion import knx2_to_float
|
|
|
|
|
|
|
|
super().update()
|
|
|
|
|
|
|
|
self._current_temp = knx2_to_float(self.value('temperature'))
|
|
|
|
self._target_temp = knx2_to_float(self.value('setpoint'))
|