From 80da6bd1e6130b43cb7a8657fe13cd3ebff505af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=B5=E6=9B=A6?= Date: Mon, 1 Jul 2024 01:11:12 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=85=B3=E6=9C=BA=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xiaomusic/xiaomusic.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/xiaomusic/xiaomusic.py b/xiaomusic/xiaomusic.py index 4b03563..f5ad92c 100644 --- a/xiaomusic/xiaomusic.py +++ b/xiaomusic/xiaomusic.py @@ -307,11 +307,25 @@ class XiaoMusic: except Exception as e: self.log.error(f"Execption {e}") + async def get_if_xiaoai_is_playing(self): + playing_info = await self.mina_service.player_get_status(self.device_id) + # WTF xiaomi api + is_playing = ( + json.loads(playing_info.get("data", {}).get("info", "{}")).get("status", -1) + == 1 + ) + return is_playing + + async def stop_if_xiaoai_is_playing(self): + is_playing = await self.get_if_xiaoai_is_playing() + if is_playing: + # stop it + ret = await self.mina_service.player_stop(self.device_id) + self.log.debug(f"force_stop_xiaoai player_stop ret:{ret}") + async def force_stop_xiaoai(self): ret = await self.mina_service.player_pause(self.device_id) self.log.debug(f"force_stop_xiaoai player_pause ret:{ret}") - # ret = await self.mina_service.player_stop(self.device_id) - # self.log.debug(f"force_stop_xiaoai player_stop ret:{ret}") # 是否在下载中 def is_downloading(self):