diff --git a/homeassistant/components/device_tracker/legacy.py b/homeassistant/components/device_tracker/legacy.py index 826f617bade..01fc8a444e1 100644 --- a/homeassistant/components/device_tracker/legacy.py +++ b/homeassistant/components/device_tracker/legacy.py @@ -291,6 +291,7 @@ async def async_extract_config( *( async_create_platform_type(hass, config, p_type, p_config) for p_type, p_config in config_per_platform(config, DOMAIN) + if p_type is not None ) ): if platform is None: diff --git a/homeassistant/components/mailbox/__init__.py b/homeassistant/components/mailbox/__init__.py index 98dd0f45d2b..3d482971ac9 100644 --- a/homeassistant/components/mailbox/__init__.py +++ b/homeassistant/components/mailbox/__init__.py @@ -86,6 +86,7 @@ async def async_setup(hass, config): setup_tasks = [ asyncio.create_task(async_setup_platform(p_type, p_config)) for p_type, p_config in config_per_platform(config, DOMAIN) + if p_type is not None ] if setup_tasks: diff --git a/homeassistant/components/notify/legacy.py b/homeassistant/components/notify/legacy.py index c5be8a1800e..5f26c952b31 100644 --- a/homeassistant/components/notify/legacy.py +++ b/homeassistant/components/notify/legacy.py @@ -102,6 +102,7 @@ async def async_setup_legacy(hass: HomeAssistant, config: ConfigType) -> None: setup_tasks = [ asyncio.create_task(async_setup_platform(integration_name, p_config)) for integration_name, p_config in config_per_platform(config, DOMAIN) + if integration_name is not None ] if setup_tasks: diff --git a/homeassistant/helpers/__init__.py b/homeassistant/helpers/__init__.py index 93383f49b1e..f74aec0efe8 100644 --- a/homeassistant/helpers/__init__.py +++ b/homeassistant/helpers/__init__.py @@ -3,7 +3,7 @@ from __future__ import annotations from collections.abc import Iterable, Sequence import re -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING from homeassistant.const import CONF_PLATFORM @@ -11,7 +11,9 @@ if TYPE_CHECKING: from .typing import ConfigType -def config_per_platform(config: ConfigType, domain: str) -> Iterable[tuple[Any, Any]]: +def config_per_platform( + config: ConfigType, domain: str +) -> Iterable[tuple[str | None, ConfigType]]: """Break a component config into different platforms. For example, will find 'switch', 'switch 2', 'switch 3', .. etc @@ -24,6 +26,8 @@ def config_per_platform(config: ConfigType, domain: str) -> Iterable[tuple[Any, if not isinstance(platform_config, list): platform_config = [platform_config] + item: ConfigType + platform: str | None for item in platform_config: try: platform = item.get(CONF_PLATFORM) diff --git a/homeassistant/helpers/entity_component.py b/homeassistant/helpers/entity_component.py index 6e7e2a6302e..da6732d05e7 100644 --- a/homeassistant/helpers/entity_component.py +++ b/homeassistant/helpers/entity_component.py @@ -121,7 +121,8 @@ class EntityComponent: # Look in config for Domain, Domain 2, Domain 3 etc and load them for p_type, p_config in config_per_platform(config, self.domain): - self.hass.async_create_task(self.async_setup_platform(p_type, p_config)) + if p_type is not None: + self.hass.async_create_task(self.async_setup_platform(p_type, p_config)) # Generic discovery listener for loading platform dynamically # Refer to: homeassistant.helpers.discovery.async_load_platform()