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:
parent
ee602e40a6
commit
e9e44dbd97
90 changed files with 627 additions and 883 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue