Skip to content

Commit c734219

Browse files
authored
Merge pull request #2304 from AppDaemon/render-template
pass kwargs thru
2 parents 1d82b22 + 374860a commit c734219

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

appdaemon/plugins/hass/hassapi.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,17 +1343,17 @@ def run_script(
13431343
# Functions that use self.render_template
13441344

13451345
@utils.sync_decorator
1346-
async def render_template(self, template: str, namespace: str | None = None) -> Any:
1346+
async def render_template(self, template: str, namespace: str | None = None, **kwargs) -> Any:
13471347
"""Renders a Home Assistant Template.
13481348
13491349
See the documentation for the `Template Integration <https://www.home-assistant.io/integrations/template>`__ and
13501350
`Templating Configuration <https://www.home-assistant.io/docs/configuration/templating>`__ for more information.
13511351
13521352
Args:
13531353
template (str): The Home Assistant template to be rendered.
1354-
namespace (str, optional): Namespace to use for the call. See the section on
1355-
`namespaces <APPGUIDE.html#namespaces>`__ for a detailed description.
1356-
In most cases it is safe to ignore this parameter.
1354+
namespace (str, optional): Optional namespace to use. Defaults to using the app's current namespace. See the
1355+
`namespace documentation <APPGUIDE.html#namespaces>`__ for more information.
1356+
**kwargs (optional): Zero or more keyword arguments that get passed to the template rendering.
13571357
13581358
Returns:
13591359
The rendered template in a native Python type.
@@ -1368,11 +1368,14 @@ async def render_template(self, template: str, namespace: str | None = None) ->
13681368
>>> self.render_template("{{ states('sensor.outside_temp') }}")
13691369
97.2
13701370
1371+
>>> self.render_template("hello {{ name }}", variables={"name": "bob"})
1372+
hello bob
1373+
13711374
"""
13721375
plugin: "HassPlugin" = self.AD.plugins.get_plugin_object(
13731376
namespace or self.namespace
13741377
)
1375-
result = await plugin.render_template(self.namespace, template)
1378+
result = await plugin.render_template(self.namespace, template, **kwargs)
13761379
try:
13771380
return literal_eval(result)
13781381
except (SyntaxError, ValueError):

appdaemon/plugins/hass/hassplugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ async def get_logbook(
888888
return result
889889

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

898898
# if we get a request for not our namespace something has gone very wrong
899899
assert namespace == self.namespace
900-
return await self.http_method("post", "/api/template", template=template)
900+
return await self.http_method("post", "/api/template", template=template, **kwargs)

docs/HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ None
1111
- Fixed a cosmetic error on admin stream disconnect
1212
- Fixed spurious entry in service dictionary causing dashboard `__name`` errors
1313
- Added setter for setter for `pin_apps`
14+
- Passing through keyword arguments to `render_template`
1415
- Fixed a bug in the error text for apps in a custom app_dir
1516

1617
**Breaking Changes**

0 commit comments

Comments
 (0)