Deprecate deprecated core constants (#106456)
This commit is contained in:
parent
2afe3364ca
commit
b08268da31
2 changed files with 57 additions and 4 deletions
|
@ -147,9 +147,42 @@ class ConfigSource(enum.StrEnum):
|
|||
|
||||
|
||||
# SOURCE_* are deprecated as of Home Assistant 2022.2, use ConfigSource instead
|
||||
SOURCE_DISCOVERED = ConfigSource.DISCOVERED.value
|
||||
SOURCE_STORAGE = ConfigSource.STORAGE.value
|
||||
SOURCE_YAML = ConfigSource.YAML.value
|
||||
_DEPRECATED_SOURCE_DISCOVERED = (ConfigSource.DISCOVERED, "2025.1")
|
||||
_DEPRECATED_SOURCE_STORAGE = (ConfigSource.STORAGE, "2025.1")
|
||||
_DEPRECATED_SOURCE_YAML = (ConfigSource.YAML, "2025.1")
|
||||
|
||||
|
||||
# Can be removed if no deprecated constant are in this module anymore
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Check if the not found name is a deprecated constant.
|
||||
|
||||
If it is, print a deprecation warning and return the value of the constant.
|
||||
Otherwise raise AttributeError.
|
||||
"""
|
||||
module_globals = globals()
|
||||
if f"_DEPRECATED_{name}" not in module_globals:
|
||||
raise AttributeError(f"Module {__name__} has no attribute {name!r}")
|
||||
|
||||
# Avoid circular import
|
||||
from .helpers.deprecation import ( # pylint: disable=import-outside-toplevel
|
||||
check_if_deprecated_constant,
|
||||
)
|
||||
|
||||
return check_if_deprecated_constant(name, module_globals)
|
||||
|
||||
|
||||
# Can be removed if no deprecated constant are in this module anymore
|
||||
def __dir__() -> list[str]:
|
||||
"""Return dir() with deprecated constants."""
|
||||
# Copied method from homeassistant.helpers.deprecattion#dir_with_deprecated_constants to avoid import cycle
|
||||
module_globals = globals()
|
||||
|
||||
return list(module_globals) + [
|
||||
name.removeprefix("_DEPRECATED_")
|
||||
for name in module_globals
|
||||
if name.startswith("_DEPRECATED_")
|
||||
]
|
||||
|
||||
|
||||
# How long to wait until things that run on startup have to finish.
|
||||
TIMEOUT_EVENT_START = 15
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue