mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Merge pull request #503 from toddeye/radiotherm-platform
Add Radio Thermostat platform
This commit is contained in:
commit
b41caa093c
@ -95,6 +95,7 @@ omit =
|
|||||||
homeassistant/components/switch/transmission.py
|
homeassistant/components/switch/transmission.py
|
||||||
homeassistant/components/switch/wemo.py
|
homeassistant/components/switch/wemo.py
|
||||||
homeassistant/components/thermostat/nest.py
|
homeassistant/components/thermostat/nest.py
|
||||||
|
homeassistant/components/thermostat/radiotherm.py
|
||||||
|
|
||||||
|
|
||||||
[report]
|
[report]
|
||||||
|
116
homeassistant/components/thermostat/radiotherm.py
Normal file
116
homeassistant/components/thermostat/radiotherm.py
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
"""
|
||||||
|
homeassistant.components.thermostat.radiotherm
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
Adds support for Radio Thermostat wifi-enabled home thermostats
|
||||||
|
"""
|
||||||
|
import logging
|
||||||
|
import datetime
|
||||||
|
from urllib.error import URLError
|
||||||
|
|
||||||
|
from homeassistant.components.thermostat import (ThermostatDevice, STATE_COOL,
|
||||||
|
STATE_IDLE, STATE_HEAT)
|
||||||
|
from homeassistant.const import (CONF_HOST, TEMP_FAHRENHEIT)
|
||||||
|
|
||||||
|
REQUIREMENTS = ['radiotherm==1.2']
|
||||||
|
|
||||||
|
|
||||||
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
""" Sets up the Radio Thermostat. """
|
||||||
|
import radiotherm
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
hosts = []
|
||||||
|
if CONF_HOST in config:
|
||||||
|
hosts = [config[CONF_HOST]]
|
||||||
|
else:
|
||||||
|
hosts.append(radiotherm.discover.discover_address())
|
||||||
|
|
||||||
|
if hosts is None:
|
||||||
|
logger.error("no radiotherm thermostats detected")
|
||||||
|
return
|
||||||
|
|
||||||
|
tstats = []
|
||||||
|
|
||||||
|
for host in hosts:
|
||||||
|
try:
|
||||||
|
tstat = radiotherm.get_thermostat(host)
|
||||||
|
tstats.append(RadioThermostat(tstat))
|
||||||
|
except (URLError, OSError):
|
||||||
|
logger.exception(
|
||||||
|
"Unable to connect to Radio Thermostat: %s", host)
|
||||||
|
|
||||||
|
add_devices(tstats)
|
||||||
|
|
||||||
|
|
||||||
|
class RadioThermostat(ThermostatDevice):
|
||||||
|
""" Represent a Radio Thermostat. """
|
||||||
|
|
||||||
|
def __init__(self, device):
|
||||||
|
self.device = device
|
||||||
|
self.set_time()
|
||||||
|
self._target_temperature = None
|
||||||
|
self._current_temperature = None
|
||||||
|
self._operation = STATE_IDLE
|
||||||
|
self._name = None
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
""" Returns the name of the Radio Thermostat. """
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unit_of_measurement(self):
|
||||||
|
""" Unit of measurement this thermostat expresses itself in. """
|
||||||
|
return TEMP_FAHRENHEIT
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_state_attributes(self):
|
||||||
|
""" Returns device specific state attributes. """
|
||||||
|
return {
|
||||||
|
"fan": self.device.fmode['human'],
|
||||||
|
"mode": self.device.tmode['human']
|
||||||
|
}
|
||||||
|
|
||||||
|
@property
|
||||||
|
def current_temperature(self):
|
||||||
|
""" Returns the current temperature. """
|
||||||
|
return round(self._current_temperature, 1)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def operation(self):
|
||||||
|
""" Returns current operation. head, cool idle """
|
||||||
|
return self._operation
|
||||||
|
|
||||||
|
@property
|
||||||
|
def target_temperature(self):
|
||||||
|
""" Returns the temperature we try to reach. """
|
||||||
|
|
||||||
|
return round(self._target_temperature, 1)
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
self._current_temperature = self.device.temp['raw']
|
||||||
|
self._name = self.device.name['raw']
|
||||||
|
if self.device.tmode['human'] == 'Cool':
|
||||||
|
self._target_temperature = self.device.t_cool['raw']
|
||||||
|
self._operation = STATE_COOL
|
||||||
|
elif self.device.tmode['human'] == 'Heat':
|
||||||
|
self._target_temperature = self.device.t_heat['raw']
|
||||||
|
self._operation = STATE_HEAT
|
||||||
|
else:
|
||||||
|
self._operation = STATE_IDLE
|
||||||
|
|
||||||
|
def set_temperature(self, temperature):
|
||||||
|
""" Set new target temperature """
|
||||||
|
if self._operation == STATE_COOL:
|
||||||
|
self.device.t_cool = temperature
|
||||||
|
elif self._operation == STATE_HEAT:
|
||||||
|
self.device.t_heat = temperature
|
||||||
|
self.device.hold = 1
|
||||||
|
|
||||||
|
def set_time(self):
|
||||||
|
""" Set device time """
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
self.device.time = {'day': now.weekday(),
|
||||||
|
'hour': now.hour, 'minute': now.minute}
|
@ -147,3 +147,6 @@ python-telegram-bot==2.8.7
|
|||||||
|
|
||||||
# CPUinfo (sensor.cpuinfo)
|
# CPUinfo (sensor.cpuinfo)
|
||||||
py-cpuinfo==0.1.6
|
py-cpuinfo==0.1.6
|
||||||
|
|
||||||
|
# Radio Thermostat (thermostat.radiotherm)
|
||||||
|
radiotherm==1.2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user