mirror of
https://github.com/XiaoMi/ha_xiaomi_home.git
synced 2026-01-17 07:10:44 +08:00
feat: simplify the unsub logic
This commit is contained in:
parent
ae4107da2d
commit
ca2edbd917
@ -851,20 +851,19 @@ class MIoTClient:
|
|||||||
async def remove_device_async(self, did: str) -> None:
|
async def remove_device_async(self, did: str) -> None:
|
||||||
if did not in self._device_list_cache:
|
if did not in self._device_list_cache:
|
||||||
return
|
return
|
||||||
self._mips_cloud.unsub_prop(did=did)
|
sub_from = self._sub_source_list.pop(did, None)
|
||||||
self._mips_cloud.unsub_event(did=did)
|
# Unsub
|
||||||
if self._ctrl_mode == CtrlMode.AUTO:
|
if sub_from:
|
||||||
if did in self._device_list_gateway:
|
if sub_from == 'cloud':
|
||||||
mips = self._mips_local.get(
|
self._mips_cloud.unsub_prop(did=did)
|
||||||
self._device_list_gateway[did]['group_id'], None)
|
self._mips_cloud.unsub_event(did=did)
|
||||||
if mips:
|
elif sub_from == 'lan':
|
||||||
mips.unsub_prop(did=did)
|
|
||||||
mips.unsub_event(did=did)
|
|
||||||
elif self._miot_lan.init_done and did in self._device_list_lan:
|
|
||||||
self._miot_lan.unsub_prop(did=did)
|
self._miot_lan.unsub_prop(did=did)
|
||||||
self._miot_lan.unsub_event(did=did)
|
self._miot_lan.unsub_event(did=did)
|
||||||
self._sub_source_list.pop(did, None)
|
elif sub_from in self._mips_local:
|
||||||
self._device_list_cache.pop(did, None)
|
mips = self._mips_local[sub_from]
|
||||||
|
mips.unsub_prop(did=did)
|
||||||
|
mips.unsub_event(did=did)
|
||||||
# Storage
|
# Storage
|
||||||
await self._storage.save_async(
|
await self._storage.save_async(
|
||||||
domain='miot_devices',
|
domain='miot_devices',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user