Skip to content

Commit f59c0a5

Browse files
authoredAug 19, 2023
🎵 add support play media for xiaoai (#1261)
1 parent 5d3c25d commit f59c0a5

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed
 

‎.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
.idea/
22
__pycache__/
3-

‎custom_components/xiaomi_miot/media_player.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,20 @@ def turn_off(self):
482482
return self.call_action(self._act_turn_off)
483483
return False
484484

485+
async def async_play_media(self, media_type, media_id, **kwargs):
486+
if not self.xiaoai_device:
487+
return
488+
aid = self.xiaoai_device.get('deviceID')
489+
api = 'https://api2.mina.mi.com/remote/ubus'
490+
dat = {
491+
'deviceId': aid,
492+
'path': 'mediaplayer',
493+
'method': 'player_play_url',
494+
'message': json.dumps({'url': media_id, 'type': 1, 'media': 'app_ios'}),
495+
}
496+
rdt = await self.xiaoai_cloud.async_request_api(api, data=dat, method='POST') or {}
497+
self.logger.info('%s: Play media: %s', self.name_model, [dat, rdt])
498+
485499
def intelligent_speaker(self, text, execute=False, silent=False, **kwargs):
486500
if srv := self._intelligent_speaker:
487501
anm = 'execute_text_directive' if execute else 'play_text'
@@ -741,7 +755,7 @@ def turn_off(self):
741755
return self.call_action(act, ['熄屏'])
742756
return super().turn_off()
743757

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

759772
@property
760773
def source(self):

0 commit comments

Comments
 (0)
Please sign in to comment.