2017-08-31 04:13:02 +00:00
|
|
|
"""
|
|
|
|
Support for Tesla HVAC system.
|
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation
|
|
|
|
https://home-assistant.io/components/climate.tesla/
|
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
|
2017-11-29 10:01:28 +00:00
|
|
|
from homeassistant.components.climate import (
|
2018-01-21 06:35:38 +00:00
|
|
|
ENTITY_ID_FORMAT, SUPPORT_OPERATION_MODE, SUPPORT_TARGET_TEMPERATURE,
|
|
|
|
ClimateDevice)
|
|
|
|
from homeassistant.components.tesla import DOMAIN as TESLA_DOMAIN
|
|
|
|
from homeassistant.components.tesla import TeslaDevice
|
2017-08-31 04:13:02 +00:00
|
|
|
from homeassistant.const import (
|
2018-01-21 06:35:38 +00:00
|
|
|
ATTR_TEMPERATURE, STATE_OFF, STATE_ON, TEMP_CELSIUS, TEMP_FAHRENHEIT)
|
2017-08-31 04:13:02 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
DEPENDENCIES = ['tesla']
|
|
|
|
|
|
|
|
OPERATION_LIST = [STATE_ON, STATE_OFF]
|
|
|
|
|
2017-11-29 10:01:28 +00:00
|
|
|
SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_OPERATION_MODE
|
|
|
|
|
2017-08-31 04:13:02 +00:00
|
|
|
|
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
|
|
|
"""Set up the Tesla climate platform."""
|
|
|
|
devices = [TeslaThermostat(device, hass.data[TESLA_DOMAIN]['controller'])
|
|
|
|
for device in hass.data[TESLA_DOMAIN]['devices']['climate']]
|
|
|
|
add_devices(devices, True)
|
|
|
|
|
|
|
|
|
|
|
|
class TeslaThermostat(TeslaDevice, ClimateDevice):
|
|
|
|
"""Representation of a Tesla climate."""
|
|
|
|
|
|
|
|
def __init__(self, tesla_device, controller):
|
|
|
|
"""Initialize the Tesla device."""
|
|
|
|
super().__init__(tesla_device, controller)
|
|
|
|
self.entity_id = ENTITY_ID_FORMAT.format(self.tesla_id)
|
|
|
|
self._target_temperature = None
|
|
|
|
self._temperature = None
|
|
|
|
|
2017-11-29 10:01:28 +00:00
|
|
|
@property
|
|
|
|
def supported_features(self):
|
|
|
|
"""Return the list of supported features."""
|
|
|
|
return SUPPORT_FLAGS
|
|
|
|
|
2017-08-31 04:13:02 +00:00
|
|
|
@property
|
|
|
|
def current_operation(self):
|
|
|
|
"""Return current operation ie. On or Off."""
|
|
|
|
mode = self.tesla_device.is_hvac_enabled()
|
|
|
|
if mode:
|
|
|
|
return OPERATION_LIST[0] # On
|
2018-02-11 17:20:28 +00:00
|
|
|
return OPERATION_LIST[1] # Off
|
2017-08-31 04:13:02 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def operation_list(self):
|
|
|
|
"""List of available operation modes."""
|
|
|
|
return OPERATION_LIST
|
|
|
|
|
|
|
|
def update(self):
|
2018-01-21 06:35:38 +00:00
|
|
|
"""Call by the Tesla device callback to update state."""
|
2017-08-31 04:13:02 +00:00
|
|
|
_LOGGER.debug("Updating: %s", self._name)
|
|
|
|
self.tesla_device.update()
|
|
|
|
self._target_temperature = self.tesla_device.get_goal_temp()
|
|
|
|
self._temperature = self.tesla_device.get_current_temp()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def temperature_unit(self):
|
|
|
|
"""Return the unit of measurement."""
|
|
|
|
tesla_temp_units = self.tesla_device.measurement
|
|
|
|
|
|
|
|
if tesla_temp_units == 'F':
|
|
|
|
return TEMP_FAHRENHEIT
|
|
|
|
return TEMP_CELSIUS
|
|
|
|
|
|
|
|
@property
|
|
|
|
def current_temperature(self):
|
|
|
|
"""Return the current temperature."""
|
|
|
|
return self._temperature
|
|
|
|
|
|
|
|
@property
|
|
|
|
def target_temperature(self):
|
|
|
|
"""Return the temperature we try to reach."""
|
|
|
|
return self._target_temperature
|
|
|
|
|
|
|
|
def set_temperature(self, **kwargs):
|
|
|
|
"""Set new target temperatures."""
|
|
|
|
_LOGGER.debug("Setting temperature for: %s", self._name)
|
|
|
|
temperature = kwargs.get(ATTR_TEMPERATURE)
|
|
|
|
if temperature:
|
|
|
|
self.tesla_device.set_temperature(temperature)
|
|
|
|
|
|
|
|
def set_operation_mode(self, operation_mode):
|
|
|
|
"""Set HVAC mode (auto, cool, heat, off)."""
|
|
|
|
_LOGGER.debug("Setting mode for: %s", self._name)
|
|
|
|
if operation_mode == OPERATION_LIST[1]: # off
|
|
|
|
self.tesla_device.set_status(False)
|
|
|
|
elif operation_mode == OPERATION_LIST[0]: # heat
|
|
|
|
self.tesla_device.set_status(True)
|