Skip to content

Commit 32d7794

Browse files
committed
Use _remove_entity to remove entities
1 parent d6eafb3 commit 32d7794

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

tests/test_discover.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -844,8 +844,6 @@ async def test_devices_from_files(
844844

845845
unique_id_migrations[key] = entity
846846

847-
await zha_device.on_remove()
848-
849847
# XXX: We re-serialize the JSON because integer enum types are converted when
850848
# serializing but will not compare properly otherwise
851849
loaded_device_data = json.loads(
@@ -874,3 +872,5 @@ async def test_devices_from_files(
874872
tsn=None,
875873
)
876874
]
875+
876+
await zha_device.on_remove()

zha/zigbee/device.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,8 +1111,10 @@ async def on_remove(self) -> None:
11111111
for callback in self._on_remove_callbacks:
11121112
callback()
11131113

1114-
for platform_entity in self._platform_entities.values():
1115-
await platform_entity.on_remove()
1114+
for platform_entity in list(self._platform_entities.values()):
1115+
# TODO: To avoid unnecessary traffic during shutdown, we don't need to emit
1116+
# an event for every entity, just the device
1117+
await self._remove_entity(platform_entity, emit_event=False)
11161118

11171119
for entity in self._pending_entities:
11181120
await entity.on_remove()

0 commit comments

Comments
 (0)