Allow to change MQTT climate hold mode (#28988)
This commit is contained in:
parent
5f4fc271d4
commit
4881bc04d8
2 changed files with 27 additions and 5 deletions
|
@ -756,12 +756,14 @@ class MqttClimate(
|
||||||
if self._away:
|
if self._away:
|
||||||
optimistic_update = optimistic_update or self._set_away_mode(False)
|
optimistic_update = optimistic_update or self._set_away_mode(False)
|
||||||
elif preset_mode == PRESET_AWAY:
|
elif preset_mode == PRESET_AWAY:
|
||||||
|
if self._hold:
|
||||||
|
self._set_hold_mode(None)
|
||||||
optimistic_update = optimistic_update or self._set_away_mode(True)
|
optimistic_update = optimistic_update or self._set_away_mode(True)
|
||||||
|
else:
|
||||||
if self._hold:
|
hold_mode = preset_mode
|
||||||
optimistic_update = optimistic_update or self._set_hold_mode(None)
|
if preset_mode == PRESET_NONE:
|
||||||
elif preset_mode not in (None, PRESET_AWAY):
|
hold_mode = None
|
||||||
optimistic_update = optimistic_update or self._set_hold_mode(preset_mode)
|
optimistic_update = optimistic_update or self._set_hold_mode(hold_mode)
|
||||||
|
|
||||||
if optimistic_update:
|
if optimistic_update:
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
|
@ -23,6 +23,7 @@ from homeassistant.components.climate.const import (
|
||||||
HVAC_MODE_FAN_ONLY,
|
HVAC_MODE_FAN_ONLY,
|
||||||
SUPPORT_TARGET_TEMPERATURE_RANGE,
|
SUPPORT_TARGET_TEMPERATURE_RANGE,
|
||||||
PRESET_NONE,
|
PRESET_NONE,
|
||||||
|
PRESET_ECO,
|
||||||
)
|
)
|
||||||
from homeassistant.components.mqtt.discovery import async_start
|
from homeassistant.components.mqtt.discovery import async_start
|
||||||
from homeassistant.const import STATE_OFF, STATE_UNAVAILABLE
|
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)
|
state = hass.states.get(ENTITY_CLIMATE)
|
||||||
assert state.attributes.get("preset_mode") is None
|
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):
|
async def test_set_hvac_action(hass, mqtt_mock):
|
||||||
"""Test setting of the HVAC action."""
|
"""Test setting of the HVAC action."""
|
||||||
|
@ -495,6 +509,12 @@ async def test_set_hold(hass, mqtt_mock):
|
||||||
state = hass.states.get(ENTITY_CLIMATE)
|
state = hass.states.get(ENTITY_CLIMATE)
|
||||||
assert state.attributes.get("preset_mode") == "hold-on"
|
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)
|
await common.async_set_preset_mode(hass, PRESET_NONE, ENTITY_CLIMATE)
|
||||||
mqtt_mock.async_publish.assert_called_once_with("hold-topic", "off", 0, False)
|
mqtt_mock.async_publish.assert_called_once_with("hold-topic", "off", 0, False)
|
||||||
state = hass.states.get(ENTITY_CLIMATE)
|
state = hass.states.get(ENTITY_CLIMATE)
|
||||||
|
|
Loading…
Add table
Reference in a new issue