]> git.basschouten.com Git - openhab-addons.git/commitdiff
iRobot zone support added (#11783)
authorNuesel <nuesel@gruenbaer.net>
Thu, 16 Dec 2021 07:53:30 +0000 (08:53 +0100)
committerGitHub <noreply@github.com>
Thu, 16 Dec 2021 07:53:30 +0000 (08:53 +0100)
Signed-off-by: Nuesel <nuesel@gruenbaer.net>
bundles/org.openhab.binding.irobot/README.md
bundles/org.openhab.binding.irobot/src/main/java/org/openhab/binding/irobot/internal/dto/MQTTProtocol.java
bundles/org.openhab.binding.irobot/src/main/java/org/openhab/binding/irobot/internal/handler/RoombaHandler.java

index 9ab3f647b4821af832b902aff01c4d3ba9110600..e68bcd8427783e5f8f900443e2ce50562f422fcd 100644 (file)
@@ -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
 
index fd9103590756f744f51cbf730c525238e567caed..a04dd7754453bd65be9cd51b73ac60839ddc080d 100644 (file)
@@ -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,13 +34,20 @@ public class MQTTProtocol {
         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 {
@@ -49,9 +55,9 @@ public class MQTTProtocol {
             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;
             }
         }
     }
index 78d7f4e1ba75bf827d8e94fed8a7d5d20ef041a4..ae0c02f2ca9b30c4314da935d0b337148e6307fc 100644 (file)
@@ -189,9 +189,38 @@ public class RoombaHandler extends BaseThingHandler {
                         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);