mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Prevent KeyError in Matter select entity (#126605)
This commit is contained in:
parent
c96d4991b9
commit
f2092ef083
@ -229,18 +229,18 @@ DISCOVERY_SCHEMAS = [
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
translation_key="startup_on_off",
|
||||
options=["On", "Off", "Toggle", "Previous"],
|
||||
measurement_to_ha=lambda x: { # pylint: disable=unnecessary-lambda
|
||||
measurement_to_ha={
|
||||
0: "Off",
|
||||
1: "On",
|
||||
2: "Toggle",
|
||||
None: "Previous",
|
||||
}.get(x),
|
||||
ha_to_native_value=lambda x: {
|
||||
}.get,
|
||||
ha_to_native_value={
|
||||
"Off": 0,
|
||||
"On": 1,
|
||||
"Toggle": 2,
|
||||
"Previous": None,
|
||||
}[x],
|
||||
}.get,
|
||||
),
|
||||
entity_class=MatterSelectEntity,
|
||||
required_attributes=(clusters.OnOff.Attributes.StartUpOnOff,),
|
||||
|
@ -97,3 +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)
|
||||
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