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,
|
|
|
|
SUPPORT_OPERATION_MODE, SUPPORT_SWING_MODE, SUPPORT_TARGET_TEMPERATURE)
|
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 (
|
|
|
|
ATTR_DISCOVERY_HASH, CONF_QOS, CONF_RETAIN, CONF_STATE_TOPIC,
|
|
|
|
CONF_UNIQUE_ID, MQTT_BASE_PLATFORM_SCHEMA, MqttAttributes,
|
|
|
|
MqttAvailability, MqttDiscoveryUpdate, MqttEntityDeviceInfo, subscription)
|
|
|
|
from .discovery import MQTT_DISCOVERY_NEW, clear_discovery_hash
|
|
|
|
|
2017-09-30 14:29:40 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
DEPENDENCIES = ['mqtt']
|
|
|
|
|
|
|
|
DEFAULT_NAME = 'MQTT HVAC'
|
|
|
|
|
|
|
|
CONF_POWER_COMMAND_TOPIC = 'power_command_topic'
|
|
|
|
CONF_POWER_STATE_TOPIC = 'power_state_topic'
|
2018-01-14 11:55:19 +00:00
|
|
|
CONF_POWER_STATE_TEMPLATE = 'power_state_template'
|
2017-09-30 14:29:40 +00:00
|
|
|
CONF_MODE_COMMAND_TOPIC = 'mode_command_topic'
|
|
|
|
CONF_MODE_STATE_TOPIC = 'mode_state_topic'
|
2018-01-14 11:55:19 +00:00
|
|
|
CONF_MODE_STATE_TEMPLATE = 'mode_state_template'
|
2017-09-30 14:29:40 +00:00
|
|
|
CONF_TEMPERATURE_COMMAND_TOPIC = 'temperature_command_topic'
|
|
|
|
CONF_TEMPERATURE_STATE_TOPIC = 'temperature_state_topic'
|
2018-01-14 11:55:19 +00:00
|
|
|
CONF_TEMPERATURE_STATE_TEMPLATE = 'temperature_state_template'
|
2017-09-30 14:29:40 +00:00
|
|
|
CONF_FAN_MODE_COMMAND_TOPIC = 'fan_mode_command_topic'
|
|
|
|
CONF_FAN_MODE_STATE_TOPIC = 'fan_mode_state_topic'
|
2018-01-14 11:55:19 +00:00
|
|
|
CONF_FAN_MODE_STATE_TEMPLATE = 'fan_mode_state_template'
|
2017-09-30 14:29:40 +00:00
|
|
|
CONF_SWING_MODE_COMMAND_TOPIC = 'swing_mode_command_topic'
|
|
|
|
CONF_SWING_MODE_STATE_TOPIC = 'swing_mode_state_topic'
|
2018-01-14 11:55:19 +00:00
|
|
|
CONF_SWING_MODE_STATE_TEMPLATE = 'swing_mode_state_template'
|
2017-09-30 14:29:40 +00:00
|
|
|
CONF_AWAY_MODE_COMMAND_TOPIC = 'away_mode_command_topic'
|
|
|
|
CONF_AWAY_MODE_STATE_TOPIC = 'away_mode_state_topic'
|
2018-01-14 11:55:19 +00:00
|
|
|
CONF_AWAY_MODE_STATE_TEMPLATE = 'away_mode_state_template'
|
2017-09-30 14:29:40 +00:00
|
|
|
CONF_HOLD_COMMAND_TOPIC = 'hold_command_topic'
|
|
|
|
CONF_HOLD_STATE_TOPIC = 'hold_state_topic'
|
2018-01-14 11:55:19 +00:00
|
|
|
CONF_HOLD_STATE_TEMPLATE = 'hold_state_template'
|
2017-09-30 14:29:40 +00:00
|
|
|
CONF_AUX_COMMAND_TOPIC = 'aux_command_topic'
|
|
|
|
CONF_AUX_STATE_TOPIC = 'aux_state_topic'
|
2018-01-14 11:55:19 +00:00
|
|
|
CONF_AUX_STATE_TEMPLATE = 'aux_state_template'
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2018-01-14 11:55:19 +00:00
|
|
|
CONF_CURRENT_TEMPERATURE_TEMPLATE = 'current_temperature_template'
|
2017-09-30 14:29:40 +00:00
|
|
|
CONF_CURRENT_TEMPERATURE_TOPIC = 'current_temperature_topic'
|
|
|
|
|
|
|
|
CONF_PAYLOAD_ON = 'payload_on'
|
|
|
|
CONF_PAYLOAD_OFF = 'payload_off'
|
|
|
|
|
|
|
|
CONF_FAN_MODE_LIST = 'fan_modes'
|
|
|
|
CONF_MODE_LIST = 'modes'
|
|
|
|
CONF_SWING_MODE_LIST = 'swing_modes'
|
|
|
|
CONF_SEND_IF_OFF = 'send_if_off'
|
|
|
|
|
2019-04-07 14:00:40 +00:00
|
|
|
CONF_TEMP_INITIAL = 'initial'
|
|
|
|
CONF_TEMP_MIN = 'min_temp'
|
|
|
|
CONF_TEMP_MAX = 'max_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 = (
|
|
|
|
CONF_POWER_STATE_TEMPLATE,
|
|
|
|
CONF_MODE_STATE_TEMPLATE,
|
|
|
|
CONF_TEMPERATURE_STATE_TEMPLATE,
|
|
|
|
CONF_FAN_MODE_STATE_TEMPLATE,
|
|
|
|
CONF_SWING_MODE_STATE_TEMPLATE,
|
|
|
|
CONF_AWAY_MODE_STATE_TEMPLATE,
|
|
|
|
CONF_HOLD_STATE_TEMPLATE,
|
|
|
|
CONF_AUX_STATE_TEMPLATE,
|
|
|
|
CONF_CURRENT_TEMPERATURE_TEMPLATE
|
|
|
|
)
|
|
|
|
|
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,
|
2018-01-14 11:55:19 +00:00
|
|
|
vol.Optional(CONF_CURRENT_TEMPERATURE_TEMPLATE): cv.template,
|
2017-09-30 14:29:40 +00:00
|
|
|
vol.Optional(CONF_CURRENT_TEMPERATURE_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-07 14:00:40 +00:00
|
|
|
vol.Optional(CONF_TEMPERATURE_COMMAND_TOPIC): mqtt.valid_publish_topic,
|
|
|
|
vol.Optional(CONF_TEMPERATURE_STATE_TEMPLATE): cv.template,
|
|
|
|
vol.Optional(CONF_TEMPERATURE_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)
|
|
|
|
# state_topic is implicitly set by MQTT discovery, remove it
|
|
|
|
discovery_payload.pop(CONF_STATE_TOPIC, None)
|
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
|
2018-11-24 09:40:07 +00:00
|
|
|
self._topic = None
|
|
|
|
self._value_templates = None
|
|
|
|
self._target_temperature = None
|
|
|
|
self._current_fan_mode = None
|
|
|
|
self._current_operation = None
|
|
|
|
self._current_swing_mode = None
|
2017-09-30 14:29:40 +00:00
|
|
|
self._unit_of_measurement = hass.config.units.temperature_unit
|
2018-11-24 09:40:07 +00:00
|
|
|
self._away = False
|
|
|
|
self._hold = None
|
2017-09-30 14:29:40 +00:00
|
|
|
self._current_temperature = None
|
2018-11-24 09:40:07 +00:00
|
|
|
self._aux = False
|
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."""
|
2019-02-05 05:52:19 +00:00
|
|
|
# state_topic is implicitly set by MQTT discovery, remove it
|
|
|
|
discovery_payload.pop(CONF_STATE_TOPIC, None)
|
2018-11-24 09:40:07 +00:00
|
|
|
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 = {
|
|
|
|
key: config.get(key) for key in (
|
|
|
|
CONF_POWER_COMMAND_TOPIC,
|
|
|
|
CONF_MODE_COMMAND_TOPIC,
|
|
|
|
CONF_TEMPERATURE_COMMAND_TOPIC,
|
|
|
|
CONF_FAN_MODE_COMMAND_TOPIC,
|
|
|
|
CONF_SWING_MODE_COMMAND_TOPIC,
|
|
|
|
CONF_AWAY_MODE_COMMAND_TOPIC,
|
|
|
|
CONF_HOLD_COMMAND_TOPIC,
|
|
|
|
CONF_AUX_COMMAND_TOPIC,
|
|
|
|
CONF_POWER_STATE_TOPIC,
|
|
|
|
CONF_MODE_STATE_TOPIC,
|
|
|
|
CONF_TEMPERATURE_STATE_TOPIC,
|
|
|
|
CONF_FAN_MODE_STATE_TOPIC,
|
|
|
|
CONF_SWING_MODE_STATE_TOPIC,
|
|
|
|
CONF_AWAY_MODE_STATE_TOPIC,
|
|
|
|
CONF_HOLD_STATE_TOPIC,
|
|
|
|
CONF_AUX_STATE_TOPIC,
|
|
|
|
CONF_CURRENT_TEMPERATURE_TOPIC
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
# set to None in non-optimistic mode
|
|
|
|
self._target_temperature = self._current_fan_mode = \
|
|
|
|
self._current_operation = self._current_swing_mode = None
|
|
|
|
if self._topic[CONF_TEMPERATURE_STATE_TOPIC] is None:
|
2019-04-07 14:00:40 +00:00
|
|
|
self._target_temperature = config[CONF_TEMP_INITIAL]
|
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 = {}
|
|
|
|
if CONF_VALUE_TEMPLATE in config:
|
|
|
|
value_template = config.get(CONF_VALUE_TEMPLATE)
|
|
|
|
value_template.hass = self.hass
|
|
|
|
value_templates = {key: value_template for key in TEMPLATE_KEYS}
|
|
|
|
for key in TEMPLATE_KEYS & config.keys():
|
|
|
|
value_templates[key] = config.get(key)
|
|
|
|
value_templates[key].hass = self.hass
|
|
|
|
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
|
|
|
|
2017-09-30 14:29:40 +00:00
|
|
|
@callback
|
2019-03-13 19:58:20 +00:00
|
|
|
def handle_current_temp_received(msg):
|
2017-09-30 14:29:40 +00:00
|
|
|
"""Handle current temperature coming via MQTT."""
|
2019-03-13 19:58:20 +00:00
|
|
|
payload = msg.payload
|
2018-01-14 11:55:19 +00:00
|
|
|
if CONF_CURRENT_TEMPERATURE_TEMPLATE in self._value_templates:
|
|
|
|
payload =\
|
|
|
|
self._value_templates[CONF_CURRENT_TEMPERATURE_TEMPLATE].\
|
|
|
|
async_render_with_possible_json_value(payload)
|
|
|
|
|
2017-09-30 14:29:40 +00:00
|
|
|
try:
|
|
|
|
self._current_temperature = 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)
|
|
|
|
|
|
|
|
if self._topic[CONF_CURRENT_TEMPERATURE_TOPIC] is not None:
|
2018-11-24 09:40:07 +00:00
|
|
|
topics[CONF_CURRENT_TEMPERATURE_TOPIC] = {
|
|
|
|
'topic': self._topic[CONF_CURRENT_TEMPERATURE_TOPIC],
|
|
|
|
'msg_callback': handle_current_temp_received,
|
2018-12-02 09:30:07 +00:00
|
|
|
'qos': qos}
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
@callback
|
2019-03-13 19:58:20 +00:00
|
|
|
def handle_mode_received(msg):
|
2017-09-30 14:29:40 +00:00
|
|
|
"""Handle receiving mode via MQTT."""
|
2019-03-13 19:58:20 +00:00
|
|
|
payload = msg.payload
|
2018-01-14 11:55:19 +00:00
|
|
|
if CONF_MODE_STATE_TEMPLATE in self._value_templates:
|
|
|
|
payload = self._value_templates[CONF_MODE_STATE_TEMPLATE].\
|
|
|
|
async_render_with_possible_json_value(payload)
|
|
|
|
|
2019-04-07 14:00:40 +00:00
|
|
|
if payload not in self._config[CONF_MODE_LIST]:
|
2017-09-30 14:29:40 +00:00
|
|
|
_LOGGER.error("Invalid mode: %s", payload)
|
|
|
|
else:
|
|
|
|
self._current_operation = payload
|
2019-03-12 21:46:48 +00:00
|
|
|
self.async_write_ha_state()
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
if self._topic[CONF_MODE_STATE_TOPIC] is not None:
|
2018-11-24 09:40:07 +00:00
|
|
|
topics[CONF_MODE_STATE_TOPIC] = {
|
|
|
|
'topic': self._topic[CONF_MODE_STATE_TOPIC],
|
|
|
|
'msg_callback': handle_mode_received,
|
2018-12-02 09:30:07 +00:00
|
|
|
'qos': qos}
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
@callback
|
2019-03-13 19:58:20 +00:00
|
|
|
def handle_temperature_received(msg):
|
2017-09-30 14:29:40 +00:00
|
|
|
"""Handle target temperature coming via MQTT."""
|
2019-03-13 19:58:20 +00:00
|
|
|
payload = msg.payload
|
2018-01-14 11:55:19 +00:00
|
|
|
if CONF_TEMPERATURE_STATE_TEMPLATE in self._value_templates:
|
|
|
|
payload = \
|
|
|
|
self._value_templates[CONF_TEMPERATURE_STATE_TEMPLATE].\
|
|
|
|
async_render_with_possible_json_value(payload)
|
|
|
|
|
2017-09-30 14:29:40 +00:00
|
|
|
try:
|
|
|
|
self._target_temperature = 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)
|
|
|
|
|
|
|
|
if self._topic[CONF_TEMPERATURE_STATE_TOPIC] is not None:
|
2018-11-24 09:40:07 +00:00
|
|
|
topics[CONF_TEMPERATURE_STATE_TOPIC] = {
|
|
|
|
'topic': self._topic[CONF_TEMPERATURE_STATE_TOPIC],
|
|
|
|
'msg_callback': handle_temperature_received,
|
2018-12-02 09:30:07 +00:00
|
|
|
'qos': qos}
|
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-03-13 19:58:20 +00:00
|
|
|
payload = msg.payload
|
2018-01-14 11:55:19 +00:00
|
|
|
if CONF_FAN_MODE_STATE_TEMPLATE in self._value_templates:
|
|
|
|
payload = \
|
|
|
|
self._value_templates[CONF_FAN_MODE_STATE_TEMPLATE].\
|
|
|
|
async_render_with_possible_json_value(payload)
|
|
|
|
|
2019-04-07 14:00:40 +00:00
|
|
|
if payload not in self._config[CONF_FAN_MODE_LIST]:
|
2017-09-30 14:29:40 +00:00
|
|
|
_LOGGER.error("Invalid fan mode: %s", payload)
|
|
|
|
else:
|
|
|
|
self._current_fan_mode = payload
|
2019-03-12 21:46:48 +00:00
|
|
|
self.async_write_ha_state()
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
if self._topic[CONF_FAN_MODE_STATE_TOPIC] is not None:
|
2018-11-24 09:40:07 +00:00
|
|
|
topics[CONF_FAN_MODE_STATE_TOPIC] = {
|
|
|
|
'topic': self._topic[CONF_FAN_MODE_STATE_TOPIC],
|
|
|
|
'msg_callback': handle_fan_mode_received,
|
2018-12-02 09:30:07 +00:00
|
|
|
'qos': qos}
|
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-03-13 19:58:20 +00:00
|
|
|
payload = msg.payload
|
2018-01-14 11:55:19 +00:00
|
|
|
if CONF_SWING_MODE_STATE_TEMPLATE in self._value_templates:
|
|
|
|
payload = \
|
|
|
|
self._value_templates[CONF_SWING_MODE_STATE_TEMPLATE].\
|
|
|
|
async_render_with_possible_json_value(payload)
|
|
|
|
|
2019-04-07 14:00:40 +00:00
|
|
|
if payload not in self._config[CONF_SWING_MODE_LIST]:
|
2017-09-30 14:29:40 +00:00
|
|
|
_LOGGER.error("Invalid swing mode: %s", payload)
|
|
|
|
else:
|
|
|
|
self._current_swing_mode = payload
|
2019-03-12 21:46:48 +00:00
|
|
|
self.async_write_ha_state()
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
if self._topic[CONF_SWING_MODE_STATE_TOPIC] is not None:
|
2018-11-24 09:40:07 +00:00
|
|
|
topics[CONF_SWING_MODE_STATE_TOPIC] = {
|
|
|
|
'topic': self._topic[CONF_SWING_MODE_STATE_TOPIC],
|
|
|
|
'msg_callback': handle_swing_mode_received,
|
2018-12-02 09:30:07 +00:00
|
|
|
'qos': qos}
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
@callback
|
2019-03-13 19:58:20 +00:00
|
|
|
def handle_away_mode_received(msg):
|
2017-09-30 14:29:40 +00:00
|
|
|
"""Handle receiving away mode via MQTT."""
|
2019-03-13 19:58:20 +00:00
|
|
|
payload = msg.payload
|
2019-04-07 14:00:40 +00:00
|
|
|
payload_on = self._config[CONF_PAYLOAD_ON]
|
|
|
|
payload_off = self._config[CONF_PAYLOAD_OFF]
|
2018-01-14 11:55:19 +00:00
|
|
|
if CONF_AWAY_MODE_STATE_TEMPLATE in self._value_templates:
|
|
|
|
payload = \
|
|
|
|
self._value_templates[CONF_AWAY_MODE_STATE_TEMPLATE].\
|
|
|
|
async_render_with_possible_json_value(payload)
|
|
|
|
if payload == "True":
|
2018-12-02 09:30:07 +00:00
|
|
|
payload = payload_on
|
2018-01-14 11:55:19 +00:00
|
|
|
elif payload == "False":
|
2018-12-02 09:30:07 +00:00
|
|
|
payload = payload_off
|
2018-01-14 11:55:19 +00:00
|
|
|
|
2018-12-02 09:30:07 +00:00
|
|
|
if payload == payload_on:
|
2017-09-30 14:29:40 +00:00
|
|
|
self._away = True
|
2018-12-02 09:30:07 +00:00
|
|
|
elif payload == payload_off:
|
2017-09-30 14:29:40 +00:00
|
|
|
self._away = False
|
|
|
|
else:
|
|
|
|
_LOGGER.error("Invalid away mode: %s", payload)
|
|
|
|
|
2019-03-12 21:46:48 +00:00
|
|
|
self.async_write_ha_state()
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
if self._topic[CONF_AWAY_MODE_STATE_TOPIC] is not None:
|
2018-11-24 09:40:07 +00:00
|
|
|
topics[CONF_AWAY_MODE_STATE_TOPIC] = {
|
|
|
|
'topic': self._topic[CONF_AWAY_MODE_STATE_TOPIC],
|
|
|
|
'msg_callback': handle_away_mode_received,
|
2018-12-02 09:30:07 +00:00
|
|
|
'qos': qos}
|
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-03-13 19:58:20 +00:00
|
|
|
payload = msg.payload
|
2019-04-07 14:00:40 +00:00
|
|
|
payload_on = self._config[CONF_PAYLOAD_ON]
|
|
|
|
payload_off = self._config[CONF_PAYLOAD_OFF]
|
2018-01-14 11:55:19 +00:00
|
|
|
if CONF_AUX_STATE_TEMPLATE in self._value_templates:
|
|
|
|
payload = self._value_templates[CONF_AUX_STATE_TEMPLATE].\
|
|
|
|
async_render_with_possible_json_value(payload)
|
|
|
|
if payload == "True":
|
2018-12-02 09:30:07 +00:00
|
|
|
payload = payload_on
|
2018-01-14 11:55:19 +00:00
|
|
|
elif payload == "False":
|
2018-12-02 09:30:07 +00:00
|
|
|
payload = payload_off
|
2018-01-14 11:55:19 +00:00
|
|
|
|
2018-12-02 09:30:07 +00:00
|
|
|
if payload == payload_on:
|
2017-09-30 14:29:40 +00:00
|
|
|
self._aux = True
|
2018-12-02 09:30:07 +00:00
|
|
|
elif payload == payload_off:
|
2017-09-30 14:29:40 +00:00
|
|
|
self._aux = False
|
|
|
|
else:
|
|
|
|
_LOGGER.error("Invalid aux mode: %s", payload)
|
|
|
|
|
2019-03-12 21:46:48 +00:00
|
|
|
self.async_write_ha_state()
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
if self._topic[CONF_AUX_STATE_TOPIC] is not None:
|
2018-11-24 09:40:07 +00:00
|
|
|
topics[CONF_AUX_STATE_TOPIC] = {
|
|
|
|
'topic': self._topic[CONF_AUX_STATE_TOPIC],
|
|
|
|
'msg_callback': handle_aux_mode_received,
|
2018-12-02 09:30:07 +00:00
|
|
|
'qos': qos}
|
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-03-13 19:58:20 +00:00
|
|
|
payload = msg.payload
|
2018-01-14 11:55:19 +00:00
|
|
|
if CONF_HOLD_STATE_TEMPLATE in self._value_templates:
|
|
|
|
payload = self._value_templates[CONF_HOLD_STATE_TEMPLATE].\
|
|
|
|
async_render_with_possible_json_value(payload)
|
|
|
|
|
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
|
|
|
|
|
|
|
if self._topic[CONF_HOLD_STATE_TOPIC] is not None:
|
2018-11-24 09:40:07 +00:00
|
|
|
topics[CONF_HOLD_STATE_TOPIC] = {
|
|
|
|
'topic': self._topic[CONF_HOLD_STATE_TOPIC],
|
|
|
|
'msg_callback': handle_hold_mode_received,
|
2018-12-02 09:30:07 +00:00
|
|
|
'qos': qos}
|
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."""
|
|
|
|
return self._current_temperature
|
|
|
|
|
|
|
|
@property
|
|
|
|
def target_temperature(self):
|
|
|
|
"""Return the temperature we try to reach."""
|
|
|
|
return self._target_temperature
|
|
|
|
|
|
|
|
@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
|
|
|
|
2018-10-01 06:50:05 +00:00
|
|
|
async def async_set_temperature(self, **kwargs):
|
2017-09-30 14:29:40 +00:00
|
|
|
"""Set new target temperatures."""
|
|
|
|
if kwargs.get(ATTR_OPERATION_MODE) is not None:
|
|
|
|
operation_mode = kwargs.get(ATTR_OPERATION_MODE)
|
2018-10-01 06:50:05 +00:00
|
|
|
await self.async_set_operation_mode(operation_mode)
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
if kwargs.get(ATTR_TEMPERATURE) is not None:
|
|
|
|
if self._topic[CONF_TEMPERATURE_STATE_TOPIC] is None:
|
|
|
|
# optimistic mode
|
|
|
|
self._target_temperature = kwargs.get(ATTR_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):
|
2017-09-30 14:29:40 +00:00
|
|
|
mqtt.async_publish(
|
|
|
|
self.hass, self._topic[CONF_TEMPERATURE_COMMAND_TOPIC],
|
2019-04-07 14:00:40 +00:00
|
|
|
kwargs.get(ATTR_TEMPERATURE), self._config[CONF_QOS],
|
|
|
|
self._config[CONF_RETAIN])
|
2017-09-30 14:29:40 +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):
|
2017-09-30 14:29:40 +00:00
|
|
|
mqtt.async_publish(
|
|
|
|
self.hass, self._topic[CONF_SWING_MODE_COMMAND_TOPIC],
|
2019-04-07 14:00:40 +00:00
|
|
|
swing_mode, self._config[CONF_QOS],
|
|
|
|
self._config[CONF_RETAIN])
|
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):
|
2017-09-30 14:29:40 +00:00
|
|
|
mqtt.async_publish(
|
|
|
|
self.hass, self._topic[CONF_FAN_MODE_COMMAND_TOPIC],
|
2019-04-07 14:00:40 +00:00
|
|
|
fan_mode, self._config[CONF_QOS],
|
|
|
|
self._config[CONF_RETAIN])
|
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-07 14:00:40 +00:00
|
|
|
qos = self._config[CONF_QOS]
|
|
|
|
retain = self._config[CONF_RETAIN]
|
2017-09-30 14:29:40 +00:00
|
|
|
if self._topic[CONF_POWER_COMMAND_TOPIC] is not None:
|
|
|
|
if (self._current_operation == STATE_OFF and
|
|
|
|
operation_mode != STATE_OFF):
|
|
|
|
mqtt.async_publish(
|
|
|
|
self.hass, self._topic[CONF_POWER_COMMAND_TOPIC],
|
2019-04-07 14:00:40 +00:00
|
|
|
self._config[CONF_PAYLOAD_ON], qos, retain)
|
2017-09-30 14:29:40 +00:00
|
|
|
elif (self._current_operation != STATE_OFF and
|
|
|
|
operation_mode == STATE_OFF):
|
|
|
|
mqtt.async_publish(
|
|
|
|
self.hass, self._topic[CONF_POWER_COMMAND_TOPIC],
|
2019-04-07 14:00:40 +00:00
|
|
|
self._config[CONF_PAYLOAD_OFF], qos, retain)
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
if self._topic[CONF_MODE_COMMAND_TOPIC] is not None:
|
|
|
|
mqtt.async_publish(
|
|
|
|
self.hass, self._topic[CONF_MODE_COMMAND_TOPIC],
|
2018-12-02 09:30:07 +00:00
|
|
|
operation_mode, qos, retain)
|
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
|
|
|
|
2018-10-01 06:50:05 +00:00
|
|
|
async def async_turn_away_mode_on(self):
|
2017-09-30 14:29:40 +00:00
|
|
|
"""Turn away mode on."""
|
|
|
|
if self._topic[CONF_AWAY_MODE_COMMAND_TOPIC] is not None:
|
|
|
|
mqtt.async_publish(self.hass,
|
|
|
|
self._topic[CONF_AWAY_MODE_COMMAND_TOPIC],
|
2019-04-07 14:00:40 +00:00
|
|
|
self._config[CONF_PAYLOAD_ON],
|
|
|
|
self._config[CONF_QOS],
|
|
|
|
self._config[CONF_RETAIN])
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
if self._topic[CONF_AWAY_MODE_STATE_TOPIC] is None:
|
|
|
|
self._away = True
|
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_turn_away_mode_off(self):
|
2017-09-30 14:29:40 +00:00
|
|
|
"""Turn away mode off."""
|
|
|
|
if self._topic[CONF_AWAY_MODE_COMMAND_TOPIC] is not None:
|
|
|
|
mqtt.async_publish(self.hass,
|
|
|
|
self._topic[CONF_AWAY_MODE_COMMAND_TOPIC],
|
2019-04-07 14:00:40 +00:00
|
|
|
self._config[CONF_PAYLOAD_OFF],
|
|
|
|
self._config[CONF_QOS],
|
|
|
|
self._config[CONF_RETAIN])
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
if self._topic[CONF_AWAY_MODE_STATE_TOPIC] is None:
|
|
|
|
self._away = False
|
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_hold_mode(self, hold_mode):
|
2017-09-30 14:29:40 +00:00
|
|
|
"""Update hold mode on."""
|
|
|
|
if self._topic[CONF_HOLD_COMMAND_TOPIC] is not None:
|
|
|
|
mqtt.async_publish(self.hass,
|
|
|
|
self._topic[CONF_HOLD_COMMAND_TOPIC],
|
2019-04-07 14:00:40 +00:00
|
|
|
hold_mode, self._config[CONF_QOS],
|
|
|
|
self._config[CONF_RETAIN])
|
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
|
|
|
|
2018-10-01 06:50:05 +00:00
|
|
|
async def async_turn_aux_heat_on(self):
|
2018-01-27 19:58:27 +00:00
|
|
|
"""Turn auxiliary heater on."""
|
2017-09-30 14:29:40 +00:00
|
|
|
if self._topic[CONF_AUX_COMMAND_TOPIC] is not None:
|
|
|
|
mqtt.async_publish(self.hass, self._topic[CONF_AUX_COMMAND_TOPIC],
|
2019-04-07 14:00:40 +00:00
|
|
|
self._config[CONF_PAYLOAD_ON],
|
|
|
|
self._config[CONF_QOS],
|
|
|
|
self._config[CONF_RETAIN])
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
if self._topic[CONF_AUX_STATE_TOPIC] is None:
|
|
|
|
self._aux = True
|
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_turn_aux_heat_off(self):
|
2018-01-27 19:58:27 +00:00
|
|
|
"""Turn auxiliary heater off."""
|
2017-09-30 14:29:40 +00:00
|
|
|
if self._topic[CONF_AUX_COMMAND_TOPIC] is not None:
|
|
|
|
mqtt.async_publish(self.hass, self._topic[CONF_AUX_COMMAND_TOPIC],
|
2019-04-07 14:00:40 +00:00
|
|
|
self._config[CONF_PAYLOAD_OFF],
|
|
|
|
self._config[CONF_QOS],
|
|
|
|
self._config[CONF_RETAIN])
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
if self._topic[CONF_AUX_STATE_TOPIC] is None:
|
|
|
|
self._aux = False
|
2019-03-12 21:46:48 +00:00
|
|
|
self.async_write_ha_state()
|
2017-11-29 10:01:28 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def supported_features(self):
|
|
|
|
"""Return the list of supported features."""
|
|
|
|
support = 0
|
|
|
|
|
|
|
|
if (self._topic[CONF_TEMPERATURE_STATE_TOPIC] is not None) or \
|
|
|
|
(self._topic[CONF_TEMPERATURE_COMMAND_TOPIC] is not None):
|
|
|
|
support |= SUPPORT_TARGET_TEMPERATURE
|
|
|
|
|
|
|
|
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]
|