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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix recursion bug #32009

Merged
merged 2 commits into from Feb 20, 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
12 changes: 11 additions & 1 deletion homeassistant/components/homeassistant/__init__.py
Expand Up @@ -55,6 +55,15 @@ async def async_handle_turn_service(service):
tasks = []

for domain, ent_ids in by_domain:
# This leads to endless loop.
if domain == DOMAIN:
_LOGGER.warning(
"Called service homeassistant.%s with invalid entity IDs %s",
service.service,
", ".join(ent_ids),
)
continue

# We want to block for all calls and only return when all calls
# have been processed. If a service does not exist it causes a 10
# second delay while we're blocking waiting for a response.
Expand All @@ -73,7 +82,8 @@ async def async_handle_turn_service(service):
hass.services.async_call(domain, service.service, data, blocking)
)

await asyncio.wait(tasks)
if tasks:
await asyncio.gather(*tasks)

service_schema = vol.Schema({ATTR_ENTITY_ID: cv.entity_ids}, extra=vol.ALLOW_EXTRA)

Expand Down
14 changes: 14 additions & 0 deletions tests/components/homeassistant/test_init.py
Expand Up @@ -372,3 +372,17 @@ async def test_turn_on_off_toggle_schema(hass, hass_read_only_user):
context=ha.Context(user_id=hass_read_only_user.id),
blocking=True,
)


async def test_not_allowing_recursion(hass, caplog):
"""Test we do not allow recursion."""
await async_setup_component(hass, "homeassistant", {})

for service in SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE:
await hass.services.async_call(
ha.DOMAIN, service, {"entity_id": "homeassistant.light"}, blocking=True,
)
assert (
f"Called service homeassistant.{service} with invalid entity IDs homeassistant.light"
in caplog.text
), service