Make variable entity_id available to value_template for MQTT binary sensor (#19195)
* MQTT binary_sensor: Make variable `entity_id` available to value_template * Review comments * Add testcase
This commit is contained in:
1 parent
e886576a64
commit
b97f0c0261
3 files changed
+33
-5
No files matched your search
@@ -149,7 +149,8 @@ class Template:
|
||||
error_value).result()
|
||||
|
||||
def async_render_with_possible_json_value(self, value,
|
||||
error_value=_SENTINEL):
|
||||
error_value=_SENTINEL,
|
||||
variables=None):
|
||||
"""Render template with value exposed.
|
||||
|
||||
If valid JSON will expose value_json too.
|
||||
@@ -159,9 +160,9 @@ class Template:
|
||||
if self._compiled is None:
|
||||
self._ensure_compiled()
|
||||
|
||||
variables = {
|
||||
'value': value
|
||||
}
|
||||
variables = dict(variables or {})
|
||||
variables['value'] = value
|
||||
|
||||
try:
|
||||
variables['value_json'] = json.loads(value)
|
||||
except ValueError:
|
||||
|
||||
Reference in new issue
Block a user