From 4804b2744ee95d788236377f677057f8ad9b1d85 Mon Sep 17 00:00:00 2001 From: Alone Date: Fri, 8 Nov 2024 14:54:44 +0800 Subject: [PATCH] =?UTF-8?q?=E2=8F=B3=20improve=20filter=20devices=20(#1682?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- custom_components/xiaomi_miot/core/xiaomi_cloud.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/custom_components/xiaomi_miot/core/xiaomi_cloud.py b/custom_components/xiaomi_miot/core/xiaomi_cloud.py index 26a316dbd..b65da4917 100644 --- a/custom_components/xiaomi_miot/core/xiaomi_cloud.py +++ b/custom_components/xiaomi_miot/core/xiaomi_cloud.py @@ -301,14 +301,15 @@ async def get_device_list(self): return None async def get_all_devices(self, homes=None): - dvs = [] + devices = { + d['did']: d + for d in await self.get_device_list() or [] + } if not isinstance(homes, list): return await self.get_device_list() or [] for home in homes: hid = int(home.get('id', 0)) uid = int(home.get('uid', 0)) - if not hid or uid == self.user_id: - continue start_did = '' has_more = True while has_more: @@ -323,10 +324,12 @@ async def get_all_devices(self, homes=None): 'get_third_device': True, }, debug=False, timeout=20) or {} rdt = rdt.get('result') or {} - dvs.extend(rdt.get('device_info') or {}) + for d in rdt.get('device_info') or []: + did = d.get('did') + devices.setdefault(did, {}).update(d) start_did = rdt.get('max_did') or '' has_more = rdt.get('has_more') and start_did - return dvs + return list(devices.values()) async def get_home_devices(self): rdt = await self.async_request_api('v2/homeroom/gethome_merged', {