mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Add as_local convenience function to jinja templates (#39618)
This commit is contained in:
parent
a9cc882394
commit
35e84d0427
@ -1051,6 +1051,7 @@ class TemplateEnvironment(ImmutableSandboxedEnvironment):
|
||||
self.filters["atan2"] = arc_tangent2
|
||||
self.filters["sqrt"] = square_root
|
||||
self.filters["as_timestamp"] = forgiving_as_timestamp
|
||||
self.filters["as_local"] = dt_util.as_local
|
||||
self.filters["timestamp_custom"] = timestamp_custom
|
||||
self.filters["timestamp_local"] = timestamp_local
|
||||
self.filters["timestamp_utc"] = timestamp_utc
|
||||
@ -1084,6 +1085,7 @@ class TemplateEnvironment(ImmutableSandboxedEnvironment):
|
||||
self.globals["atan2"] = arc_tangent2
|
||||
self.globals["float"] = forgiving_float
|
||||
self.globals["now"] = dt_util.now
|
||||
self.globals["as_local"] = dt_util.as_local
|
||||
self.globals["utcnow"] = dt_util.utcnow
|
||||
self.globals["as_timestamp"] = forgiving_as_timestamp
|
||||
self.globals["relative_time"] = relative_time
|
||||
|
@ -511,6 +511,19 @@ def test_timestamp_local(hass):
|
||||
)
|
||||
|
||||
|
||||
def test_as_local(hass):
|
||||
"""Test converting time to local."""
|
||||
|
||||
hass.states.async_set("test.object", "available")
|
||||
last_updated = hass.states.get("test.object").last_updated
|
||||
assert template.Template(
|
||||
"{{ as_local(states.test.object.last_updated) }}", hass
|
||||
).async_render() == str(dt_util.as_local(last_updated))
|
||||
assert template.Template(
|
||||
"{{ states.test.object.last_updated | as_local }}", hass
|
||||
).async_render() == str(dt_util.as_local(last_updated))
|
||||
|
||||
|
||||
def test_to_json(hass):
|
||||
"""Test the object to JSON string filter."""
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user