mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Fail when rendering undefined objects in Jinja2 templates
By not successfully rendering unknown objects to an empty string the caller provided error_value actually gets used. This allows, for instance, the MQTT sensor to retain its state when an unexpected or unwanted message (#2733/#3834) is received.
This commit is contained in:
parent
18f5258aaf
commit
c8add59ea5
@ -60,7 +60,7 @@ class MqttSensor(Entity):
|
|||||||
"""A new MQTT message has been received."""
|
"""A new MQTT message has been received."""
|
||||||
if value_template is not None:
|
if value_template is not None:
|
||||||
payload = value_template.render_with_possible_json_value(
|
payload = value_template.render_with_possible_json_value(
|
||||||
payload)
|
payload, self._state)
|
||||||
self._state = payload
|
self._state = payload
|
||||||
self.update_ha_state()
|
self.update_ha_state()
|
||||||
|
|
||||||
|
@ -402,7 +402,7 @@ class TemplateEnvironment(ImmutableSandboxedEnvironment):
|
|||||||
"""Test if callback is safe."""
|
"""Test if callback is safe."""
|
||||||
return isinstance(obj, AllStates) or super().is_safe_callable(obj)
|
return isinstance(obj, AllStates) or super().is_safe_callable(obj)
|
||||||
|
|
||||||
ENV = TemplateEnvironment()
|
ENV = TemplateEnvironment(undefined=jinja2.StrictUndefined)
|
||||||
ENV.filters['round'] = forgiving_round
|
ENV.filters['round'] = forgiving_round
|
||||||
ENV.filters['multiply'] = multiply
|
ENV.filters['multiply'] = multiply
|
||||||
ENV.filters['timestamp_custom'] = timestamp_custom
|
ENV.filters['timestamp_custom'] = timestamp_custom
|
||||||
|
Loading…
x
Reference in New Issue
Block a user