Allow to change MQTT climate hold mode (#28988)
parent
5f4fc271d4
commit
4881bc04d8
|
@ -756,12 +756,14 @@ class MqttClimate(
|
|||
if self._away:
|
||||
optimistic_update = optimistic_update or self._set_away_mode(False)
|
||||
elif preset_mode == PRESET_AWAY:
|
||||
if self._hold:
|
||||
self._set_hold_mode(None)
|
||||
optimistic_update = optimistic_update or self._set_away_mode(True)
|
||||
|
||||
if self._hold:
|
||||
optimistic_update = optimistic_update or self._set_hold_mode(None)
|
||||
elif preset_mode not in (None, PRESET_AWAY):
|
||||
optimistic_update = optimistic_update or self._set_hold_mode(preset_mode)
|
||||
else:
|
||||
hold_mode = preset_mode
|
||||
if preset_mode == PRESET_NONE:
|
||||
hold_mode = None
|
||||
optimistic_update = optimistic_update or self._set_hold_mode(hold_mode)
|
||||
|
||||
if optimistic_update:
|
||||
self.async_write_ha_state()
|
||||
|
|
|
@ -23,6 +23,7 @@ from homeassistant.components.climate.const import (
|
|||
HVAC_MODE_FAN_ONLY,
|
||||
SUPPORT_TARGET_TEMPERATURE_RANGE,
|
||||
PRESET_NONE,
|
||||
PRESET_ECO,
|
||||
)
|
||||
from homeassistant.components.mqtt.discovery import async_start
|
||||
from homeassistant.const import STATE_OFF, STATE_UNAVAILABLE
|
||||
|
@ -446,6 +447,19 @@ async def test_set_away_mode(hass, mqtt_mock):
|
|||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("preset_mode") is None
|
||||
|
||||
await common.async_set_preset_mode(hass, "hold-on", ENTITY_CLIMATE)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
await common.async_set_preset_mode(hass, "away", ENTITY_CLIMATE)
|
||||
mqtt_mock.async_publish.assert_has_calls(
|
||||
[
|
||||
unittest.mock.call("hold-topic", "off", 0, False),
|
||||
unittest.mock.call("away-mode-topic", "AN", 0, False),
|
||||
]
|
||||
)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("preset_mode") == "away"
|
||||
|
||||
|
||||
async def test_set_hvac_action(hass, mqtt_mock):
|
||||
"""Test setting of the HVAC action."""
|
||||
|
@ -495,6 +509,12 @@ async def test_set_hold(hass, mqtt_mock):
|
|||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("preset_mode") == "hold-on"
|
||||
|
||||
await common.async_set_preset_mode(hass, PRESET_ECO, ENTITY_CLIMATE)
|
||||
mqtt_mock.async_publish.assert_called_once_with("hold-topic", "eco", 0, False)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("preset_mode") == PRESET_ECO
|
||||
|
||||
await common.async_set_preset_mode(hass, PRESET_NONE, ENTITY_CLIMATE)
|
||||
mqtt_mock.async_publish.assert_called_once_with("hold-topic", "off", 0, False)
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
|
|
Loading…
Reference in New Issue