mirror of
https://github.com/esphome/esphome.git
synced 2026-10-08 12:04:03 +00:00
[core] Let cv.rename_key pass non-dict input through (#20331)
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user