Skip to content

Commit

Permalink
iRobot zone support added (#11783)
Browse files Browse the repository at this point in the history
Signed-off-by: Nuesel <[email protected]>
  • Loading branch information
Nuesel authored Dec 16, 2021
1 parent 956f6e7 commit e54dec5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
7 changes: 5 additions & 2 deletions bundles/org.openhab.binding.irobot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,13 @@ Error codes. Data type is string in order to be able to utilize mapping to human
You can clean one or many specific regions of a given map by sending the following String to the command channel:

```
cleanRegions:<pmapId>;<region_id1>,<region_id2>,..
cleanRegions:<pmapId>;[r=]<region_id1>,[r=]<region_id2>,z=<zone_id1>,...;[<user_pmapv_id>]
```

The easiest way to determine the pmapId and region_ids is to monitor the last_command channel while starting a new mission for the specific region with the iRobot-App.
Some devices support cleaning rooms (aka regions). Additionally, support for cleaning rectangle areas previously defined in the iRobot-App (aka zones) may be available.
If the type string such as `r=` (region) or `z=` (zone) is omnitted, the type defaults to region.

The easiest way to determine the pmapId, region_ids/zoneids and userPmapvId is to monitor the last_command channel while starting a new mission for the specific region or zone with the iRobot-App.

## Known Problems / Caveats

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
*/
package org.openhab.binding.irobot.internal.dto;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import com.google.gson.JsonElement;
import com.google.gson.annotations.SerializedName;
Expand All @@ -35,23 +34,30 @@ public static class CleanRoomsRequest extends CommandRequest {
public int ordered;
@SerializedName("pmap_id")
public String pmapId;
@SerializedName("user_pmapv_id")
public String userPmapvId;
public List<Region> regions;

public CleanRoomsRequest(String cmd, String mapId, String[] regions) {
public CleanRoomsRequest(String cmd, String mapId, String[] pregions, String[] types, String userPmapvId) {
super(cmd);
ordered = 1;
pmapId = mapId;
this.regions = Arrays.stream(regions).map(i -> new Region(i)).collect(Collectors.toList());
this.userPmapvId = userPmapvId;

regions = new ArrayList<Region>();
for (int i = 0; (i < pregions.length) && (i < types.length); i++) {
regions.add(new Region(pregions[i], types[i]));
}
}

public static class Region {
@SerializedName("region_id")
public String regionId;
public String type;

public Region(String id) {
public Region(String id, String type) {
this.regionId = id;
this.type = "rid";
this.type = type;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,38 @@ public void handleCommand(ChannelUID channelUID, Command command) {
String[] params = cmds[1].split(";");

String mapId = params[0];
String[] regionIds = params[1].split(",");

MQTTProtocol.Request request = new MQTTProtocol.CleanRoomsRequest("start", mapId, regionIds);
String userPmapvId;
if (params.length >= 3) {
userPmapvId = params[2];
} else {
userPmapvId = null;
}

String[] regions = params[1].split(",");
String regionIds[] = new String[regions.length];
String regionTypes[] = new String[regions.length];

for (int i = 0; i < regions.length; i++) {
String[] regionDetails = regions[i].split("=");

if (regionDetails.length >= 2) {
if (regionDetails[0].equals("r")) {
regionIds[i] = regionDetails[1];
regionTypes[i] = "rid";
} else if (regionDetails[0].equals("z")) {
regionIds[i] = regionDetails[1];
regionTypes[i] = "zid";
} else {
regionIds[i] = regionDetails[0];
regionTypes[i] = "rid";
}
} else {
regionIds[i] = regionDetails[0];
regionTypes[i] = "rid";
}
}
MQTTProtocol.Request request = new MQTTProtocol.CleanRoomsRequest("start", mapId, regionIds,
regionTypes, userPmapvId);
connection.send(request.getTopic(), gson.toJson(request));
} else {
logger.warn("Invalid request: {}", cmd);
Expand Down

0 comments on commit e54dec5

Please sign in to comment.