Skip to content

Commit

Permalink
feat: 统计设备型号
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxi committed Dec 2, 2024
1 parent 8f9bba0 commit cb2af0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 5 additions & 3 deletions xiaomusic/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def init(self):
async def run_with_cancel(self, func, *args, **kwargs):
try:
asyncio.ensure_future(asyncio.to_thread(func, *args, **kwargs))
self.log.info("analytics run_with_cancel success")
except Exception as e:
self.log.warning(f"analytics run_with_cancel failed {e}")
return None
Expand Down Expand Up @@ -66,17 +67,18 @@ def _send_daily_event(self):
self.gtag.send(events=event_list)
self.current_date = current_date

async def send_play_event(self, name, sec):
async def send_play_event(self, name, sec, hardware):
try:
await self.run_with_cancel(self._send_play_event, name, sec)
await self.run_with_cancel(self._send_play_event, name, sec, hardware)
except Exception as e:
self.log.warning(f"analytics send_play_event failed {e}")
self.init()

def _send_play_event(self, name, sec):
def _send_play_event(self, name, sec, hardware):
event = self.gtag.create_new_event(name="play")
event.set_event_param(name="version", value=__version__)
event.set_event_param(name="music", value=name)
event.set_event_param(name="sec", value=sec)
event.set_event_param(name="hardware", value=hardware)
event_list = [event]
self.gtag.send(events=event_list)
8 changes: 6 additions & 2 deletions xiaomusic/xiaomusic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,11 @@ def __init__(self, xiaomusic: XiaoMusic, device: Device, group_name: str):

@property
def did(self):
return self.xiaomusic.device_id_did[self.device_id]
return self.device.did

@property
def hardware(self):
return self.device.hardware

def get_cur_music(self):
return self.device.cur_music
Expand Down Expand Up @@ -1442,7 +1446,7 @@ async def _playmusic(self, name):
return

self.log.info(f"【{name}】已经开始播放了")
await self.xiaomusic.analytics.send_play_event(name, sec)
await self.xiaomusic.analytics.send_play_event(name, sec, self.hardware)

if self.device.play_type == PLAY_TYPE_SIN:
self.log.info(f"【{name}】单曲播放时不会设置下一首歌的定时器")
Expand Down

0 comments on commit cb2af0e

Please sign in to comment.