]> git.basschouten.com Git - openhab-addons.git/blob
ffb2e3566772c191644268ba8944a48d5c9c277a
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.shelly.internal.api1;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.shelly.internal.api1.Shelly1ApiJsonDTO.ShellyStatusSensor.ShellyMotionSettings;
20 import org.openhab.core.thing.CommonTriggerEvents;
21
22 import com.google.gson.annotations.SerializedName;
23
24 /**
25  * The {@link Shelly1ApiJsonDTO} is used for the JSon/GSon mapping
26  *
27  * @author Markus Michels - Initial contribution
28  */
29 public class Shelly1ApiJsonDTO {
30     public static final String SHELLY_NULL_URL = "null";
31     public static final String SHELLY_URL_DEVINFO = "/shelly";
32     public static final String SHELLY_URL_STATUS = "/status";
33     public static final String SHELLY_URL_SETTINGS = "/settings";
34     public static final String SHELLY_URL_SETTINGS_AP = "/settings/ap";
35     public static final String SHELLY_URL_SETTINGS_STA = "/settings/sta";
36     public static final String SHELLY_URL_SETTINGS_LOGIN = "/settings/sta";
37     public static final String SHELLY_URL_SETTINGS_CLOUD = "/settings/cloud";
38     public static final String SHELLY_URL_LIST_IR = "/ir/list";
39     public static final String SHELLY_URL_SEND_IR = "/ir/emit";
40     public static final String SHELLY_URL_RESTART = "/reboot";
41
42     public static final String SHELLY_URL_SETTINGS_RELAY = "/settings/relay";
43     public static final String SHELLY_URL_STATUS_RELEAY = "/status/relay";
44     public static final String SHELLY_URL_CONTROL_RELEAY = "/relay";
45
46     public static final String SHELLY_URL_SETTINGS_EMETER = "/settings/emeter";
47     public static final String SHELLY_URL_STATUS_EMETER = "/emeter";
48     public static final String SHELLY_URL_DATA_EMETER = "/emeter/{0}/em_data.csv";
49
50     public static final String SHELLY_URL_CONTROL_ROLLER = "/roller";
51     public static final String SHELLY_URL_SETTINGS_ROLLER = "/settings/roller";
52
53     public static final String SHELLY_URL_SETTINGS_LIGHT = "/settings/light";
54     public static final String SHELLY_URL_STATUS_LIGHT = "/light";
55     public static final String SHELLY_URL_CONTROL_LIGHT = "/light";
56
57     public static final String SHELLY_URL_SETTINGS_DIMMER = "/settings/light";
58
59     // Wakeup reasons
60     public static final String SHELLY_WAKEUPT_SENSOR = "SENSOR"; // new sensordata
61     public static final String SHELLY_WAKEUPT_PERIODIC = "PERIODIC"; // periodic wakeup
62     public static final String SHELLY_WAKEUPT_BUTTON = "BUTTON"; // button pressed
63     public static final String SHELLY_WAKEUPT_POWERON = "POWERON"; // device powered up
64     public static final String SHELLY_WAKEUPT_EXT_POWER = "EXT_POWER"; // charger connected
65     public static final String SHELLY_WAKEUPT_UNKNOWN = "UNKNOWN"; // other event
66
67     //
68     // Action URLs according to the device type
69     //
70     public static final String SHELLY_EVENTURL_SUFFIX = "_url";
71
72     // Relay
73     public static final String SHELLY_EVENT_BTN_ON = "btn_on";
74     public static final String SHELLY_EVENT_BTN_OFF = "btn_off";
75     public static final String SHELLY_EVENT_OUT_ON = "out_on";
76     public static final String SHELLY_EVENT_OUT_OFF = "out_off";
77     public static final String SHELLY_EVENT_SHORTPUSH = "shortpush";
78     public static final String SHELLY_EVENT_LONGPUSH = "longpush";
79     // Button
80     public static final String SHELLY_EVENT_DOUBLE_SHORTPUSH = "double_shortpush";
81     public static final String SHELLY_EVENT_TRIPLE_SHORTPUSH = "triple_shortpush";
82     public static final String SHELLY_EVENT_SHORT_LONGTPUSH = "shortpush_longpush";
83     public static final String SHELLY_EVENT_LONG_SHORTPUSH = "longpush_shortpush";
84
85     // Dimmer
86     public static final String SHELLY_EVENT_BTN1_ON = "btn1_on";
87     public static final String SHELLY_EVENT_BTN1_OFF = "btn1_off";
88     public static final String SHELLY_EVENT_BTN2_ON = "btn2_on";
89     public static final String SHELLY_EVENT_BTN2_OFF = "btn2_off";
90     public static final String SHELLY_EVENT_SHORTPUSH1 = "btn1_shortpush";
91     public static final String SHELLY_EVENT_LONGPUSH1 = "btn1_longpush";
92     public static final String SHELLY_EVENT_SHORTPUSH2 = "btn2_shortpush";
93     public static final String SHELLY_EVENT_LONGPUSH2 = "btn2_longpush";
94
95     // Roller
96     public static final String SHELLY_EVENT_ROLLER_OPEN = "roller_open";
97     public static final String SHELLY_EVENT_ROLLER_CLOSE = "roller_close";
98     public static final String SHELLY_EVENT_ROLLER_STOP = "roller_stop";
99     public static final String SHELLY_EVENT_ROLLER_CALIB = "roller_calibrating";
100
101     // Roller states
102     public static final String SHELLY_RSTATE_OPEN = "open";
103     public static final String SHELLY_RSTATE_STOP = "stop";
104     public static final String SHELLY_RSTATE_CLOSE = "close";
105
106     // Sensors
107     public static final String SHELLY_EVENT_SENSORREPORT = "report";
108     public static final String SHELLY_EVENT_DARK = "dark";
109     public static final String SHELLY_EVENT_TWILIGHT = "twilight";
110     public static final String SHELLY_EVENT_BRIGHT = "bright";
111     public static final String SHELLY_EVENT_FLOOD_DETECTED = "flood_detected";
112     public static final String SHELLY_EVENT_FLOOD_GONE = "flood_gone";
113     public static final String SHELLY_EVENT_VIBRATION = "vibration"; // DW 1.6.5+
114     public static final String SHELLY_EVENT_OPEN = "open"; // DW 1.6.5+
115     public static final String SHELLY_EVENT_CLOSE = "close"; // DW 1.6.5+
116     public static final String SHELLY_EVENT_TEMP_OVER = "temp_over"; // FW 1.7
117     public static final String SHELLY_EVENT_TEMP_UNDER = "temp_under"; // FW 1.7
118
119     // Gas
120     public static final String SHELLY_EVENT_ALARM_MILD = "alarm_mild"; // DW 1.7+
121     public static final String SHELLY_EVENT_ALARM_HEAVY = "alarm_heavy"; // DW 1.7+
122     public static final String SHELLY_EVENT_ALARM_OFF = "alarm_off"; // DW 1.7+
123
124     //
125     // API values
126     //
127     public static final double SHELLY_API_INVTEMP = 999.0;
128
129     public static final String SHELLY_BTNT_MOMENTARY = "momentary";
130     public static final String SHELLY_BTNT_MOM_ON_RELEASE = "momentary_on_release";
131     public static final String SHELLY_BTNT_ONE_BUTTON = "one_button";
132     public static final String SHELLY_BTNT_TWO_BUTTON = "dual_button";
133     public static final String SHELLY_BTNT_TOGGLE = "toggle";
134     public static final String SHELLY_BTNT_EDGE = "edge";
135     public static final String SHELLY_BTNT_DETACHED = "detached";
136
137     public static final String SHELLY_STATE_LAST = "last";
138     public static final String SHELLY_STATE_STOP = "stop";
139
140     public static final String SHELLY_INP_MODE_OPENCLOSE = "openclose";
141     public static final String SHELLY_INP_MODE_ONEBUTTON = "onebutton";
142
143     public static final String SHELLY_OBSTMODE_DISABLED = "disabled";
144     public static final String SHELLY_SAFETYM_WHILEOPENING = "while_opening";
145
146     public static final String SHELLY_ALWD_TRIGGER_NONE = "none";
147     public static final String SHELLY_ALWD_ROLLER_TURN_OPEN = "open";
148     public static final String SHELLY_ALWD_ROLLER_TURN_CLOSE = "close";
149     public static final String SHELLY_ALWD_ROLLER_TURN_STOP = "stop";
150
151     // API Error Codes
152     public static final String SHELLY_APIERR_UNAUTHORIZED = "Unauthorized";
153     public static final String SHELLY_APIERR_TIMEOUT = "Timeout";
154     public static final String SHELLY_APIERR_NOT_CALIBRATED = "Not calibrated!";
155
156     // API device types / properties
157     public static final String SHELLY_CLASS_RELAY = "relay"; // Relay: relay mode
158     public static final String SHELLY_CLASS_ROLLER = "roller"; // Relay: roller mode
159     public static final String SHELLY_CLASS_LIGHT = "light"; // Bulb: color mode
160     public static final String SHELLY_CLASS_EMETER = "emeter"; // EM/EM3: emeter
161
162     public static final String SHELLY_API_ON = "on";
163     public static final String SHELLY_API_OFF = "off";
164     public static final String SHELLY_API_TRUE = "true";
165     public static final String SHELLY_API_FALSE = "false";
166
167     public static final String SHELLY_API_MODE = "mode";
168     public static final String SHELLY_MODE_RELAY = "relay"; // Relay: relay mode
169     public static final String SHELLY_MODE_ROLLER = "roller"; // Relay: roller mode
170     public static final String SHELLY_MODE_COLOR = "color"; // Bulb/RGBW2: color mode
171     public static final String SHELLY_MODE_WHITE = "white"; // Bulb/RGBW2: white mode
172
173     public static final String SHELLY_LED_STATUS_DISABLE = "led_status_disable";
174     public static final String SHELLY_LED_POWER_DISABLE = "led_power_disable";
175
176     public static final String SHELLY_API_STOPR_NORMAL = "normal";
177     public static final String SHELLY_API_STOPR_SAFETYSW = "safety_switch";
178     public static final String SHELLY_API_STOPR_OBSTACLE = "obstacle";
179     public static final String SHELLY_API_STOPR_OVERPOWER = "overpower";
180
181     public static final String SHELLY_TIMER_AUTOON = "auto_on";
182     public static final String SHELLY_TIMER_AUTOOFF = "auto_off";
183     public static final String SHELLY_TIMER_ACTIVE = "has_timer";
184
185     public static final String SHELLY_LIGHT_TURN = "turn";
186     public static final String SHELLY_LIGHT_DEFSTATE = "def_state";
187     public static final String SHELLY_LIGHTTIMER = "timer";
188
189     public static final String SHELLY_COLOR_RED = "red";
190     public static final String SHELLY_COLOR_BLUE = "blue";
191     public static final String SHELLY_COLOR_GREEN = "green";
192     public static final String SHELLY_COLOR_YELLOW = "yellow";
193     public static final String SHELLY_COLOR_WHITE = "white";
194     public static final String SHELLY_COLOR_GAIN = "gain";
195     public static final String SHELLY_COLOR_BRIGHTNESS = "brightness";
196     public static final String SHELLY_COLOR_TEMP = "temp";
197     public static final String SHELLY_COLOR_EFFECT = "effect";
198
199     public static final int SHELLY_MIN_ROLLER_POS = 0;
200     public static final int SHELLY_MAX_ROLLER_POS = 100;
201     public static final int SHELLY_MIN_BRIGHTNESS = 0;
202     public static final int SHELLY_MAX_BRIGHTNESS = 100;
203     public static final int SHELLY_MIN_GAIN = 0;
204     public static final int SHELLY_MAX_GAIN = 100;
205     public static final int SHELLY_MIN_COLOR = 0;
206     public static final int SHELLY_MAX_COLOR = 255;
207     public static final int SHELLY_DIM_STEPSIZE = 10;
208
209     // color temperature: 3000 = warm, 4750 = white, 6565 = cold; gain: 0..100
210     public static final int MIN_COLOR_TEMP_BULB = 3000;
211     public static final int MAX_COLOR_TEMP_BULB = 6500;
212     public static final int MIN_COLOR_TEMP_DUO = 2700;
213     public static final int MAX_COLOR_TEMP_DUO = 6500;
214     public static final int COLOR_TEMP_RANGE_BULB = MAX_COLOR_TEMP_DUO - MIN_COLOR_TEMP_DUO;
215     public static final int COLOR_TEMP_RANGE_DUO = MAX_COLOR_TEMP_DUO - MIN_COLOR_TEMP_DUO;
216     public static final double MIN_BRIGHTNESS = 0.0;
217     public static final double MAX_BRIGHTNESS = 100.0;
218     public static final double SATURATION_FACTOR = 2.55;
219     public static final double GAIN_FACTOR = SHELLY_MAX_GAIN / 100;
220     public static final double BRIGHTNESS_FACTOR = SHELLY_MAX_BRIGHTNESS / 100;
221
222     // Door/Window
223     public static final String SHELLY_API_ILLUM_DARK = "dark";
224     public static final String SHELLY_API_ILLUM_TWILIGHT = "twilight";
225     public static final String SHELLY_API_ILLUM_BRIGHT = "bright";
226     public static final String SHELLY_API_DWSTATE_OPEN = "open";
227     public static final String SHELLY_API_DWSTATE_CLOSE = "close";
228
229     // Shelly Sense
230     public static final String SHELLY_IR_CODET_STORED = "stored";
231     public static final String SHELLY_IR_CODET_PRONTO = "pronto";
232     public static final String SHELLY_IR_CODET_PRONTO_HEX = "pronto_hex";
233
234     // Bulb/Duo/RGBW2
235     public static final int SHELLY_MIN_EFFECT = 0;
236     public static final int SHELLY_MAX_EFFECT = 6;
237
238     // Button
239     public static final String SHELLY_BTNEVENT_1SHORTPUSH = "S";
240     public static final String SHELLY_BTNEVENT_2SHORTPUSH = "SS";
241     public static final String SHELLY_BTNEVENT_3SHORTPUSH = "SSS";
242     public static final String SHELLY_BTNEVENT_LONGPUSH = "L";
243     public static final String SHELLY_BTNEVENT_SHORTLONGPUSH = "SL";
244     public static final String SHELLY_BTNEVENT_LONGSHORTPUSH = "LS";
245
246     public static final String SHELLY_TEMP_CELSIUS = "C";
247     public static final String SHELLY_TEMP_FAHRENHEIT = "F";
248
249     // Motion
250     public static final int SHELLY_MOTION_SLEEPTIME_OFFSET = 3; // we need to substract and offset
251
252     // TRV
253     public static final int SHELLY_TRV_MIN_TEMP = 5; // < 5: means: lowest (valve fully closed)
254     public static final int SHELLY_TRV_MAX_TEMP = 30; // > 30: means: highest (valve fully open)
255
256     public static final String SHELLY_TRV_MODE_MANUAL = "manual";
257     public static final String SHELLY_TRV_MODE_AUTO = "automatic";
258
259     // CoIoT Multicast setting
260     public static final String SHELLY_COIOT_MCAST = "mcast";
261
262     public static class ShellySettingsDevice {
263         public String type;
264         public String mode; // Gen 1
265         public String id; // Gen2: service name
266         public String name; // Gen2: configured device name
267         public String profile; // Gen 2
268         public String mac;
269         public String hostname;
270         public String fw;
271         public Boolean auth;
272         public Integer gen;
273         public String coiot;
274         public Integer longid;
275
276         @SerializedName("num_outputs")
277         public Integer numOutputs;
278         @SerializedName("num_meters")
279         public Integer numMeters;
280         @SerializedName("num_emeters")
281         public Integer numEMeters;
282         @SerializedName("num_rollers")
283         public Integer numRollers;
284     }
285
286     public static class ShellySettingsWiFiAp {
287         public Boolean enabled;
288         public String ssid;
289         public String key;
290         public Boolean rangeExtender; // Gen2 only
291     }
292
293     public static class ShellySettingsWiFiNetwork {
294         public Boolean enabled;
295         public String ssid;
296         public Integer rssi;
297
298         @SerializedName("ipv4_method")
299         public String ipv4Method;
300         public String ip;
301         public String gw;
302         public String mask;
303         public String dns;
304     }
305
306     public static class ShellySettingsMqtt {
307         public Boolean enable;
308         public String server;
309         public String user;
310         @SerializedName("reconnect_timeout_max")
311         public Double reconnectTimeoutMax;
312         @SerializedName("reconnect_timeout_min")
313         public Double reconnectTimeoutMin;
314         @SerializedName("clean_session")
315         public Boolean cleanSession;
316         @SerializedName("keep_alive")
317         public Integer keepAlive;
318         @SerializedName("will_topic")
319         public String willTopic;
320         @SerializedName("will_message")
321         public String willMessage;
322         @SerializedName("max_qos")
323         public Integer maxQOS;
324         public Boolean retain;
325         @SerializedName("update_period")
326         public Integer updatePeriod;
327     }
328
329     public static class ShellySettingsCoiot { // FW 1.6+
330         @SerializedName("update_period")
331         public Integer updatePeriod;
332         public Boolean enabled; // Motion 1.0.7: Coap can be disabled
333         public String peer; // if set the device uses singlecast CoAP, mcast=set back to Multicast
334     }
335
336     public static class ShellyStatusMqtt {
337         public Boolean connected;
338     }
339
340     public static class ShellySettingsSntp {
341         public String server;
342         public Boolean enabled;
343     }
344
345     public static class ShellySettingsLogin {
346         public Boolean enabled;
347         public Boolean unprotected;
348         public String username;
349         public String password;
350     }
351
352     public static class ShellySettingsBuildInfo {
353         @SerializedName("build_id")
354         public String buildId;
355         @SerializedName("build_timestamp")
356         public String buildTimestamp;
357         @SerializedName("build_version")
358         public String buildVersion;
359     }
360
361     public static class ShellyStatusCloud {
362         public Boolean enabled;
363         public Boolean connected;
364     }
365
366     public static class ShellySettingsHwInfo {
367         @SerializedName("hw_revision")
368         public String hwRevision;
369         @SerializedName("batch_id")
370         public Integer batchId;
371     }
372
373     public static class ShellySettingsScheduleRules {
374     }
375
376     public static class ShellySettingsRelay {
377         public String name;
378         @SerializedName("default_state")
379         public String defaultState; // Accepted values: off, on, last, switch
380         @SerializedName("btn_type")
381         public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
382         @SerializedName("btn1_type") // Shelly 1L
383         public String btnType1;
384         @SerializedName("btn2_type") // Shelly 1L
385         public String btnType2;
386         @SerializedName("has_timer")
387         public Boolean hasTimer; // Whether a timer is currently armed for this channel
388         @SerializedName("auto_on")
389         public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
390         @SerializedName("auto_off")
391         public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
392         @SerializedName("btn_on_url")
393         public String btnOnUrl; // input is activated
394         @SerializedName("btnOffUrl")
395         public String btnOffUrl; // input is deactivated
396         @SerializedName("out_on_url")
397         public String outOnUrl; // output is activated
398         @SerializedName("out_off_url")
399         public String outOffUrl; // output is deactivated
400         @SerializedName("roller_open_url")
401         public String rollerOpenUrl; // to access when roller reaches open position
402         @SerializedName("roller_close_url")
403         public String rollerCloseUrl; // to access when roller reaches close position
404         @SerializedName("roller_stop_url")
405         public String rollerStopUrl; // to access when roller stopped
406         @SerializedName("longpush_url")
407         public String pushLongUrl; // to access when roller stopped
408         @SerializedName("shortpush_url")
409         public String pushShortUrl; // to access when roller stopped
410
411         // Status information
412         public Integer id;
413         public Boolean ison;
414         public Boolean overpower;
415         @SerializedName("is_valid")
416         public Boolean isValid;
417     }
418
419     public static class ShellySettingsDimmer {
420         public String name; // unique name of the device
421         public Boolean ison; // true: output is ON
422         @SerializedName("default_state")
423         public String defaultState; // Accepted values: off, on, last, switch
424         @SerializedName("auto_on")
425         public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
426         @SerializedName("auto_off")
427         public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
428         @SerializedName("btn1_on_url")
429         public String btn1OnUrl; // URL to access when SW input is activated
430         @SerializedName("btn1_off_url")
431         public String btn1OffUrl; // URL to access when SW input is deactivated
432         @SerializedName("btn2_on_url")
433         public String btn2OnUrl; // URL to access when SW input is activated
434         @SerializedName("btn2_off_url")
435         public String btn2OoffUrl; // URL to access when SW input is deactivated
436         @SerializedName("out_on_url")
437         public String outOnUrl; // URL to access when output is activated
438         @SerializedName("out_off_url")
439         public String outOffUrl; // URL to access when output is deactivated
440         @SerializedName("longpush_url")
441         public String pushLongUrl; // long push button event
442         @SerializedName("shortpush_url")
443         public String pushShortUrl; // short push button event
444         @SerializedName("btn_type")
445         public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
446         @SerializedName("btn1_type")
447         public String btnType1; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
448         @SerializedName("btn2_type")
449         public String btnType2; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
450         @SerializedName("swap_inputs")
451         public Integer swapInputs; // 0=no
452     }
453
454     public static class ShellySettingsRoller {
455         public Double maxtime;
456         @SerializedName("maxtime_open")
457         public Double maxtimeOpen;
458         @SerializedName("maxtime_close")
459         public Double maxtimeClose;
460         @SerializedName("default_state")
461         public String defaultState; // see SHELLY_STATE_xxx
462         public Boolean swap;
463         @SerializedName("swap_inputs")
464         public Boolean swapInputs;
465         @SerializedName("input_mode")
466         public String inputMode; // see SHELLY_INP_MODE_OPENCLOSE
467         @SerializedName("button_type")
468         public String buttonType; // // see SHELLY_BTNT_xxx
469         @SerializedName("btn_Reverse")
470         public Integer btnReverse;
471         public String state;
472         public Double power;
473         @SerializedName("is_valid")
474         public Boolean isValid;
475         @SerializedName("safety_switch")
476         public Boolean safetySwitch;
477         @SerializedName("obstacle_mode")
478         public String obstaclMode; // SHELLY_OBSTMODE_
479         @SerializedName("obstacle_action")
480         public String obstacleAction; // see SHELLY_STATE_xxx
481         @SerializedName("obstacle_power")
482         public Integer obstaclePower;
483         @SerializedName("obstacle_delay")
484         public Integer obstacleDelay;
485         @SerializedName("safety_mode")
486         public String safetyMode; // see SHELLY_SAFETYM_xxx
487         @SerializedName("safety_action")
488         public String safetyAction; // see SHELLY_STATE_xxx
489         @SerializedName("safety_allowed_on_trigger")
490         public String safetyAllowedOnTrigger; // see SHELLY_ALWD_TRIGGER_xxx
491         @SerializedName("off_power")
492         public Integer offPower;
493         public Boolean positioning;
494     }
495
496     public static class ShellySettingsRgbwLight {
497         public String name;
498         public Boolean ison; // true: output is ON
499         public Integer brightness;
500         public Integer temp;
501         public Integer transition;
502         @SerializedName("default_state")
503         public String defaultState;
504         @SerializedName("auto_on")
505         public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
506         @SerializedName("auto_off")
507         public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
508         public Boolean schedule;
509         @SerializedName("btn_type")
510         public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
511         @SerializedName("btn_reverse")
512         public Integer btnReverse; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
513         @SerializedName("out_on_url")
514         public String outOnUrl; // output is activated
515         @SerializedName("out_off_url")
516         public String outOffUrl; // output is deactivated
517     }
518
519     public static class ShellyFavPos { // FW 1.9.2+ in roller mode
520         public String name;
521         public Integer pos;
522     }
523
524     public static class ShellyInputState {
525         public Integer input;
526
527         // Shelly Button
528         public String event;
529         @SerializedName("event_cnt")
530         public Integer eventCount;
531     }
532
533     public static class ShellySettingsMeter {
534         @SerializedName("is_valid")
535         public Boolean isValid;
536         public Double power;
537         public Double[] counters = { 0.0, 0.0, 0.0 };
538         public Double total;
539         public Long timestamp;
540     }
541
542     public static class ShellySettingsEMeter { // ShellyEM meter
543         @SerializedName("is_valid")
544         public Boolean isValid; // Whether the associated meter is functioning properly
545         public Double power; // Instantaneous power, Watts
546         public Double reactive; // Instantaneous reactive power, Watts
547         public Double voltage; // RMS voltage, Volts
548         public Double total; // Total consumed energy, Wh
549         @SerializedName("total_returned")
550         public Double totalReturned; // Total returned energy, Wh
551
552         public Double pf; // 3EM
553         public Double current; // 3EM
554     }
555
556     public static class ShellyEMNCurrentSettings {
557         // "emeter_n":{ "range_extender":1, "mismatch_threshold":0.00}
558         @SerializedName("range_extender")
559         public Integer rangeExtender;
560         @SerializedName("mismatch_threshold")
561         public Double mismatchThreshold;
562     }
563
564     public static class ShellyEMNCurrentStatus {
565         // "emeter_n":{"current":2.28,"ixsum":2.29,"mismatch":false,"is_valid":true}
566         public Double current;
567         public Double ixsum;
568         public Boolean mismatch;
569         @SerializedName("is_valid")
570         public Boolean isValid;
571     }
572
573     public static class ShellySettingsUpdate {
574         public String status;
575         @SerializedName("has_update")
576         public Boolean hasUpdate;
577         @SerializedName("new_version")
578         public String newVersion;
579         @SerializedName("old_version")
580         public String oldVersion;
581         @SerializedName("beta_version")
582         public String betaVersion;
583     }
584
585     public static class ShellySettingsGlobal {
586         // https://shelly-api-docs.shelly.cloud/#shelly1pm-settings
587         @SerializedName("wifi_ap")
588         public ShellySettingsWiFiAp wifiAp = new ShellySettingsWiFiAp();
589         @SerializedName("wifi_sta")
590         public ShellySettingsWiFiNetwork wifiSta = new ShellySettingsWiFiNetwork();
591         @SerializedName("wifi_sta1")
592         public ShellySettingsWiFiNetwork wifiSta1 = new ShellySettingsWiFiNetwork();
593         @SerializedName("wifirecovery_reboot_enabled")
594         public Boolean wifiRecoveryReboot; // FW 1.10+
595         @SerializedName("ap_roaming")
596         public ShellyApRoaming apRoaming; // FW 1.10+
597
598         public ShellySettingsMqtt mqtt = new ShellySettingsMqtt();
599         public ShellySettingsSntp sntp = new ShellySettingsSntp();
600         public ShellySettingsCoiot coiot = new ShellySettingsCoiot();
601         public ShellySettingsLogin login = new ShellySettingsLogin();
602         @SerializedName("pin_code")
603         public String pinCode;
604         @SerializedName("coiot_execute_enable")
605         public Boolean coiotExecuteEnable;
606         public String name;
607         public Boolean discoverable; // FW 1.6+
608         public String fw;
609         @SerializedName("build_info")
610         public ShellySettingsBuildInfo buildInfo = new ShellySettingsBuildInfo();
611         public ShellyStatusCloud cloud = new ShellyStatusCloud();
612         @SerializedName("sleep_mode")
613         public ShellySensorSleepMode sleepMode; // FW 1.6
614         @SerializedName("external_power")
615         public Integer externalPower; // H&T FW 1.6, seems to be the same like charger for the Sense
616         @SerializedName("debug_enable") // FW 1.10+
617         public Boolean debugEnable;
618
619         public String timezone;
620         public Double lat;
621         public Double lng;
622         public Boolean tzautodetect;
623         public String time;
624
625         public ShellySettingsHwInfo hwinfo;
626         public String mode;
627         @SerializedName("max_power")
628         public Double maxPower;
629         public Boolean calibrated;
630
631         public Double voltage; // AC voltage for Shelly 2.5
632         @SerializedName("supply_voltage")
633         public Long supplyVoltage; // Shelly 1PM/1L: 0=110V, 1=220V
634
635         public @Nullable ArrayList<ShellySettingsRelay> relays;
636         public @Nullable ArrayList<ShellySettingsInput> inputs; // ix3
637         public @Nullable ArrayList<ShellySettingsDimmer> dimmers;
638         public @Nullable ArrayList<ShellySettingsRoller> rollers;
639         public @Nullable ArrayList<ShellySettingsRgbwLight> lights;
640         public @Nullable ArrayList<ShellySettingsEMeter> emeters;
641         @SerializedName("emeter_n")
642         public ShellyEMNCurrentSettings neutralCurrent;
643         public @Nullable ArrayList<ShellyThermnostat> thermostats; // TRV
644
645         @SerializedName("ext_switch_enable")
646         public Boolean externalSwitchEnable;
647         @SerializedName("ext_switch")
648         public ShellyStatusSensor.ShellyExtSwitchSettings extSwitch;
649         @SerializedName("ext_temperature")
650         public ShellyStatusSensor.ShellyExtTemperature extTemperature; // Shelly 1/1PM: sensor values
651         @SerializedName("ext_humidity")
652         public ShellyStatusSensor.ShellyExtHumidity extHumidity; // Shelly 1/1PM: sensor values
653         public ShellyStatusSensor.ShellyExtVoltage extVoltage; // Shelly Â´Plus 1/1PM: sensor values
654         public ShellyStatusSensor.ShellyExtAnalogInput extAnalogInput; // Shelly Â´Plus 1/1PM: sensor values
655         public ShellyStatusSensor.ShellyExtDigitalInput extDigitalInput; // Shelly Â´Plus 1/1PM: state of digital input
656
657         @SerializedName("temperature_units")
658         public String temperatureUnits = "C"; // Either'C'or'F'
659
660         @SerializedName("led_status_disable")
661         public Boolean ledStatusDisable; // PlugS only Disable LED indication for network
662                                          // status
663         @SerializedName("led_power_disable")
664         public Boolean ledPowerDisable; // PlugS only Disable LED indication for network
665                                         // status
666         @SerializedName("light_sensor")
667         public String lightSensor; // Sense: sensor type
668         @SerializedName("rain_sensor")
669         public Boolean rainSensor; // Flood: true=in rain mode
670
671         // FW 1.5.7: Door Window
672         @SerializedName("dark_treshold")
673         public Integer darkTreshold; // Illumination definition for "dark" in lux
674         @SerializedName("twilight_treshold")
675         public Integer twiLightTreshold; // Illumination definition for "twilight" in lux
676         @SerializedName("dark_url")
677         public String darkUrl; // URL to report to when luminance <= dark_threshold
678         @SerializedName("twilight_url")
679         public String twiLightUrl; // URL reports when luminance > dark_threshold AND luminance <=
680         @SerializedName("close_url")
681         public String closeUrl; // URL reports when DW contact is closed FW 1.6.5+
682         @SerializedName("vibration_url")
683         public String vibrationUrl; // URL reports when DW detects vibration FW 1.6.5+
684
685         // Gas FW 1.7
686         @SerializedName("set_volume")
687         public Integer volume; // Speaker volume for alarm
688         @SerializedName("alarm_off_url")
689         public String alarmOffUrl; // URL reports when alarm went off
690         @SerializedName("alarm_mild_url")
691         public String alarmMidUrl; // URL reports middle alarm
692         @SerializedName("alarm_heavy_url")
693         public String alarmHeavyfUrl; // URL reports heavy alarm
694
695         // Roller with FW 1.9.2+
696         @SerializedName("favorites_enabled")
697         public Boolean favoritesEnabled = false;
698         public ArrayList<ShellyFavPos> favorites;
699
700         // Motion
701         public ShellyMotionSettings motion;
702         @SerializedName("tamper_sensitivity")
703         public Integer tamperSensitivity;
704         @SerializedName("dark_threshold")
705         public Integer darkThreshold;
706         @SerializedName("twilight_threshold")
707         public Integer twilightThreshold;
708
709         @SerializedName("sleep_time") // Shelly Motion
710         public Integer sleepTime;
711
712         // Gen2
713         public Boolean ethernet;
714         public Boolean bluetooth;
715     }
716
717     public static class ShellySettingsAttributes {
718         @SerializedName("device_type")
719         public String deviceType; // Device model identifier
720         @SerializedName("device_mac")
721         public String deviceMac; // MAC address of the device in hexadecimal
722         @SerializedName("wifi_ap")
723         public String wifiAp; // WiFi access poInteger configuration, see /settings/ap for details
724         @SerializedName("wifi_sta")
725         public String wifiSta; // WiFi client configuration. See /settings/sta for details
726         public String login; // credentials used for HTTP Basic authentication for the REST interface. If
727                              // enabled is true clients must include an Authorization: Basic ... HTTP header with valid
728                              // credentials when performing TP requests.
729         public String name; // unique name of the device.
730         public String fw; // current FW version
731     }
732
733     public static class ShellyActionsStats {
734         public Integer skipped;
735     }
736
737     public static class ShellySettingsStatus {
738         public String name; // FW 1.8: Symbolic Device name is configurable
739
740         @SerializedName("wifi_sta")
741         public ShellySettingsWiFiNetwork wifiSta = new ShellySettingsWiFiNetwork(); // WiFi client configuration. See
742                                                                                     // /settings/sta for details
743         public ShellyStatusCloud cloud = new ShellyStatusCloud();
744         public ShellyStatusMqtt mqtt = new ShellyStatusMqtt();
745
746         public String time;
747         public Integer serial = -1;
748         @SerializedName("has_update")
749         public Boolean hasUpdate;
750         public String mac;
751         public Boolean discoverable; // FW 1.6+
752         @SerializedName("cfg_changed_cnt")
753         public Integer cfgChangedCount; // FW 1.8
754         @SerializedName("actions_stats")
755         public ShellyActionsStats astats;
756
757         public ArrayList<ShellySettingsRelay> relays;
758         public Double voltage; // Shelly 2.5
759         public Integer input; // RGBW2 has no JSON array
760         public ArrayList<ShellyInputState> inputs;
761         public ArrayList<ShellyShortLightStatus> dimmers;
762         public ArrayList<ShellyRollerStatus> rollers;
763         public ArrayList<ShellySettingsLight> lights;
764         public ArrayList<ShellySettingsMeter> meters;
765
766         public ArrayList<ShellySettingsEMeter> emeters;
767         @SerializedName("emeter_n")
768         public ShellyEMNCurrentStatus neutralCurrent;
769
770         public Double totalCurrent;
771         public Double totalPower;
772         public Double totalReturned;
773
774         @SerializedName("ext_temperature")
775         public ShellyStatusSensor.ShellyExtTemperature extTemperature; // Shelly 1/1PM: sensor values
776         @SerializedName("ext_humidity")
777         public ShellyStatusSensor.ShellyExtHumidity extHumidity; // Shelly 1/1PM: sensor values
778         public ShellyStatusSensor.ShellyExtVoltage extVoltage; // Shelly Â´Plus 1/1PM: sensor values
779         public ShellyStatusSensor.ShellyExtAnalogInput extAnalogInput; // Shelly Â´Plus 1/1PM: sensor values
780         public ShellyStatusSensor.ShellyExtDigitalInput extDigitalInput; // Shelly Â´Plus 1/1PM: sensor values
781         @SerializedName("ext_switch")
782         public ShellyStatusSensor.ShellyExtSwitchStatus extSwitch;
783
784         // Internal device temp
785         public ShellySensorTmp tmp; // Shelly 1PM
786         public Double temperature; // Shelly 2.5
787         public Boolean overtemperature;
788
789         // Shelly Dimmer only
790         public Boolean loaderror;
791         public Boolean overload;
792
793         // Shelly TRV
794         public Boolean calibrated;
795         public ArrayList<ShellyThermnostat> thermostats;
796
797         public ShellySettingsUpdate update = new ShellySettingsUpdate();
798         @SerializedName("ram_total")
799         public Long ramTotal;
800         @SerializedName("ram_free")
801         public Long ramFree;
802         @SerializedName("fs_size")
803         public Long fsSize;
804         @SerializedName("fs_free")
805         public Long fsFree;
806         public Long uptime;
807
808         @SerializedName("sleep_time") // Shelly Motion
809         public Integer sleepTime;
810
811         public String json;
812     }
813
814     public static class ShellySettingsInput {
815         @SerializedName("btn_type")
816         public String btnType;
817     }
818
819     public static class ShellyControlRelay {
820         // https://shelly-api-docs.shelly.cloud/#shelly1-1pm-settings-relay-0
821         @SerializedName("is_valid")
822         public Boolean isValid;
823         @SerializedName("has_timer")
824         public Boolean hasTimer; // Whether a timer is currently armed for this channel
825         @SerializedName("timer_remaining")
826         public Integer timerRemaining; // FW 1.6+
827         public Boolean overpower; // Shelly1PM only if maximum allowed power was exceeded
828
829         public String turn; // Accepted values are on and off. This will turn ON/OFF the respective output
830                             // channel when request is sent .
831         public Integer timer; // A one-shot flip-back timer in seconds.
832     }
833
834     public static class ShellyShortStatusRelay {
835         public String name; // FW 1.8+: Channel could now have a logical name
836         @SerializedName("is_valid")
837         public Boolean isValid;
838         public Boolean ison; // Whether output channel is on or off
839         @SerializedName("has_timer")
840         public Boolean hasTimer; // Whether a timer is currently armed for this channel
841         @SerializedName("timer_remaining")
842         public Integer timerRemaining;
843         public Boolean overpower; // Shelly1PM only if maximum allowed power was exceeded
844         public Double temperature; // Internal device temperature
845         public Boolean overtemperature; // Device over heated
846     }
847
848     public static class ShellyShortLightStatus {
849         public Boolean ison; // Whether output channel is on or off
850         public String mode; // color or white - valid only for Bulb and RGBW2 even Dimmer returns it also
851         public Integer brightness; // brightness: 0.100%
852         @SerializedName("has_timer")
853         public Boolean hasTimer;
854         @SerializedName("timer_duration")
855         public Integer timerDuration;
856     }
857
858     public static class ShellyStatusRelay {
859         public String name; // FW 1.8: Symbolic channel name is configurable
860
861         @SerializedName("wifi_sta")
862         public ShellySettingsWiFiNetwork wifiSta; // WiFi status
863         public ShellySettingsCoiot coiot; // Firmware 1.6+
864         public Integer serial;
865         public String mac; // MAC
866         public ArrayList<ShellyShortStatusRelay> relays; // relay status
867         public ArrayList<ShellySettingsMeter> meters; // current meter value
868         public ArrayList<ShellyInputState> inputs; // Firmware 1.5.6+
869
870         @SerializedName("ext_temperature")
871         public ShellyStatusSensor.ShellyExtTemperature extTemperature; // Shelly 1/1PM: sensor values
872         @SerializedName("ext_humidity")
873         public ShellyStatusSensor.ShellyExtHumidity extHumidity; // Shelly 1/1PM: sensor values
874
875         public Double temperature; // device temp acc. on the selected temp unit
876         public ShellySensorTmp tmp;
877     }
878
879     public static class ShellyStatusDimmer {
880         @SerializedName("wifi_sta")
881         public ShellySettingsWiFiNetwork wifiSta; // WiFi status
882         public ArrayList<ShellyShortLightStatus> lights; // relay status
883         public ArrayList<ShellySettingsMeter> meters; // current meter value
884
885         public ShellySensorTmp tmp;
886         public Boolean overtemperature;
887
888         public Boolean loaderror;
889         public Boolean overload;
890     }
891
892     public static class ShellyRollerStatus {
893         public String name; // FW 1.8: Symbolic name is configurable
894
895         @SerializedName("roller_pos")
896         public Integer rollerPos; // number Desired position in percent
897         public Integer duration; // If specified, the motor will move for this period in seconds. If missing, the
898                                  // value of maxtime in /settings/roller/N will be used.
899         public String state; // One of stop, open, close
900         public Double power; // Current power consumption in Watts
901         @SerializedName("is_valid")
902         public Boolean isValid; // If the power meter functions properly
903         @SerializedName("safety_switch")
904         public Boolean safetySwitch; // Whether the safety input is currently triggered
905         public Boolean overtemperature;
906         @SerializedName("stop_reason")
907         public String stopReason; // Last cause for stopping: normal, safety_switch, obstacle
908         @SerializedName("last_direction")
909         public String lastDirection; // Last direction of motion, open or close
910         public Boolean calibrating;
911         public Boolean positioning; // true when calibration was performed
912         @SerializedName("current_pos")
913         public Integer currentPos; // current position 0..100, 100=open
914     }
915
916     public static class ShellyOtaCheckResult {
917         public String status;
918     }
919
920     public static class ShellyApRoaming {
921         public Boolean enabled;
922         public Integer threshold;
923     }
924
925     public static class ShellySensorSleepMode {
926         public Integer period;
927         public String unit;
928     }
929
930     // Shelly TRV
931     public class ShellyThermnostat {
932         public class ShellyThermTargetTemp {
933             public Boolean enabled;
934             public Double value;
935             public String unit;
936         }
937
938         public class ShellyThermTemp {
939             public Double value;
940             public String units;
941             @SerializedName("is_valid")
942             public Boolean isValid;
943         }
944
945         public Double pos;
946         @SerializedName("target_t")
947         public ShellyThermTargetTemp targetTemp;
948         public Boolean schedule;
949         @SerializedName("schedule_profile")
950         public Integer profile;
951         @SerializedName("schedule_profile_names")
952         public String[] profileNames;
953         public ShellyThermTemp tmp;
954         @SerializedName("boost_minutes")
955         public Integer boostMinutes;
956         @SerializedName("window_open")
957         public Boolean windowOpen;
958     }
959
960     public static class ShellySensorTmp {
961         public Double value; // Temperature in configured unites
962         public String units; // 'C' or 'F'
963         public Double tC; // temperature in deg C
964         public Double tF; // temperature in deg F
965         @SerializedName("is_valid")
966         public Boolean isValid; // whether the internal sensor is operating properly
967     }
968
969     public static class ShellyStatusSensor {
970         // https://shelly-api-docs.shelly.cloud/#h-amp-t-settings
971
972         public static class ShellySensorHum {
973             public Double value; // relative humidity in %
974         }
975
976         public static class ShellySensorBat {
977             public Double value; // estimated remaining battery capacity in %
978             public Double voltage; // battery voltage
979         }
980
981         // Door/Window sensor
982         public static class ShellySensorState {
983             @SerializedName("is_valid")
984             public Boolean isValid; // whether the internal sensor is operating properly
985             public String state; // Shelly Door/Window
986
987             // Shelly Motion
988             public Boolean motion;
989             public Boolean vibration;
990             @SerializedName("timestamp")
991             public Long motionTimestamp;
992             @SerializedName("active")
993             public Boolean motionActive;
994         }
995
996         public static class ShellySensorLux {
997             @SerializedName("is_valid")
998             public Boolean isValid; // whether the internal sensor is operating properly
999             public Double value;
1000
1001             public String illumination;
1002         }
1003
1004         public static class ShellySensorAccel {
1005             public Integer tilt; // Tilt in Â°
1006             public Integer vibration; // Whether vibration is detected
1007         }
1008
1009         public static class ShellyMotionSettings {
1010             public Integer sensitivity;
1011             @SerializedName("blind_time_minutes")
1012             public Integer blindTimeMinutes;
1013             @SerializedName("pulse_count")
1014             public Integer pulseCount;
1015             @SerializedName("operating_mode")
1016             public Integer operatingMode;
1017             public Boolean enabled;
1018         }
1019
1020         public static class ShellyExtTemperature {
1021             public static class ShellyShortTemp {
1022                 public String hwID; // e.g. "2882379497020381",
1023                 public Double tC; // temperature in deg C
1024                 public Double tF; // temperature in deg F
1025             }
1026
1027             // Shelly 1/1PM have up to 3 sensors
1028             // for whatever reasons it's not an array, but 3 independent elements
1029             @SerializedName("0")
1030             public ShellyShortTemp sensor1;
1031             @SerializedName("1")
1032             public ShellyShortTemp sensor2;
1033             @SerializedName("2")
1034             public ShellyShortTemp sensor3;
1035             @SerializedName("3")
1036             public ShellyShortTemp sensor4;
1037             @SerializedName("4")
1038             public ShellyShortTemp sensor5;
1039         }
1040
1041         public static class ShellyExtHumidity {
1042             public static class ShellyShortHum {
1043                 public Double hum; // Humidity reading of sensor 0, percent
1044             }
1045
1046             public ShellyExtHumidity() {
1047             }
1048
1049             public ShellyExtHumidity(double hum) {
1050                 sensor1 = new ShellyShortHum();
1051                 sensor1.hum = hum;
1052             }
1053
1054             @SerializedName("0")
1055             public ShellyShortHum sensor1;
1056         }
1057
1058         public static class ShellyExtVoltage {
1059             public static class ShellyShortVoltage {
1060                 public Double voltage;
1061             }
1062
1063             public ShellyExtVoltage() {
1064             }
1065
1066             public ShellyExtVoltage(double voltage) {
1067                 sensor1 = new ShellyShortVoltage();
1068                 sensor1.voltage = voltage;
1069             }
1070
1071             @SerializedName("0")
1072             public ShellyShortVoltage sensor1;
1073         }
1074
1075         public static class ShellyExtDigitalInput {
1076             public static class ShellyShortDigitalInput {
1077                 public Boolean state;
1078             }
1079
1080             public ShellyExtDigitalInput() {
1081             }
1082
1083             public ShellyExtDigitalInput(boolean state) {
1084                 sensor1 = new ShellyShortDigitalInput();
1085                 sensor1.state = state;
1086             }
1087
1088             @SerializedName("0")
1089             public ShellyShortDigitalInput sensor1;
1090         }
1091
1092         public static class ShellyExtAnalogInput {
1093             public static class ShellyShortAnalogInput {
1094                 public Double percent;
1095             }
1096
1097             public ShellyExtAnalogInput() {
1098             }
1099
1100             public ShellyExtAnalogInput(double percent) {
1101                 sensor1 = new ShellyShortAnalogInput();
1102                 sensor1.percent = percent;
1103             }
1104
1105             @SerializedName("0")
1106             public ShellyShortAnalogInput sensor1;
1107         }
1108
1109         public static class ShellyADC {
1110             public Double voltage;
1111         }
1112
1113         public static class ShellyExtSwitchSettings {
1114             public static class ShellyExtSwitchSettingsInput {
1115                 @SerializedName("relay_num")
1116                 public Integer relayNum;
1117             }
1118
1119             @SerializedName("0")
1120             public ShellyExtSwitchSettingsInput input0;
1121         }
1122
1123         public static class ShellyExtSwitchStatus {
1124             public static class ShellyExtSwitchStatusInput {
1125                 public Integer input;
1126             }
1127
1128             @SerializedName("0")
1129             public ShellyExtSwitchStatusInput input0;
1130         }
1131
1132         public ShellySensorTmp tmp;
1133         public ShellySensorHum hum;
1134         public ShellySensorLux lux;
1135         public ShellySensorAccel accel;
1136         public ShellySensorBat bat;
1137         @SerializedName("sensor")
1138         public ShellySensorState sensor;
1139         public Boolean smoke; // SHelly Smoke
1140         public Boolean flood; // Shelly Flood: true = flood condition detected
1141         public Boolean mute; // mute enabled/disabled
1142         @SerializedName("rain_sensor")
1143         public Boolean rainSensor; // Shelly Flood: true=in rain mode
1144
1145         public Boolean motion; // Shelly Sense: true=motion detected
1146         public Boolean charger; // Shelly Sense, TRV: true=charger connected
1147
1148         @SerializedName("act_reasons")
1149         public List<Object> actReasons; // HT/Smoke/Flood: list of reasons which woke up the device
1150
1151         @SerializedName("sensor_error")
1152         public String sensorError; // 1.5.7: Only displayed in case of error
1153
1154         // FW 1.7: Shelly Gas
1155         @SerializedName("gas_sensor")
1156         public ShellyStatusGasSensor gasSensor;
1157         @SerializedName("concentration")
1158         public ShellyStatusGasConcentration concentration;
1159         public ArrayList<ShellyStatusValve> valves;
1160
1161         // FW 1.7 Button
1162         @SerializedName("connect_retries")
1163         public Integer connectRetries;
1164         public ArrayList<ShellyInputState> inputs; // Firmware 1.5.6+
1165
1166         // Shelly UNI FW 1.9+
1167         public ArrayList<ShellyADC> adcs;
1168
1169         // Shelly TRV
1170         public Boolean calibrated;
1171         public ArrayList<ShellyThermnostat> thermostats;
1172     }
1173
1174     public static class ShellySettingsSmoke {
1175         @SerializedName("temperature_units")
1176         public String temperatureUnits; // Either 'C' or 'F'
1177         @SerializedName("temperature_threshold")
1178         public Integer temperatureThreshold; // Temperature delta (in configured degree units) which triggers an update
1179         @SerializedName("sleep_mode_period")
1180         public Integer sleepModePeriod; // Periodic update period in hours, between 1 and 24
1181     }
1182
1183     // Shelly Gas
1184     // "gas_sensor":{"sensor_state":"normal","self_test_state":"not_completed","alarm_state":"none"},
1185     // "concentration":{"ppm":0,"is_valid":true},
1186     public static class ShellyStatusGasSensor {
1187         @SerializedName("sensor_state")
1188         public String sensorState;
1189         @SerializedName("self_test_state")
1190         public String selfTestState;
1191         @SerializedName("alarm_state")
1192         public String alarmState;
1193     }
1194
1195     public static class ShellyStatusGasConcentration {
1196         public Integer ppm;
1197         @SerializedName("is_valid")
1198         public Boolean isValid;
1199     }
1200
1201     public static class ShellyStatusValve {
1202         public String state; // closed/opened/not_connected/failure/closing/opening/checking
1203     }
1204
1205     public static class ShellySettingsLight {
1206         public Integer red; // red brightness, 0..255, applies in mode="color"
1207         public Integer green; // green brightness, 0..255, applies in mode="color"
1208         public Integer blue; // blue brightness, 0..255, applies in mode="color"
1209         public Integer white; // white brightness, 0..255, applies in mode="color"
1210         public Integer gain; // gain for all channels, 0..100, applies in mode="color"
1211         public Integer temp; // color temperature in K, 3000..6500, applies in mode="white"
1212         public Integer brightness; // brightness, 0..100, applies in mode="white"
1213         public Integer effect; // Currently applied effect, description: 0: Off, 1: Meteor Shower, 2: Gradual
1214                                // Change, 3: Breath,
1215                                // 4: Flash, 5: On/Off Gradual, 6: Red/Green Change
1216         @SerializedName("default_state")
1217         public String defaultState; // one of on, off or last
1218         @SerializedName("auto_on")
1219         public Double autoOn; // see above
1220         @SerializedName("auto_off")
1221         public Double autoOff; // see above
1222
1223         public Integer dcpower; // RGW2:Set to true for 24 V power supply, false for 12 V
1224
1225         // Shelly Dimmer
1226         public String mode;
1227         public Boolean ison;
1228     }
1229
1230     public static class ShellySettingsNightMode { // FW1.5.7+
1231         public Integer enabled;
1232         @SerializedName("start_time")
1233         public String startTime;
1234         @SerializedName("end_time")
1235         public String endTime;
1236         public Integer brightness;
1237     }
1238
1239     public static class ShellyStatusLightChannel {
1240         public Boolean ison;
1241         public Double power;
1242         public Boolean overpower;
1243         @SerializedName("has_timer")
1244         public Boolean hasTimer;
1245         @SerializedName("timer_started")
1246         public Integer timerStarted;
1247         @SerializedName("timer_duration")
1248         public Integer timerDuration;
1249         @SerializedName("timer_remaining")
1250         public Integer timerRemaining;
1251
1252         public Integer red; // red brightness, 0..255, applies in mode="color"
1253         public Integer green; // green brightness, 0..255, applies in mode="color"
1254         public Integer blue; // blue brightness, 0..255, applies in mode="color"
1255         public Integer white; // white brightness, 0..255, applies in mode="color"
1256         public Integer gain; // gain for all channels, 0..100, applies in mode="color"
1257         public Integer temp; // color temperature in K, 3000..6500, applies in mode="white"
1258         public Integer brightness; // brightness, 0..100, applies in mode="white"
1259         public Integer effect; // Currently applied effect, description: 0: Off, 1: Meteor Shower, 2: Gradual
1260                                // Change, 3: Breath,
1261     }
1262
1263     public static class ShellyStatusLight {
1264         public Boolean ison; // Whether output channel is on or off
1265         public Integer input;
1266
1267         public ArrayList<ShellyStatusLightChannel> lights;
1268         public ArrayList<ShellySettingsMeter> meters;
1269     }
1270
1271     public static class ShellySenseKeyCode {
1272         String id; // ID of the stored IR code into Shelly Sense.
1273         String name; // Short description or name of the stored IR code.
1274     }
1275
1276     public static class ShellySendKeyList {
1277         @SerializedName("key_codes")
1278         public ArrayList<ShellySenseKeyCode> keyCodes;
1279     }
1280
1281     /**
1282      * Shelly Dimmer returns light[]. However, the structure doesn't match the lights[] of a Bulb/RGBW2.
1283      * The tag lights[] will be replaced with dimmers[] so this could be mapped to a different Gson structure.
1284      * The function requires that it's only called when the device is a dimmer - on get settings and get status
1285      *
1286      * @param json Input Json as received by the API
1287      * @return Modified Json
1288      */
1289     public static String fixDimmerJson(String json) {
1290         return !json.contains("\"lights\":[") ? json
1291                 : json.replaceFirst(java.util.regex.Pattern.quote("\"lights\":["), "\"dimmers\":[");
1292     }
1293
1294     /**
1295      * Convert Shelly Button events into OH button states
1296      *
1297      * @param eventType S/SS/SSS or L
1298      * @return OH button states
1299      */
1300     public static String mapButtonEvent(String eventType) {
1301         // decode different codings
1302         // 0..2: CoAP
1303         // S/SS/SSS/L: CoAP for Button and xi3
1304         // shortpush/double_shortpush/triple_shortpush/longpush: REST
1305         switch (eventType) {
1306             case "0":
1307                 return CommonTriggerEvents.RELEASED;
1308             case "1":
1309             case SHELLY_BTNEVENT_1SHORTPUSH:
1310             case SHELLY_EVENT_SHORTPUSH:
1311                 return CommonTriggerEvents.SHORT_PRESSED;
1312             case SHELLY_BTNEVENT_2SHORTPUSH:
1313             case SHELLY_EVENT_DOUBLE_SHORTPUSH:
1314                 return CommonTriggerEvents.DOUBLE_PRESSED;
1315             case SHELLY_BTNEVENT_3SHORTPUSH:
1316             case SHELLY_EVENT_TRIPLE_SHORTPUSH:
1317                 return "TRIPLE_PRESSED";
1318             case "2":
1319             case SHELLY_BTNEVENT_LONGPUSH:
1320             case SHELLY_EVENT_LONGPUSH:
1321                 return CommonTriggerEvents.LONG_PRESSED;
1322             case SHELLY_BTNEVENT_SHORTLONGPUSH:
1323             case SHELLY_EVENT_SHORT_LONGTPUSH:
1324                 return "SHORT_LONG_PRESSED";
1325             case SHELLY_BTNEVENT_LONGSHORTPUSH:
1326             case SHELLY_EVENT_LONG_SHORTPUSH:
1327                 return "LONG_SHORT_PRESSED";
1328             default:
1329                 return "";
1330         }
1331     }
1332 }