From 00e881aad389bd3c30e677ff986a62d081e85557 Mon Sep 17 00:00:00 2001 From: GH0st3rs Date: Thu, 14 Jul 2022 19:37:50 +0300 Subject: [PATCH 1/3] #1181 Solved --- .../vacuum/dreame/dreamevacuum_miot.py | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/miio/integrations/vacuum/dreame/dreamevacuum_miot.py b/miio/integrations/vacuum/dreame/dreamevacuum_miot.py index 8fa048b7f..8b44dd528 100644 --- a/miio/integrations/vacuum/dreame/dreamevacuum_miot.py +++ b/miio/integrations/vacuum/dreame/dreamevacuum_miot.py @@ -2,6 +2,7 @@ import logging from enum import Enum +import threading from typing import Dict, Optional import click @@ -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__) @@ -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}, } @@ -609,8 +612,8 @@ def forward(self, distance: int) -> None: def rotate(self, rotatation: int) -> None: """Rotate vacuum.""" if ( - rotatation < self.MANUAL_ROTATION_MIN - or rotatation > self.MANUAL_ROTATION_MAX + rotatation < self.MANUAL_ROTATION_MIN or + rotatation > self.MANUAL_ROTATION_MAX ): raise DeviceException( "Given rotation is invalid, should be [%s, %s], was %s" @@ -629,3 +632,44 @@ 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), + ) + def set_voice(self, url: str, md5sum: str, size: int): + """Upload voice package + + :param str url: URL or path to languaeg pack + + :param str md5sum: MD5 hash for file if URL used + + :param int size: File size in bytes if URL used""" + 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': 'MA'}, + {'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!") From e74a39a6906e98fd0cb682721cd2fab2181abc9c Mon Sep 17 00:00:00 2001 From: GH0st3rs Date: Thu, 14 Jul 2022 20:34:48 +0300 Subject: [PATCH 2/3] Fixed a few issues --- .../vacuum/dreame/dreamevacuum_miot.py | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/miio/integrations/vacuum/dreame/dreamevacuum_miot.py b/miio/integrations/vacuum/dreame/dreamevacuum_miot.py index 8b44dd528..e35e52a0c 100644 --- a/miio/integrations/vacuum/dreame/dreamevacuum_miot.py +++ b/miio/integrations/vacuum/dreame/dreamevacuum_miot.py @@ -1,8 +1,8 @@ """Dreame Vacuum.""" import logging -from enum import Enum import threading +from enum import Enum from typing import Dict, Optional import click @@ -612,8 +612,8 @@ def forward(self, distance: int) -> None: def rotate(self, rotatation: int) -> None: """Rotate vacuum.""" if ( - rotatation < self.MANUAL_ROTATION_MIN or - rotatation > self.MANUAL_ROTATION_MAX + rotatation < self.MANUAL_ROTATION_MIN + or rotatation > self.MANUAL_ROTATION_MAX ): raise DeviceException( "Given rotation is invalid, should be [%s, %s], was %s" @@ -639,19 +639,21 @@ def rotate(self, rotatation: int) -> None: click.argument("size", type=int, default=0), ) def set_voice(self, url: str, md5sum: str, size: int): - """Upload voice package + """Upload voice package. :param str url: URL or path to languaeg pack :param str md5sum: MD5 hash for file if URL used - :param int size: File size in bytes if URL used""" + :param int size: File size in bytes if URL used + """ 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.") + "You need to pass md5 and file size when using URL for updating." + ) return local_url = url else: @@ -665,11 +667,11 @@ def set_voice(self, url: str, md5sum: str, size: int): click.echo(f"Hosting file at {local_url}") params = [ - {'piid': 3, 'value': 'MA'}, - {'piid': 4, 'value': local_url}, - {'piid': 5, 'value': md5sum}, - {'piid': 6, 'value': size}, + {"piid": 3, "value": "MA"}, + {"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: + result_status = self.call_action("set_voice", params=params) + if result_status["code"] == 0: click.echo("Installation complete!") From 6a011a38e9878b6e6b5c35e6fd27aa2bae237b32 Mon Sep 17 00:00:00 2001 From: GH0st3rs Date: Thu, 14 Jul 2022 21:32:16 +0300 Subject: [PATCH 3/3] Update voice_id parameter --- .../integrations/vacuum/dreame/dreamevacuum_miot.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/miio/integrations/vacuum/dreame/dreamevacuum_miot.py b/miio/integrations/vacuum/dreame/dreamevacuum_miot.py index e35e52a0c..78b6053e2 100644 --- a/miio/integrations/vacuum/dreame/dreamevacuum_miot.py +++ b/miio/integrations/vacuum/dreame/dreamevacuum_miot.py @@ -637,15 +637,16 @@ def rotate(self, rotatation: int) -> None: 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): + def set_voice(self, url: str, md5sum: str, size: int, voice_id: str): """Upload voice package. - :param str url: URL or path to languaeg pack - + :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 @@ -667,7 +668,7 @@ def set_voice(self, url: str, md5sum: str, size: int): click.echo(f"Hosting file at {local_url}") params = [ - {"piid": 3, "value": "MA"}, + {"piid": 3, "value": voice_id}, {"piid": 4, "value": local_url}, {"piid": 5, "value": md5sum}, {"piid": 6, "value": size}, @@ -675,3 +676,5 @@ def set_voice(self, url: str, md5sum: str, size: int): result_status = self.call_action("set_voice", params=params) if result_status["code"] == 0: click.echo("Installation complete!") + + return result_status