Handle non documented options at Home Connect select entities (#140608)

* Allow non documented options at select entities

* Don't allow undocumented options
This commit is contained in:
J. Diego Rodríguez Royo 2025-03-15 14:17:16 +01:00 committed by Franck Nijhof
parent 9d8dbfbf3f
commit 28cad1d085
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
2 changed files with 29 additions and 5 deletions

View File

@ -415,6 +415,7 @@ class HomeConnectSelectEntity(HomeConnectEntity, SelectEntity):
"""Select setting class for Home Connect."""
entity_description: HomeConnectSelectEntityDescription
_original_option_keys: set[str | None]
def __init__(
self,
@ -423,6 +424,7 @@ class HomeConnectSelectEntity(HomeConnectEntity, SelectEntity):
desc: HomeConnectSelectEntityDescription,
) -> None:
"""Initialize the entity."""
self._original_option_keys = set(desc.values_translation_key)
super().__init__(
coordinator,
appliance,
@ -477,10 +479,12 @@ class HomeConnectSelectEntity(HomeConnectEntity, SelectEntity):
)
if setting and setting.constraints and setting.constraints.allowed_values:
self._original_option_keys = set(setting.constraints.allowed_values)
self._attr_options = [
self.entity_description.values_translation_key[option]
for option in setting.constraints.allowed_values
if option in self.entity_description.values_translation_key
for option in self._original_option_keys
if option is not None
and option in self.entity_description.values_translation_key
]
@ -497,7 +501,7 @@ class HomeConnectSelectOptionEntity(HomeConnectOptionEntity, SelectEntity):
desc: HomeConnectSelectEntityDescription,
) -> None:
"""Initialize the entity."""
self._original_option_keys = set(desc.values_translation_key.keys())
self._original_option_keys = set(desc.values_translation_key)
super().__init__(
coordinator,
appliance,
@ -530,5 +534,5 @@ class HomeConnectSelectOptionEntity(HomeConnectOptionEntity, SelectEntity):
self.entity_description.values_translation_key[option]
for option in self._original_option_keys
if option is not None
and option in self.entity_description.values_translation_key
]
self.__dict__.pop("options", None)

View File

@ -522,9 +522,18 @@ async def test_select_functionality(
(
"select.hood_ambient_light_color",
SettingKey.BSH_COMMON_AMBIENT_LIGHT_COLOR,
[f"BSH.Common.EnumType.AmbientLightColor.Color{i}" for i in range(50)],
[f"BSH.Common.EnumType.AmbientLightColor.Color{i}" for i in range(1, 50)],
{str(i) for i in range(1, 50)},
),
(
"select.hood_ambient_light_color",
SettingKey.BSH_COMMON_AMBIENT_LIGHT_COLOR,
[
"A.Non.Documented.Option",
"BSH.Common.EnumType.AmbientLightColor.Color42",
],
{"42"},
),
],
)
async def test_fetch_allowed_values(
@ -813,6 +822,17 @@ async def test_select_entity_error(
"laundry_care_washer_enum_type_temperature_ul_extra_hot",
},
),
(
"select.washer_temperature",
OptionKey.LAUNDRY_CARE_WASHER_TEMPERATURE,
[
"A.Non.Documented.Option",
"LaundryCare.Washer.EnumType.Temperature.UlWarm",
],
{
"laundry_care_washer_enum_type_temperature_ul_warm",
},
),
],
)
async def test_options_functionality(