mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
Avoid constructing mqtt availability template objects when there is no template (#118171)
This commit is contained in:
parent
c368ffffd5
commit
8b3cad372e
@ -498,10 +498,10 @@ class MqttAvailabilityMixin(Entity):
|
|||||||
}
|
}
|
||||||
|
|
||||||
for avail_topic_conf in self._avail_topics.values():
|
for avail_topic_conf in self._avail_topics.values():
|
||||||
avail_topic_conf[CONF_AVAILABILITY_TEMPLATE] = MqttValueTemplate(
|
if template := avail_topic_conf[CONF_AVAILABILITY_TEMPLATE]:
|
||||||
avail_topic_conf[CONF_AVAILABILITY_TEMPLATE],
|
avail_topic_conf[CONF_AVAILABILITY_TEMPLATE] = MqttValueTemplate(
|
||||||
entity=self,
|
template, entity=self
|
||||||
).async_render_with_possible_json_value
|
).async_render_with_possible_json_value
|
||||||
|
|
||||||
self._avail_config = config
|
self._avail_config = config
|
||||||
|
|
||||||
@ -537,7 +537,9 @@ class MqttAvailabilityMixin(Entity):
|
|||||||
"""Handle a new received MQTT availability message."""
|
"""Handle a new received MQTT availability message."""
|
||||||
topic = msg.topic
|
topic = msg.topic
|
||||||
avail_topic = self._avail_topics[topic]
|
avail_topic = self._avail_topics[topic]
|
||||||
payload = avail_topic[CONF_AVAILABILITY_TEMPLATE](msg.payload)
|
template = avail_topic[CONF_AVAILABILITY_TEMPLATE]
|
||||||
|
payload = template(msg.payload) if template else msg.payload
|
||||||
|
|
||||||
if payload == avail_topic[CONF_PAYLOAD_AVAILABLE]:
|
if payload == avail_topic[CONF_PAYLOAD_AVAILABLE]:
|
||||||
self._available[topic] = True
|
self._available[topic] = True
|
||||||
self._available_latest = True
|
self._available_latest = True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user