mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Prevent KeyError when Matter device has invalid value for ModeSelect (#126672)
This commit is contained in:
parent
354ee35ee4
commit
5e7d5c6312
@ -105,7 +105,7 @@ class MatterModeSelectEntity(MatterSelectEntity):
|
||||
)
|
||||
modes = {mode.mode: mode.label for mode in cluster.supportedModes}
|
||||
self._attr_options = list(modes.values())
|
||||
self._attr_current_option = modes[cluster.currentMode]
|
||||
self._attr_current_option = modes.get(cluster.currentMode)
|
||||
# handle optional Description attribute as descriptive name for the mode
|
||||
if desc := getattr(cluster, "description", None):
|
||||
self._attr_name = desc
|
||||
|
@ -97,8 +97,8 @@ async def test_attribute_select_entities(
|
||||
await trigger_subscription_callback(hass, matter_client)
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == "on"
|
||||
# test that an invalid value (e.g. 255) leads to an unknown state
|
||||
set_node_attribute(light_node, 1, 6, 16387, 255)
|
||||
# test that an invalid value (e.g. 253) leads to an unknown state
|
||||
set_node_attribute(light_node, 1, 6, 16387, 253)
|
||||
await trigger_subscription_callback(hass, matter_client)
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == "unknown"
|
||||
|
Loading…
x
Reference in New Issue
Block a user