Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 增加小爱音箱通过url播放歌曲的服务 #1261

Merged
merged 5 commits into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading