2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.irobot.internal.dto;
15 import java.util.Arrays;
16 import java.util.List;
17 import java.util.stream.Collectors;
19 import com.google.gson.JsonElement;
20 import com.google.gson.annotations.SerializedName;
23 * iRobot MQTT protocol messages
25 * @author Pavel Fedin - Initial contribution
26 * @author Florian Binder - Added CleanRoomsRequest
29 public class MQTTProtocol {
30 public interface Request {
31 public String getTopic();
34 public static class CleanRoomsRequest extends CommandRequest {
36 @SerializedName("pmap_id")
38 public List<Region> regions;
40 public CleanRoomsRequest(String cmd, String mapId, String[] regions) {
44 this.regions = Arrays.stream(regions).map(i -> new Region(i)).collect(Collectors.toList());
47 public static class Region {
48 @SerializedName("region_id")
49 public String regionId;
52 public Region(String id) {
59 public static class CommandRequest implements Request {
60 public String command;
62 public String initiator;
64 public CommandRequest(String cmd) {
66 time = System.currentTimeMillis() / 1000;
67 initiator = "openhab";
71 public String getTopic() {
76 public static class DeltaRequest implements Request {
77 public StateValue state;
79 public DeltaRequest(StateValue state) {
84 public String getTopic() {
89 public static class CleanMissionStatus {
92 public String initiator;
96 public static class BinStatus {
97 public boolean present;
101 public static class SignalStrength {
106 public static class Schedule {
107 public String[] cycle;
111 public static final int NUM_WEEK_DAYS = 7;
113 public Schedule(int cycles_bitmask) {
114 cycle = new String[NUM_WEEK_DAYS];
115 for (int i = 0; i < NUM_WEEK_DAYS; i++) {
116 enableCycle(i, (cycles_bitmask & (1 << i)) != 0);
120 public Schedule(String[] cycle) {
124 public boolean cycleEnabled(int i) {
125 return cycle[i].equals("start");
128 public void enableCycle(int i, boolean enable) {
129 cycle[i] = enable ? "start" : "none";
133 public static class StateValue {
134 // Just some common type, nothing to do here
135 protected StateValue() {
139 public static class OpenOnly extends StateValue {
140 public boolean openOnly;
142 public OpenOnly(boolean openOnly) {
143 this.openOnly = openOnly;
147 public static class BinPause extends StateValue {
148 public boolean binPause;
150 public BinPause(boolean binPause) {
151 this.binPause = binPause;
155 public static class PowerBoost extends StateValue {
156 public boolean carpetBoost;
157 public boolean vacHigh;
159 public PowerBoost(boolean carpetBoost, boolean vacHigh) {
160 this.carpetBoost = carpetBoost;
161 this.vacHigh = vacHigh;
165 public static class CleanPasses extends StateValue {
166 public boolean noAutoPasses;
167 public boolean twoPass;
169 public CleanPasses(boolean noAutoPasses, boolean twoPass) {
170 this.noAutoPasses = noAutoPasses;
171 this.twoPass = twoPass;
175 public static class CleanSchedule extends StateValue {
176 public Schedule cleanSchedule;
178 public CleanSchedule(Schedule schedule) {
179 cleanSchedule = schedule;
183 public static class MapUploadAllowed extends StateValue {
184 public boolean mapUploadAllowed;
186 public MapUploadAllowed(boolean mapUploadAllowed) {
187 this.mapUploadAllowed = mapUploadAllowed;
191 public static class SubModSwVer {
196 public String mobBtl;
201 // "reported" messages never contain the full state, only a part.
202 // Therefore all the fields in this class are nullable
203 public static class GenericState extends StateValue {
204 // "cleanMissionStatus":{"cycle":"clean","phase":"hmUsrDock","expireM":0,"rechrgM":0,"error":0,"notReady":0,"mssnM":1,"sqft":7,"initiator":"rmtApp","nMssn":39}
205 public CleanMissionStatus cleanMissionStatus;
207 public Integer batPct;
208 // "bin":{"present":true,"full":false}
209 public BinStatus bin;
210 // "signal":{"rssi":-55,"snr":33}
211 public SignalStrength signal;
212 // "cleanSchedule":{"cycle":["none","start","start","start","start","none","none"],"h":[9,12,12,12,12,12,9],"m":[0,0,0,0,0,0,0]}
213 public Schedule cleanSchedule;
215 public Boolean openOnly;
217 public Boolean binPause;
218 // "carpetBoost":true
219 public Boolean carpetBoost;
221 public Boolean vacHigh;
222 // "noAutoPasses":true
223 public Boolean noAutoPasses;
225 public Boolean twoPass;
226 // "mapUploadAllowed":true
227 public Boolean mapUploadAllowed;
228 // "softwareVer":"v2.4.6-3"
229 public String softwareVer;
230 // "navSwVer":"01.12.01#1"
231 public String navSwVer;
232 // "wifiSwVer":"20992"
233 public String wifiSwVer;
234 // "mobilityVer":"5806"
235 public String mobilityVer;
236 // "bootloaderVer":"4042"
237 public String bootloaderVer;
239 public String umiVer;
242 // "batteryType":"lith"
243 public String batteryType;
246 // "nav": "lewis-nav+3.2.4-EPMF+build-HEAD-7834b608797+12", "mob":"3.2.4-XX+build-HEAD-7834b608797+12",
247 // "pwr": "0.5.0+build-HEAD-7834b608797+12",
248 // "sft":"1.1.0+Lewis-Builds/Lewis-Certified-Safety/lewis-safety-bbbe81f2c82+21",
249 // "mobBtl": "4.2", "linux":"linux+2.1.6_lock-1+lewis-release-rt419+12",
250 // "con":"2.1.6-tags/release-2.1.6@c6b6585a/build"}
251 public SubModSwVer subModSwVer;
253 // {"command":"start","initiator":"localApp","time":1610283995,"ordered":1,"pmap_id":"AAABBBCCCSDDDEEEFFF","regions":[{"region_id":"6","type":"rid"}]}
254 public JsonElement lastCommand;
257 // Data comes as JSON string: {"state":{"reported":<Actual content here>}}
258 // or: {"state":{"desired":<Some content here>}}
259 // Of the second form i've so far observed only: {"state":{"desired":{"echo":null}}}
260 // I don't know what it is, so let's ignore it.
261 public static class ReportedState {
262 public GenericState reported;
265 public static class StateMessage {
266 public ReportedState state;
270 public static class RobotCapabilities {
273 public Integer multiPass;
274 public Integer carpetBoost;
276 public Integer binFullDetect;
277 public Integer langOta;
281 public Integer scvConf;
285 * JSON of the following contents (addresses are undisclosed):
289 * "hostname":"Roomba-<blid>",
290 * "robotname":"Roomba",
291 * "robotid":"<blid>", --> available on some models only
292 * "ip":"XXX.XXX.XXX.XXX",
293 * "mac":"XX:XX:XX:XX:XX:XX",
314 public static class DiscoveryResponse {
316 public String hostname;
317 public String robotname;
318 public String robotid;
325 public RobotCapabilities cap;
329 public static class BlidResponse {
330 public String robotid;
331 public String hostname;