2015-11-23 18:52:08 +00:00
|
|
|
"""
|
2016-06-24 08:06:58 +00:00
|
|
|
The Homematic thermostat platform.
|
2015-11-23 18:52:08 +00:00
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation at
|
|
|
|
https://home-assistant.io/components/thermostat.homematic/
|
2016-06-24 08:06:58 +00:00
|
|
|
|
|
|
|
Important: For this platform to work the homematic component has to be
|
|
|
|
properly configured.
|
|
|
|
|
|
|
|
Configuration:
|
|
|
|
|
|
|
|
thermostat:
|
|
|
|
- platform: homematic
|
|
|
|
address: "<Homematic address for device>" # e.g. "JEQ0XXXXXXX"
|
|
|
|
name: "<User defined name>" (optional)
|
2015-11-23 18:52:08 +00:00
|
|
|
"""
|
|
|
|
|
2016-06-24 08:06:58 +00:00
|
|
|
import logging
|
|
|
|
import homeassistant.components.homematic as homematic
|
2015-11-23 18:52:08 +00:00
|
|
|
from homeassistant.components.thermostat import ThermostatDevice
|
2016-04-10 23:26:08 +00:00
|
|
|
from homeassistant.helpers.temperature import convert
|
2016-06-24 08:06:58 +00:00
|
|
|
from homeassistant.const import TEMP_CELSIUS, STATE_UNKNOWN
|
2015-11-23 18:52:08 +00:00
|
|
|
|
2016-06-24 08:06:58 +00:00
|
|
|
DEPENDENCIES = ['homematic']
|
2015-11-23 18:52:08 +00:00
|
|
|
|
2016-04-10 23:26:08 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2015-11-23 18:52:08 +00:00
|
|
|
|
2016-06-24 08:06:58 +00:00
|
|
|
def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
|
|
|
"""Setup the platform."""
|
2016-06-25 19:37:51 +00:00
|
|
|
if discovery_info:
|
|
|
|
return homematic.setup_hmdevice_discovery_helper(HMThermostat,
|
|
|
|
discovery_info,
|
|
|
|
add_callback_devices)
|
|
|
|
# Manual
|
2016-06-24 08:06:58 +00:00
|
|
|
return homematic.setup_hmdevice_entity_helper(HMThermostat,
|
|
|
|
config,
|
|
|
|
add_callback_devices)
|
2015-11-23 18:52:08 +00:00
|
|
|
|
|
|
|
|
2016-06-24 08:06:58 +00:00
|
|
|
class HMThermostat(homematic.HMDevice, ThermostatDevice):
|
|
|
|
"""Represents a Homematic Thermostat in Home Assistant."""
|
2015-11-23 18:52:08 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
2016-03-07 21:44:35 +00:00
|
|
|
"""Return the unit of measurement that is used."""
|
2016-04-20 03:30:44 +00:00
|
|
|
return TEMP_CELSIUS
|
2015-11-23 18:52:08 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def current_temperature(self):
|
2016-03-07 21:44:35 +00:00
|
|
|
"""Return the current temperature."""
|
2016-06-24 08:06:58 +00:00
|
|
|
if not self.available:
|
|
|
|
return None
|
|
|
|
return self._data["ACTUAL_TEMPERATURE"]
|
2015-11-23 18:52:08 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def target_temperature(self):
|
2016-06-24 08:06:58 +00:00
|
|
|
"""Return the target temperature."""
|
|
|
|
if not self.available:
|
|
|
|
return None
|
|
|
|
return self._data["SET_TEMPERATURE"]
|
2015-11-23 18:52:08 +00:00
|
|
|
|
|
|
|
def set_temperature(self, temperature):
|
2016-03-07 21:44:35 +00:00
|
|
|
"""Set new target temperature."""
|
2016-06-24 08:06:58 +00:00
|
|
|
if not self.available:
|
|
|
|
return None
|
|
|
|
self._hmdevice.set_temperature(temperature)
|
2015-11-23 18:52:08 +00:00
|
|
|
|
2016-04-10 23:26:08 +00:00
|
|
|
@property
|
|
|
|
def min_temp(self):
|
|
|
|
"""Return the minimum temperature - 4.5 means off."""
|
2016-04-20 03:30:44 +00:00
|
|
|
return convert(4.5, TEMP_CELSIUS, self.unit_of_measurement)
|
2016-04-10 23:26:08 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def max_temp(self):
|
|
|
|
"""Return the maximum temperature - 30.5 means on."""
|
2016-04-20 03:30:44 +00:00
|
|
|
return convert(30.5, TEMP_CELSIUS, self.unit_of_measurement)
|
2016-04-10 23:26:08 +00:00
|
|
|
|
2016-06-24 08:06:58 +00:00
|
|
|
def _check_hm_to_ha_object(self):
|
|
|
|
"""Check if possible to use the HM Object as this HA type."""
|
|
|
|
from pyhomematic.devicetypes.thermostats import HMThermostat\
|
|
|
|
as pyHMThermostat
|
|
|
|
|
|
|
|
# Check compatibility from HMDevice
|
|
|
|
if not super()._check_hm_to_ha_object():
|
|
|
|
return False
|
|
|
|
|
|
|
|
# Check if the homematic device correct for this HA device
|
|
|
|
if isinstance(self._hmdevice, pyHMThermostat):
|
|
|
|
return True
|
|
|
|
|
|
|
|
_LOGGER.critical("This %s can't be use as thermostat", self._name)
|
|
|
|
return False
|
|
|
|
|
|
|
|
def _init_data_struct(self):
|
|
|
|
"""Generate a data dict (self._data) from hm metadata."""
|
|
|
|
super()._init_data_struct()
|
|
|
|
|
|
|
|
# Add state to data dict
|
|
|
|
self._data.update({"CONTROL_MODE": STATE_UNKNOWN,
|
|
|
|
"SET_TEMPERATURE": STATE_UNKNOWN,
|
|
|
|
"ACTUAL_TEMPERATURE": STATE_UNKNOWN})
|