forked from DeebotUniverse/client.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cut direction for lawn mower goat g1 (DeebotUniverse#514)
- Loading branch information
Showing
7 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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,43 @@ | ||
"""Cut direction command module.""" | ||
|
||
from __future__ import annotations | ||
|
||
from types import MappingProxyType | ||
from typing import TYPE_CHECKING, Any | ||
|
||
from deebot_client.command import InitParam | ||
from deebot_client.events import CutDirectionEvent | ||
from deebot_client.message import HandlingResult | ||
|
||
from .common import JsonGetCommand, JsonSetCommand | ||
|
||
if TYPE_CHECKING: | ||
from deebot_client.event_bus import EventBus | ||
|
||
|
||
class GetCutDirection(JsonGetCommand): | ||
"""Get cut direction command.""" | ||
|
||
name = "getCutDirection" | ||
|
||
@classmethod | ||
def _handle_body_data_dict( | ||
cls, event_bus: EventBus, data: dict[str, Any] | ||
) -> HandlingResult: | ||
"""Handle message->body->data and notify the correct event subscribers. | ||
:return: A message response | ||
""" | ||
event_bus.notify(CutDirectionEvent(angle=data["angle"])) | ||
return HandlingResult.success() | ||
|
||
|
||
class SetCutDirection(JsonSetCommand): | ||
"""Set cut direction command.""" | ||
|
||
name = "setCutDirection" | ||
get_command = GetCutDirection | ||
_mqtt_params = MappingProxyType({"angle": InitParam(int)}) | ||
|
||
def __init__(self, angle: int) -> None: | ||
super().__init__({"angle": angle}) |
This file contains 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 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 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,20 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
from deebot_client.commands.json import GetCutDirection, SetCutDirection | ||
from deebot_client.events import CutDirectionEvent | ||
from tests.helpers import get_request_json, get_success_body | ||
|
||
from . import assert_command, assert_set_command | ||
|
||
|
||
async def test_GetCutDirection() -> None: | ||
json = get_request_json(get_success_body({"angle": 90})) | ||
await assert_command(GetCutDirection(), json, CutDirectionEvent(90)) | ||
|
||
|
||
@pytest.mark.parametrize("angle", [1, 45, 90]) | ||
async def test_SetCutDirection(angle: int) -> None: | ||
args = {"angle": angle} | ||
await assert_set_command(SetCutDirection(angle), args, CutDirectionEvent(angle)) |
This file contains 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