From 52e1282d8c569286c52a9fee79a6791ccc9819da Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Mon, 16 Nov 2020 20:10:55 +0100 Subject: [PATCH] Make MQTT climate return PRESET_NONE when no preset is set (#43257) --- homeassistant/components/mqtt/climate.py | 2 +- tests/components/mqtt/test_climate.py | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/mqtt/climate.py b/homeassistant/components/mqtt/climate.py index 68579559e35..8b762a82f02 100644 --- a/homeassistant/components/mqtt/climate.py +++ b/homeassistant/components/mqtt/climate.py @@ -640,7 +640,7 @@ class MqttClimate( return self._hold if self._away: return PRESET_AWAY - return None + return PRESET_NONE @property def preset_modes(self): diff --git a/tests/components/mqtt/test_climate.py b/tests/components/mqtt/test_climate.py index 3c629a82012..4d049753f43 100644 --- a/tests/components/mqtt/test_climate.py +++ b/tests/components/mqtt/test_climate.py @@ -438,11 +438,11 @@ async def test_set_away_mode_pessimistic(hass, mqtt_mock): await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) - assert state.attributes.get("preset_mode") is None + assert state.attributes.get("preset_mode") == "none" await common.async_set_preset_mode(hass, "away", ENTITY_CLIMATE) state = hass.states.get(ENTITY_CLIMATE) - assert state.attributes.get("preset_mode") is None + assert state.attributes.get("preset_mode") == "none" async_fire_mqtt_message(hass, "away-state", "ON") state = hass.states.get(ENTITY_CLIMATE) @@ -450,11 +450,11 @@ async def test_set_away_mode_pessimistic(hass, mqtt_mock): async_fire_mqtt_message(hass, "away-state", "OFF") state = hass.states.get(ENTITY_CLIMATE) - assert state.attributes.get("preset_mode") is None + assert state.attributes.get("preset_mode") == "none" async_fire_mqtt_message(hass, "away-state", "nonsense") state = hass.states.get(ENTITY_CLIMATE) - assert state.attributes.get("preset_mode") is None + assert state.attributes.get("preset_mode") == "none" async def test_set_away_mode(hass, mqtt_mock): @@ -467,7 +467,7 @@ async def test_set_away_mode(hass, mqtt_mock): await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) - assert state.attributes.get("preset_mode") is None + assert state.attributes.get("preset_mode") == "none" await common.async_set_preset_mode(hass, "away", ENTITY_CLIMATE) mqtt_mock.async_publish.assert_called_once_with("away-mode-topic", "AN", 0, False) mqtt_mock.async_publish.reset_mock() @@ -477,7 +477,7 @@ async def test_set_away_mode(hass, mqtt_mock): await common.async_set_preset_mode(hass, PRESET_NONE, ENTITY_CLIMATE) mqtt_mock.async_publish.assert_called_once_with("away-mode-topic", "AUS", 0, False) state = hass.states.get(ENTITY_CLIMATE) - assert state.attributes.get("preset_mode") is None + assert state.attributes.get("preset_mode") == "none" await common.async_set_preset_mode(hass, "hold-on", ENTITY_CLIMATE) mqtt_mock.async_publish.reset_mock() @@ -525,7 +525,7 @@ async def test_set_hold_pessimistic(hass, mqtt_mock): async_fire_mqtt_message(hass, "hold-state", "off") state = hass.states.get(ENTITY_CLIMATE) - assert state.attributes.get("preset_mode") is None + assert state.attributes.get("preset_mode") == "none" async def test_set_hold(hass, mqtt_mock): @@ -534,7 +534,7 @@ async def test_set_hold(hass, mqtt_mock): await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) - assert state.attributes.get("preset_mode") is None + assert state.attributes.get("preset_mode") == "none" await common.async_set_preset_mode(hass, "hold-on", ENTITY_CLIMATE) mqtt_mock.async_publish.assert_called_once_with("hold-topic", "hold-on", 0, False) mqtt_mock.async_publish.reset_mock() @@ -550,7 +550,7 @@ async def test_set_hold(hass, mqtt_mock): 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) - assert state.attributes.get("preset_mode") is None + assert state.attributes.get("preset_mode") == "none" async def test_set_preset_mode_twice(hass, mqtt_mock): @@ -559,7 +559,7 @@ async def test_set_preset_mode_twice(hass, mqtt_mock): await hass.async_block_till_done() state = hass.states.get(ENTITY_CLIMATE) - assert state.attributes.get("preset_mode") is None + assert state.attributes.get("preset_mode") == "none" await common.async_set_preset_mode(hass, "hold-on", ENTITY_CLIMATE) mqtt_mock.async_publish.assert_called_once_with("hold-topic", "hold-on", 0, False) mqtt_mock.async_publish.reset_mock() @@ -735,7 +735,7 @@ async def test_set_with_templates(hass, mqtt_mock, caplog): assert state.attributes.get("temperature") == 1031 # Away Mode - assert state.attributes.get("preset_mode") is None + assert state.attributes.get("preset_mode") == "none" async_fire_mqtt_message(hass, "away-state", '"ON"') state = hass.states.get(ENTITY_CLIMATE) assert state.attributes.get("preset_mode") == "away" @@ -743,7 +743,7 @@ async def test_set_with_templates(hass, mqtt_mock, caplog): # Away Mode with JSON values async_fire_mqtt_message(hass, "away-state", "false") state = hass.states.get(ENTITY_CLIMATE) - assert state.attributes.get("preset_mode") is None + assert state.attributes.get("preset_mode") == "none" async_fire_mqtt_message(hass, "away-state", "true") state = hass.states.get(ENTITY_CLIMATE)