Fix incorrect type hint in config_per_platform helper (#63890)

* Adjust base helper

* Filter type is not None in mailbox

* Filter empty platforms in device_tracker

* Filter out empty platform in notify

* Filter out empty platform in entity_component

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2022-01-11 17:28:37 +01:00 committed by GitHub
parent 6eb0447566
commit 4eae888546
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 3 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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)

View File

@ -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()