Skip to content

Commit

Permalink
Add soundpack install support for vacuum/dreame (#1457)
Browse files Browse the repository at this point in the history
  • Loading branch information
GH0st3rs authored Jul 14, 2022
1 parent 1ac82ab commit ec64f0c
Showing 1 changed file with 49 additions and 0 deletions.
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

0 comments on commit ec64f0c

Please sign in to comment.