2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Spider thermostats."""
|
2018-07-25 09:51:48 +00:00
|
|
|
|
|
|
|
import logging
|
|
|
|
|
2019-02-14 19:34:43 +00:00
|
|
|
from homeassistant.components.climate import ClimateDevice
|
|
|
|
from homeassistant.components.climate.const import (
|
2019-03-21 05:56:46 +00:00
|
|
|
STATE_COOL, STATE_HEAT, STATE_IDLE, SUPPORT_FAN_MODE,
|
|
|
|
SUPPORT_OPERATION_MODE, SUPPORT_TARGET_TEMPERATURE)
|
2019-02-14 19:34:43 +00:00
|
|
|
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
2018-07-25 09:51:48 +00:00
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import DOMAIN as SPIDER_DOMAIN
|
|
|
|
|
2019-02-10 13:54:30 +00:00
|
|
|
FAN_LIST = [
|
|
|
|
'Auto',
|
|
|
|
'Low',
|
|
|
|
'Medium',
|
|
|
|
'High',
|
|
|
|
'Boost 10',
|
|
|
|
'Boost 20',
|
2019-02-13 20:21:14 +00:00
|
|
|
'Boost 30',
|
2019-02-10 13:54:30 +00:00
|
|
|
]
|
|
|
|
|
2018-07-25 09:51:48 +00:00
|
|
|
OPERATION_LIST = [
|
|
|
|
STATE_HEAT,
|
|
|
|
STATE_COOL,
|
|
|
|
]
|
|
|
|
|
|
|
|
HA_STATE_TO_SPIDER = {
|
|
|
|
STATE_COOL: 'Cool',
|
|
|
|
STATE_HEAT: 'Heat',
|
2019-02-13 20:21:14 +00:00
|
|
|
STATE_IDLE: 'Idle',
|
2018-07-25 09:51:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SPIDER_STATE_TO_HA = {value: key for key, value in HA_STATE_TO_SPIDER.items()}
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2018-07-25 09:51:48 +00:00
|
|
|
"""Set up the Spider thermostat."""
|
|
|
|
if discovery_info is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
devices = [SpiderThermostat(hass.data[SPIDER_DOMAIN]['controller'], device)
|
|
|
|
for device in hass.data[SPIDER_DOMAIN]['thermostats']]
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities(devices, True)
|
2018-07-25 09:51:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SpiderThermostat(ClimateDevice):
|
|
|
|
"""Representation of a thermostat."""
|
|
|
|
|
|
|
|
def __init__(self, api, thermostat):
|
|
|
|
"""Initialize the thermostat."""
|
|
|
|
self.api = api
|
|
|
|
self.thermostat = thermostat
|
|
|
|
|
|
|
|
@property
|
|
|
|
def supported_features(self):
|
|
|
|
"""Return the list of supported features."""
|
|
|
|
supports = SUPPORT_TARGET_TEMPERATURE
|
|
|
|
|
|
|
|
if self.thermostat.has_operation_mode:
|
2019-02-10 13:54:30 +00:00
|
|
|
supports |= SUPPORT_OPERATION_MODE
|
|
|
|
|
|
|
|
if self.thermostat.has_fan_mode:
|
|
|
|
supports |= SUPPORT_FAN_MODE
|
2018-07-25 09:51:48 +00:00
|
|
|
|
|
|
|
return supports
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unique_id(self):
|
|
|
|
"""Return the id of the thermostat, if any."""
|
|
|
|
return self.thermostat.id
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the thermostat, if any."""
|
|
|
|
return self.thermostat.name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def temperature_unit(self):
|
|
|
|
"""Return the unit of measurement."""
|
|
|
|
return TEMP_CELSIUS
|
|
|
|
|
|
|
|
@property
|
|
|
|
def current_temperature(self):
|
|
|
|
"""Return the current temperature."""
|
|
|
|
return self.thermostat.current_temperature
|
|
|
|
|
|
|
|
@property
|
|
|
|
def target_temperature(self):
|
|
|
|
"""Return the temperature we try to reach."""
|
|
|
|
return self.thermostat.target_temperature
|
|
|
|
|
|
|
|
@property
|
|
|
|
def target_temperature_step(self):
|
|
|
|
"""Return the supported step of target temperature."""
|
|
|
|
return self.thermostat.temperature_steps
|
|
|
|
|
|
|
|
@property
|
|
|
|
def min_temp(self):
|
|
|
|
"""Return the minimum temperature."""
|
|
|
|
return self.thermostat.minimum_temperature
|
|
|
|
|
|
|
|
@property
|
|
|
|
def max_temp(self):
|
|
|
|
"""Return the maximum temperature."""
|
|
|
|
return self.thermostat.maximum_temperature
|
|
|
|
|
|
|
|
@property
|
|
|
|
def current_operation(self):
|
|
|
|
"""Return current operation ie. heat, cool, idle."""
|
|
|
|
return SPIDER_STATE_TO_HA[self.thermostat.operation_mode]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def operation_list(self):
|
|
|
|
"""Return the list of available operation modes."""
|
|
|
|
return OPERATION_LIST
|
|
|
|
|
|
|
|
def set_temperature(self, **kwargs):
|
|
|
|
"""Set new target temperature."""
|
|
|
|
temperature = kwargs.get(ATTR_TEMPERATURE)
|
|
|
|
if temperature is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
self.thermostat.set_temperature(temperature)
|
|
|
|
|
|
|
|
def set_operation_mode(self, operation_mode):
|
|
|
|
"""Set new target operation mode."""
|
|
|
|
self.thermostat.set_operation_mode(
|
|
|
|
HA_STATE_TO_SPIDER.get(operation_mode))
|
|
|
|
|
2019-02-10 13:54:30 +00:00
|
|
|
@property
|
|
|
|
def current_fan_mode(self):
|
|
|
|
"""Return the fan setting."""
|
|
|
|
return self.thermostat.current_fan_speed
|
|
|
|
|
|
|
|
def set_fan_mode(self, fan_mode):
|
|
|
|
"""Set fan mode."""
|
|
|
|
self.thermostat.set_fan_speed(fan_mode)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def fan_list(self):
|
|
|
|
"""List of available fan modes."""
|
|
|
|
return FAN_LIST
|
|
|
|
|
2018-07-25 09:51:48 +00:00
|
|
|
def update(self):
|
|
|
|
"""Get the latest data."""
|
2018-07-27 04:43:20 +00:00
|
|
|
self.thermostat = self.api.get_thermostat(self.unique_id)
|