Add is_number as a test for use in select, selectattr, reject, and re… (#63732)

pull/63826/head
Petro31 2022-01-10 07:00:43 -05:00 committed by GitHub
parent 912ff76fda
commit 9c6c13a55c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -1939,6 +1939,7 @@ class TemplateEnvironment(ImmutableSandboxedEnvironment):
self.globals["unpack"] = struct_unpack
self.globals["slugify"] = slugify
self.globals["iif"] = iif
self.tests["is_number"] = is_number
self.tests["match"] = regex_match
self.tests["search"] = regex_search

View File

@ -314,6 +314,12 @@ def test_isnumber(hass, value, expected):
)
== expected
)
assert (
template.Template("{{ value is is_number }}", hass).async_render(
{"value": value}
)
== expected
)
def test_rounding_value(hass):