1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Async reduce coro (#5001)

* Asyncio coro reduce

* Replace comments
This commit is contained in:
Pascal Vizeli
2016-12-26 14:10:23 +01:00
committed by Paulus Schoutsen
parent 22d1bf0acd
commit 244cdf43d0
6 changed files with 47 additions and 36 deletions

View File

@@ -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()