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;
16 * iRobot MQTT protocol messages
18 * @author Pavel Fedin - Initial contribution
21 public class MQTTProtocol {
22 public interface Request {
23 public String getTopic();
26 public static class CommandRequest implements Request {
27 public String command;
29 public String initiator;
31 public CommandRequest(String cmd) {
33 time = System.currentTimeMillis() / 1000;
34 initiator = "localApp";
38 public String getTopic() {
43 public static class DeltaRequest implements Request {
44 public StateValue state;
46 public DeltaRequest(StateValue state) {
51 public String getTopic() {
56 public static class CleanMissionStatus {
62 public static class BinStatus {
63 public boolean present;
67 public static class SignalStrength {
72 public static class Schedule {
73 public String[] cycle;
77 public static final int NUM_WEEK_DAYS = 7;
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);
86 public Schedule(String[] cycle) {
90 public boolean cycleEnabled(int i) {
91 return cycle[i].equals("start");
94 public void enableCycle(int i, boolean enable) {
95 cycle[i] = enable ? "start" : "none";
99 public static class StateValue {
100 // Just some common type, nothing to do here
101 protected StateValue() {
105 public static class OpenOnly extends StateValue {
106 public boolean openOnly;
108 public OpenOnly(boolean openOnly) {
109 this.openOnly = openOnly;
113 public static class BinPause extends StateValue {
114 public boolean binPause;
116 public BinPause(boolean binPause) {
117 this.binPause = binPause;
121 public static class PowerBoost extends StateValue {
122 public boolean carpetBoost;
123 public boolean vacHigh;
125 public PowerBoost(boolean carpetBoost, boolean vacHigh) {
126 this.carpetBoost = carpetBoost;
127 this.vacHigh = vacHigh;
131 public static class CleanPasses extends StateValue {
132 public boolean noAutoPasses;
133 public boolean twoPass;
135 public CleanPasses(boolean noAutoPasses, boolean twoPass) {
136 this.noAutoPasses = noAutoPasses;
137 this.twoPass = twoPass;
141 public static class CleanSchedule extends StateValue {
142 public Schedule cleanSchedule;
144 public CleanSchedule(Schedule schedule) {
145 cleanSchedule = schedule;
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;
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;
163 public Boolean openOnly;
165 public Boolean binPause;
166 // "carpetBoost":true
167 public Boolean carpetBoost;
169 public Boolean vacHigh;
170 // "noAutoPasses":true
171 public Boolean noAutoPasses;
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;
185 public String umiVer;
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;
196 public static class StateMessage {
197 public ReportedState state;