Skip to content
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

Protocol additions #50

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions automower_ble/mower.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
MowerActivity,
ModeOfOperation,
TaskInformation,
OverrideAction,
)
from .models import MowerModels
from .error_codes import ErrorCodes
Expand Down Expand Up @@ -213,6 +214,13 @@ async def main(mower: Mower):
)
)
print("\t" + ErrorCodes(last_message["code"]).name)

mower_name = await mower.get_parameter("GetUserMowerNameAsAsciiString")
print("Mower name: " + mower_name)

override = await mower.get_parameter("GetOverride")
print("Mower override: " + str(OverrideAction(override["action"])))

# print("Running for 3 hours")
# await mower.mower_override()

Expand Down
79 changes: 70 additions & 9 deletions automower_ble/protocol.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"getModeOfOperation": {
"major": 4586,
"minor": 1,
"responseType":"uint8",
"responseType": "uint8",
"description": "Get mode of operation"
},
"mowerState": {
Expand Down Expand Up @@ -144,7 +144,7 @@
"responseType": "no_response",
"description": "Main override request"
},
"requestTrigger":{
"requestTrigger": {
"major": 4586,
"minor": 4,
"responseType": "no_response",
Expand All @@ -153,7 +153,7 @@
"keepalive": {
"major": 4674,
"minor": 2,
"responseType":"no_response",
"responseType": "no_response",
"description": "Sending a keep alive to the mower"
},
"getStartupSequenceRequiredRequest": {
Expand All @@ -168,22 +168,22 @@
"responseType": "bool",
"description": "Check if the operator is logged in or not"
},
"getRestrictionReason":{
"getRestrictionReason": {
"major": 4658,
"minor": 0,
"responseType":"uint8",
"responseType": "uint8",
"description": "Get the type of reason of restriction"
},
"getNumberOfTasks" : {
"getNumberOfTasks": {
"major": 4690,
"minor": 4,
"responseType":"uint32",
"responseType": "uint32",
"description": "Get the number of tasks"
},
"getTask": {
"major": 4690,
"minor": 5,
"requestType":{
"requestType": {
"task": "uint8"
},
"responseType": {
Expand All @@ -196,8 +196,69 @@
"on_friday": "bool",
"on_saturday": "bool",
"on_sunday": "bool",
"unknown": "uint16"
"unknown": "uint16"
},
"description": "Get a specified task"
},
"GetUserMowerNameAsAsciiString": {
"major": 4698,
"minor": 5,
"description": "Get the user defined mower name",
"responseType": "ascii"
},
"GetOverride": {
"major": 4658,
"minor": 2,
"description": "Get the override status of the mower",
"responseType": {
"action": "uint8",
"startTime": "tUnixTime",
"duration": "uint32"
}
},
"SetOverrideMow": {
"major": 4658,
"minor": 3,
"description": "Enable override mow for the specified duration",
"requestType": {
"duration": "uint32"
},
"responseType": "no_response"
},
"SetOverridePark": {
"major": 4658,
"minor": 4,
"description": "Park the mower for the specified duration",
"requestType": {
"duration": "uint32"
},
"responseType": "no_response"
},
"SetOverrideParkUntilNextStart": {
"major": 4658,
"minor": 5,
"description": "Park until next scheduled start",
"responseType": "no_response"
},
"ClearOverride": {
"major": 4658,
"minor": 6,
"description": "Clear the override status of the mower",
"responseType": "no_response"
},
"GetReversingDistance": {
"major": 4716,
"minor": 0,
"description": "Get reversing distance from charging station in mm",
"responseType": "uint16"
},
"SetReversingDistance": {
"major": 4716,
"minor": 1,
"description": "Set the reversing distance from charging station in mm. In the app, this is controlled in whole cm from 15cm to 300cm",
"requestType": {
"distance": "uint16"
},
"responseType": "no_response"
}
}
17 changes: 16 additions & 1 deletion automower_ble/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class MowerActivity(Enum):
STOPPED_IN_GARDEN = 6 # Mower has stopped. Needs manual action to resume


class OverrideAction(Enum):
NONE = 0
FORCEDPARK = 1
FORCEDMOW = 2


class TaskInformation(object):
def __init__(
self,
Expand Down Expand Up @@ -163,7 +169,7 @@ def generate_request(self, **kwargs) -> bytearray:

return self.request_data

def parse_response(self, response_data: bytearray) -> int | None:
def parse_response(self, response_data: bytearray) -> int | str | dict | None:
response_length = response_data[17]
data = response_data[19 : 19 + response_length]
response = dict()
Expand All @@ -184,6 +190,15 @@ def parse_response(self, response_data: bytearray) -> int | None:
elif (dtype == "uint8") or (dtype == "bool"):
response[name] = data[dpos]
dpos += 1
elif dtype == "ascii":
if len(self.response_data_type) != 1:
raise ValueError(
"ASCII response type can currently only be used when there is only one response type"
)
response[name] = data.decode("ascii").rstrip(
"\x00"
) # Remove trailing null bytes
dpos += len(data)
else:
raise ValueError("Unknown data type: " + dtype)
if dpos != len(data):
Expand Down