Remove None from device sub config entries when updating with sub config entry

This commit is contained in:
G Johansson 2025-07-08 15:40:20 +00:00
parent 9d2ffa6372
commit 20a4e91098
2 changed files with 21 additions and 8 deletions

View File

@ -1095,6 +1095,7 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]):
] ]
| {add_config_subentry_id} | {add_config_subentry_id}
} }
config_entries_subentries[add_config_entry_id].discard(None)
if ( if (
remove_config_entry_id is not UNDEFINED remove_config_entry_id is not UNDEFINED

View File

@ -2969,12 +2969,17 @@ async def test_update_remove_config_subentries(
entry = device_registry.async_get_or_create( entry = device_registry.async_get_or_create(
config_entry_id=config_entry_1.entry_id, config_entry_id=config_entry_1.entry_id,
config_subentry_id="mock-subentry-id-1-1",
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
identifiers={("bridgeid", "0123")}, identifiers={("bridgeid", "0123")},
manufacturer="manufacturer", manufacturer="manufacturer",
model="model", model="model",
) )
assert entry.config_entries_subentries == {config_entry_1.entry_id: {None}}
entry = device_registry.async_update_device(
entry.id,
add_config_entry_id=config_entry_1.entry_id,
add_config_subentry_id="mock-subentry-id-1-1",
)
entry_id = entry.id entry_id = entry.id
assert entry.config_entries == {config_entry_1.entry_id} assert entry.config_entries == {config_entry_1.entry_id}
assert entry.config_entries_subentries == { assert entry.config_entries_subentries == {
@ -3113,12 +3118,19 @@ async def test_update_remove_config_subentries(
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(update_events) == 8 assert len(update_events) == 9
assert update_events[0].data == { assert update_events[0].data == {
"action": "create", "action": "create",
"device_id": entry_id, "device_id": entry_id,
} }
assert update_events[1].data == { assert update_events[1].data == {
"action": "update",
"device_id": entry_id,
"changes": {
"config_entries_subentries": {config_entry_1.entry_id: {None}},
},
}
assert update_events[2].data == {
"action": "update", "action": "update",
"device_id": entry_id, "device_id": entry_id,
"changes": { "changes": {
@ -3127,7 +3139,7 @@ async def test_update_remove_config_subentries(
}, },
}, },
} }
assert update_events[2].data == { assert update_events[3].data == {
"action": "update", "action": "update",
"device_id": entry_id, "device_id": entry_id,
"changes": { "changes": {
@ -3140,7 +3152,7 @@ async def test_update_remove_config_subentries(
}, },
}, },
} }
assert update_events[3].data == { assert update_events[4].data == {
"action": "update", "action": "update",
"device_id": entry_id, "device_id": entry_id,
"changes": { "changes": {
@ -3154,7 +3166,7 @@ async def test_update_remove_config_subentries(
}, },
}, },
} }
assert update_events[4].data == { assert update_events[5].data == {
"action": "update", "action": "update",
"device_id": entry_id, "device_id": entry_id,
"changes": { "changes": {
@ -3168,7 +3180,7 @@ async def test_update_remove_config_subentries(
}, },
}, },
} }
assert update_events[5].data == { assert update_events[6].data == {
"action": "update", "action": "update",
"device_id": entry_id, "device_id": entry_id,
"changes": { "changes": {
@ -3187,7 +3199,7 @@ async def test_update_remove_config_subentries(
"primary_config_entry": config_entry_1.entry_id, "primary_config_entry": config_entry_1.entry_id,
}, },
} }
assert update_events[6].data == { assert update_events[7].data == {
"action": "update", "action": "update",
"device_id": entry_id, "device_id": entry_id,
"changes": { "changes": {
@ -3198,7 +3210,7 @@ async def test_update_remove_config_subentries(
}, },
}, },
} }
assert update_events[7].data == { assert update_events[8].data == {
"action": "remove", "action": "remove",
"device_id": entry_id, "device_id": entry_id,
} }