From 7e2af515ed57f087d80b52172d390c4bce4a8e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=B5=E6=9B=A6?= Date: Mon, 24 Jun 2024 15:38:41 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=99=BB=E9=99=86=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E4=B8=8D=E9=98=BB=E5=A1=9E=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xiaomusic/xiaomusic.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/xiaomusic/xiaomusic.py b/xiaomusic/xiaomusic.py index 9eb7e5de3..be293cc88 100644 --- a/xiaomusic/xiaomusic.py +++ b/xiaomusic/xiaomusic.py @@ -143,27 +143,30 @@ async def login_miboy(self, session): self.miio_service = MiIOService(account) async def try_update_device_id(self): - hardware_data = await self.mina_service.device_list() # fix multi xiaoai problems we check did first # why we use this way to fix? # some videos and articles already in the Internet # we do not want to change old way, so we check if miotDID in `env` first # to set device id - for h in hardware_data: - if did := self.config.mi_did: - if h.get("miotDID", "") == str(did): + try: + hardware_data = await self.mina_service.device_list() + for h in hardware_data: + if did := self.config.mi_did: + if h.get("miotDID", "") == str(did): + self.device_id = h.get("deviceID") + break + else: + continue + if h.get("hardware", "") == self.config.hardware: self.device_id = h.get("deviceID") break - else: - continue - if h.get("hardware", "") == self.config.hardware: - self.device_id = h.get("deviceID") - break - else: - self.log.error( - f"we have no hardware: {self.config.hardware} please use `micli mina` to check" - ) + else: + self.log.error( + f"we have no hardware: {self.config.hardware} please use `micli mina` to check" + ) + except Exception: + pass async def _init_data_hardware(self): if self.config.cookie: