diff --git a/homeassistant/components/alarm_control_panel/__init__.py b/homeassistant/components/alarm_control_panel/__init__.py index 54be6aa4d0b44483b256d44619d3988cc946d303..ea7727cea33493f475b0902750a3b867ce42047b 100644 --- a/homeassistant/components/alarm_control_panel/__init__.py +++ b/homeassistant/components/alarm_control_panel/__init__.py @@ -152,40 +152,48 @@ class AlarmControlPanel(Entity): """Send disarm command.""" raise NotImplementedError() - @asyncio.coroutine def async_alarm_disarm(self, code=None): - """Send disarm command.""" - yield from self.hass.loop.run_in_executor( + """Send disarm command. + + This method must be run in the event loop and returns a coroutine. + """ + return self.hass.loop.run_in_executor( None, self.alarm_disarm, code) def alarm_arm_home(self, code=None): """Send arm home command.""" raise NotImplementedError() - @asyncio.coroutine def async_alarm_arm_home(self, code=None): - """Send arm home command.""" - yield from self.hass.loop.run_in_executor( + """Send arm home command. + + This method must be run in the event loop and returns a coroutine. + """ + return self.hass.loop.run_in_executor( None, self.alarm_arm_home, code) def alarm_arm_away(self, code=None): """Send arm away command.""" raise NotImplementedError() - @asyncio.coroutine def async_alarm_arm_away(self, code=None): - """Send arm away command.""" - yield from self.hass.loop.run_in_executor( + """Send arm away command. + + This method must be run in the event loop and returns a coroutine. + """ + return self.hass.loop.run_in_executor( None, self.alarm_arm_away, code) def alarm_trigger(self, code=None): """Send alarm trigger command.""" raise NotImplementedError() - @asyncio.coroutine def async_alarm_trigger(self, code=None): - """Send alarm trigger command.""" - yield from self.hass.loop.run_in_executor( + """Send alarm trigger command. + + This method must be run in the event loop and returns a coroutine. + """ + return self.hass.loop.run_in_executor( None, self.alarm_trigger, code) @property diff --git a/homeassistant/components/camera/__init__.py b/homeassistant/components/camera/__init__.py index 427d4535ef6af956b633f0ef33a8443d83ed816c..8a114cb627d1e7c3862d5a35a76095ea53dbce3a 100644 --- a/homeassistant/components/camera/__init__.py +++ b/homeassistant/components/camera/__init__.py @@ -81,15 +81,12 @@ class Camera(Entity): """Return bytes of camera image.""" raise NotImplementedError() - @asyncio.coroutine def async_camera_image(self): """Return bytes of camera image. - This method must be run in the event loop. + This method must be run in the event loop and returns a coroutine. """ - image = yield from self.hass.loop.run_in_executor( - None, self.camera_image) - return image + return self.hass.loop.run_in_executor(None, self.camera_image) @asyncio.coroutine def handle_async_mjpeg_stream(self, request): diff --git a/homeassistant/components/remote/__init__.py b/homeassistant/components/remote/__init__.py index 2baef2011fc5e758d20982749b5fdcb873ee8a2c..118a160c3059a2633566839e41d1e5122e76962c 100755 --- a/homeassistant/components/remote/__init__.py +++ b/homeassistant/components/remote/__init__.py @@ -149,6 +149,9 @@ class RemoteDevice(ToggleEntity): raise NotImplementedError() def async_send_command(self, **kwargs): - """Send a command to a device.""" - yield from self.hass.loop.run_in_executor( + """Send a command to a device. + + This method must be run in the event loop and returns a coroutine. + """ + return self.hass.loop.run_in_executor( None, ft.partial(self.send_command, **kwargs)) diff --git a/homeassistant/components/scene/__init__.py b/homeassistant/components/scene/__init__.py index 3f532a33151544008378f98bd1b2aea1af1d6832..7e20338f4ab0d35e0e81d65813bcc9e091568ffc 100644 --- a/homeassistant/components/scene/__init__.py +++ b/homeassistant/components/scene/__init__.py @@ -96,10 +96,9 @@ class Scene(Entity): """Activate scene. Try to get entities into requested state.""" raise NotImplementedError() - @asyncio.coroutine def async_activate(self): """Activate scene. Try to get entities into requested state. - This method is a coroutine. + This method must be run in the event loop and returns a coroutine. """ - yield from self.hass.loop.run_in_executor(None, self.activate) + return self.hass.loop.run_in_executor(None, self.activate) diff --git a/homeassistant/components/tts/__init__.py b/homeassistant/components/tts/__init__.py index 32cbbaa265bc39d8e9163c41249d4bdc169f4909..bd19de52a9834112c2bf6cff461144c8717754a2 100644 --- a/homeassistant/components/tts/__init__.py +++ b/homeassistant/components/tts/__init__.py @@ -384,17 +384,15 @@ class Provider(object): """Load tts audio file from provider.""" raise NotImplementedError() - @asyncio.coroutine def async_get_tts_audio(self, message): """Load tts audio file from provider. Return a tuple of file extension and data as bytes. - This method is a coroutine. + This method must be run in the event loop and returns a coroutine. """ - extension, data = yield from self.hass.loop.run_in_executor( + return self.hass.loop.run_in_executor( None, self.get_tts_audio, message) - return (extension, data) class TextToSpeechView(HomeAssistantView): diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index 4137a31b8b673f319cd5a22fbbd26513130c5b6e..0d2f56f18072dcad3d0e23a91bf2feddc8fb09e8 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -346,20 +346,24 @@ class ToggleEntity(Entity): """Turn the entity on.""" raise NotImplementedError() - @asyncio.coroutine def async_turn_on(self, **kwargs): - """Turn the entity on.""" - yield from self.hass.loop.run_in_executor( + """Turn the entity on. + + This method must be run in the event loop and returns a coroutine. + """ + return self.hass.loop.run_in_executor( None, ft.partial(self.turn_on, **kwargs)) def turn_off(self, **kwargs) -> None: """Turn the entity off.""" raise NotImplementedError() - @asyncio.coroutine def async_turn_off(self, **kwargs): - """Turn the entity off.""" - yield from self.hass.loop.run_in_executor( + """Turn the entity off. + + This method must be run in the event loop and returns a coroutine. + """ + return self.hass.loop.run_in_executor( None, ft.partial(self.turn_off, **kwargs)) def toggle(self) -> None: @@ -369,10 +373,12 @@ class ToggleEntity(Entity): else: self.turn_on() - @asyncio.coroutine def async_toggle(self): - """Toggle the entity.""" + """Toggle the entity. + + This method must be run in the event loop and returns a coroutine. + """ if self.is_on: - yield from self.async_turn_off() + return self.async_turn_off() else: - yield from self.async_turn_on() + return self.async_turn_on()