core/homeassistant/components/thermostat/heatmiser.py

115 lines
3.2 KiB
Python
Raw Normal View History

2015-12-11 12:45:27 +00:00
"""
2016-03-07 21:44:35 +00:00
Support for the PRT Heatmiser themostats using the V3 protocol.
2015-12-11 12:45:27 +00:00
See https://github.com/andylockran/heatmiserV3 for more info on the
heatmiserV3 module dependency.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/thermostat.heatmiser/
"""
import logging
2016-02-19 05:27:50 +00:00
2015-12-11 12:45:27 +00:00
from homeassistant.components.thermostat import ThermostatDevice
from homeassistant.const import TEMP_CELCIUS
CONF_IPADDRESS = 'ipaddress'
CONF_PORT = 'port'
CONF_TSTATS = 'tstats'
REQUIREMENTS = ["heatmiserV3==0.9.1"]
_LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None):
2016-03-07 21:44:35 +00:00
"""Setup the heatmiser thermostat."""
2015-12-16 22:36:40 +00:00
from heatmiserV3 import heatmiser, connection
2015-12-16 21:52:49 +00:00
2015-12-11 12:45:27 +00:00
ipaddress = str(config[CONF_IPADDRESS])
port = str(config[CONF_PORT])
if ipaddress is None or port is None:
_LOGGER.error("Missing required configuration items %s or %s",
CONF_IPADDRESS, CONF_PORT)
return False
2015-12-16 22:36:40 +00:00
serport = connection.connection(ipaddress, port)
2015-12-11 12:45:27 +00:00
serport.open()
tstats = []
if CONF_TSTATS in config:
tstats = config[CONF_TSTATS]
if tstats is None:
_LOGGER.error("No thermostats configured.")
return False
for tstat in tstats:
add_devices([
HeatmiserV3Thermostat(
2015-12-16 22:36:40 +00:00
heatmiser,
2015-12-11 12:45:27 +00:00
tstat.get("id"),
tstat.get("name"),
serport)
])
return
class HeatmiserV3Thermostat(ThermostatDevice):
2016-03-07 21:44:35 +00:00
"""Representation of a HeatmiserV3 thermostat."""
2015-12-16 22:21:32 +00:00
2015-12-16 22:36:40 +00:00
# pylint: disable=too-many-instance-attributes
def __init__(self, heatmiser, device, name, serport):
2016-03-07 21:44:35 +00:00
"""Initialize the thermostat."""
2015-12-16 22:36:40 +00:00
self.heatmiser = heatmiser
2015-12-11 12:45:27 +00:00
self.device = device
self.serport = serport
self._current_temperature = None
self._name = name
self._id = device
self.dcb = None
self.update()
self._target_temperature = int(self.dcb.get("roomset"))
@property
def name(self):
2016-03-07 21:44:35 +00:00
"""Return the name of the thermostat, if any."""
2015-12-11 12:45:27 +00:00
return self._name
@property
def unit_of_measurement(self):
2016-03-07 21:44:35 +00:00
"""Return the unit of measurement which this thermostat uses."""
2015-12-11 12:45:27 +00:00
return TEMP_CELCIUS
@property
def current_temperature(self):
2016-03-07 21:44:35 +00:00
"""Return the current temperature."""
2015-12-11 12:45:27 +00:00
if self.dcb is not None:
low = self.dcb.get("floortemplow ")
high = self.dcb.get("floortemphigh")
temp = (high*256 + low)/10.0
self._current_temperature = temp
else:
self._current_temperature = None
return self._current_temperature
@property
def target_temperature(self):
2016-03-07 21:44:35 +00:00
"""Return the temperature we try to reach."""
2015-12-11 12:45:27 +00:00
return self._target_temperature
def set_temperature(self, temperature):
2016-03-07 21:44:35 +00:00
"""Set new target temperature."""
2015-12-11 12:45:27 +00:00
temperature = int(temperature)
2015-12-16 22:21:32 +00:00
self.heatmiser.hmSendAddress(
2015-12-11 12:45:27 +00:00
self._id,
18,
temperature,
1,
self.serport)
self._target_temperature = int(temperature)
def update(self):
2016-03-07 21:44:35 +00:00
"""Get the latest data."""
self.dcb = self.heatmiser.hmReadAddress(self._id, 'prt', self.serport)