-
-
Notifications
You must be signed in to change notification settings - Fork 592
Add fan speed presets to VacuumInterface #1405
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
Merged
rytilahti
merged 36 commits into
rytilahti:master
from
2pirko:vacuum_interface_fan_speed_presets2
May 23, 2022
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
4e63252
Added Xiaomi Vaccum Mop 2 Ultra and Pro+
2pirko 6e8f278
Updated automatic formatting using black
2pirko e21387c
Removed duplicated supported models
2pirko 469cc89
Extended dreame test to test all supported models
2pirko 2db536c
Added test for invalid dreame model
2pirko 05a6ea1
Formatting by black
2pirko 2db26f4
import isort
2pirko 7723bfa
Updated readme with newly supported models
2pirko 2dd5e61
Added support for Vacuum interface: VaccumDevice and VacuumMiotDevice
2pirko c354dd4
Merge branch 'master' into vaccum_device
2pirko dc1ccfa
Fixed isort
2pirko 5ba5374
Removing unnecessary pass
2pirko 866e856
Feedback from PR: VaccumDevice renamed to VacuumInterface
2pirko 4f7c5da
Step2: VacuumInterface no moreinherits Device
2pirko c25552f
Unit test fixed
2pirko 4910920
Merge branch 'master' into vaccum_device
2pirko 4ce7c75
Merge branch 'master' into vaccum_device
2pirko c5ad8c8
Merge branch 'master' into vaccum_device
2pirko 1ac8138
VaccumInterface published as symbol available for the "interface" pac…
2pirko 01406ea
Merge branch 'master' into vaccum_device
2pirko af8fffb
Added two methods into VacuumInterface:
2pirko 580b94f
Added vacuum unit test
2pirko ccad8fb
Merge branch 'master' into vacuum_interface_fan_speed_presets
2pirko a3a8ee0
Fixed python 3.10
2pirko f7065e3
Imporved test coverage
2pirko ebdd15f
Additional increase of test coverage
2pirko 9ec88b0
Added test for param validation in set_fan_speed_preset()
2pirko 3da873d
unit test simplification
2pirko 74f8452
Feedback from PR
2pirko 3465302
Minor DOCS improvement
2pirko 410f5e7
Minor docs update
2pirko 5db1b58
Feedback from PR
2pirko 8c52d44
Merge branch 'master' into vacuum_interface_fan_speed_presets2
2pirko b7cc703
Updated noqa codes for new flake8 version
2pirko c7ebce0
remove copyright notice update
rytilahti 372702a
Rework docstrings
rytilahti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| """Interfaces API.""" | ||
|
|
||
| from .vacuuminterface import VacuumInterface | ||
| from .vacuuminterface import FanspeedPresets, VacuumInterface | ||
|
|
||
| __all__ = ["VacuumInterface"] | ||
| __all__ = ["FanspeedPresets", "VacuumInterface"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,46 @@ | ||
| """`VacuumInterface` is an interface (abstract class) with shared API for all vacuum | ||
| devices.""" | ||
| from abc import abstractmethod | ||
| from typing import Dict | ||
|
|
||
| # Dictionary of predefined fan speeds | ||
| FanspeedPresets = Dict[str, int] | ||
|
|
||
|
|
||
| class VacuumInterface: | ||
| """Vacuum API interface.""" | ||
|
|
||
| @abstractmethod | ||
| def home(self): | ||
| """Return to home.""" | ||
| """Return vacuum robot to home station/dock.""" | ||
|
|
||
| @abstractmethod | ||
| def start(self): | ||
| """Start cleaning.""" | ||
|
|
||
| @abstractmethod | ||
| def stop(self): | ||
| """Validate that Stop cleaning.""" | ||
| """Stop cleaning.""" | ||
|
|
||
| def pause(self): | ||
| """Pause cleaning.""" | ||
| """Pause cleaning. | ||
|
|
||
| :raises RuntimeError: if the method is not supported by the device | ||
| """ | ||
| raise RuntimeError("`pause` not supported") | ||
|
|
||
| @abstractmethod | ||
| def fan_speed_presets(self) -> FanspeedPresets: | ||
| """Return available fan speed presets. | ||
|
|
||
| The returned object is a dictionary where the key is user-readable name and the | ||
| value is input for :func:`set_fan_speed_preset()`. | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| def set_fan_speed_preset(self, speed_preset: int) -> None: | ||
| """Set fan speed preset speed. | ||
|
|
||
| :param speed_preset: a value from :func:`fan_speed_presets()` | ||
| :raises ValueError: for invalid preset value | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| """Test of vacuum devices.""" | ||
| from collections.abc import Iterable | ||
| from typing import List, Sequence, Tuple, Type | ||
|
|
||
| import pytest | ||
|
|
||
| from miio.device import Device | ||
| from miio.integrations.vacuum.roborock.vacuum import ROCKROBO_V1 | ||
| from miio.interfaces import VacuumInterface | ||
|
|
||
| # list of all supported vacuum classes | ||
| VACUUM_CLASSES: Tuple[Type[VacuumInterface], ...] = tuple( | ||
| cl for cl in VacuumInterface.__subclasses__() # type: ignore | ||
| ) | ||
|
|
||
|
|
||
| def _all_vacuum_models() -> Sequence[Tuple[Type[Device], str]]: | ||
| """:return: list of tuples with supported vacuum models with corresponding class""" | ||
| result: List[Tuple[Type[Device], str]] = [] | ||
| for cls in VACUUM_CLASSES: | ||
| assert issubclass(cls, Device) | ||
| vacuum_models = cls.supported_models | ||
| assert isinstance(vacuum_models, Iterable) | ||
| for model in vacuum_models: | ||
| result.append((cls, model)) | ||
| return result # type: ignore | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("cls, model", _all_vacuum_models()) | ||
| def test_vacuum_fan_speed_presets(cls: Type[Device], model: str) -> None: | ||
| """Test method VacuumInterface.fan_speed_presets()""" | ||
| if model == ROCKROBO_V1: | ||
| return # this model cannot be tested because presets depends on firmware | ||
rytilahti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| dev = cls("127.0.0.1", "68ffffffffffffffffffffffffffffff", model=model) | ||
| assert isinstance(dev, VacuumInterface) | ||
| presets = dev.fan_speed_presets() | ||
| assert presets is not None, "presets must be defined" | ||
| assert bool(presets), "presets cannot be empty" | ||
| assert isinstance(presets, dict), "presets must be dictionary" | ||
| for name, value in presets.items(): | ||
| assert isinstance(name, str), "presets key must be string" | ||
| assert name, "presets key cannot be empty" | ||
| assert isinstance(value, int), "presets value must be integer" | ||
| assert value >= 0, "presets value must be >= 0" | ||
rytilahti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @pytest.mark.parametrize("cls, model", _all_vacuum_models()) | ||
| def test_vacuum_set_fan_speed_presets_fails(cls: Type[Device], model: str) -> None: | ||
| """Test method VacuumInterface.fan_speed_presets()""" | ||
| if model == ROCKROBO_V1: | ||
| return # this model cannot be tested because presets depends on firmware | ||
| dev = cls("127.0.0.1", "68ffffffffffffffffffffffffffffff", model=model) | ||
| assert isinstance(dev, VacuumInterface) | ||
| with pytest.raises(ValueError): | ||
| dev.set_fan_speed_preset(-1) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.