mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
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:
parent
6eb0447566
commit
4eae888546
@ -291,6 +291,7 @@ async def async_extract_config(
|
|||||||
*(
|
*(
|
||||||
async_create_platform_type(hass, config, p_type, p_config)
|
async_create_platform_type(hass, config, p_type, p_config)
|
||||||
for p_type, p_config in config_per_platform(config, DOMAIN)
|
for p_type, p_config in config_per_platform(config, DOMAIN)
|
||||||
|
if p_type is not None
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
if platform is None:
|
if platform is None:
|
||||||
|
@ -86,6 +86,7 @@ async def async_setup(hass, config):
|
|||||||
setup_tasks = [
|
setup_tasks = [
|
||||||
asyncio.create_task(async_setup_platform(p_type, p_config))
|
asyncio.create_task(async_setup_platform(p_type, p_config))
|
||||||
for p_type, p_config in config_per_platform(config, DOMAIN)
|
for p_type, p_config in config_per_platform(config, DOMAIN)
|
||||||
|
if p_type is not None
|
||||||
]
|
]
|
||||||
|
|
||||||
if setup_tasks:
|
if setup_tasks:
|
||||||
|
@ -102,6 +102,7 @@ async def async_setup_legacy(hass: HomeAssistant, config: ConfigType) -> None:
|
|||||||
setup_tasks = [
|
setup_tasks = [
|
||||||
asyncio.create_task(async_setup_platform(integration_name, p_config))
|
asyncio.create_task(async_setup_platform(integration_name, p_config))
|
||||||
for integration_name, p_config in config_per_platform(config, DOMAIN)
|
for integration_name, p_config in config_per_platform(config, DOMAIN)
|
||||||
|
if integration_name is not None
|
||||||
]
|
]
|
||||||
|
|
||||||
if setup_tasks:
|
if setup_tasks:
|
||||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from collections.abc import Iterable, Sequence
|
from collections.abc import Iterable, Sequence
|
||||||
import re
|
import re
|
||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from homeassistant.const import CONF_PLATFORM
|
from homeassistant.const import CONF_PLATFORM
|
||||||
|
|
||||||
@ -11,7 +11,9 @@ if TYPE_CHECKING:
|
|||||||
from .typing import ConfigType
|
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.
|
"""Break a component config into different platforms.
|
||||||
|
|
||||||
For example, will find 'switch', 'switch 2', 'switch 3', .. etc
|
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):
|
if not isinstance(platform_config, list):
|
||||||
platform_config = [platform_config]
|
platform_config = [platform_config]
|
||||||
|
|
||||||
|
item: ConfigType
|
||||||
|
platform: str | None
|
||||||
for item in platform_config:
|
for item in platform_config:
|
||||||
try:
|
try:
|
||||||
platform = item.get(CONF_PLATFORM)
|
platform = item.get(CONF_PLATFORM)
|
||||||
|
@ -121,7 +121,8 @@ class EntityComponent:
|
|||||||
|
|
||||||
# Look in config for Domain, Domain 2, Domain 3 etc and load them
|
# 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):
|
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
|
# Generic discovery listener for loading platform dynamically
|
||||||
# Refer to: homeassistant.helpers.discovery.async_load_platform()
|
# Refer to: homeassistant.helpers.discovery.async_load_platform()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user