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 1 commit
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
133 changes: 132 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,134 @@
.idea/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# test_files
.vscode/

.idea/
24 changes: 24 additions & 0 deletions custom_components/xiaomi_miot/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@
},
),
},
'intelligent_speaker_play_by_url': {
'method': 'async_intelligent_speaker_play_by_url',
'schema': XIAOMI_MIIO_SERVICE_SCHEMA.extend(
{
vol.Required('url', default=''): vol.Any(cv.string, None),
},
),
},
}


Expand Down Expand Up @@ -374,6 +382,22 @@ async def async_update_xiaoai_device(self):
break
return self.xiaoai_device

async def async_intelligent_speaker_play_by_url(self, url):
if not self.xiaoai_device:
return
aid = self.xiaoai_device.get('deviceID')
self.update_attrs({
'xiaoai_id': aid,
})
api = 'https://api2.mina.mi.com/remote/ubus'
dat = {
'deviceId': aid,
'path': 'mediaplayer',
'method': 'player_play_url',
'message': json.dumps({"url": url, "type": 1, "media": "app_ios"}),
}
return await self.xiaoai_cloud.async_request_api(api, data=dat, method='POST') or {}

async def async_update_play_status(self, now=None):
if not self.xiaoai_device:
return
Expand Down
20 changes: 19 additions & 1 deletion custom_components/xiaomi_miot/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ send_command:
text:
params:
description: Params for the method.
example: ['on']
example: ["on"]
required: true
selector:
object:
Expand Down Expand Up @@ -213,6 +213,24 @@ xiaoai_wakeup:
selector:
boolean:

intelligent_speaker_play_by_url:
description: Play music by url on Xiaoai speaker / 让小爱音箱播放链接中的歌曲
fields:
entity_id:
description: ID of the xiaoai entity.
example: media_player.xiaoai_x08c
required: true
selector:
entity:
integration: xiaomi_miot
domain: media_player
url:
description: URL of music.
example: https://example.com/example.mp3
required: true
selector:
text:

get_device_data:
description: Get xiaomi device data from cloud.
fields:
Expand Down