Skip to content

Commit

Permalink
🎵 add support play media for xiaoai (#1261)
Browse files Browse the repository at this point in the history
  • Loading branch information
Heyxk authored Aug 19, 2023
1 parent 5d3c25d commit f59c0a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.idea/
__pycache__/

19 changes: 16 additions & 3 deletions custom_components/xiaomi_miot/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,20 @@ def turn_off(self):
return self.call_action(self._act_turn_off)
return False

async def async_play_media(self, media_type, media_id, **kwargs):
if not self.xiaoai_device:
return
aid = self.xiaoai_device.get('deviceID')
api = 'https://api2.mina.mi.com/remote/ubus'
dat = {
'deviceId': aid,
'path': 'mediaplayer',
'method': 'player_play_url',
'message': json.dumps({'url': media_id, 'type': 1, 'media': 'app_ios'}),
}
rdt = await self.xiaoai_cloud.async_request_api(api, data=dat, method='POST') or {}
self.logger.info('%s: Play media: %s', self.name_model, [dat, rdt])

def intelligent_speaker(self, text, execute=False, silent=False, **kwargs):
if srv := self._intelligent_speaker:
anm = 'execute_text_directive' if execute else 'play_text'
Expand Down Expand Up @@ -741,7 +755,7 @@ def turn_off(self):
return self.call_action(act, ['熄屏'])
return super().turn_off()

def play_media(self, media_type, media_id, **kwargs):
async def async_play_media(self, media_type, media_id, **kwargs):
"""Play a piece of media."""
tim = str(int(time.time() * 1000))
pms = {
Expand All @@ -752,9 +766,8 @@ def play_media(self, media_type, media_id, **kwargs):
'ts': tim,
'sign': hashlib.md5(f'mitvsignsalt{media_id}{self._api_key}{tim[-5:]}'.encode()).hexdigest(),
}
rdt = self.request_mitv_api('controller', params=pms)
rdt = await self.async_request_mitv_api('controller', params=pms)
self.logger.info('%s: Play media: %s', self.name_model, [pms, rdt])
return not not rdt

@property
def source(self):
Expand Down

0 comments on commit f59c0a5

Please sign in to comment.