diff --git a/.gitignore b/.gitignore index b22ec9270..2483976dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ .idea/ __pycache__/ - diff --git a/custom_components/xiaomi_miot/media_player.py b/custom_components/xiaomi_miot/media_player.py index e67535e4d..9cf5ba799 100644 --- a/custom_components/xiaomi_miot/media_player.py +++ b/custom_components/xiaomi_miot/media_player.py @@ -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' @@ -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 = { @@ -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):