Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions appdaemon/plugins/hass/hassapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1343,17 +1343,17 @@ def run_script(
# Functions that use self.render_template

@utils.sync_decorator
async def render_template(self, template: str, namespace: str | None = None) -> Any:
async def render_template(self, template: str, namespace: str | None = None, **kwargs) -> Any:
"""Renders a Home Assistant Template.

See the documentation for the `Template Integration <https://www.home-assistant.io/integrations/template>`__ and
`Templating Configuration <https://www.home-assistant.io/docs/configuration/templating>`__ for more information.

Args:
template (str): The Home Assistant template to be rendered.
namespace (str, optional): Namespace to use for the call. See the section on
`namespaces <APPGUIDE.html#namespaces>`__ for a detailed description.
In most cases it is safe to ignore this parameter.
namespace (str, optional): Optional namespace to use. Defaults to using the app's current namespace. See the
`namespace documentation <APPGUIDE.html#namespaces>`__ for more information.
**kwargs (optional): Zero or more keyword arguments that get passed to the template rendering.

Returns:
The rendered template in a native Python type.
Expand All @@ -1368,11 +1368,14 @@ async def render_template(self, template: str, namespace: str | None = None) ->
>>> self.render_template("{{ states('sensor.outside_temp') }}")
97.2

>>> self.render_template("hello {{ name }}", variables={"name": "bob"})
hello bob

"""
plugin: "HassPlugin" = self.AD.plugins.get_plugin_object(
namespace or self.namespace
)
result = await plugin.render_template(self.namespace, template)
result = await plugin.render_template(self.namespace, template, **kwargs)
try:
return literal_eval(result)
except (SyntaxError, ValueError):
Expand Down
4 changes: 2 additions & 2 deletions appdaemon/plugins/hass/hassplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ async def get_logbook(
return result

@utils.warning_decorator(error_text='Unexpected error rendering template')
async def render_template(self, namespace: str, template: str):
async def render_template(self, namespace: str, template: str, **kwargs):
self.logger.debug(
"render_template() namespace=%s data=%s",
namespace,
Expand All @@ -897,4 +897,4 @@ async def render_template(self, namespace: str, template: str):

# if we get a request for not our namespace something has gone very wrong
assert namespace == self.namespace
return await self.http_method("post", "/api/template", template=template)
return await self.http_method("post", "/api/template", template=template, **kwargs)
1 change: 1 addition & 0 deletions docs/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ None
- Fixed a cosmetic error on admin stream disconnect
- Fixed spurious entry in service dictionary causing dashboard `__name`` errors
- Added setter for setter for `pin_apps`
- Passing through keyword arguments to `render_template`
- Fixed a bug in the error text for apps in a custom app_dir

**Breaking Changes**
Expand Down
Loading