From 8c13902707b9dcaec8b2beceef71030e2686719b Mon Sep 17 00:00:00 2001 From: Teemu Rytilahti Date: Fri, 3 Feb 2023 18:00:00 +0100 Subject: [PATCH] Fix tests --- .../roborock/vacuum/tests/test_vacuum.py | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/miio/integrations/roborock/vacuum/tests/test_vacuum.py b/miio/integrations/roborock/vacuum/tests/test_vacuum.py index 9f5e2f392..bb057e004 100644 --- a/miio/integrations/roborock/vacuum/tests/test_vacuum.py +++ b/miio/integrations/roborock/vacuum/tests/test_vacuum.py @@ -4,9 +4,10 @@ import pytest -from miio import RoborockVacuum, UnsupportedFeatureException -from miio.tests.dummies import DummyDevice +from miio import DeviceError, RoborockVacuum, UnsupportedFeatureException +from miio.tests.dummies import DummyDevice, DummyMiIOProtocol +from ..updatehelper import UpdateHelper from ..vacuum import ( ROCKROBO_Q7_MAX, ROCKROBO_S7, @@ -18,6 +19,20 @@ from ..vacuumcontainers import VacuumStatus +class DummyRoborockProtocol(DummyMiIOProtocol): + """Roborock-specific dummy protocol handler. + + The vacuum reports 'unknown_method' instead of device error for unknown commands. + """ + + def send(self, command: str, parameters=None, retry_count=3, extra_parameters=None): + """Overridden send() to return values from `self.return_values`.""" + try: + return super().send(command, parameters, retry_count, extra_parameters) + except DeviceError: + return "unknown_method" + + class DummyVacuum(DummyDevice, RoborockVacuum): STATE_CHARGING = 8 STATE_CLEANING = 5 @@ -48,7 +63,7 @@ def __init__(self, *args, **kwargs): } self._maps = None self._map_enum_cache = None - + self._status_helper = UpdateHelper(self.vacuum_status) self.dummies = { "consumables": [ { @@ -138,6 +153,7 @@ def __init__(self, *args, **kwargs): } super().__init__(args, kwargs) + self._protocol = DummyRoborockProtocol(self) def set_water_box_custom_mode_callback(self, parameters): assert parameters == self.dummies["water_box_custom_mode"]