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;
22 * iRobot MQTT protocol messages
24 * @author Pavel Fedin - Initial contribution
25 * @author Florian Binder - Added CleanRoomsRequest
28 public class MQTTProtocol {
29 public interface Request {
30 public String getTopic();
33 public static class CleanRoomsRequest extends CommandRequest {
35 public String pmap_id;
36 public List<Region> regions;
38 public CleanRoomsRequest(String cmd, String mapId, String[] regions) {
42 this.regions = Arrays.stream(regions).map(i -> new Region(i)).collect(Collectors.toList());
45 public static class Region {
46 public String region_id;
49 public Region(String id) {
56 public static class CommandRequest implements Request {
57 public String command;
59 public String initiator;
61 public CommandRequest(String cmd) {
63 time = System.currentTimeMillis() / 1000;
64 initiator = "openhab";
68 public String getTopic() {
73 public static class DeltaRequest implements Request {
74 public StateValue state;
76 public DeltaRequest(StateValue state) {
81 public String getTopic() {
86 public static class CleanMissionStatus {
89 public String initiator;
93 public static class BinStatus {
94 public boolean present;
98 public static class SignalStrength {
103 public static class Schedule {
104 public String[] cycle;
108 public static final int NUM_WEEK_DAYS = 7;
110 public Schedule(int cycles_bitmask) {
111 cycle = new String[NUM_WEEK_DAYS];
112 for (int i = 0; i < NUM_WEEK_DAYS; i++) {
113 enableCycle(i, (cycles_bitmask & (1 << i)) != 0);
117 public Schedule(String[] cycle) {
121 public boolean cycleEnabled(int i) {
122 return cycle[i].equals("start");
125 public void enableCycle(int i, boolean enable) {
126 cycle[i] = enable ? "start" : "none";
130 public static class StateValue {
131 // Just some common type, nothing to do here
132 protected StateValue() {
136 public static class OpenOnly extends StateValue {
137 public boolean openOnly;
139 public OpenOnly(boolean openOnly) {
140 this.openOnly = openOnly;
144 public static class BinPause extends StateValue {
145 public boolean binPause;
147 public BinPause(boolean binPause) {
148 this.binPause = binPause;
152 public static class PowerBoost extends StateValue {
153 public boolean carpetBoost;
154 public boolean vacHigh;
156 public PowerBoost(boolean carpetBoost, boolean vacHigh) {
157 this.carpetBoost = carpetBoost;
158 this.vacHigh = vacHigh;
162 public static class CleanPasses extends StateValue {
163 public boolean noAutoPasses;
164 public boolean twoPass;
166 public CleanPasses(boolean noAutoPasses, boolean twoPass) {
167 this.noAutoPasses = noAutoPasses;
168 this.twoPass = twoPass;
172 public static class CleanSchedule extends StateValue {
173 public Schedule cleanSchedule;
175 public CleanSchedule(Schedule schedule) {
176 cleanSchedule = schedule;
180 public static class MapUploadAllowed extends StateValue {
181 public boolean mapUploadAllowed;
183 public MapUploadAllowed(boolean mapUploadAllowed) {
184 this.mapUploadAllowed = mapUploadAllowed;
188 public static class SubModSwVer {
193 public String mobBtl;
198 // "reported" messages never contain the full state, only a part.
199 // Therefore all the fields in this class are nullable
200 public static class GenericState extends StateValue {
201 // "cleanMissionStatus":{"cycle":"clean","phase":"hmUsrDock","expireM":0,"rechrgM":0,"error":0,"notReady":0,"mssnM":1,"sqft":7,"initiator":"rmtApp","nMssn":39}
202 public CleanMissionStatus cleanMissionStatus;
204 public Integer batPct;
205 // "bin":{"present":true,"full":false}
206 public BinStatus bin;
207 // "signal":{"rssi":-55,"snr":33}
208 public SignalStrength signal;
209 // "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]}
210 public Schedule cleanSchedule;
212 public Boolean openOnly;
214 public Boolean binPause;
215 // "carpetBoost":true
216 public Boolean carpetBoost;
218 public Boolean vacHigh;
219 // "noAutoPasses":true
220 public Boolean noAutoPasses;
222 public Boolean twoPass;
223 // "mapUploadAllowed":true
224 public Boolean mapUploadAllowed;
225 // "softwareVer":"v2.4.6-3"
226 public String softwareVer;
227 // "navSwVer":"01.12.01#1"
228 public String navSwVer;
229 // "wifiSwVer":"20992"
230 public String wifiSwVer;
231 // "mobilityVer":"5806"
232 public String mobilityVer;
233 // "bootloaderVer":"4042"
234 public String bootloaderVer;
236 public String umiVer;
239 // "batteryType":"lith"
240 public String batteryType;
243 // "nav": "lewis-nav+3.2.4-EPMF+build-HEAD-7834b608797+12", "mob":"3.2.4-XX+build-HEAD-7834b608797+12",
244 // "pwr": "0.5.0+build-HEAD-7834b608797+12",
245 // "sft":"1.1.0+Lewis-Builds/Lewis-Certified-Safety/lewis-safety-bbbe81f2c82+21",
246 // "mobBtl": "4.2", "linux":"linux+2.1.6_lock-1+lewis-release-rt419+12",
247 // "con":"2.1.6-tags/release-2.1.6@c6b6585a/build"}
248 public SubModSwVer subModSwVer;
250 // {"command":"start","initiator":"localApp","time":1610283995,"ordered":1,"pmap_id":"AAABBBCCCSDDDEEEFFF","regions":[{"region_id":"6","type":"rid"}]}
251 public JsonElement lastCommand;
254 // Data comes as JSON string: {"state":{"reported":<Actual content here>}}
255 // or: {"state":{"desired":<Some content here>}}
256 // Of the second form i've so far observed only: {"state":{"desired":{"echo":null}}}
257 // I don't know what it is, so let's ignore it.
258 public static class ReportedState {
259 public GenericState reported;
262 public static class StateMessage {
263 public ReportedState state;