diff --git a/neatobotvac/integrationpluginneatobotvac.json b/neatobotvac/integrationpluginneatobotvac.json index 639e6735..9e2ab636 100644 --- a/neatobotvac/integrationpluginneatobotvac.json +++ b/neatobotvac/integrationpluginneatobotvac.json @@ -16,6 +16,9 @@ "createMethods": ["User"], "interfaces": ["account"], "setupMethod": "oauth", + "settingsTypes": [ + + ], "stateTypes":[ { "id": "e8f47781-e3fd-416f-a9ac-51ef942d0573", @@ -36,11 +39,7 @@ } ], "actionTypes": [ - { - "id": "a4b5f07f-e71a-4c3a-8d6b-50162a455159", - "name": "getMaps", - "displayName": "Get available maps" - } + ] }, { @@ -99,13 +98,21 @@ }, { "id": "dce4f7f3-a0a6-46bb-9216-c9089d9e9b0d", - "name": "state", + "name": "robotState", "displayName": "Cleaning state", "displayNameEvent": "Cleaning state changed", "type": "QString", "possibleValues": ["docked", "cleaning", "paused", "traveling", "stopped", "error"], "defaultValue": "docked" }, + { + "id": "cb22b48c-1c21-4d52-bde6-847287435685", + "name": "errorMessage", + "displayName": "Error message", + "displayNameEvent": "Error message changes", + "type": "QString", + "defaultValue": "no error" + }, { "id": "1b8abd35-8276-44ba-8c75-a647877b2e11", "name": "charging", @@ -170,6 +177,3 @@ } ] } - - - diff --git a/neatobotvac/integrationpluginneatobotvac.py b/neatobotvac/integrationpluginneatobotvac.py index ddf398b4..fc9aae0e 100644 --- a/neatobotvac/integrationpluginneatobotvac.py +++ b/neatobotvac/integrationpluginneatobotvac.py @@ -139,16 +139,27 @@ def refreshRobot(thing): rbtStartAv = rbtStateCommands['start'] rbtPauseAv = rbtStateCommands['pause'] rbtResumeAv = rbtStateCommands['resume'] - if rbtStateDetails['isDocked'] == True: - thing.setStateValue(robotStateStateTypeId, "docked") - elif rbtPauseAv == True: - thing.setStateValue(robotStateStateTypeId, "cleaning") - elif rbtResumeAv == True: - thing.setStateValue(robotStateStateTypeId, "paused") - elif rbtStartAv == True: - thing.setStateValue(robotStateStateTypeId, "stopped") + if rbtStateJson['error'] == None: + rbtError = "no error" else: - thing.setStateValue(robotStateStateTypeId, "error") + rbtError = rbtStateJson['error'] + # alert state hasn't been implemented yet (not sure what would trigger an alert, haven't seen one yet) + if rbtStateJson['alert'] == None: + rbtAlert = "no alert" + else: + rbtAlert = rbtStateJson['alert'] + logger.log("error: %s: -- alert: %s" % (rbtError, rbtAlert)) + if rbtStateDetails['isDocked'] == True: + thing.setStateValue(robotRobotStateStateTypeId, "docked") + elif rbtPauseAv == True: + thing.setStateValue(robotRobotStateStateTypeId, "cleaning") + elif rbtResumeAv == True: + thing.setStateValue(robotRobotStateStateTypeId, "paused") + elif rbtStartAv == True: + thing.setStateValue(robotRobotStateStateTypeId, "stopped") + else: + thing.setStateValue(robotRobotStateStateTypeId, "error") + thing.setStateValue(robotErrorMessageStateTypeId, rbtError) def pollService(): @@ -159,7 +170,6 @@ def pollService(): refreshRobot(thing) except: logger.warn("Error refreshing robot state") - # restart the timer for next poll global pollTimer pollTimer = threading.Timer(60, pollService) @@ -167,17 +177,25 @@ def pollService(): def executeAction(info): - return; # Temporary, to not accidentally start it - + # return; # Temporary, to not accidentally start it + if info.actionTypeId == robotStartCleaningActionTypeId: - # To do: add a parameter to the start action which takes a zone id - thingsAndRobots[info.thing].start_cleaning() + refreshRobot(info.thing) + if info.thing.stateValue(robotRobotStateStateTypeId) == "paused": + thingsAndRobots[info.thing].resume_cleaning() + else: + # To do: add a parameter to the start action which takes a zone id + cleanWithRobot(info.thing, None, None) refreshRobot(info.thing) info.finish(nymea.ThingErrorNoError) return if info.actionTypeId == robotPauseCleaningActionTypeId: - thingsAndRobots[info.thing].pause_cleaning() + refreshRobot(info.thing) + if info.thing.stateValue(robotRobotStateStateTypeId) == "paused": + thingsAndRobots[info.thing].resume_cleaning() + else: + thingsAndRobots[info.thing].pause_cleaning() refreshRobot(info.thing) info.finish(nymea.ThingErrorNoError) return @@ -194,6 +212,28 @@ def executeAction(info): info.finish(nymea.ThingErrorNoError) return +def cleanWithRobot(robotThing, mapID, boundaryID): + # To do: add a parameter to the start action which takes a zone id --> this should now be represented by mapID & boundaryID + robot = thingsAndRobots[robotThing] + logger.log("Cleaning with robot:", robot, robotThing) + boolEco = robotThing.setting(robotSettingsEcoParamTypeId) + boolCare = robotThing.setting(robotSettingsCareParamTypeId) + boolNogo = robotThing.setting(robotSettingsNoGoLinesParamTypeId) + if boolEco == False: + intEco = 2 + else: + intEco = 1 + if boolCare == False: + intCare = 1 + else: + intCare = 2 + if boolNogo == False: + intNogo = 2 + else: + intNogo = 4 + logger.log("Settings: Eco:", boolEco, "Care:", boolCare, "Enable nogo:", boolNogo, "mapID:", mapID, "boundaryID:", boundaryID) + thingsAndRobots[robotThing].start_cleaning(mode=intEco, navigation_mode=intCare, category=intNogo, boundary_id=boundaryID, map_id=mapID) + refreshRobot(robotThing) def browseThing(browseResult): robotThing = browseResult.thing @@ -241,6 +281,8 @@ def browseThing(browseResult): def executeBrowserItem(info): # TODO: An item in the browser has been clicked. logger.log("Browser item clicked:", info.itemId) + logger.log("Parent item:", ) + # cleanWithRobot(info.thing, mapID, boundaryID) info.finish(nymea.ThingErrorNoError) @@ -248,4 +290,4 @@ def deinit(): global pollTimer # If we started a poll timer, cancel it on shutdown. if pollTimer is not None: - pollTimer.cancel() + pollTimer.cancel() \ No newline at end of file