diff --git a/homeassistant/components/zha/helpers.py b/homeassistant/components/zha/helpers.py index f70c8a9cb3e..2030ffcdb3d 100644 --- a/homeassistant/components/zha/helpers.py +++ b/homeassistant/components/zha/helpers.py @@ -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( diff --git a/tests/components/zha/test_helpers.py b/tests/components/zha/test_helpers.py index d3392685437..f6dc8291d9f 100644 --- a/tests/components/zha/test_helpers.py +++ b/tests/components/zha/test_helpers.py @@ -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)