@@ -482,6 +482,20 @@ def turn_off(self):
482
482
return self .call_action (self ._act_turn_off )
483
483
return False
484
484
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
+
485
499
def intelligent_speaker (self , text , execute = False , silent = False , ** kwargs ):
486
500
if srv := self ._intelligent_speaker :
487
501
anm = 'execute_text_directive' if execute else 'play_text'
@@ -741,7 +755,7 @@ def turn_off(self):
741
755
return self .call_action (act , ['熄屏' ])
742
756
return super ().turn_off ()
743
757
744
- def play_media (self , media_type , media_id , ** kwargs ):
758
+ async def async_play_media (self , media_type , media_id , ** kwargs ):
745
759
"""Play a piece of media."""
746
760
tim = str (int (time .time () * 1000 ))
747
761
pms = {
@@ -752,9 +766,8 @@ def play_media(self, media_type, media_id, **kwargs):
752
766
'ts' : tim ,
753
767
'sign' : hashlib .md5 (f'mitvsignsalt{ media_id } { self ._api_key } { tim [- 5 :]} ' .encode ()).hexdigest (),
754
768
}
755
- rdt = self .request_mitv_api ('controller' , params = pms )
769
+ rdt = await self .async_request_mitv_api ('controller' , params = pms )
756
770
self .logger .info ('%s: Play media: %s' , self .name_model , [pms , rdt ])
757
- return not not rdt
758
771
759
772
@property
760
773
def source (self ):
0 commit comments