Skip to content

Commit

Permalink
Allow template method to be named different for tests and filters (#549)
Browse files Browse the repository at this point in the history
  • Loading branch information
frenck authored Jan 10, 2024
1 parent 2872cc4 commit a70ba9e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions custom_components/spook/templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class AbstractSpookTemplateFunction(ABC):

hass: HomeAssistant
name: str
filter_name: str | None = None
test_name: str | None = None

requires_hass_object: bool = True
is_available_in_limited_environment: bool = False
Expand Down Expand Up @@ -59,19 +61,19 @@ def async_register(
if self.is_filter:
# pylint: disable-next=protected-access
if is_limited and not self.is_available_in_limited_environment:
environment.filters[self.name] = unsupported_in_limited_environment(
self.name
)
environment.filters[
self.filter_name or self.name
] = unsupported_in_limited_environment(self.name)
else:
environment.filters[self.name] = self.function()
environment.filters[self.filter_name or self.name] = self.function()

if self.is_test:
if is_limited and not self.is_available_in_limited_environment:
environment.tests[self.name] = unsupported_in_limited_environment(
self.name
)
environment.tests[
self.test_name or self.name
] = unsupported_in_limited_environment(self.name)
else:
environment.tests[self.name] = self.function()
environment.tests[self.test_name or self.name] = self.function()

@final
@callback
Expand Down

0 comments on commit a70ba9e

Please sign in to comment.