2019-04-03 15:40:03 +00:00
|
|
|
"""Support for MQTT climate devices."""
|
2017-09-30 14:29:40 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
import voluptuous as vol
|
|
|
|
|
2019-01-27 17:54:52 +00:00
|
|
|
from homeassistant.components import climate, mqtt
|
2017-09-30 14:29:40 +00:00
|
|
|
from homeassistant.components.climate import (
|
2019-03-21 05:56:46 +00:00
|
|
|
PLATFORM_SCHEMA as CLIMATE_PLATFORM_SCHEMA, ClimateDevice)
|
2019-02-14 19:34:43 +00:00
|
|
|
from homeassistant.components.climate.const import (
|
2019-03-21 05:56:46 +00:00
|
|
|
ATTR_OPERATION_MODE, DEFAULT_MAX_TEMP, DEFAULT_MIN_TEMP, STATE_AUTO,
|
|
|
|
STATE_COOL, STATE_DRY, STATE_FAN_ONLY, STATE_HEAT, SUPPORT_AUX_HEAT,
|
|
|
|
SUPPORT_AWAY_MODE, SUPPORT_FAN_MODE, SUPPORT_HOLD_MODE,
|
2019-04-08 13:28:42 +00:00
|
|
|
SUPPORT_OPERATION_MODE, SUPPORT_SWING_MODE, SUPPORT_TARGET_TEMPERATURE,
|
|
|
|
ATTR_TARGET_TEMP_LOW,
|
|
|
|
ATTR_TARGET_TEMP_HIGH, SUPPORT_TARGET_TEMPERATURE_LOW,
|
|
|
|
SUPPORT_TARGET_TEMPERATURE_HIGH)
|
2019-01-27 17:54:52 +00:00
|
|
|
from homeassistant.components.fan import SPEED_HIGH, SPEED_LOW, SPEED_MEDIUM
|
|
|
|
from homeassistant.const import (
|
|
|
|
ATTR_TEMPERATURE, CONF_DEVICE, CONF_NAME, CONF_VALUE_TEMPLATE, STATE_OFF,
|
|
|
|
STATE_ON)
|
|
|
|
from homeassistant.core import callback
|
2017-09-30 14:29:40 +00:00
|
|
|
import homeassistant.helpers.config_validation as cv
|
2018-09-28 14:57:17 +00:00
|
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
2019-01-27 17:54:52 +00:00
|
|
|
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import (
|
2019-04-14 03:25:45 +00:00
|
|
|
ATTR_DISCOVERY_HASH, CONF_QOS, CONF_RETAIN, CONF_UNIQUE_ID,
|
|
|
|
MQTT_BASE_PLATFORM_SCHEMA, MqttAttributes, MqttAvailability,
|
|
|
|
MqttDiscoveryUpdate, MqttEntityDeviceInfo, subscription)
|
2019-03-21 05:56:46 +00:00
|
|
|
from .discovery import MQTT_DISCOVERY_NEW, clear_discovery_hash
|
|
|
|
|
2017-09-30 14:29:40 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
DEFAULT_NAME = 'MQTT HVAC'
|
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
CONF_AUX_COMMAND_TOPIC = 'aux_command_topic'
|
|
|
|
CONF_AUX_STATE_TEMPLATE = 'aux_state_template'
|
|
|
|
CONF_AUX_STATE_TOPIC = 'aux_state_topic'
|
2017-09-30 14:29:40 +00:00
|
|
|
CONF_AWAY_MODE_COMMAND_TOPIC = 'away_mode_command_topic'
|
2018-01-14 11:55:19 +00:00
|
|
|
CONF_AWAY_MODE_STATE_TEMPLATE = 'away_mode_state_template'
|
2019-04-14 03:34:39 +00:00
|
|
|
CONF_AWAY_MODE_STATE_TOPIC = 'away_mode_state_topic'
|
|
|
|
CONF_CURRENT_TEMP_TEMPLATE = 'current_temperature_template'
|
|
|
|
CONF_CURRENT_TEMP_TOPIC = 'current_temperature_topic'
|
|
|
|
CONF_FAN_MODE_COMMAND_TOPIC = 'fan_mode_command_topic'
|
|
|
|
CONF_FAN_MODE_LIST = 'fan_modes'
|
|
|
|
CONF_FAN_MODE_STATE_TEMPLATE = 'fan_mode_state_template'
|
|
|
|
CONF_FAN_MODE_STATE_TOPIC = 'fan_mode_state_topic'
|
2017-09-30 14:29:40 +00:00
|
|
|
CONF_HOLD_COMMAND_TOPIC = 'hold_command_topic'
|
2018-01-14 11:55:19 +00:00
|
|
|
CONF_HOLD_STATE_TEMPLATE = 'hold_state_template'
|
2019-04-14 03:34:39 +00:00
|
|
|
CONF_HOLD_STATE_TOPIC = 'hold_state_topic'
|
|
|
|
CONF_MODE_COMMAND_TOPIC = 'mode_command_topic'
|
2017-09-30 14:29:40 +00:00
|
|
|
CONF_MODE_LIST = 'modes'
|
2019-04-14 03:34:39 +00:00
|
|
|
CONF_MODE_STATE_TEMPLATE = 'mode_state_template'
|
|
|
|
CONF_MODE_STATE_TOPIC = 'mode_state_topic'
|
|
|
|
CONF_PAYLOAD_OFF = 'payload_off'
|
|
|
|
CONF_PAYLOAD_ON = 'payload_on'
|
|
|
|
CONF_POWER_COMMAND_TOPIC = 'power_command_topic'
|
|
|
|
CONF_POWER_STATE_TEMPLATE = 'power_state_template'
|
|
|
|
CONF_POWER_STATE_TOPIC = 'power_state_topic'
|
2017-09-30 14:29:40 +00:00
|
|
|
CONF_SEND_IF_OFF = 'send_if_off'
|
2019-04-14 03:34:39 +00:00
|
|
|
CONF_SWING_MODE_COMMAND_TOPIC = 'swing_mode_command_topic'
|
|
|
|
CONF_SWING_MODE_LIST = 'swing_modes'
|
|
|
|
CONF_SWING_MODE_STATE_TEMPLATE = 'swing_mode_state_template'
|
|
|
|
CONF_SWING_MODE_STATE_TOPIC = 'swing_mode_state_topic'
|
|
|
|
CONF_TEMP_COMMAND_TOPIC = 'temperature_command_topic'
|
|
|
|
CONF_TEMP_HIGH_COMMAND_TOPIC = 'temperature_high_command_topic'
|
|
|
|
CONF_TEMP_HIGH_STATE_TEMPLATE = 'temperature_high_state_template'
|
|
|
|
CONF_TEMP_HIGH_STATE_TOPIC = 'temperature_high_state_topic'
|
|
|
|
CONF_TEMP_LOW_COMMAND_TOPIC = 'temperature_low_command_topic'
|
|
|
|
CONF_TEMP_LOW_STATE_TEMPLATE = 'temperature_low_state_template'
|
|
|
|
CONF_TEMP_LOW_STATE_TOPIC = 'temperature_low_state_topic'
|
|
|
|
CONF_TEMP_STATE_TEMPLATE = 'temperature_state_template'
|
|
|
|
CONF_TEMP_STATE_TOPIC = 'temperature_state_topic'
|
2019-04-07 14:00:40 +00:00
|
|
|
CONF_TEMP_INITIAL = 'initial'
|
|
|
|
CONF_TEMP_MAX = 'max_temp'
|
2019-04-14 03:34:39 +00:00
|
|
|
CONF_TEMP_MIN = 'min_temp'
|
2018-10-08 18:24:25 +00:00
|
|
|
CONF_TEMP_STEP = 'temp_step'
|
2018-06-07 17:50:12 +00:00
|
|
|
|
2018-11-24 09:40:07 +00:00
|
|
|
TEMPLATE_KEYS = (
|
2019-04-14 03:34:39 +00:00
|
|
|
CONF_AUX_STATE_TEMPLATE,
|
2018-11-24 09:40:07 +00:00
|
|
|
CONF_AWAY_MODE_STATE_TEMPLATE,
|
2019-04-14 03:34:39 +00:00
|
|
|
CONF_CURRENT_TEMP_TEMPLATE,
|
|
|
|
CONF_FAN_MODE_STATE_TEMPLATE,
|
2018-11-24 09:40:07 +00:00
|
|
|
CONF_HOLD_STATE_TEMPLATE,
|
2019-04-14 03:34:39 +00:00
|
|
|
CONF_MODE_STATE_TEMPLATE,
|
|
|
|
CONF_POWER_STATE_TEMPLATE,
|
|
|
|
CONF_SWING_MODE_STATE_TEMPLATE,
|
|
|
|
CONF_TEMP_HIGH_STATE_TEMPLATE,
|
|
|
|
CONF_TEMP_LOW_STATE_TEMPLATE,
|
|
|
|
CONF_TEMP_STATE_TEMPLATE,
|
|
|
|
)
|
|
|
|
|
|
|
|
TOPIC_KEYS = (
|
|
|
|
CONF_AUX_COMMAND_TOPIC,
|
|
|
|
CONF_AUX_STATE_TOPIC,
|
|
|
|
CONF_AWAY_MODE_COMMAND_TOPIC,
|
|
|
|
CONF_AWAY_MODE_STATE_TOPIC,
|
|
|
|
CONF_CURRENT_TEMP_TOPIC,
|
|
|
|
CONF_FAN_MODE_COMMAND_TOPIC,
|
|
|
|
CONF_FAN_MODE_STATE_TOPIC,
|
|
|
|
CONF_HOLD_COMMAND_TOPIC,
|
|
|
|
CONF_HOLD_STATE_TOPIC,
|
|
|
|
CONF_MODE_COMMAND_TOPIC,
|
|
|
|
CONF_MODE_STATE_TOPIC,
|
|
|
|
CONF_POWER_COMMAND_TOPIC,
|
|
|
|
CONF_POWER_STATE_TOPIC,
|
|
|
|
CONF_SWING_MODE_COMMAND_TOPIC,
|
|
|
|
CONF_SWING_MODE_STATE_TOPIC,
|
|
|
|
CONF_TEMP_COMMAND_TOPIC,
|
|
|
|
CONF_TEMP_HIGH_COMMAND_TOPIC,
|
|
|
|
CONF_TEMP_HIGH_STATE_TOPIC,
|
|
|
|
CONF_TEMP_LOW_COMMAND_TOPIC,
|
|
|
|
CONF_TEMP_LOW_STATE_TOPIC,
|
|
|
|
CONF_TEMP_STATE_TOPIC,
|
2018-11-24 09:40:07 +00:00
|
|
|
)
|
|
|
|
|
2017-10-13 05:00:09 +00:00
|
|
|
SCHEMA_BASE = CLIMATE_PLATFORM_SCHEMA.extend(MQTT_BASE_PLATFORM_SCHEMA.schema)
|
|
|
|
PLATFORM_SCHEMA = SCHEMA_BASE.extend({
|
2017-09-30 14:29:40 +00:00
|
|
|
vol.Optional(CONF_AUX_COMMAND_TOPIC): mqtt.valid_publish_topic,
|
2019-04-07 14:00:40 +00:00
|
|
|
vol.Optional(CONF_AUX_STATE_TEMPLATE): cv.template,
|
2017-09-30 14:29:40 +00:00
|
|
|
vol.Optional(CONF_AUX_STATE_TOPIC): mqtt.valid_subscribe_topic,
|
2019-04-07 14:00:40 +00:00
|
|
|
vol.Optional(CONF_AWAY_MODE_COMMAND_TOPIC): mqtt.valid_publish_topic,
|
2018-01-14 11:55:19 +00:00
|
|
|
vol.Optional(CONF_AWAY_MODE_STATE_TEMPLATE): cv.template,
|
2019-04-07 14:00:40 +00:00
|
|
|
vol.Optional(CONF_AWAY_MODE_STATE_TOPIC): mqtt.valid_subscribe_topic,
|
2019-04-14 03:34:39 +00:00
|
|
|
vol.Optional(CONF_CURRENT_TEMP_TEMPLATE): cv.template,
|
|
|
|
vol.Optional(CONF_CURRENT_TEMP_TOPIC): mqtt.valid_subscribe_topic,
|
2019-04-07 14:00:40 +00:00
|
|
|
vol.Optional(CONF_DEVICE): mqtt.MQTT_ENTITY_DEVICE_INFO_SCHEMA,
|
|
|
|
vol.Optional(CONF_FAN_MODE_COMMAND_TOPIC): mqtt.valid_publish_topic,
|
2017-09-30 14:29:40 +00:00
|
|
|
vol.Optional(CONF_FAN_MODE_LIST,
|
|
|
|
default=[STATE_AUTO, SPEED_LOW,
|
|
|
|
SPEED_MEDIUM, SPEED_HIGH]): cv.ensure_list,
|
2019-04-07 14:00:40 +00:00
|
|
|
vol.Optional(CONF_FAN_MODE_STATE_TEMPLATE): cv.template,
|
|
|
|
vol.Optional(CONF_FAN_MODE_STATE_TOPIC): mqtt.valid_subscribe_topic,
|
|
|
|
vol.Optional(CONF_HOLD_COMMAND_TOPIC): mqtt.valid_publish_topic,
|
|
|
|
vol.Optional(CONF_HOLD_STATE_TEMPLATE): cv.template,
|
|
|
|
vol.Optional(CONF_HOLD_STATE_TOPIC): mqtt.valid_subscribe_topic,
|
|
|
|
vol.Optional(CONF_MODE_COMMAND_TOPIC): mqtt.valid_publish_topic,
|
2017-09-30 14:29:40 +00:00
|
|
|
vol.Optional(CONF_MODE_LIST,
|
|
|
|
default=[STATE_AUTO, STATE_OFF, STATE_COOL, STATE_HEAT,
|
|
|
|
STATE_DRY, STATE_FAN_ONLY]): cv.ensure_list,
|
2019-04-07 14:00:40 +00:00
|
|
|
vol.Optional(CONF_MODE_STATE_TEMPLATE): cv.template,
|
|
|
|
vol.Optional(CONF_MODE_STATE_TOPIC): mqtt.valid_subscribe_topic,
|
2017-09-30 14:29:40 +00:00
|
|
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
|
|
|
vol.Optional(CONF_PAYLOAD_ON, default="ON"): cv.string,
|
|
|
|
vol.Optional(CONF_PAYLOAD_OFF, default="OFF"): cv.string,
|
2019-04-07 14:00:40 +00:00
|
|
|
vol.Optional(CONF_POWER_COMMAND_TOPIC): mqtt.valid_publish_topic,
|
|
|
|
vol.Optional(CONF_POWER_STATE_TEMPLATE): cv.template,
|
|
|
|
vol.Optional(CONF_POWER_STATE_TOPIC): mqtt.valid_subscribe_topic,
|
|
|
|
vol.Optional(CONF_RETAIN, default=mqtt.DEFAULT_RETAIN): cv.boolean,
|
|
|
|
vol.Optional(CONF_SEND_IF_OFF, default=True): cv.boolean,
|
|
|
|
vol.Optional(CONF_SWING_MODE_COMMAND_TOPIC): mqtt.valid_publish_topic,
|
|
|
|
vol.Optional(CONF_SWING_MODE_LIST,
|
|
|
|
default=[STATE_ON, STATE_OFF]): cv.ensure_list,
|
|
|
|
vol.Optional(CONF_SWING_MODE_STATE_TEMPLATE): cv.template,
|
|
|
|
vol.Optional(CONF_SWING_MODE_STATE_TOPIC): mqtt.valid_subscribe_topic,
|
|
|
|
vol.Optional(CONF_TEMP_INITIAL, default=21): cv.positive_int,
|
|
|
|
vol.Optional(CONF_TEMP_MIN, default=DEFAULT_MIN_TEMP): vol.Coerce(float),
|
|
|
|
vol.Optional(CONF_TEMP_MAX, default=DEFAULT_MAX_TEMP): vol.Coerce(float),
|
2018-12-15 16:28:08 +00:00
|
|
|
vol.Optional(CONF_TEMP_STEP, default=1.0): vol.Coerce(float),
|
2019-04-14 03:34:39 +00:00
|
|
|
vol.Optional(CONF_TEMP_COMMAND_TOPIC): mqtt.valid_publish_topic,
|
|
|
|
vol.Optional(CONF_TEMP_HIGH_COMMAND_TOPIC): mqtt.valid_publish_topic,
|
|
|
|
vol.Optional(CONF_TEMP_HIGH_STATE_TOPIC): mqtt.valid_subscribe_topic,
|
|
|
|
vol.Optional(CONF_TEMP_LOW_COMMAND_TOPIC): mqtt.valid_publish_topic,
|
|
|
|
vol.Optional(CONF_TEMP_LOW_STATE_TOPIC): mqtt.valid_subscribe_topic,
|
|
|
|
vol.Optional(CONF_TEMP_STATE_TEMPLATE): cv.template,
|
|
|
|
vol.Optional(CONF_TEMP_STATE_TOPIC): mqtt.valid_subscribe_topic,
|
2018-12-15 16:28:08 +00:00
|
|
|
vol.Optional(CONF_UNIQUE_ID): cv.string,
|
2019-04-07 14:00:40 +00:00
|
|
|
vol.Optional(CONF_VALUE_TEMPLATE): cv.template,
|
2019-01-21 00:42:35 +00:00
|
|
|
}).extend(mqtt.MQTT_AVAILABILITY_SCHEMA.schema).extend(
|
|
|
|
mqtt.MQTT_JSON_ATTRS_SCHEMA.schema)
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
|
2018-09-28 14:57:17 +00:00
|
|
|
async def async_setup_platform(hass: HomeAssistantType, config: ConfigType,
|
|
|
|
async_add_entities, discovery_info=None):
|
|
|
|
"""Set up MQTT climate device through configuration.yaml."""
|
|
|
|
await _async_setup_entity(hass, config, async_add_entities)
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
|
|
"""Set up MQTT climate device dynamically through MQTT discovery."""
|
|
|
|
async def async_discover(discovery_payload):
|
|
|
|
"""Discover and add a MQTT climate device."""
|
2019-01-08 15:53:02 +00:00
|
|
|
try:
|
2019-02-05 05:52:19 +00:00
|
|
|
discovery_hash = discovery_payload.pop(ATTR_DISCOVERY_HASH)
|
2019-01-08 15:53:02 +00:00
|
|
|
config = PLATFORM_SCHEMA(discovery_payload)
|
|
|
|
await _async_setup_entity(hass, config, async_add_entities,
|
2019-01-01 10:12:40 +00:00
|
|
|
config_entry, discovery_hash)
|
2019-01-08 15:53:02 +00:00
|
|
|
except Exception:
|
|
|
|
if discovery_hash:
|
|
|
|
clear_discovery_hash(hass, discovery_hash)
|
|
|
|
raise
|
2018-09-28 14:57:17 +00:00
|
|
|
|
|
|
|
async_dispatcher_connect(
|
|
|
|
hass, MQTT_DISCOVERY_NEW.format(climate.DOMAIN, 'mqtt'),
|
|
|
|
async_discover)
|
2018-06-25 13:13:19 +00:00
|
|
|
|
2018-09-28 14:57:17 +00:00
|
|
|
|
|
|
|
async def _async_setup_entity(hass, config, async_add_entities,
|
2019-01-01 10:12:40 +00:00
|
|
|
config_entry=None, discovery_hash=None):
|
2018-09-28 14:57:17 +00:00
|
|
|
"""Set up the MQTT climate devices."""
|
2019-01-01 10:12:40 +00:00
|
|
|
async_add_entities([MqttClimate(hass, config, config_entry,
|
|
|
|
discovery_hash,)])
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
|
2019-01-21 00:42:35 +00:00
|
|
|
class MqttClimate(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
|
|
|
|
MqttEntityDeviceInfo, ClimateDevice):
|
2018-06-07 17:50:12 +00:00
|
|
|
"""Representation of an MQTT climate device."""
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2019-01-01 10:12:40 +00:00
|
|
|
def __init__(self, hass, config, config_entry, discovery_hash):
|
2017-09-30 14:29:40 +00:00
|
|
|
"""Initialize the climate device."""
|
2018-11-24 09:40:07 +00:00
|
|
|
self._config = config
|
2018-12-15 16:28:08 +00:00
|
|
|
self._unique_id = config.get(CONF_UNIQUE_ID)
|
2018-11-24 09:40:07 +00:00
|
|
|
self._sub_state = None
|
|
|
|
|
2017-09-30 14:29:40 +00:00
|
|
|
self.hass = hass
|
2019-04-14 03:34:39 +00:00
|
|
|
self._aux = False
|
|
|
|
self._away = False
|
2018-11-24 09:40:07 +00:00
|
|
|
self._current_fan_mode = None
|
|
|
|
self._current_operation = None
|
|
|
|
self._current_swing_mode = None
|
2019-04-14 03:34:39 +00:00
|
|
|
self._current_temp = None
|
2018-11-24 09:40:07 +00:00
|
|
|
self._hold = None
|
2019-04-14 03:34:39 +00:00
|
|
|
self._target_temp = None
|
|
|
|
self._target_temp_high = None
|
|
|
|
self._target_temp_low = None
|
|
|
|
self._topic = None
|
|
|
|
self._unit_of_measurement = hass.config.units.temperature_unit
|
|
|
|
self._value_templates = None
|
2018-12-02 09:30:07 +00:00
|
|
|
|
2018-11-24 09:40:07 +00:00
|
|
|
self._setup_from_config(config)
|
|
|
|
|
2018-12-15 16:28:08 +00:00
|
|
|
device_config = config.get(CONF_DEVICE)
|
2018-11-24 09:40:07 +00:00
|
|
|
|
2019-01-21 00:42:35 +00:00
|
|
|
MqttAttributes.__init__(self, config)
|
2019-01-15 22:26:37 +00:00
|
|
|
MqttAvailability.__init__(self, config)
|
2018-11-24 09:40:07 +00:00
|
|
|
MqttDiscoveryUpdate.__init__(self, discovery_hash,
|
|
|
|
self.discovery_update)
|
2019-01-01 10:12:40 +00:00
|
|
|
MqttEntityDeviceInfo.__init__(self, device_config, config_entry)
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2018-10-01 06:50:05 +00:00
|
|
|
async def async_added_to_hass(self):
|
2017-09-30 14:29:40 +00:00
|
|
|
"""Handle being added to home assistant."""
|
2018-11-28 12:16:43 +00:00
|
|
|
await super().async_added_to_hass()
|
2018-11-24 09:40:07 +00:00
|
|
|
await self._subscribe_topics()
|
|
|
|
|
|
|
|
async def discovery_update(self, discovery_payload):
|
|
|
|
"""Handle updated discovery message."""
|
|
|
|
config = PLATFORM_SCHEMA(discovery_payload)
|
2018-12-02 09:30:07 +00:00
|
|
|
self._config = config
|
2018-11-24 09:40:07 +00:00
|
|
|
self._setup_from_config(config)
|
2019-01-21 00:42:35 +00:00
|
|
|
await self.attributes_discovery_update(config)
|
2018-11-24 09:40:07 +00:00
|
|
|
await self.availability_discovery_update(config)
|
2019-01-01 10:12:40 +00:00
|
|
|
await self.device_info_discovery_update(config)
|
2018-11-24 09:40:07 +00:00
|
|
|
await self._subscribe_topics()
|
2019-03-12 21:46:48 +00:00
|
|
|
self.async_write_ha_state()
|
2018-11-24 09:40:07 +00:00
|
|
|
|
|
|
|
def _setup_from_config(self, config):
|
|
|
|
"""(Re)Setup the entity."""
|
|
|
|
self._topic = {
|
2019-04-14 03:34:39 +00:00
|
|
|
key: config.get(key) for key in TOPIC_KEYS
|
2018-11-24 09:40:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# set to None in non-optimistic mode
|
2019-04-14 03:34:39 +00:00
|
|
|
self._target_temp = self._current_fan_mode = \
|
2018-11-24 09:40:07 +00:00
|
|
|
self._current_operation = self._current_swing_mode = None
|
2019-04-14 03:34:39 +00:00
|
|
|
self._target_temp_low = None
|
|
|
|
self._target_temp_high = None
|
2019-04-08 13:28:42 +00:00
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
if self._topic[CONF_TEMP_STATE_TOPIC] is None:
|
|
|
|
self._target_temp = config[CONF_TEMP_INITIAL]
|
|
|
|
if self._topic[CONF_TEMP_LOW_STATE_TOPIC] is None:
|
|
|
|
self._target_temp_low = config[CONF_TEMP_INITIAL]
|
|
|
|
if self._topic[CONF_TEMP_HIGH_STATE_TOPIC] is None:
|
|
|
|
self._target_temp_high = config[CONF_TEMP_INITIAL]
|
2019-04-08 13:28:42 +00:00
|
|
|
|
2018-11-24 09:40:07 +00:00
|
|
|
if self._topic[CONF_FAN_MODE_STATE_TOPIC] is None:
|
|
|
|
self._current_fan_mode = SPEED_LOW
|
|
|
|
if self._topic[CONF_SWING_MODE_STATE_TOPIC] is None:
|
|
|
|
self._current_swing_mode = STATE_OFF
|
|
|
|
if self._topic[CONF_MODE_STATE_TOPIC] is None:
|
|
|
|
self._current_operation = STATE_OFF
|
|
|
|
self._away = False
|
|
|
|
self._hold = None
|
|
|
|
self._aux = False
|
|
|
|
|
|
|
|
value_templates = {}
|
2019-04-14 03:34:39 +00:00
|
|
|
for key in TEMPLATE_KEYS:
|
|
|
|
value_templates[key] = lambda value: value
|
2018-11-24 09:40:07 +00:00
|
|
|
if CONF_VALUE_TEMPLATE in config:
|
|
|
|
value_template = config.get(CONF_VALUE_TEMPLATE)
|
|
|
|
value_template.hass = self.hass
|
2019-04-14 03:34:39 +00:00
|
|
|
value_templates = {
|
|
|
|
key: value_template.async_render_with_possible_json_value
|
|
|
|
for key in TEMPLATE_KEYS}
|
2018-11-24 09:40:07 +00:00
|
|
|
for key in TEMPLATE_KEYS & config.keys():
|
2019-04-14 03:34:39 +00:00
|
|
|
tpl = config[key]
|
|
|
|
value_templates[key] = tpl.async_render_with_possible_json_value
|
|
|
|
tpl.hass = self.hass
|
2018-11-24 09:40:07 +00:00
|
|
|
self._value_templates = value_templates
|
|
|
|
|
|
|
|
async def _subscribe_topics(self):
|
|
|
|
"""(Re)Subscribe to topics."""
|
|
|
|
topics = {}
|
2019-04-07 14:00:40 +00:00
|
|
|
qos = self._config[CONF_QOS]
|
2018-01-02 02:32:29 +00:00
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
def add_subscription(topics, topic, msg_callback):
|
|
|
|
if self._topic[topic] is not None:
|
|
|
|
topics[topic] = {
|
|
|
|
'topic': self._topic[topic],
|
|
|
|
'msg_callback': msg_callback,
|
|
|
|
'qos': qos}
|
|
|
|
|
|
|
|
def render_template(msg, template_name):
|
|
|
|
template = self._value_templates[template_name]
|
|
|
|
return template(msg.payload)
|
|
|
|
|
2017-09-30 14:29:40 +00:00
|
|
|
@callback
|
2019-04-14 03:34:39 +00:00
|
|
|
def handle_temperature_received(msg, template_name, attr):
|
|
|
|
"""Handle temperature coming via MQTT."""
|
|
|
|
payload = render_template(msg, template_name)
|
2018-01-14 11:55:19 +00:00
|
|
|
|
2017-09-30 14:29:40 +00:00
|
|
|
try:
|
2019-04-14 03:34:39 +00:00
|
|
|
setattr(self, attr, float(payload))
|
2019-03-12 21:46:48 +00:00
|
|
|
self.async_write_ha_state()
|
2017-09-30 14:29:40 +00:00
|
|
|
except ValueError:
|
|
|
|
_LOGGER.error("Could not parse temperature from %s", payload)
|
|
|
|
|
|
|
|
@callback
|
2019-04-14 03:34:39 +00:00
|
|
|
def handle_current_temperature_received(msg):
|
|
|
|
"""Handle current temperature coming via MQTT."""
|
|
|
|
handle_temperature_received(
|
|
|
|
msg, CONF_CURRENT_TEMP_TEMPLATE, '_current_temp')
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
add_subscription(topics, CONF_CURRENT_TEMP_TOPIC,
|
|
|
|
handle_current_temperature_received)
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
@callback
|
2019-04-14 03:34:39 +00:00
|
|
|
def handle_target_temperature_received(msg):
|
2017-09-30 14:29:40 +00:00
|
|
|
"""Handle target temperature coming via MQTT."""
|
2019-04-14 03:34:39 +00:00
|
|
|
handle_temperature_received(
|
|
|
|
msg, CONF_TEMP_STATE_TEMPLATE, '_target_temp')
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
add_subscription(topics, CONF_TEMP_STATE_TOPIC,
|
|
|
|
handle_target_temperature_received)
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2019-04-08 13:28:42 +00:00
|
|
|
@callback
|
|
|
|
def handle_temperature_low_received(msg):
|
|
|
|
"""Handle target temperature low coming via MQTT."""
|
2019-04-14 03:34:39 +00:00
|
|
|
handle_temperature_received(
|
|
|
|
msg, CONF_TEMP_LOW_STATE_TEMPLATE, '_target_temp_low')
|
2019-04-08 13:28:42 +00:00
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
add_subscription(topics, CONF_TEMP_LOW_STATE_TOPIC,
|
|
|
|
handle_temperature_low_received)
|
2019-04-08 13:28:42 +00:00
|
|
|
|
|
|
|
@callback
|
|
|
|
def handle_temperature_high_received(msg):
|
|
|
|
"""Handle target temperature high coming via MQTT."""
|
2019-04-14 03:34:39 +00:00
|
|
|
handle_temperature_received(
|
|
|
|
msg, CONF_TEMP_HIGH_STATE_TEMPLATE, '_target_temp_high')
|
|
|
|
|
|
|
|
add_subscription(topics, CONF_TEMP_HIGH_STATE_TOPIC,
|
|
|
|
handle_temperature_high_received)
|
|
|
|
|
|
|
|
@callback
|
|
|
|
def handle_mode_received(msg, template_name, attr, mode_list):
|
|
|
|
"""Handle receiving listed mode via MQTT."""
|
|
|
|
payload = render_template(msg, template_name)
|
|
|
|
|
|
|
|
if payload not in self._config[mode_list]:
|
|
|
|
_LOGGER.error("Invalid %s mode: %s", mode_list, payload)
|
|
|
|
else:
|
|
|
|
setattr(self, attr, payload)
|
2019-04-08 13:28:42 +00:00
|
|
|
self.async_write_ha_state()
|
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
@callback
|
|
|
|
def handle_current_mode_received(msg):
|
|
|
|
"""Handle receiving mode via MQTT."""
|
|
|
|
handle_mode_received(msg, CONF_MODE_STATE_TEMPLATE,
|
|
|
|
'_current_operation', CONF_MODE_LIST)
|
|
|
|
|
|
|
|
add_subscription(topics, CONF_MODE_STATE_TOPIC,
|
|
|
|
handle_current_mode_received)
|
2019-04-08 13:28:42 +00:00
|
|
|
|
2017-09-30 14:29:40 +00:00
|
|
|
@callback
|
2019-03-13 19:58:20 +00:00
|
|
|
def handle_fan_mode_received(msg):
|
2017-09-30 14:29:40 +00:00
|
|
|
"""Handle receiving fan mode via MQTT."""
|
2019-04-14 03:34:39 +00:00
|
|
|
handle_mode_received(msg, CONF_FAN_MODE_STATE_TEMPLATE,
|
|
|
|
'_current_fan_mode', CONF_FAN_MODE_LIST)
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
add_subscription(topics, CONF_FAN_MODE_STATE_TOPIC,
|
|
|
|
handle_fan_mode_received)
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
@callback
|
2019-03-13 19:58:20 +00:00
|
|
|
def handle_swing_mode_received(msg):
|
2017-09-30 14:29:40 +00:00
|
|
|
"""Handle receiving swing mode via MQTT."""
|
2019-04-14 03:34:39 +00:00
|
|
|
handle_mode_received(msg, CONF_SWING_MODE_STATE_TEMPLATE,
|
|
|
|
'_current_swing_mode', CONF_SWING_MODE_LIST)
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
add_subscription(topics, CONF_SWING_MODE_STATE_TOPIC,
|
|
|
|
handle_swing_mode_received)
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
@callback
|
2019-04-14 03:34:39 +00:00
|
|
|
def handle_onoff_mode_received(msg, template_name, attr):
|
|
|
|
"""Handle receiving on/off mode via MQTT."""
|
|
|
|
payload = render_template(msg, template_name)
|
2019-04-07 14:00:40 +00:00
|
|
|
payload_on = self._config[CONF_PAYLOAD_ON]
|
|
|
|
payload_off = self._config[CONF_PAYLOAD_OFF]
|
2019-04-14 03:34:39 +00:00
|
|
|
|
|
|
|
if payload == "True":
|
|
|
|
payload = payload_on
|
|
|
|
elif payload == "False":
|
|
|
|
payload = payload_off
|
2018-01-14 11:55:19 +00:00
|
|
|
|
2018-12-02 09:30:07 +00:00
|
|
|
if payload == payload_on:
|
2019-04-14 03:34:39 +00:00
|
|
|
setattr(self, attr, True)
|
2018-12-02 09:30:07 +00:00
|
|
|
elif payload == payload_off:
|
2019-04-14 03:34:39 +00:00
|
|
|
setattr(self, attr, False)
|
2017-09-30 14:29:40 +00:00
|
|
|
else:
|
2019-04-14 03:34:39 +00:00
|
|
|
_LOGGER.error("Invalid %s mode: %s", attr, payload)
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2019-03-12 21:46:48 +00:00
|
|
|
self.async_write_ha_state()
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
@callback
|
|
|
|
def handle_away_mode_received(msg):
|
|
|
|
"""Handle receiving away mode via MQTT."""
|
|
|
|
handle_onoff_mode_received(
|
|
|
|
msg, CONF_AWAY_MODE_STATE_TEMPLATE, '_away')
|
|
|
|
|
|
|
|
add_subscription(topics, CONF_AWAY_MODE_STATE_TOPIC,
|
|
|
|
handle_away_mode_received)
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
@callback
|
2019-03-13 19:58:20 +00:00
|
|
|
def handle_aux_mode_received(msg):
|
2017-09-30 14:29:40 +00:00
|
|
|
"""Handle receiving aux mode via MQTT."""
|
2019-04-14 03:34:39 +00:00
|
|
|
handle_onoff_mode_received(
|
|
|
|
msg, CONF_AUX_STATE_TEMPLATE, '_aux')
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
add_subscription(topics, CONF_AUX_STATE_TOPIC,
|
|
|
|
handle_aux_mode_received)
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
@callback
|
2019-03-13 19:58:20 +00:00
|
|
|
def handle_hold_mode_received(msg):
|
2017-09-30 14:29:40 +00:00
|
|
|
"""Handle receiving hold mode via MQTT."""
|
2019-04-14 03:34:39 +00:00
|
|
|
payload = render_template(msg, CONF_HOLD_STATE_TEMPLATE)
|
2018-01-14 11:55:19 +00:00
|
|
|
|
2017-09-30 14:29:40 +00:00
|
|
|
self._hold = payload
|
2019-03-12 21:46:48 +00:00
|
|
|
self.async_write_ha_state()
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
add_subscription(topics, CONF_HOLD_STATE_TOPIC,
|
|
|
|
handle_hold_mode_received)
|
2018-11-24 09:40:07 +00:00
|
|
|
|
|
|
|
self._sub_state = await subscription.async_subscribe_topics(
|
|
|
|
self.hass, self._sub_state,
|
|
|
|
topics)
|
|
|
|
|
|
|
|
async def async_will_remove_from_hass(self):
|
|
|
|
"""Unsubscribe when removed."""
|
2018-12-19 13:05:24 +00:00
|
|
|
self._sub_state = await subscription.async_unsubscribe_topics(
|
|
|
|
self.hass, self._sub_state)
|
2019-01-21 00:42:35 +00:00
|
|
|
await MqttAttributes.async_will_remove_from_hass(self)
|
2018-11-24 09:40:07 +00:00
|
|
|
await MqttAvailability.async_will_remove_from_hass(self)
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def should_poll(self):
|
|
|
|
"""Return the polling state."""
|
|
|
|
return False
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the climate device."""
|
2019-04-07 14:00:40 +00:00
|
|
|
return self._config[CONF_NAME]
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2018-12-15 16:28:08 +00:00
|
|
|
@property
|
|
|
|
def unique_id(self):
|
|
|
|
"""Return a unique ID."""
|
|
|
|
return self._unique_id
|
|
|
|
|
2017-09-30 14:29:40 +00:00
|
|
|
@property
|
|
|
|
def temperature_unit(self):
|
|
|
|
"""Return the unit of measurement."""
|
|
|
|
return self._unit_of_measurement
|
|
|
|
|
|
|
|
@property
|
|
|
|
def current_temperature(self):
|
|
|
|
"""Return the current temperature."""
|
2019-04-14 03:34:39 +00:00
|
|
|
return self._current_temp
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def target_temperature(self):
|
|
|
|
"""Return the temperature we try to reach."""
|
2019-04-14 03:34:39 +00:00
|
|
|
return self._target_temp
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2019-04-08 13:28:42 +00:00
|
|
|
@property
|
|
|
|
def target_temperature_low(self):
|
|
|
|
"""Return the low target temperature we try to reach."""
|
2019-04-14 03:34:39 +00:00
|
|
|
return self._target_temp_low
|
2019-04-08 13:28:42 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def target_temperature_high(self):
|
|
|
|
"""Return the high target temperature we try to reach."""
|
2019-04-14 03:34:39 +00:00
|
|
|
return self._target_temp_high
|
2019-04-08 13:28:42 +00:00
|
|
|
|
2017-09-30 14:29:40 +00:00
|
|
|
@property
|
|
|
|
def current_operation(self):
|
|
|
|
"""Return current operation ie. heat, cool, idle."""
|
|
|
|
return self._current_operation
|
|
|
|
|
|
|
|
@property
|
|
|
|
def operation_list(self):
|
|
|
|
"""Return the list of available operation modes."""
|
2019-04-07 14:00:40 +00:00
|
|
|
return self._config[CONF_MODE_LIST]
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def target_temperature_step(self):
|
|
|
|
"""Return the supported step of target temperature."""
|
2019-04-07 14:00:40 +00:00
|
|
|
return self._config[CONF_TEMP_STEP]
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_away_mode_on(self):
|
|
|
|
"""Return if away mode is on."""
|
|
|
|
return self._away
|
|
|
|
|
|
|
|
@property
|
|
|
|
def current_hold_mode(self):
|
|
|
|
"""Return hold mode setting."""
|
|
|
|
return self._hold
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_aux_heat_on(self):
|
|
|
|
"""Return true if away mode is on."""
|
|
|
|
return self._aux
|
|
|
|
|
|
|
|
@property
|
|
|
|
def current_fan_mode(self):
|
|
|
|
"""Return the fan setting."""
|
|
|
|
return self._current_fan_mode
|
|
|
|
|
|
|
|
@property
|
|
|
|
def fan_list(self):
|
|
|
|
"""Return the list of available fan modes."""
|
2019-04-07 14:00:40 +00:00
|
|
|
return self._config[CONF_FAN_MODE_LIST]
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
def _publish(self, topic, payload):
|
|
|
|
if self._topic[topic] is not None:
|
|
|
|
mqtt.async_publish(
|
|
|
|
self.hass, self._topic[topic], payload,
|
|
|
|
self._config[CONF_QOS], self._config[CONF_RETAIN])
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
def _set_temperature(self, temp, cmnd_topic, state_topic, attr):
|
|
|
|
if temp is not None:
|
|
|
|
if self._topic[state_topic] is None:
|
2017-09-30 14:29:40 +00:00
|
|
|
# optimistic mode
|
2019-04-14 03:34:39 +00:00
|
|
|
setattr(self, attr, temp)
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2019-04-07 14:00:40 +00:00
|
|
|
if (self._config[CONF_SEND_IF_OFF] or
|
2018-12-02 09:30:07 +00:00
|
|
|
self._current_operation != STATE_OFF):
|
2019-04-14 03:34:39 +00:00
|
|
|
self._publish(cmnd_topic, temp)
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
async def async_set_temperature(self, **kwargs):
|
|
|
|
"""Set new target temperatures."""
|
|
|
|
if kwargs.get(ATTR_OPERATION_MODE) is not None:
|
|
|
|
operation_mode = kwargs.get(ATTR_OPERATION_MODE)
|
|
|
|
await self.async_set_operation_mode(operation_mode)
|
2019-04-08 13:28:42 +00:00
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
self._set_temperature(
|
|
|
|
kwargs.get(ATTR_TEMPERATURE), CONF_TEMP_COMMAND_TOPIC,
|
|
|
|
CONF_TEMP_STATE_TOPIC, '_target_temp')
|
2019-04-08 13:28:42 +00:00
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
self._set_temperature(
|
|
|
|
kwargs.get(ATTR_TARGET_TEMP_LOW), CONF_TEMP_LOW_COMMAND_TOPIC,
|
|
|
|
CONF_TEMP_LOW_STATE_TOPIC, '_target_temp_low')
|
2019-04-08 13:28:42 +00:00
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
self._set_temperature(
|
|
|
|
kwargs.get(ATTR_TARGET_TEMP_HIGH), CONF_TEMP_HIGH_COMMAND_TOPIC,
|
|
|
|
CONF_TEMP_HIGH_STATE_TOPIC, '_target_temp_high')
|
2019-04-08 13:28:42 +00:00
|
|
|
|
2019-03-12 21:46:48 +00:00
|
|
|
# Always optimistic?
|
|
|
|
self.async_write_ha_state()
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2018-10-01 06:50:05 +00:00
|
|
|
async def async_set_swing_mode(self, swing_mode):
|
2017-09-30 14:29:40 +00:00
|
|
|
"""Set new swing mode."""
|
2019-04-07 14:00:40 +00:00
|
|
|
if (self._config[CONF_SEND_IF_OFF] or
|
2018-12-02 09:30:07 +00:00
|
|
|
self._current_operation != STATE_OFF):
|
2019-04-14 03:34:39 +00:00
|
|
|
self._publish(CONF_SWING_MODE_COMMAND_TOPIC,
|
|
|
|
swing_mode)
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
if self._topic[CONF_SWING_MODE_STATE_TOPIC] is None:
|
|
|
|
self._current_swing_mode = swing_mode
|
2019-03-12 21:46:48 +00:00
|
|
|
self.async_write_ha_state()
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2018-10-01 06:50:05 +00:00
|
|
|
async def async_set_fan_mode(self, fan_mode):
|
2017-09-30 14:29:40 +00:00
|
|
|
"""Set new target temperature."""
|
2019-04-07 14:00:40 +00:00
|
|
|
if (self._config[CONF_SEND_IF_OFF] or
|
2018-12-02 09:30:07 +00:00
|
|
|
self._current_operation != STATE_OFF):
|
2019-04-14 03:34:39 +00:00
|
|
|
self._publish(CONF_FAN_MODE_COMMAND_TOPIC,
|
|
|
|
fan_mode)
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
if self._topic[CONF_FAN_MODE_STATE_TOPIC] is None:
|
2018-02-11 17:20:28 +00:00
|
|
|
self._current_fan_mode = fan_mode
|
2019-03-12 21:46:48 +00:00
|
|
|
self.async_write_ha_state()
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2018-10-01 06:50:05 +00:00
|
|
|
async def async_set_operation_mode(self, operation_mode) -> None:
|
2017-09-30 14:29:40 +00:00
|
|
|
"""Set new operation mode."""
|
2019-04-14 03:34:39 +00:00
|
|
|
if (self._current_operation == STATE_OFF and
|
|
|
|
operation_mode != STATE_OFF):
|
|
|
|
self._publish(CONF_POWER_COMMAND_TOPIC,
|
|
|
|
self._config[CONF_PAYLOAD_ON])
|
|
|
|
elif (self._current_operation != STATE_OFF and
|
|
|
|
operation_mode == STATE_OFF):
|
|
|
|
self._publish(CONF_POWER_COMMAND_TOPIC,
|
|
|
|
self._config[CONF_PAYLOAD_OFF])
|
|
|
|
|
|
|
|
self._publish(CONF_MODE_COMMAND_TOPIC,
|
|
|
|
operation_mode)
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
if self._topic[CONF_MODE_STATE_TOPIC] is None:
|
|
|
|
self._current_operation = operation_mode
|
2019-03-12 21:46:48 +00:00
|
|
|
self.async_write_ha_state()
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def current_swing_mode(self):
|
|
|
|
"""Return the swing setting."""
|
|
|
|
return self._current_swing_mode
|
|
|
|
|
|
|
|
@property
|
|
|
|
def swing_list(self):
|
|
|
|
"""List of available swing modes."""
|
2019-04-07 14:00:40 +00:00
|
|
|
return self._config[CONF_SWING_MODE_LIST]
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
def _set_away_mode(self, state):
|
|
|
|
self._publish(CONF_AWAY_MODE_COMMAND_TOPIC,
|
|
|
|
self._config[CONF_PAYLOAD_ON] if state
|
|
|
|
else self._config[CONF_PAYLOAD_OFF])
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
if self._topic[CONF_AWAY_MODE_STATE_TOPIC] is None:
|
2019-04-14 03:34:39 +00:00
|
|
|
self._away = state
|
2019-03-12 21:46:48 +00:00
|
|
|
self.async_write_ha_state()
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
async def async_turn_away_mode_on(self):
|
|
|
|
"""Turn away mode on."""
|
|
|
|
self._set_away_mode(True)
|
|
|
|
|
2018-10-01 06:50:05 +00:00
|
|
|
async def async_turn_away_mode_off(self):
|
2017-09-30 14:29:40 +00:00
|
|
|
"""Turn away mode off."""
|
2019-04-14 03:34:39 +00:00
|
|
|
self._set_away_mode(False)
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2018-10-01 06:50:05 +00:00
|
|
|
async def async_set_hold_mode(self, hold_mode):
|
2017-09-30 14:29:40 +00:00
|
|
|
"""Update hold mode on."""
|
2019-04-14 03:34:39 +00:00
|
|
|
self._publish(CONF_HOLD_COMMAND_TOPIC, hold_mode)
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
if self._topic[CONF_HOLD_STATE_TOPIC] is None:
|
2018-02-11 17:20:28 +00:00
|
|
|
self._hold = hold_mode
|
2019-03-12 21:46:48 +00:00
|
|
|
self.async_write_ha_state()
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
def _set_aux_heat(self, state):
|
|
|
|
self._publish(CONF_AUX_COMMAND_TOPIC,
|
|
|
|
self._config[CONF_PAYLOAD_ON] if state
|
|
|
|
else self._config[CONF_PAYLOAD_OFF])
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
if self._topic[CONF_AUX_STATE_TOPIC] is None:
|
2019-04-14 03:34:39 +00:00
|
|
|
self._aux = state
|
2019-03-12 21:46:48 +00:00
|
|
|
self.async_write_ha_state()
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
async def async_turn_aux_heat_on(self):
|
|
|
|
"""Turn auxiliary heater on."""
|
|
|
|
self._set_aux_heat(True)
|
|
|
|
|
2018-10-01 06:50:05 +00:00
|
|
|
async def async_turn_aux_heat_off(self):
|
2018-01-27 19:58:27 +00:00
|
|
|
"""Turn auxiliary heater off."""
|
2019-04-14 03:34:39 +00:00
|
|
|
self._set_aux_heat(False)
|
2017-11-29 10:01:28 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def supported_features(self):
|
|
|
|
"""Return the list of supported features."""
|
|
|
|
support = 0
|
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
if (self._topic[CONF_TEMP_STATE_TOPIC] is not None) or \
|
|
|
|
(self._topic[CONF_TEMP_COMMAND_TOPIC] is not None):
|
2017-11-29 10:01:28 +00:00
|
|
|
support |= SUPPORT_TARGET_TEMPERATURE
|
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
if (self._topic[CONF_TEMP_LOW_STATE_TOPIC] is not None) or \
|
|
|
|
(self._topic[CONF_TEMP_LOW_COMMAND_TOPIC] is not None):
|
2019-04-08 13:28:42 +00:00
|
|
|
support |= SUPPORT_TARGET_TEMPERATURE_LOW
|
|
|
|
|
2019-04-14 03:34:39 +00:00
|
|
|
if (self._topic[CONF_TEMP_HIGH_STATE_TOPIC] is not None) or \
|
|
|
|
(self._topic[CONF_TEMP_HIGH_COMMAND_TOPIC] is not None):
|
2019-04-08 13:28:42 +00:00
|
|
|
support |= SUPPORT_TARGET_TEMPERATURE_HIGH
|
|
|
|
|
2017-11-29 10:01:28 +00:00
|
|
|
if (self._topic[CONF_MODE_COMMAND_TOPIC] is not None) or \
|
|
|
|
(self._topic[CONF_MODE_STATE_TOPIC] is not None):
|
|
|
|
support |= SUPPORT_OPERATION_MODE
|
|
|
|
|
|
|
|
if (self._topic[CONF_FAN_MODE_STATE_TOPIC] is not None) or \
|
|
|
|
(self._topic[CONF_FAN_MODE_COMMAND_TOPIC] is not None):
|
|
|
|
support |= SUPPORT_FAN_MODE
|
|
|
|
|
|
|
|
if (self._topic[CONF_SWING_MODE_STATE_TOPIC] is not None) or \
|
|
|
|
(self._topic[CONF_SWING_MODE_COMMAND_TOPIC] is not None):
|
|
|
|
support |= SUPPORT_SWING_MODE
|
|
|
|
|
|
|
|
if (self._topic[CONF_AWAY_MODE_STATE_TOPIC] is not None) or \
|
|
|
|
(self._topic[CONF_AWAY_MODE_COMMAND_TOPIC] is not None):
|
|
|
|
support |= SUPPORT_AWAY_MODE
|
|
|
|
|
|
|
|
if (self._topic[CONF_HOLD_STATE_TOPIC] is not None) or \
|
|
|
|
(self._topic[CONF_HOLD_COMMAND_TOPIC] is not None):
|
|
|
|
support |= SUPPORT_HOLD_MODE
|
|
|
|
|
|
|
|
if (self._topic[CONF_AUX_STATE_TOPIC] is not None) or \
|
|
|
|
(self._topic[CONF_AUX_COMMAND_TOPIC] is not None):
|
|
|
|
support |= SUPPORT_AUX_HEAT
|
|
|
|
|
|
|
|
return support
|
2018-06-07 17:50:12 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def min_temp(self):
|
|
|
|
"""Return the minimum temperature."""
|
2019-04-07 14:00:40 +00:00
|
|
|
return self._config[CONF_TEMP_MIN]
|
2018-06-07 17:50:12 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def max_temp(self):
|
|
|
|
"""Return the maximum temperature."""
|
2019-04-07 14:00:40 +00:00
|
|
|
return self._config[CONF_TEMP_MAX]
|