Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard for callbacks in service helper #31339

Merged
merged 1 commit into from Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions homeassistant/components/camera/__init__.py
Expand Up @@ -400,19 +400,17 @@ def turn_off(self):
"""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."""
Expand Down
8 changes: 6 additions & 2 deletions homeassistant/helpers/service.py
Expand Up @@ -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(
Expand Down