-
Notifications
You must be signed in to change notification settings - Fork 73
Add Q10 remote control trait #812
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6f71fae
Add Q10 remote control trait
Kraina68512 4fda00e
Just update the comments
Kraina68512 fb5b039
Add files via upload
Kraina68512 9883f64
Add RemoteCommand enum for navigation commands
Kraina68512 fb54c79
Refactor remote control commands for Q10 devices
Kraina68512 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| """Traits for Q10 B01 devices.""" | ||
|
|
||
| from roborock.data.b01_q10.b01_q10_code_mappings import ( | ||
| B01_Q10_DP, | ||
| RemoteCommand, | ||
| ) | ||
| from typing import Any | ||
|
|
||
| from .command import CommandTrait | ||
|
|
||
|
|
||
| class RemoteTrait: | ||
| """Trait for sending vacuum commands. | ||
|
|
||
| This is a wrapper around the CommandTrait for sending remote related | ||
| commands to Q10 devices. | ||
| """ | ||
|
|
||
| def __init__(self, command: CommandTrait) -> None: | ||
| """Initialize the RemoteTrait.""" | ||
| self._command = command | ||
|
|
||
| async def _send_remote(self, action: RemoteCommand) -> None: | ||
| await self._command.send(B01_Q10_DP.COMMON, params={B01_Q10_DP.REMOTE: action.value}) | ||
|
|
||
| async def forward(self) -> None: | ||
allenporter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """Move forward.""" | ||
| await self._send_remote(RemoteCommand.FORWARD) | ||
|
|
||
| async def left(self) -> None: | ||
| """Turn left.""" | ||
| await self._send_remote(RemoteCommand.LEFT) | ||
|
|
||
| async def right(self) -> None: | ||
| """Turn right.""" | ||
| await self._send_remote(RemoteCommand.RIGHT) | ||
|
|
||
| async def stop(self) -> None: | ||
| """Stop last moving command or start remote control.""" | ||
| await self._send_remote(RemoteCommand.STOP) | ||
|
|
||
| async def exit(self) -> None: | ||
| """Exit remote control.""" | ||
| await self._send_remote(RemoteCommand.EXIT) | ||
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,50 @@ | ||
| import json | ||
| from collections.abc import Awaitable, Callable | ||
| from typing import Any | ||
|
|
||
| import pytest | ||
|
|
||
| from roborock.devices.traits.b01.q10 import Q10PropertiesApi | ||
| from roborock.devices.traits.b01.q10.remote import RemoteTrait | ||
| from tests.fixtures.channel_fixtures import FakeChannel | ||
|
|
||
|
|
||
| @pytest.fixture(name="fake_channel") | ||
| def fake_channel_fixture() -> FakeChannel: | ||
| return FakeChannel() | ||
|
|
||
|
|
||
| @pytest.fixture(name="q10_api") | ||
| def q10_api_fixture(fake_channel: FakeChannel) -> Q10PropertiesApi: | ||
| return Q10PropertiesApi(fake_channel) # type: ignore[arg-type] | ||
|
|
||
|
|
||
| @pytest.fixture(name="remote") | ||
| def remote_fixture(q10_api: Q10PropertiesApi) -> RemoteTrait: | ||
| return q10_api.remote | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("command_fn", "expected_payload"), | ||
| [ | ||
| (lambda x: x.forward(), {"101": {"12": 0}}), | ||
| (lambda x: x.left(), {"101": {"12": 2}}), | ||
| (lambda x: x.right(), {"101": {"12": 3}}), | ||
| (lambda x: x.stop(), {"101": {"12": 4}}), | ||
| (lambda x: x.exit(), {"101": {"12": 5}}), | ||
| ], | ||
| ) | ||
| async def test_remote_commands( | ||
| remote: RemoteTrait, | ||
| fake_channel: FakeChannel, | ||
| command_fn: Callable[[RemoteTrait], Awaitable[None]], | ||
| expected_payload: dict[str, Any], | ||
| ) -> None: | ||
| """Test sending a remote start command.""" | ||
| await command_fn(remote) | ||
|
|
||
| assert len(fake_channel.published_messages) == 1 | ||
| message = fake_channel.published_messages[0] | ||
| assert message.payload | ||
| payload_data = json.loads(message.payload.decode()) | ||
| assert payload_data == {"dps": expected_payload} |
Oops, something went wrong.
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.