Add a guard when there are no integration platforms loaded (#70182)

This commit is contained in:
J. Nick Koston 2022-04-17 19:45:52 -10:00 committed by GitHub
parent b74986f9c3
commit b4ef150339
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View file

@ -69,6 +69,9 @@ async def async_process_integration_platform(
that the integration platforms are loaded before the entities
are created.
"""
if DATA_INTEGRATION_PLATFORMS not in hass.data:
# There are no integraton platforms loaded yet
return
integration_platforms: list[IntegrationPlatform] = hass.data[
DATA_INTEGRATION_PLATFORMS
]

View file

@ -1,6 +1,9 @@
"""Test integration platform helpers."""
from unittest.mock import Mock
from homeassistant.helpers.integration_platform import (
async_process_integration_platform,
)
from homeassistant.setup import ATTR_COMPONENT, EVENT_COMPONENT_LOADED
from tests.common import mock_platform
@ -41,3 +44,10 @@ async def test_process_integration_platforms(hass):
hass, "event"
)
assert len(processed) == 2
async def test_process_integration_platforms_none_loaded(hass):
"""Test processing integrations with none loaded."""
# Verify we can call async_process_integration_platform
# when there are none loaded and it does not throw
await async_process_integration_platform(hass, "any")