Fix callback and async (#31281)

* Fix callback and async

* Fix a return

* Fix test

* Fix mqtt tests

* Fix some more callbacks
This commit is contained in:
Paulus Schoutsen 2020-01-29 13:59:45 -08:00 committed by GitHub
parent ee602e40a6
commit e9e44dbd97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
90 changed files with 627 additions and 883 deletions

View file

@ -596,23 +596,17 @@ class ToggleEntity(Entity):
"""Turn the entity on."""
raise NotImplementedError()
def async_turn_on(self, **kwargs):
"""Turn the entity on.
This method must be run in the event loop and returns a coroutine.
"""
return self.hass.async_add_job(ft.partial(self.turn_on, **kwargs))
async def async_turn_on(self, **kwargs):
"""Turn the entity on."""
await self.hass.async_add_job(ft.partial(self.turn_on, **kwargs))
def turn_off(self, **kwargs: Any) -> None:
"""Turn the entity off."""
raise NotImplementedError()
def async_turn_off(self, **kwargs):
"""Turn the entity off.
This method must be run in the event loop and returns a coroutine.
"""
return self.hass.async_add_job(ft.partial(self.turn_off, **kwargs))
async def async_turn_off(self, **kwargs):
"""Turn the entity off."""
await self.hass.async_add_job(ft.partial(self.turn_off, **kwargs))
def toggle(self, **kwargs: Any) -> None:
"""Toggle the entity."""
@ -621,11 +615,9 @@ class ToggleEntity(Entity):
else:
self.turn_on(**kwargs)
def async_toggle(self, **kwargs):
"""Toggle the entity.
This method must be run in the event loop and returns a coroutine.
"""
async def async_toggle(self, **kwargs):
"""Toggle the entity."""
if self.is_on:
return self.async_turn_off(**kwargs)
return self.async_turn_on(**kwargs)
await self.async_turn_off(**kwargs)
else:
await self.async_turn_on(**kwargs)