Make MQTT climate return PRESET_NONE when no preset is set (#43257)

pull/43297/head
Erik Montnemery 2020-11-16 20:10:55 +01:00 committed by GitHub
parent 4ffba281db
commit 52e1282d8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 13 deletions

View File

@ -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):

View File

@ -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)