From 042321be6019366fc5449e3015f6234ff6513424 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Fri, 13 May 2022 17:28:36 +0200 Subject: [PATCH] Support this variable in template button actions (#71792) --- homeassistant/components/template/button.py | 2 +- tests/components/template/test_button.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/template/button.py b/homeassistant/components/template/button.py index d6f41649734..ac83f76ca91 100644 --- a/homeassistant/components/template/button.py +++ b/homeassistant/components/template/button.py @@ -93,4 +93,4 @@ class TemplateButtonEntity(TemplateEntity, ButtonEntity): async def async_press(self) -> None: """Press the button.""" - await self._command_press.async_run(context=self._context) + await self.async_run_script(self._command_press, context=self._context) diff --git a/tests/components/template/test_button.py b/tests/components/template/test_button.py index 25bced16ed2..48bedd8e928 100644 --- a/tests/components/template/test_button.py +++ b/tests/components/template/test_button.py @@ -68,7 +68,10 @@ async def test_all_optional_config(hass, calls): "template": { "unique_id": "test", "button": { - "press": {"service": "test.automation"}, + "press": { + "service": "test.automation", + "data_template": {"caller": "{{ this.entity_id }}"}, + }, "device_class": "restart", "unique_id": "test", "name": "test", @@ -104,6 +107,7 @@ async def test_all_optional_config(hass, calls): ) assert len(calls) == 1 + assert calls[0].data["caller"] == _TEST_OPTIONS_BUTTON _verify( hass,