Allow resetting MQTT climate attributes and ignore empty values (#87936)

Allow reseting MQTT climate attributes
This commit is contained in:
Jan Bouwhuis 2023-02-15 16:31:49 +01:00 committed by GitHub
parent 61539686a4
commit 03e9dff327
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 3 deletions

View file

@ -646,7 +646,16 @@ class MqttClimate(MqttEntity, ClimateEntity):
) -> None:
"""Handle climate attributes coming via MQTT."""
payload = render_template(msg, template_name)
if not payload:
_LOGGER.debug(
"Invalid empty payload for attribute %s, ignoring update",
attr,
)
return
if payload == PAYLOAD_NONE:
setattr(self, attr, None)
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)
return
try:
setattr(self, attr, float(payload))
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)