Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rytilahti committed Feb 3, 2023
1 parent df9de6c commit 8c13902
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions miio/integrations/roborock/vacuum/tests/test_vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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": [
{
Expand Down Expand Up @@ -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"]
Expand Down

0 comments on commit 8c13902

Please sign in to comment.