[core] Let cv.rename_key pass non-dict input through (#20331)

This commit is contained in:
Jesse Hills
2026-10-08 17:29:56 +13:00
committed by GitHub
parent 0a7763d902
commit 73bbd75d3f
2 changed files with 10 additions and 0 deletions
+5
View File
@@ -2872,9 +2872,14 @@ def rename_key(
When ``removed_in`` is set, a deprecation warning is logged if the old key is
present. Pass ``component`` (the platform/component name) alongside
``removed_in`` so the warning identifies where it originates.
Input that is not a dictionary is returned unchanged, so the schema that
follows reports it as a normal configuration error.
"""
def validator(config: dict) -> dict:
if not isinstance(config, dict):
return config
config = config.copy()
if old_key in config:
has_at_most_one_key(old_key, new_key)(config)
@@ -3120,6 +3120,11 @@ def test_rename_key_absent() -> None:
assert cv.rename_key("old", "new")({"other": 5}) == {"other": 5}
@pytest.mark.parametrize("value", ["an_id", 1, None, ["old"]])
def test_rename_key_non_dict_passes_through(value: object) -> None:
assert cv.rename_key("old", "new")(value) == value
def test_rename_key_no_removed_in_is_silent(
caplog: pytest.LogCaptureFixture,
) -> None: