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

[irobot] Added zone support #11783

Merged
merged 1 commit into from
Dec 16, 2021
Merged
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
iRobot zone support added
Signed-off-by: Nuesel <[email protected]>
  • Loading branch information
Nuesel committed Dec 15, 2021
commit df9a9494e995641d37dcf90b9c8d2ea14ae8adc5
7 changes: 5 additions & 2 deletions bundles/org.openhab.binding.irobot/README.md
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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;
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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);