Guard for callbacks in service helper (#31339)
parent
a53c3d10fe
commit
c6baf026a7
|
@ -400,19 +400,17 @@ class Camera(Entity):
|
||||||
"""Turn off camera."""
|
"""Turn off camera."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@callback
|
async def async_turn_off(self):
|
||||||
def async_turn_off(self):
|
|
||||||
"""Turn off camera."""
|
"""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):
|
def turn_on(self):
|
||||||
"""Turn off camera."""
|
"""Turn off camera."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@callback
|
async def async_turn_on(self):
|
||||||
def async_turn_on(self):
|
|
||||||
"""Turn off camera."""
|
"""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):
|
def enable_motion_detection(self):
|
||||||
"""Enable motion detection in the camera."""
|
"""Enable motion detection in the camera."""
|
||||||
|
|
|
@ -370,9 +370,13 @@ async def _handle_service_platform_call(
|
||||||
entity.async_set_context(context)
|
entity.async_set_context(context)
|
||||||
|
|
||||||
if isinstance(func, str):
|
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:
|
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):
|
if asyncio.iscoroutine(result):
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
|
|
Loading…
Reference in New Issue