From f463f4d8c6fd15ae8472b63268d32c3f60d49a6f Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Wed, 1 Nov 2017 15:48:09 +0100 Subject: [PATCH] WIP: Cleanup async stuff on templates (#10275) Cleanup async stuff on templates --- homeassistant/components/cover/template.py | 2 +- homeassistant/components/switch/template.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/cover/template.py b/homeassistant/components/cover/template.py index 843f0ed8a4c..34aa636185e 100644 --- a/homeassistant/components/cover/template.py +++ b/homeassistant/components/cover/template.py @@ -301,7 +301,7 @@ class CoverTemplate(CoverDevice): def async_stop_cover(self, **kwargs): """Fire the stop action.""" if self._stop_script: - self.hass.async_add_job(self._stop_script.async_run()) + yield from self._stop_script.async_run() @asyncio.coroutine def async_set_cover_position(self, **kwargs): diff --git a/homeassistant/components/switch/template.py b/homeassistant/components/switch/template.py index b9753ba6629..93ebf98e9ac 100644 --- a/homeassistant/components/switch/template.py +++ b/homeassistant/components/switch/template.py @@ -152,13 +152,15 @@ class SwitchTemplate(SwitchDevice): """Return the entity_picture to use in the frontend, if any.""" return self._entity_picture - def turn_on(self, **kwargs): + @asyncio.coroutine + def async_turn_on(self, **kwargs): """Fire the on action.""" - self._on_script.run() + yield from self._on_script.async_run() - def turn_off(self, **kwargs): + @asyncio.coroutine + def async_turn_off(self, **kwargs): """Fire the off action.""" - self._off_script.run() + yield from self._off_script.async_run() @asyncio.coroutine def async_update(self):