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

Add soundpack install support for vacuum/dreame #1457

Merged
merged 3 commits into from
Jul 14, 2022
Merged
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
49 changes: 49 additions & 0 deletions miio/integrations/vacuum/dreame/dreamevacuum_miot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Dreame Vacuum."""

import logging
import threading
from enum import Enum
from typing import Dict, Optional

Expand All @@ -11,6 +12,7 @@
from miio.interfaces import FanspeedPresets, VacuumInterface
from miio.miot_device import DeviceStatus as DeviceStatusContainer
from miio.miot_device import MiotDevice, MiotMapping
from miio.updater import OneShotServer

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -66,6 +68,7 @@
"reset_sidebrush_life": {"siid": 28, "aiid": 1},
"move": {"siid": 21, "aiid": 1},
"play_sound": {"siid": 24, "aiid": 3},
"set_voice": {"siid": 24, "aiid": 2},
}


Expand Down Expand Up @@ -629,3 +632,49 @@ def rotate(self, rotatation: int) -> None:
},
],
)

@command(
click.argument("url", type=str),
click.argument("md5sum", type=str, required=False),
click.argument("size", type=int, default=0),
click.argument("voice_id", type=str, default="CP"),
)
def set_voice(self, url: str, md5sum: str, size: int, voice_id: str):
"""Upload voice package.

:param str url: URL or path to language pack
:param str md5sum: MD5 hash for file if URL used
:param int size: File size in bytes if URL used
:param str voice_id: In original it is country code for the selected
voice pack. You can put here what you like, I guess it doesn't matter (default: CP - Custom Packet)
"""
local_url = None
server = None
if url.startswith("http"):
if md5sum is None or size == 0:
click.echo(
"You need to pass md5 and file size when using URL for updating."
)
return
local_url = url
else:
server = OneShotServer(file=url)
local_url = server.url()
md5sum = server.md5
size = len(server.payload)

t = threading.Thread(target=server.serve_once)
t.start()
click.echo(f"Hosting file at {local_url}")

params = [
{"piid": 3, "value": voice_id},
{"piid": 4, "value": local_url},
{"piid": 5, "value": md5sum},
{"piid": 6, "value": size},
]
result_status = self.call_action("set_voice", params=params)
if result_status["code"] == 0:
click.echo("Installation complete!")

return result_status