Remove unused keys from the ZHA config schema (#125710)

pull/126062/head
puddly 2024-09-13 11:34:06 -04:00 committed by Franck Nijhof
parent 1dcd5471a0
commit 06d4b3281b
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
2 changed files with 41 additions and 1 deletions

View File

@ -1166,7 +1166,8 @@ CONF_ZHA_OPTIONS_SCHEMA = vol.Schema(
CONF_CONSIDER_UNAVAILABLE_BATTERY,
default=CONF_DEFAULT_CONSIDER_UNAVAILABLE_BATTERY,
): cv.positive_int,
}
},
extra=vol.REMOVE_EXTRA,
)
CONF_ZHA_ALARM_SCHEMA = vol.Schema(

View File

@ -5,16 +5,23 @@ from typing import Any
import pytest
import voluptuous_serialize
from zigpy.application import ControllerApplication
from zigpy.types.basic import uint16_t
from zigpy.zcl.clusters import lighting
import homeassistant.components.zha.const as zha_const
from homeassistant.components.zha.helpers import (
cluster_command_schema_to_vol_schema,
convert_to_zcl_values,
create_zha_config,
exclude_none_values,
get_zha_data,
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry
_LOGGER = logging.getLogger(__name__)
@ -177,3 +184,35 @@ def test_exclude_none_values(
for key in expected_output:
assert expected_output[key] == obj[key]
async def test_create_zha_config_remove_unused(
hass: HomeAssistant,
config_entry: MockConfigEntry,
mock_zigpy_connect: ControllerApplication,
) -> None:
"""Test creating ZHA config data with unused keys."""
config_entry.add_to_hass(hass)
options = config_entry.options.copy()
options["custom_configuration"]["zha_options"]["some_random_key"] = "a value"
hass.config_entries.async_update_entry(config_entry, options=options)
assert (
config_entry.options["custom_configuration"]["zha_options"]["some_random_key"]
== "a value"
)
status = await async_setup_component(
hass,
zha_const.DOMAIN,
{zha_const.DOMAIN: {zha_const.CONF_ENABLE_QUIRKS: False}},
)
assert status is True
await hass.async_block_till_done()
ha_zha_data = get_zha_data(hass)
# Does not error out
create_zha_config(hass, ha_zha_data)