Add support for cleaning individual rooms only

master
Michael Zanetti 2021-04-11 20:04:09 +02:00
parent 6e6c32bc13
commit 2a9a1f2d0b
2 changed files with 41 additions and 23 deletions

View File

@ -149,10 +149,10 @@
"paramTypes": [ "paramTypes": [
{ {
"id": "08a86cca-cdc9-4520-af1d-8413a0c274b5", "id": "08a86cca-cdc9-4520-af1d-8413a0c274b5",
"name": "zones", "name": "zone",
"displayName": "Zones to clean", "displayName": "Zones to clean",
"type": "QStringList", "type": "QString",
"defaultValue": [] "defaultValue": ""
} }
] ]
}, },

View File

@ -91,7 +91,7 @@ def setupThing(info):
# If no poll timer is set up yet, start it now # If no poll timer is set up yet, start it now
logger.log("Creating polltimer") logger.log("Creating polltimer")
global pollTimer global pollTimer
if pollTimer is not None: if pollTimer is None:
pollTimer = threading.Timer(5, pollService) pollTimer = threading.Timer(5, pollService)
pollTimer.start() pollTimer.start()
@ -112,7 +112,6 @@ def setupThing(info):
info.finish(nymea.ThingErrorHardwareFailure, "Unable to connect to neato API.") info.finish(nymea.ThingErrorHardwareFailure, "Unable to connect to neato API.")
return; return;
logger.log(robot.get_robot_state())
info.thing.setStateValue(robotConnectedStateTypeId, True) info.thing.setStateValue(robotConnectedStateTypeId, True)
# set up polling for robot status # set up polling for robot status
info.finish(nymea.ThingErrorNoError) info.finish(nymea.ThingErrorNoError)
@ -177,15 +176,23 @@ def pollService():
def executeAction(info): def executeAction(info):
# return; # Temporary, to not accidentally start it
if info.actionTypeId == robotStartCleaningActionTypeId: if info.actionTypeId == robotStartCleaningActionTypeId:
zone = info.paramValue(robotStartCleaningActionZoneParamTypeId)
logger.log("zone", zone)
if zone != "":
ids = zone[9:];
mapId = ids.split(";")[0]
boundaryId = ids.split(";")[1]
cleanWithRobot(info.thing, mapId, boundaryId)
else:
refreshRobot(info.thing) refreshRobot(info.thing)
if info.thing.stateValue(robotRobotStateStateTypeId) == "paused": if info.thing.stateValue(robotRobotStateStateTypeId) == "paused":
thingsAndRobots[info.thing].resume_cleaning() thingsAndRobots[info.thing].resume_cleaning()
else: else:
# To do: add a parameter to the start action which takes a zone id
cleanWithRobot(info.thing, None, None) cleanWithRobot(info.thing, None, None)
refreshRobot(info.thing) refreshRobot(info.thing)
info.finish(nymea.ThingErrorNoError) info.finish(nymea.ThingErrorNoError)
return return
@ -212,10 +219,11 @@ def executeAction(info):
info.finish(nymea.ThingErrorNoError) info.finish(nymea.ThingErrorNoError)
return return
def cleanWithRobot(robotThing, mapID, boundaryID): 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 # 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] robot = thingsAndRobots[robotThing]
logger.log("Cleaning with robot:", robot, robotThing) logger.log("Cleaning with robot:", robot, robotThing, mapID, boundaryID)
boolEco = robotThing.setting(robotSettingsEcoParamTypeId) boolEco = robotThing.setting(robotSettingsEcoParamTypeId)
boolCare = robotThing.setting(robotSettingsCareParamTypeId) boolCare = robotThing.setting(robotSettingsCareParamTypeId)
boolNogo = robotThing.setting(robotSettingsNoGoLinesParamTypeId) boolNogo = robotThing.setting(robotSettingsNoGoLinesParamTypeId)
@ -233,7 +241,7 @@ def cleanWithRobot(robotThing, mapID, boundaryID):
intNogo = 4 intNogo = 4
logger.log("Settings: Eco:", boolEco, "Care:", boolCare, "Enable nogo:", boolNogo, "mapID:", mapID, "boundaryID:", boundaryID) 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) thingsAndRobots[robotThing].start_cleaning(mode=intEco, navigation_mode=intCare, category=intNogo, boundary_id=boundaryID, map_id=mapID)
refreshRobot(robotThing)
def browseThing(browseResult): def browseThing(browseResult):
robotThing = browseResult.thing robotThing = browseResult.thing
@ -270,20 +278,30 @@ def browseThing(browseResult):
logger.log("boundaries", type(boundaries), boundaries.json()) logger.log("boundaries", type(boundaries), boundaries.json())
for boundary in boundaries.json()["data"]["boundaries"]: for boundary in boundaries.json()["data"]["boundaries"]:
# if boundary["type"] == "polygon": if boundary["type"] == "polygon":
logger.log("vertices:", json.dumps(boundary["vertices"])) logger.log("vertices:", boundary)
browseResult.addItem(nymea.BrowserItem(boundary["id"], boundary["name"], json.dumps(boundary), executable=True, disabled=not boundary["enabled"], icon=nymea.BrowserIconFavorites)) browseResult.addItem(nymea.BrowserItem("boundary-" + mapId + ";" + boundary["id"], boundary["name"], json.dumps(boundary), executable=True, disabled=not boundary["enabled"], icon=nymea.BrowserIconFavorites))
browseResult.finish(nymea.ThingErrorNoError) browseResult.finish(nymea.ThingErrorNoError)
return return
def executeBrowserItem(info): def executeBrowserItem(info):
# TODO: An item in the browser has been clicked.
logger.log("Browser item clicked:", info.itemId) logger.log("Browser item clicked:", info.itemId)
logger.log("Parent item:", ) if info.itemId.startswith("boundary-"):
# cleanWithRobot(info.thing, mapID, boundaryID) ids = info.itemId[9:];
logger.log("IDS:", ids)
mapId = ids.split(";")[0]
boundaryId = ids.split(";")[1]
logger.log("Cleaning boundary:", mapId, boundaryId)
cleanWithRobot(info.thing, mapId, boundaryId)
refreshRobot(info.thing)
info.finish(nymea.ThingErrorNoError) info.finish(nymea.ThingErrorNoError)
return
logger.warn("Can't execute browser item:", info.itemId)
info.finish(nymea.ThingErrorItemNotExecutable)
def deinit(): def deinit():