mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Guard for callbacks in service helper (#31339)
This commit is contained in:
parent
b22dfa119b
commit
d405069406
@ -400,19 +400,17 @@ class Camera(Entity):
|
||||
"""Turn off camera."""
|
||||
raise NotImplementedError()
|
||||
|
||||
@callback
|
||||
def async_turn_off(self):
|
||||
async def async_turn_off(self):
|
||||
"""Turn off camera."""
|
||||
return self.hass.async_add_job(self.turn_off)
|
||||
await self.hass.async_add_job(self.turn_off)
|
||||
|
||||
def turn_on(self):
|
||||
"""Turn off camera."""
|
||||
raise NotImplementedError()
|
||||
|
||||
@callback
|
||||
def async_turn_on(self):
|
||||
async def async_turn_on(self):
|
||||
"""Turn off camera."""
|
||||
return self.hass.async_add_job(self.turn_on)
|
||||
await self.hass.async_add_job(self.turn_on)
|
||||
|
||||
def enable_motion_detection(self):
|
||||
"""Enable motion detection in the camera."""
|
||||
|
@ -370,9 +370,13 @@ async def _handle_service_platform_call(
|
||||
entity.async_set_context(context)
|
||||
|
||||
if isinstance(func, str):
|
||||
result = await hass.async_add_job(partial(getattr(entity, func), **data))
|
||||
result = hass.async_add_job(partial(getattr(entity, func), **data))
|
||||
else:
|
||||
result = await hass.async_add_job(func, entity, data)
|
||||
result = hass.async_add_job(func, entity, data)
|
||||
|
||||
# Guard because callback functions do not return a task when passed to async_add_job.
|
||||
if result is not None:
|
||||
result = await result
|
||||
|
||||
if asyncio.iscoroutine(result):
|
||||
_LOGGER.error(
|
||||
|
Loading…
x
Reference in New Issue
Block a user