Fix MQTT climate action null warnings (#64658)
This commit is contained in:
parent
f6c679699f
commit
0cabf3e577
2 changed files with 17 additions and 0 deletions
|
@ -125,6 +125,8 @@ CONF_TEMP_MAX = "max_temp"
|
||||||
CONF_TEMP_MIN = "min_temp"
|
CONF_TEMP_MIN = "min_temp"
|
||||||
CONF_TEMP_STEP = "temp_step"
|
CONF_TEMP_STEP = "temp_step"
|
||||||
|
|
||||||
|
PAYLOAD_NONE = "None"
|
||||||
|
|
||||||
MQTT_CLIMATE_ATTRIBUTES_BLOCKED = frozenset(
|
MQTT_CLIMATE_ATTRIBUTES_BLOCKED = frozenset(
|
||||||
{
|
{
|
||||||
climate.ATTR_AUX_HEAT,
|
climate.ATTR_AUX_HEAT,
|
||||||
|
@ -441,6 +443,12 @@ class MqttClimate(MqttEntity, ClimateEntity):
|
||||||
if payload in CURRENT_HVAC_ACTIONS:
|
if payload in CURRENT_HVAC_ACTIONS:
|
||||||
self._action = payload
|
self._action = payload
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
elif not payload or payload == PAYLOAD_NONE:
|
||||||
|
_LOGGER.debug(
|
||||||
|
"Invalid %s action: %s, ignoring",
|
||||||
|
CURRENT_HVAC_ACTIONS,
|
||||||
|
payload,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"Invalid %s action: %s",
|
"Invalid %s action: %s",
|
||||||
|
|
|
@ -900,6 +900,15 @@ async def test_get_with_templates(hass, mqtt_mock, caplog):
|
||||||
state = hass.states.get(ENTITY_CLIMATE)
|
state = hass.states.get(ENTITY_CLIMATE)
|
||||||
assert state.attributes.get("hvac_action") == "cooling"
|
assert state.attributes.get("hvac_action") == "cooling"
|
||||||
|
|
||||||
|
# Test ignoring null values
|
||||||
|
async_fire_mqtt_message(hass, "action", "null")
|
||||||
|
state = hass.states.get(ENTITY_CLIMATE)
|
||||||
|
assert state.attributes.get("hvac_action") == "cooling"
|
||||||
|
assert (
|
||||||
|
"Invalid ['off', 'heating', 'cooling', 'drying', 'idle', 'fan'] action: None, ignoring"
|
||||||
|
in caplog.text
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_set_with_templates(hass, mqtt_mock, caplog):
|
async def test_set_with_templates(hass, mqtt_mock, caplog):
|
||||||
"""Test setting various attributes with templates."""
|
"""Test setting various attributes with templates."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue