-
Notifications
You must be signed in to change notification settings - Fork 75
feat: Add a trait for working with routines #574
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
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,26 @@ | ||
| """Routines trait for V1 devices.""" | ||
|
|
||
| from roborock.data.containers import HomeDataScene | ||
| from roborock.web_api import UserWebApiClient | ||
|
|
||
|
|
||
| class RoutinesTrait: | ||
| """Trait for interacting with routines.""" | ||
|
|
||
| def __init__(self, device_id: str, web_api: UserWebApiClient) -> None: | ||
| """Initialize the routines trait.""" | ||
| self._device_id = device_id | ||
| self._web_api = web_api | ||
|
|
||
| async def get_routines(self) -> list[HomeDataScene]: | ||
| """Get available routines.""" | ||
| return await self._web_api.get_routines(self._device_id) | ||
|
|
||
| async def execute_routine(self, routine_id: int) -> None: | ||
| """Execute a routine by its ID. | ||
|
|
||
| Technically, routines are per-device, but the API does not | ||
| require the device ID to execute them. This can execute a | ||
| routine for any device but it is exposed here for convenience. | ||
| """ | ||
| await self._web_api.execute_routine(routine_id) |
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 |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| """Tests for the RoutinesTrait.""" | ||
|
|
||
| from unittest.mock import AsyncMock | ||
|
|
||
| import pytest | ||
|
|
||
| from roborock.data.containers import HomeDataScene | ||
| from roborock.devices.device import RoborockDevice | ||
| from roborock.devices.traits.v1.routines import RoutinesTrait | ||
|
|
||
|
|
||
| @pytest.fixture(name="routines_trait") | ||
| def routines_trait_fixture(device: RoborockDevice) -> RoutinesTrait: | ||
| """Fixture for the routines trait.""" | ||
| assert device.v1_properties | ||
| return device.v1_properties.routines | ||
|
|
||
|
|
||
| async def test_get_routines(routines_trait: RoutinesTrait, web_api_client: AsyncMock) -> None: | ||
| """Test getting routines.""" | ||
| web_api_client.get_routines.return_value = [HomeDataScene(id=1, name="test_scene")] | ||
| routines = await routines_trait.get_routines() | ||
| assert len(routines) == 1 | ||
| assert routines[0].name == "test_scene" | ||
| web_api_client.get_routines.assert_called_once() | ||
|
|
||
|
|
||
| async def test_execute_routine(routines_trait: RoutinesTrait, web_api_client: AsyncMock) -> None: | ||
| """Test executing a routine.""" | ||
| await routines_trait.execute_routine(1) | ||
| web_api_client.execute_routine.assert_called_once_with(1) |
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.