mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 04:50:05 +00:00
Ensure backwards compatibility for new-style configs in old triggers and conditions (#156446)
This commit is contained in:
@@ -6,6 +6,7 @@ import voluptuous as vol
|
||||
from homeassistant.helpers.automation import (
|
||||
get_absolute_description_key,
|
||||
get_relative_description_key,
|
||||
move_options_fields_to_top_level,
|
||||
move_top_level_schema_fields_to_options,
|
||||
)
|
||||
|
||||
@@ -106,3 +107,76 @@ async def test_move_schema_fields_to_options(
|
||||
assert (
|
||||
move_top_level_schema_fields_to_options(config, schema_dict) == expected_config
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("config", "expected_config"),
|
||||
[
|
||||
(
|
||||
{
|
||||
"platform": "test",
|
||||
"options": {
|
||||
"entity": "sensor.test",
|
||||
"from": "open",
|
||||
"to": "closed",
|
||||
"for": {"hours": 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
"platform": "test",
|
||||
"entity": "sensor.test",
|
||||
"from": "open",
|
||||
"to": "closed",
|
||||
"for": {"hours": 1},
|
||||
},
|
||||
),
|
||||
(
|
||||
{
|
||||
"platform": "test",
|
||||
"entity": "sensor.test",
|
||||
"from": "open",
|
||||
"to": "closed",
|
||||
"for": {"hours": 1},
|
||||
},
|
||||
{
|
||||
"platform": "test",
|
||||
"entity": "sensor.test",
|
||||
"from": "open",
|
||||
"to": "closed",
|
||||
"for": {"hours": 1},
|
||||
},
|
||||
),
|
||||
(
|
||||
{
|
||||
"platform": "test",
|
||||
"options": 456,
|
||||
},
|
||||
{
|
||||
"platform": "test",
|
||||
"options": 456,
|
||||
},
|
||||
),
|
||||
(
|
||||
{
|
||||
"platform": "test",
|
||||
"options": {
|
||||
"entity": "sensor.test",
|
||||
},
|
||||
"extra_field": "extra_value",
|
||||
},
|
||||
{
|
||||
"platform": "test",
|
||||
"options": {
|
||||
"entity": "sensor.test",
|
||||
},
|
||||
"extra_field": "extra_value",
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_move_options_fields_to_top_level(config, expected_config) -> None:
|
||||
"""Test moving options fields to top-level."""
|
||||
base_schema = vol.Schema({vol.Required("platform"): str})
|
||||
original_config = config.copy()
|
||||
assert move_options_fields_to_top_level(config, base_schema) == expected_config
|
||||
assert config == original_config # Ensure original config is not modified
|
||||
|
||||
Reference in New Issue
Block a user