]> git.basschouten.com Git - openhab-addons.git/blob
edc30fe06580f92201c7087289ab51b744632d86
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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 /**
16  * iRobot MQTT protocol messages
17  *
18  * @author Pavel Fedin - Initial contribution
19  *
20  */
21 public class MQTTProtocol {
22     public interface Request {
23         public String getTopic();
24     }
25
26     public static class CommandRequest implements Request {
27         public String command;
28         public long time;
29         public String initiator;
30
31         public CommandRequest(String cmd) {
32             command = cmd;
33             time = System.currentTimeMillis() / 1000;
34             initiator = "localApp";
35         }
36
37         @Override
38         public String getTopic() {
39             return "cmd";
40         }
41     }
42
43     public static class DeltaRequest implements Request {
44         public StateValue state;
45
46         public DeltaRequest(StateValue state) {
47             this.state = state;
48         }
49
50         @Override
51         public String getTopic() {
52             return "delta";
53         }
54     }
55
56     public static class CleanMissionStatus {
57         public String cycle;
58         public String phase;
59         public int error;
60     }
61
62     public static class BinStatus {
63         public boolean present;
64         public boolean full;
65     }
66
67     public static class SignalStrength {
68         public int rssi;
69         public int snr;
70     }
71
72     public static class Schedule {
73         public String[] cycle;
74         public int[] h;
75         public int[] m;
76
77         public static final int NUM_WEEK_DAYS = 7;
78
79         public Schedule(int cycles_bitmask) {
80             cycle = new String[NUM_WEEK_DAYS];
81             for (int i = 0; i < NUM_WEEK_DAYS; i++) {
82                 enableCycle(i, (cycles_bitmask & (1 << i)) != 0);
83             }
84         }
85
86         public Schedule(String[] cycle) {
87             this.cycle = cycle;
88         }
89
90         public boolean cycleEnabled(int i) {
91             return cycle[i].equals("start");
92         }
93
94         public void enableCycle(int i, boolean enable) {
95             cycle[i] = enable ? "start" : "none";
96         }
97     }
98
99     public static class StateValue {
100         // Just some common type, nothing to do here
101         protected StateValue() {
102         }
103     }
104
105     public static class OpenOnly extends StateValue {
106         public boolean openOnly;
107
108         public OpenOnly(boolean openOnly) {
109             this.openOnly = openOnly;
110         }
111     }
112
113     public static class BinPause extends StateValue {
114         public boolean binPause;
115
116         public BinPause(boolean binPause) {
117             this.binPause = binPause;
118         }
119     }
120
121     public static class PowerBoost extends StateValue {
122         public boolean carpetBoost;
123         public boolean vacHigh;
124
125         public PowerBoost(boolean carpetBoost, boolean vacHigh) {
126             this.carpetBoost = carpetBoost;
127             this.vacHigh = vacHigh;
128         }
129     }
130
131     public static class CleanPasses extends StateValue {
132         public boolean noAutoPasses;
133         public boolean twoPass;
134
135         public CleanPasses(boolean noAutoPasses, boolean twoPass) {
136             this.noAutoPasses = noAutoPasses;
137             this.twoPass = twoPass;
138         }
139     }
140
141     public static class CleanSchedule extends StateValue {
142         public Schedule cleanSchedule;
143
144         public CleanSchedule(Schedule schedule) {
145             cleanSchedule = schedule;
146         }
147     }
148
149     // "reported" messages never contain the full state, only a part.
150     // Therefore all the fields in this class are nullable
151     public static class GenericState extends StateValue {
152         // "cleanMissionStatus":{"cycle":"clean","phase":"hmUsrDock","expireM":0,"rechrgM":0,"error":0,"notReady":0,"mssnM":1,"sqft":7,"initiator":"rmtApp","nMssn":39}
153         public CleanMissionStatus cleanMissionStatus;
154         // "batPct":100
155         public Integer batPct;
156         // "bin":{"present":true,"full":false}
157         public BinStatus bin;
158         // "signal":{"rssi":-55,"snr":33}
159         public SignalStrength signal;
160         // "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]}
161         public Schedule cleanSchedule;
162         // "openOnly":false
163         public Boolean openOnly;
164         // "binPause":true
165         public Boolean binPause;
166         // "carpetBoost":true
167         public Boolean carpetBoost;
168         // "vacHigh":false
169         public Boolean vacHigh;
170         // "noAutoPasses":true
171         public Boolean noAutoPasses;
172         // "twoPass":true
173         public Boolean twoPass;
174         // "softwareVer":"v2.4.6-3"
175         public String softwareVer;
176         // "navSwVer":"01.12.01#1"
177         public String navSwVer;
178         // "wifiSwVer":"20992"
179         public String wifiSwVer;
180         // "mobilityVer":"5806"
181         public String mobilityVer;
182         // "bootloaderVer":"4042"
183         public String bootloaderVer;
184         // "umiVer":"6",
185         public String umiVer;
186     }
187
188     // Data comes as JSON string: {"state":{"reported":<Actual content here>}}
189     // or: {"state":{"desired":<Some content here>}}
190     // Of the second form i've so far observed only: {"state":{"desired":{"echo":null}}}
191     // I don't know what it is, so let's ignore it.
192     public static class ReportedState {
193         public GenericState reported;
194     }
195
196     public static class StateMessage {
197         public ReportedState state;
198     }
199 };