]> git.basschouten.com Git - openhab-addons.git/blob
db71ca99cf89d151fdb68fdce00c41066e4dd9e8
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.irobot.internal.dto;
14
15 import java.util.Arrays;
16 import java.util.List;
17 import java.util.stream.Collectors;
18
19 import com.google.gson.JsonElement;
20
21 /**
22  * iRobot MQTT protocol messages
23  *
24  * @author Pavel Fedin - Initial contribution
25  * @author Florian Binder - Added CleanRoomsRequest
26  *
27  */
28 public class MQTTProtocol {
29     public interface Request {
30         public String getTopic();
31     }
32
33     public static class CleanRoomsRequest extends CommandRequest {
34         public int ordered;
35         public String pmap_id;
36         public List<Region> regions;
37
38         public CleanRoomsRequest(String cmd, String mapId, String[] regions) {
39             super(cmd);
40             ordered = 1;
41             pmap_id = mapId;
42             this.regions = Arrays.stream(regions).map(i -> new Region(i)).collect(Collectors.toList());
43         }
44
45         public static class Region {
46             public String region_id;
47             public String type;
48
49             public Region(String id) {
50                 this.region_id = id;
51                 this.type = "rid";
52             }
53         }
54     }
55
56     public static class CommandRequest implements Request {
57         public String command;
58         public long time;
59         public String initiator;
60
61         public CommandRequest(String cmd) {
62             command = cmd;
63             time = System.currentTimeMillis() / 1000;
64             initiator = "openhab";
65         }
66
67         @Override
68         public String getTopic() {
69             return "cmd";
70         }
71     }
72
73     public static class DeltaRequest implements Request {
74         public StateValue state;
75
76         public DeltaRequest(StateValue state) {
77             this.state = state;
78         }
79
80         @Override
81         public String getTopic() {
82             return "delta";
83         }
84     }
85
86     public static class CleanMissionStatus {
87         public String cycle;
88         public String phase;
89         public String initiator;
90         public int error;
91     }
92
93     public static class BinStatus {
94         public boolean present;
95         public boolean full;
96     }
97
98     public static class SignalStrength {
99         public int rssi;
100         public int snr;
101     }
102
103     public static class Schedule {
104         public String[] cycle;
105         public int[] h;
106         public int[] m;
107
108         public static final int NUM_WEEK_DAYS = 7;
109
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);
114             }
115         }
116
117         public Schedule(String[] cycle) {
118             this.cycle = cycle;
119         }
120
121         public boolean cycleEnabled(int i) {
122             return cycle[i].equals("start");
123         }
124
125         public void enableCycle(int i, boolean enable) {
126             cycle[i] = enable ? "start" : "none";
127         }
128     }
129
130     public static class StateValue {
131         // Just some common type, nothing to do here
132         protected StateValue() {
133         }
134     }
135
136     public static class OpenOnly extends StateValue {
137         public boolean openOnly;
138
139         public OpenOnly(boolean openOnly) {
140             this.openOnly = openOnly;
141         }
142     }
143
144     public static class BinPause extends StateValue {
145         public boolean binPause;
146
147         public BinPause(boolean binPause) {
148             this.binPause = binPause;
149         }
150     }
151
152     public static class PowerBoost extends StateValue {
153         public boolean carpetBoost;
154         public boolean vacHigh;
155
156         public PowerBoost(boolean carpetBoost, boolean vacHigh) {
157             this.carpetBoost = carpetBoost;
158             this.vacHigh = vacHigh;
159         }
160     }
161
162     public static class CleanPasses extends StateValue {
163         public boolean noAutoPasses;
164         public boolean twoPass;
165
166         public CleanPasses(boolean noAutoPasses, boolean twoPass) {
167             this.noAutoPasses = noAutoPasses;
168             this.twoPass = twoPass;
169         }
170     }
171
172     public static class CleanSchedule extends StateValue {
173         public Schedule cleanSchedule;
174
175         public CleanSchedule(Schedule schedule) {
176             cleanSchedule = schedule;
177         }
178     }
179
180     public static class MapUploadAllowed extends StateValue {
181         public boolean mapUploadAllowed;
182
183         public MapUploadAllowed(boolean mapUploadAllowed) {
184             this.mapUploadAllowed = mapUploadAllowed;
185         }
186     }
187
188     public static class SubModSwVer {
189         public String nav;
190         public String mob;
191         public String pwr;
192         public String sft;
193         public String mobBtl;
194         public String linux;
195         public String con;
196     }
197
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;
203         // "batPct":100
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;
211         // "openOnly":false
212         public Boolean openOnly;
213         // "binPause":true
214         public Boolean binPause;
215         // "carpetBoost":true
216         public Boolean carpetBoost;
217         // "vacHigh":false
218         public Boolean vacHigh;
219         // "noAutoPasses":true
220         public Boolean noAutoPasses;
221         // "twoPass":true
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;
235         // "umiVer":"6",
236         public String umiVer;
237         // "sku":"R981040"
238         public String sku;
239         // "batteryType":"lith"
240         public String batteryType;
241         // Used by i7:
242         // "subModSwVer":{
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;
249         // "lastCommand":
250         // {"command":"start","initiator":"localApp","time":1610283995,"ordered":1,"pmap_id":"AAABBBCCCSDDDEEEFFF","regions":[{"region_id":"6","type":"rid"}]}
251         public JsonElement lastCommand;
252     }
253
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;
260     }
261
262     public static class StateMessage {
263         public ReportedState state;
264     }
265 };