mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Use HVACAction in mqtt (#71726)
This commit is contained in:
parent
8f50a70ff5
commit
a0f741778a
@ -15,7 +15,6 @@ from homeassistant.components.climate.const import (
|
|||||||
ATTR_HVAC_MODE,
|
ATTR_HVAC_MODE,
|
||||||
ATTR_TARGET_TEMP_HIGH,
|
ATTR_TARGET_TEMP_HIGH,
|
||||||
ATTR_TARGET_TEMP_LOW,
|
ATTR_TARGET_TEMP_LOW,
|
||||||
CURRENT_HVAC_ACTIONS,
|
|
||||||
DEFAULT_MAX_TEMP,
|
DEFAULT_MAX_TEMP,
|
||||||
DEFAULT_MIN_TEMP,
|
DEFAULT_MIN_TEMP,
|
||||||
FAN_AUTO,
|
FAN_AUTO,
|
||||||
@ -529,21 +528,23 @@ class MqttClimate(MqttEntity, ClimateEntity):
|
|||||||
def handle_action_received(msg):
|
def handle_action_received(msg):
|
||||||
"""Handle receiving action via MQTT."""
|
"""Handle receiving action via MQTT."""
|
||||||
payload = render_template(msg, CONF_ACTION_TEMPLATE)
|
payload = render_template(msg, CONF_ACTION_TEMPLATE)
|
||||||
if payload in CURRENT_HVAC_ACTIONS:
|
if not payload or payload == PAYLOAD_NONE:
|
||||||
self._action = payload
|
|
||||||
self.async_write_ha_state()
|
|
||||||
elif not payload or payload == PAYLOAD_NONE:
|
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Invalid %s action: %s, ignoring",
|
"Invalid %s action: %s, ignoring",
|
||||||
CURRENT_HVAC_ACTIONS,
|
[e.value for e in HVACAction],
|
||||||
payload,
|
payload,
|
||||||
)
|
)
|
||||||
else:
|
return
|
||||||
|
try:
|
||||||
|
self._action = HVACAction(payload)
|
||||||
|
except ValueError:
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"Invalid %s action: %s",
|
"Invalid %s action: %s",
|
||||||
CURRENT_HVAC_ACTIONS,
|
[e.value for e in HVACAction],
|
||||||
payload,
|
payload,
|
||||||
)
|
)
|
||||||
|
return
|
||||||
|
self.async_write_ha_state()
|
||||||
|
|
||||||
add_subscription(topics, CONF_ACTION_TOPIC, handle_action_received)
|
add_subscription(topics, CONF_ACTION_TOPIC, handle_action_received)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user