Skip to content

Commit 3d744f0

Browse files
authored
Make _EventDeviceRegistryUpdatedData_Remove JSON serializable (home-assistant#149734)
1 parent f7c8cdb commit 3d744f0

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

homeassistant/helpers/device_registry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class _EventDeviceRegistryUpdatedData_Remove(TypedDict):
156156

157157
action: Literal["remove"]
158158
device_id: str
159-
device: DeviceEntry
159+
device: dict[str, Any]
160160

161161

162162
class _EventDeviceRegistryUpdatedData_Update(TypedDict):
@@ -1319,7 +1319,7 @@ def async_remove_device(self, device_id: str) -> None:
13191319
self.hass.bus.async_fire_internal(
13201320
EVENT_DEVICE_REGISTRY_UPDATED,
13211321
_EventDeviceRegistryUpdatedData_Remove(
1322-
action="remove", device_id=device_id, device=device
1322+
action="remove", device_id=device_id, device=device.dict_repr
13231323
),
13241324
)
13251325
self.async_schedule_save()

homeassistant/helpers/entity_registry.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,13 +1103,13 @@ def async_device_modified(
11031103
entities = async_entries_for_device(
11041104
self, event.data["device_id"], include_disabled_entities=True
11051105
)
1106-
removed_device = event.data["device"]
1106+
removed_device_dict = event.data["device"]
11071107
for entity in entities:
11081108
config_entry_id = entity.config_entry_id
11091109
if (
1110-
config_entry_id in removed_device.config_entries
1110+
config_entry_id in removed_device_dict["config_entries"]
11111111
and entity.config_subentry_id
1112-
in removed_device.config_entries_subentries[config_entry_id]
1112+
in removed_device_dict["config_entries_subentries"][config_entry_id]
11131113
):
11141114
self.async_remove(entity.entity_id)
11151115
else:

tests/helpers/test_device_registry.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,7 +1652,7 @@ async def test_removing_config_entries(
16521652
assert update_events[4].data == {
16531653
"action": "remove",
16541654
"device_id": entry3.id,
1655-
"device": entry3,
1655+
"device": entry3.dict_repr,
16561656
}
16571657

16581658

@@ -1725,12 +1725,12 @@ async def test_deleted_device_removing_config_entries(
17251725
assert update_events[3].data == {
17261726
"action": "remove",
17271727
"device_id": entry.id,
1728-
"device": entry2,
1728+
"device": entry2.dict_repr,
17291729
}
17301730
assert update_events[4].data == {
17311731
"action": "remove",
17321732
"device_id": entry3.id,
1733-
"device": entry3,
1733+
"device": entry3.dict_repr,
17341734
}
17351735

17361736
device_registry.async_clear_config_entry(config_entry_1.entry_id)
@@ -1976,7 +1976,7 @@ async def test_removing_config_subentries(
19761976
assert update_events[7].data == {
19771977
"action": "remove",
19781978
"device_id": entry.id,
1979-
"device": entry,
1979+
"device": entry.dict_repr,
19801980
}
19811981

19821982

@@ -2106,7 +2106,7 @@ async def test_deleted_device_removing_config_subentries(
21062106
assert update_events[4].data == {
21072107
"action": "remove",
21082108
"device_id": entry.id,
2109-
"device": entry4,
2109+
"device": entry4.dict_repr,
21102110
}
21112111

21122112
device_registry.async_clear_config_subentry(config_entry_1.entry_id, None)
@@ -2930,7 +2930,7 @@ async def test_update_remove_config_entries(
29302930
assert update_events[6].data == {
29312931
"action": "remove",
29322932
"device_id": entry3.id,
2933-
"device": entry3,
2933+
"device": entry3.dict_repr,
29342934
}
29352935

29362936

@@ -3208,7 +3208,7 @@ async def test_update_remove_config_subentries(
32083208
assert update_events[7].data == {
32093209
"action": "remove",
32103210
"device_id": entry_id,
3211-
"device": entry_before_remove,
3211+
"device": entry_before_remove.dict_repr,
32123212
}
32133213

32143214

@@ -3551,7 +3551,7 @@ async def test_restore_device(
35513551
assert update_events[2].data == {
35523552
"action": "remove",
35533553
"device_id": entry.id,
3554-
"device": entry,
3554+
"device": entry.dict_repr,
35553555
}
35563556
assert update_events[3].data == {
35573557
"action": "create",
@@ -3874,7 +3874,7 @@ async def test_restore_shared_device(
38743874
assert update_events[3].data == {
38753875
"action": "remove",
38763876
"device_id": entry.id,
3877-
"device": updated_device,
3877+
"device": updated_device.dict_repr,
38783878
}
38793879
assert update_events[4].data == {
38803880
"action": "create",
@@ -3883,7 +3883,7 @@ async def test_restore_shared_device(
38833883
assert update_events[5].data == {
38843884
"action": "remove",
38853885
"device_id": entry.id,
3886-
"device": entry2,
3886+
"device": entry2.dict_repr,
38873887
}
38883888
assert update_events[6].data == {
38893889
"action": "create",

0 commit comments

Comments
 (0)