2016-03-07 22:39:52 +00:00
|
|
|
"""Helper methods for components within Home Assistant."""
|
2021-03-17 17:34:19 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-04-20 15:40:41 +00:00
|
|
|
from collections.abc import Iterable, Sequence
|
2022-01-11 16:28:37 +00:00
|
|
|
from typing import TYPE_CHECKING
|
2016-07-28 03:33:49 +00:00
|
|
|
|
2020-07-06 22:58:53 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from .typing import ConfigType
|
2016-07-28 03:33:49 +00:00
|
|
|
|
2015-01-19 08:02:25 +00:00
|
|
|
|
2022-01-11 16:28:37 +00:00
|
|
|
def config_per_platform(
|
|
|
|
config: ConfigType, domain: str
|
|
|
|
) -> Iterable[tuple[str | None, ConfigType]]:
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Break a component config into different platforms.
|
2016-03-07 22:39:52 +00:00
|
|
|
|
2014-12-07 07:57:02 +00:00
|
|
|
For example, will find 'switch', 'switch 2', 'switch 3', .. etc
|
2016-10-29 19:19:27 +00:00
|
|
|
Async friendly.
|
2014-12-07 07:57:02 +00:00
|
|
|
"""
|
2023-12-04 11:48:49 +00:00
|
|
|
# pylint: disable-next=import-outside-toplevel
|
|
|
|
from homeassistant import config as ha_config
|
|
|
|
|
|
|
|
# pylint: disable-next=import-outside-toplevel
|
|
|
|
from .deprecation import _print_deprecation_warning
|
2019-09-24 20:53:03 +00:00
|
|
|
|
2023-12-04 11:48:49 +00:00
|
|
|
_print_deprecation_warning(
|
|
|
|
config_per_platform,
|
|
|
|
"config.config_per_platform",
|
|
|
|
"function",
|
|
|
|
"called",
|
|
|
|
"2024.6",
|
|
|
|
)
|
|
|
|
return ha_config.config_per_platform(config, domain)
|
2014-12-07 07:57:02 +00:00
|
|
|
|
2016-06-11 05:53:31 +00:00
|
|
|
|
2023-12-04 11:48:49 +00:00
|
|
|
config_per_platform.__name__ = "helpers.config_per_platform"
|
2015-09-29 06:09:05 +00:00
|
|
|
|
|
|
|
|
2021-03-18 21:58:19 +00:00
|
|
|
def extract_domain_configs(config: ConfigType, domain: str) -> Sequence[str]:
|
2016-10-29 19:19:27 +00:00
|
|
|
"""Extract keys from config for given domain name.
|
|
|
|
|
|
|
|
Async friendly.
|
|
|
|
"""
|
2023-12-04 11:48:49 +00:00
|
|
|
# pylint: disable-next=import-outside-toplevel
|
|
|
|
from homeassistant import config as ha_config
|
|
|
|
|
|
|
|
# pylint: disable-next=import-outside-toplevel
|
|
|
|
from .deprecation import _print_deprecation_warning
|
|
|
|
|
|
|
|
_print_deprecation_warning(
|
|
|
|
extract_domain_configs,
|
|
|
|
"config.extract_domain_configs",
|
|
|
|
"function",
|
|
|
|
"called",
|
|
|
|
"2024.6",
|
|
|
|
)
|
|
|
|
return ha_config.extract_domain_configs(config, domain)
|
|
|
|
|
|
|
|
|
|
|
|
extract_domain_configs.__name__ = "helpers.extract_domain_configs"
|