]> git.basschouten.com Git - openhab-addons.git/blob
c5304fe4e1ce102c3d4d84af8a37eefe61351219
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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 mac;
265         public String hostname;
266         public String fw;
267         public Boolean auth;
268         public Integer gen;
269         public String coiot;
270         public Integer longid;
271
272         @SerializedName("num_outputs")
273         public Integer numOutputs;
274         @SerializedName("num_meters")
275         public Integer numMeters;
276         @SerializedName("num_emeters")
277         public Integer numEMeters;
278         @SerializedName("num_rollers")
279         public Integer numRollers;
280     }
281
282     public static class ShellySettingsWiFiAp {
283         public Boolean enabled;
284         public String ssid;
285         public String key;
286         public Boolean rangeExtender; // Gen2 only
287     }
288
289     public static class ShellySettingsWiFiNetwork {
290         public Boolean enabled;
291         public String ssid;
292         public Integer rssi;
293
294         @SerializedName("ipv4_method")
295         public String ipv4Method;
296         public String ip;
297         public String gw;
298         public String mask;
299         public String dns;
300     }
301
302     public static class ShellySettingsMqtt {
303         public Boolean enable;
304         public String server;
305         public String user;
306         @SerializedName("reconnect_timeout_max")
307         public Double reconnectTimeoutMax;
308         @SerializedName("reconnect_timeout_min")
309         public Double reconnectTimeoutMin;
310         @SerializedName("clean_session")
311         public Boolean cleanSession;
312         @SerializedName("keep_alive")
313         public Integer keepAlive;
314         @SerializedName("will_topic")
315         public String willTopic;
316         @SerializedName("will_message")
317         public String willMessage;
318         @SerializedName("max_qos")
319         public Integer maxQOS;
320         public Boolean retain;
321         @SerializedName("update_period")
322         public Integer updatePeriod;
323     }
324
325     public static class ShellySettingsCoiot { // FW 1.6+
326         @SerializedName("update_period")
327         public Integer updatePeriod;
328         public Boolean enabled; // Motion 1.0.7: Coap can be disabled
329         public String peer; // if set the device uses singlecast CoAP, mcast=set back to Multicast
330     }
331
332     public static class ShellyStatusMqtt {
333         public Boolean connected;
334     }
335
336     public static class ShellySettingsSntp {
337         public String server;
338         public Boolean enabled;
339     }
340
341     public static class ShellySettingsLogin {
342         public Boolean enabled;
343         public Boolean unprotected;
344         public String username;
345         public String password;
346     }
347
348     public static class ShellySettingsBuildInfo {
349         @SerializedName("build_id")
350         public String buildId;
351         @SerializedName("build_timestamp")
352         public String buildTimestamp;
353         @SerializedName("build_version")
354         public String buildVersion;
355     }
356
357     public static class ShellyStatusCloud {
358         public Boolean enabled;
359         public Boolean connected;
360     }
361
362     public static class ShellySettingsHwInfo {
363         @SerializedName("hw_revision")
364         public String hwRevision;
365         @SerializedName("batch_id")
366         public Integer batchId;
367     }
368
369     public static class ShellySettingsScheduleRules {
370     }
371
372     public static class ShellySettingsRelay {
373         public String name;
374         @SerializedName("default_state")
375         public String defaultState; // Accepted values: off, on, last, switch
376         @SerializedName("btn_type")
377         public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
378         @SerializedName("btn1_type") // Shelly 1L
379         public String btnType1;
380         @SerializedName("btn2_type") // Shelly 1L
381         public String btnType2;
382         @SerializedName("has_timer")
383         public Boolean hasTimer; // Whether a timer is currently armed for this channel
384         @SerializedName("auto_on")
385         public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
386         @SerializedName("auto_off")
387         public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
388         @SerializedName("btn_on_url")
389         public String btnOnUrl; // input is activated
390         @SerializedName("btnOffUrl")
391         public String btnOffUrl; // input is deactivated
392         @SerializedName("out_on_url")
393         public String outOnUrl; // output is activated
394         @SerializedName("out_off_url")
395         public String outOffUrl; // output is deactivated
396         @SerializedName("roller_open_url")
397         public String rollerOpenUrl; // to access when roller reaches open position
398         @SerializedName("roller_close_url")
399         public String rollerCloseUrl; // to access when roller reaches close position
400         @SerializedName("roller_stop_url")
401         public String rollerStopUrl; // to access when roller stopped
402         @SerializedName("longpush_url")
403         public String pushLongUrl; // to access when roller stopped
404         @SerializedName("shortpush_url")
405         public String pushShortUrl; // to access when roller stopped
406
407         // Status information
408         public Integer id;
409         public Boolean ison;
410         public Boolean overpower;
411         @SerializedName("is_valid")
412         public Boolean isValid;
413     }
414
415     public static class ShellySettingsDimmer {
416         public String name; // unique name of the device
417         public Boolean ison; // true: output is ON
418         @SerializedName("default_state")
419         public String defaultState; // Accepted values: off, on, last, switch
420         @SerializedName("auto_on")
421         public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
422         @SerializedName("auto_off")
423         public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
424         @SerializedName("btn1_on_url")
425         public String btn1OnUrl; // URL to access when SW input is activated
426         @SerializedName("btn1_off_url")
427         public String btn1OffUrl; // URL to access when SW input is deactivated
428         @SerializedName("btn2_on_url")
429         public String btn2OnUrl; // URL to access when SW input is activated
430         @SerializedName("btn2_off_url")
431         public String btn2OoffUrl; // URL to access when SW input is deactivated
432         @SerializedName("out_on_url")
433         public String outOnUrl; // URL to access when output is activated
434         @SerializedName("out_off_url")
435         public String outOffUrl; // URL to access when output is deactivated
436         @SerializedName("longpush_url")
437         public String pushLongUrl; // long push button event
438         @SerializedName("shortpush_url")
439         public String pushShortUrl; // short push button event
440         @SerializedName("btn_type")
441         public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
442         @SerializedName("btn1_type")
443         public String btnType1; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
444         @SerializedName("btn2_type")
445         public String btnType2; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
446         @SerializedName("swap_inputs")
447         public Integer swapInputs; // 0=no
448     }
449
450     public static class ShellySettingsRoller {
451         public Double maxtime;
452         @SerializedName("maxtime_open")
453         public Double maxtimeOpen;
454         @SerializedName("maxtime_close")
455         public Double maxtimeClose;
456         @SerializedName("default_state")
457         public String defaultState; // see SHELLY_STATE_xxx
458         public Boolean swap;
459         @SerializedName("swap_inputs")
460         public Boolean swapInputs;
461         @SerializedName("input_mode")
462         public String inputMode; // see SHELLY_INP_MODE_OPENCLOSE
463         @SerializedName("button_type")
464         public String buttonType; // // see SHELLY_BTNT_xxx
465         @SerializedName("btn_Reverse")
466         public Integer btnReverse;
467         public String state;
468         public Double power;
469         @SerializedName("is_valid")
470         public Boolean isValid;
471         @SerializedName("safety_switch")
472         public Boolean safetySwitch;
473         @SerializedName("obstacle_mode")
474         public String obstaclMode; // SHELLY_OBSTMODE_
475         @SerializedName("obstacle_action")
476         public String obstacleAction; // see SHELLY_STATE_xxx
477         @SerializedName("obstacle_power")
478         public Integer obstaclePower;
479         @SerializedName("obstacle_delay")
480         public Integer obstacleDelay;
481         @SerializedName("safety_mode")
482         public String safetyMode; // see SHELLY_SAFETYM_xxx
483         @SerializedName("safety_action")
484         public String safetyAction; // see SHELLY_STATE_xxx
485         @SerializedName("safety_allowed_on_trigger")
486         public String safetyAllowedOnTrigger; // see SHELLY_ALWD_TRIGGER_xxx
487         @SerializedName("off_power")
488         public Integer offPower;
489         public Boolean positioning;
490     }
491
492     public static class ShellySettingsRgbwLight {
493         public String name;
494         public Boolean ison; // true: output is ON
495         public Integer brightness;
496         public Integer temp;
497         public Integer transition;
498         @SerializedName("default_state")
499         public String defaultState;
500         @SerializedName("auto_on")
501         public Double autoOn; // Automatic flip back timer, seconds. Will engage after turning Shelly1 OFF.
502         @SerializedName("auto_off")
503         public Double autoOff; // Automatic flip back timer, seconds. Will engage after turning Shelly1 ON.
504         public Boolean schedule;
505         @SerializedName("btn_type")
506         public String btnType; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
507         @SerializedName("btn_reverse")
508         public Integer btnReverse; // Accepted values: momentary, toggle, edge, detached - // see SHELLY_BTNT_xxx
509         @SerializedName("out_on_url")
510         public String outOnUrl; // output is activated
511         @SerializedName("out_off_url")
512         public String outOffUrl; // output is deactivated
513     }
514
515     public static class ShellyFavPos { // FW 1.9.2+ in roller mode
516         public String name;
517         public Integer pos;
518     }
519
520     public static class ShellyInputState {
521         public Integer input;
522
523         // Shelly Button
524         public String event;
525         @SerializedName("event_cnt")
526         public Integer eventCount;
527     }
528
529     public static class ShellySettingsMeter {
530         @SerializedName("is_valid")
531         public Boolean isValid;
532         public Double power;
533         public Double[] counters = { 0.0, 0.0, 0.0 };
534         public Double total;
535         public Long timestamp;
536     }
537
538     public static class ShellySettingsEMeter { // ShellyEM meter
539         @SerializedName("is_valid")
540         public Boolean isValid; // Whether the associated meter is functioning properly
541         public Double power; // Instantaneous power, Watts
542         public Double reactive; // Instantaneous reactive power, Watts
543         public Double voltage; // RMS voltage, Volts
544         public Double total; // Total consumed energy, Wh
545         @SerializedName("total_returned")
546         public Double totalReturned; // Total returned energy, Wh
547
548         public Double pf; // 3EM
549         public Double current; // 3EM
550     }
551
552     public static class ShellySettingsUpdate {
553         public String status;
554         @SerializedName("has_update")
555         public Boolean hasUpdate;
556         @SerializedName("new_version")
557         public String newVersion;
558         @SerializedName("old_version")
559         public String oldVersion;
560         @SerializedName("beta_version")
561         public String betaVersion;
562     }
563
564     public static class ShellySettingsGlobal {
565         // https://shelly-api-docs.shelly.cloud/#shelly1pm-settings
566         public ShellySettingsDevice device = new ShellySettingsDevice();
567         @SerializedName("wifi_ap")
568         public ShellySettingsWiFiAp wifiAp = new ShellySettingsWiFiAp();
569         @SerializedName("wifi_sta")
570         public ShellySettingsWiFiNetwork wifiSta = new ShellySettingsWiFiNetwork();
571         @SerializedName("wifi_sta1")
572         public ShellySettingsWiFiNetwork wifiSta1 = new ShellySettingsWiFiNetwork();
573         @SerializedName("wifirecovery_reboot_enabled")
574         public Boolean wifiRecoveryReboot; // FW 1.10+
575         @SerializedName("ap_roaming")
576         public ShellyApRoaming apRoaming; // FW 1.10+
577
578         public ShellySettingsMqtt mqtt = new ShellySettingsMqtt();
579         public ShellySettingsSntp sntp = new ShellySettingsSntp();
580         public ShellySettingsCoiot coiot = new ShellySettingsCoiot();
581         public ShellySettingsLogin login = new ShellySettingsLogin();
582         @SerializedName("pin_code")
583         public String pinCode;
584         @SerializedName("coiot_execute_enable")
585         public Boolean coiotExecuteEnable;
586         public String name;
587         public Boolean discoverable; // FW 1.6+
588         public String fw;
589         @SerializedName("build_info")
590         public ShellySettingsBuildInfo buildInfo = new ShellySettingsBuildInfo();
591         public ShellyStatusCloud cloud = new ShellyStatusCloud();
592         @SerializedName("sleep_mode")
593         public ShellySensorSleepMode sleepMode; // FW 1.6
594         @SerializedName("external_power")
595         public Integer externalPower; // H&T FW 1.6, seems to be the same like charger for the Sense
596         @SerializedName("debug_enable") // FW 1.10+
597         public Boolean debugEnable;
598
599         public String timezone;
600         public Double lat;
601         public Double lng;
602         public Boolean tzautodetect;
603         public String time;
604
605         public ShellySettingsHwInfo hwinfo;
606         public String mode;
607         @SerializedName("max_power")
608         public Double maxPower;
609         public Boolean calibrated;
610
611         public Double voltage; // AC voltage for Shelly 2.5
612         @SerializedName("supply_voltage")
613         public Long supplyVoltage; // Shelly 1PM/1L: 0=110V, 1=220V
614
615         public @Nullable ArrayList<ShellySettingsRelay> relays;
616         public @Nullable ArrayList<ShellySettingsInput> inputs; // ix3
617         public @Nullable ArrayList<ShellySettingsDimmer> dimmers;
618         public @Nullable ArrayList<ShellySettingsRoller> rollers;
619         public @Nullable ArrayList<ShellySettingsRgbwLight> lights;
620         public @Nullable ArrayList<ShellySettingsEMeter> emeters;
621         public @Nullable ArrayList<ShellyThermnostat> thermostats; // TRV
622
623         @SerializedName("ext_switch_enable")
624         public Boolean externalSwitchEnable;
625         @SerializedName("ext_switch")
626         public ShellyStatusSensor.ShellyExtSwitchSettings extSwitch;
627         @SerializedName("ext_temperature")
628         public ShellyStatusSensor.ShellyExtTemperature extTemperature; // Shelly 1/1PM: sensor values
629         @SerializedName("ext_humidity")
630         public ShellyStatusSensor.ShellyExtHumidity extHumidity; // Shelly 1/1PM: sensor values
631         public ShellyStatusSensor.ShellyExtVoltage extVoltage; // Shelly Â´Plus 1/1PM: sensor values
632         public ShellyStatusSensor.ShellyExtAnalogInput extAnalogInput; // Shelly Â´Plus 1/1PM: sensor values
633         public ShellyStatusSensor.ShellyExtDigitalInput extDigitalInput; // Shelly Â´Plus 1/1PM: state of digital input
634
635         @SerializedName("temperature_units")
636         public String temperatureUnits = "C"; // Either'C'or'F'
637
638         @SerializedName("led_status_disable")
639         public Boolean ledStatusDisable; // PlugS only Disable LED indication for network
640                                          // status
641         @SerializedName("led_power_disable")
642         public Boolean ledPowerDisable; // PlugS only Disable LED indication for network
643                                         // status
644         @SerializedName("light_sensor")
645         public String lightSensor; // Sense: sensor type
646         @SerializedName("rain_sensor")
647         public Boolean rainSensor; // Flood: true=in rain mode
648
649         // FW 1.5.7: Door Window
650         @SerializedName("dark_treshold")
651         public Integer darkTreshold; // Illumination definition for "dark" in lux
652         @SerializedName("twilight_treshold")
653         public Integer twiLightTreshold; // Illumination definition for "twilight" in lux
654         @SerializedName("dark_url")
655         public String darkUrl; // URL to report to when luminance <= dark_threshold
656         @SerializedName("twilight_url")
657         public String twiLightUrl; // URL reports when luminance > dark_threshold AND luminance <=
658         @SerializedName("close_url")
659         public String closeUrl; // URL reports when DW contact is closed FW 1.6.5+
660         @SerializedName("vibration_url")
661         public String vibrationUrl; // URL reports when DW detects vibration FW 1.6.5+
662
663         // Gas FW 1.7
664         @SerializedName("set_volume")
665         public Integer volume; // Speaker volume for alarm
666         @SerializedName("alarm_off_url")
667         public String alarmOffUrl; // URL reports when alarm went off
668         @SerializedName("alarm_mild_url")
669         public String alarmMidUrl; // URL reports middle alarm
670         @SerializedName("alarm_heavy_url")
671         public String alarmHeavyfUrl; // URL reports heavy alarm
672
673         // Roller with FW 1.9.2+
674         @SerializedName("favorites_enabled")
675         public Boolean favoritesEnabled = false;
676         public ArrayList<ShellyFavPos> favorites;
677
678         // Motion
679         public ShellyMotionSettings motion;
680         @SerializedName("tamper_sensitivity")
681         public Integer tamperSensitivity;
682         @SerializedName("dark_threshold")
683         public Integer darkThreshold;
684         @SerializedName("twilight_threshold")
685         public Integer twilightThreshold;
686
687         @SerializedName("sleep_time") // Shelly Motion
688         public Integer sleepTime;
689
690         // Gen2
691         public Boolean ethernet;
692         public Boolean bluetooth;
693     }
694
695     public static class ShellySettingsAttributes {
696         @SerializedName("device_type")
697         public String deviceType; // Device model identifier
698         @SerializedName("device_mac")
699         public String deviceMac; // MAC address of the device in hexadecimal
700         @SerializedName("wifi_ap")
701         public String wifiAp; // WiFi access poInteger configuration, see /settings/ap for details
702         @SerializedName("wifi_sta")
703         public String wifiSta; // WiFi client configuration. See /settings/sta for details
704         public String login; // credentials used for HTTP Basic authentication for the REST interface. If
705                              // enabled is true clients must include an Authorization: Basic ... HTTP header with valid
706                              // credentials when performing TP requests.
707         public String name; // unique name of the device.
708         public String fw; // current FW version
709     }
710
711     public static class ShellyActionsStats {
712         public Integer skipped;
713     }
714
715     public static class ShellySettingsStatus {
716         public String name; // FW 1.8: Symbolic Device name is configurable
717
718         @SerializedName("wifi_sta")
719         public ShellySettingsWiFiNetwork wifiSta = new ShellySettingsWiFiNetwork(); // WiFi client configuration. See
720                                                                                     // /settings/sta for details
721         public ShellyStatusCloud cloud = new ShellyStatusCloud();
722         public ShellyStatusMqtt mqtt = new ShellyStatusMqtt();
723
724         public String time;
725         public Integer serial = -1;
726         @SerializedName("has_update")
727         public Boolean hasUpdate;
728         public String mac;
729         public Boolean discoverable; // FW 1.6+
730         @SerializedName("cfg_changed_cnt")
731         public Integer cfgChangedCount; // FW 1.8
732         @SerializedName("actions_stats")
733         public ShellyActionsStats astats;
734
735         public ArrayList<ShellySettingsRelay> relays;
736         public Double voltage; // Shelly 2.5
737         public Integer input; // RGBW2 has no JSON array
738         public ArrayList<ShellyInputState> inputs;
739         public ArrayList<ShellyShortLightStatus> dimmers;
740         public ArrayList<ShellyRollerStatus> rollers;
741         public ArrayList<ShellySettingsLight> lights;
742         public ArrayList<ShellySettingsMeter> meters;
743
744         public ArrayList<ShellySettingsEMeter> emeters;
745         public Double totalCurrent;
746         public Double totalPower;
747         public Double totalReturned;
748
749         @SerializedName("ext_temperature")
750         public ShellyStatusSensor.ShellyExtTemperature extTemperature; // Shelly 1/1PM: sensor values
751         @SerializedName("ext_humidity")
752         public ShellyStatusSensor.ShellyExtHumidity extHumidity; // Shelly 1/1PM: sensor values
753         public ShellyStatusSensor.ShellyExtVoltage extVoltage; // Shelly Â´Plus 1/1PM: sensor values
754         public ShellyStatusSensor.ShellyExtAnalogInput extAnalogInput; // Shelly Â´Plus 1/1PM: sensor values
755         public ShellyStatusSensor.ShellyExtDigitalInput extDigitalInput; // Shelly Â´Plus 1/1PM: sensor values
756         @SerializedName("ext_switch")
757         public ShellyStatusSensor.ShellyExtSwitchStatus extSwitch;
758
759         // Internal device temp
760         public ShellySensorTmp tmp; // Shelly 1PM
761         public Double temperature; // Shelly 2.5
762         public Boolean overtemperature;
763
764         // Shelly Dimmer only
765         public Boolean loaderror;
766         public Boolean overload;
767
768         // Shelly TRV
769         public Boolean calibrated;
770         public ArrayList<ShellyThermnostat> thermostats;
771
772         public ShellySettingsUpdate update = new ShellySettingsUpdate();
773         @SerializedName("ram_total")
774         public Long ramTotal;
775         @SerializedName("ram_free")
776         public Long ramFree;
777         @SerializedName("fs_size")
778         public Long fsSize;
779         @SerializedName("fs_free")
780         public Long fsFree;
781         public Long uptime;
782
783         @SerializedName("sleep_time") // Shelly Motion
784         public Integer sleepTime;
785
786         public String json;
787     }
788
789     public static class ShellySettingsInput {
790         @SerializedName("btn_type")
791         public String btnType;
792     }
793
794     public static class ShellyControlRelay {
795         // https://shelly-api-docs.shelly.cloud/#shelly1-1pm-settings-relay-0
796         @SerializedName("is_valid")
797         public Boolean isValid;
798         @SerializedName("has_timer")
799         public Boolean hasTimer; // Whether a timer is currently armed for this channel
800         @SerializedName("timer_remaining")
801         public Integer timerRemaining; // FW 1.6+
802         public Boolean overpower; // Shelly1PM only if maximum allowed power was exceeded
803
804         public String turn; // Accepted values are on and off. This will turn ON/OFF the respective output
805                             // channel when request is sent .
806         public Integer timer; // A one-shot flip-back timer in seconds.
807     }
808
809     public static class ShellyShortStatusRelay {
810         public String name; // FW 1.8+: Channel could now have a logical name
811         @SerializedName("is_valid")
812         public Boolean isValid;
813         public Boolean ison; // Whether output channel is on or off
814         @SerializedName("has_timer")
815         public Boolean hasTimer; // Whether a timer is currently armed for this channel
816         @SerializedName("timer_remaining")
817         public Integer timerRemaining;
818         public Boolean overpower; // Shelly1PM only if maximum allowed power was exceeded
819         public Double temperature; // Internal device temperature
820         public Boolean overtemperature; // Device over heated
821     }
822
823     public static class ShellyShortLightStatus {
824         public Boolean ison; // Whether output channel is on or off
825         public String mode; // color or white - valid only for Bulb and RGBW2 even Dimmer returns it also
826         public Integer brightness; // brightness: 0.100%
827         @SerializedName("has_timer")
828         public Boolean hasTimer;
829         @SerializedName("timer_duration")
830         public Integer timerDuration;
831     }
832
833     public static class ShellyStatusRelay {
834         public String name; // FW 1.8: Symbolic channel name is configurable
835
836         @SerializedName("wifi_sta")
837         public ShellySettingsWiFiNetwork wifiSta; // WiFi status
838         public ShellySettingsCoiot coiot; // Firmware 1.6+
839         public Integer serial;
840         public String mac; // MAC
841         public ArrayList<ShellyShortStatusRelay> relays; // relay status
842         public ArrayList<ShellySettingsMeter> meters; // current meter value
843         public ArrayList<ShellyInputState> inputs; // Firmware 1.5.6+
844
845         @SerializedName("ext_temperature")
846         public ShellyStatusSensor.ShellyExtTemperature extTemperature; // Shelly 1/1PM: sensor values
847         @SerializedName("ext_humidity")
848         public ShellyStatusSensor.ShellyExtHumidity extHumidity; // Shelly 1/1PM: sensor values
849
850         public Double temperature; // device temp acc. on the selected temp unit
851         public ShellySensorTmp tmp;
852     }
853
854     public static class ShellyStatusDimmer {
855         @SerializedName("wifi_sta")
856         public ShellySettingsWiFiNetwork wifiSta; // WiFi status
857         public ArrayList<ShellyShortLightStatus> lights; // relay status
858         public ArrayList<ShellySettingsMeter> meters; // current meter value
859
860         public ShellySensorTmp tmp;
861         public Boolean overtemperature;
862
863         public Boolean loaderror;
864         public Boolean overload;
865     }
866
867     public static class ShellyRollerStatus {
868         public String name; // FW 1.8: Symbolic name is configurable
869
870         @SerializedName("roller_pos")
871         public Integer rollerPos; // number Desired position in percent
872         public Integer duration; // If specified, the motor will move for this period in seconds. If missing, the
873                                  // value of maxtime in /settings/roller/N will be used.
874         public String state; // One of stop, open, close
875         public Double power; // Current power consumption in Watts
876         @SerializedName("is_valid")
877         public Boolean isValid; // If the power meter functions properly
878         @SerializedName("safety_switch")
879         public Boolean safetySwitch; // Whether the safety input is currently triggered
880         public Boolean overtemperature;
881         @SerializedName("stop_reason")
882         public String stopReason; // Last cause for stopping: normal, safety_switch, obstacle
883         @SerializedName("last_direction")
884         public String lastDirection; // Last direction of motion, open or close
885         public Boolean calibrating;
886         public Boolean positioning; // true when calibration was performed
887         @SerializedName("current_pos")
888         public Integer currentPos; // current position 0..100, 100=open
889     }
890
891     public static class ShellyOtaCheckResult {
892         public String status;
893     }
894
895     public static class ShellyApRoaming {
896         public Boolean enabled;
897         public Integer threshold;
898     }
899
900     public static class ShellySensorSleepMode {
901         public Integer period;
902         public String unit;
903     }
904
905     // Shelly TRV
906     public class ShellyThermnostat {
907         public class ShellyThermTargetTemp {
908             public Boolean enabled;
909             public Double value;
910             public String unit;
911         }
912
913         public class ShellyThermTemp {
914             public Double value;
915             public String units;
916             @SerializedName("is_valid")
917             public Boolean isValid;
918         }
919
920         public Double pos;
921         @SerializedName("target_t")
922         public ShellyThermTargetTemp targetTemp;
923         public Boolean schedule;
924         @SerializedName("schedule_profile")
925         public Integer profile;
926         @SerializedName("schedule_profile_names")
927         public String[] profileNames;
928         public ShellyThermTemp tmp;
929         @SerializedName("boost_minutes")
930         public Integer boostMinutes;
931         @SerializedName("window_open")
932         public Boolean windowOpen;
933     }
934
935     public static class ShellySensorTmp {
936         public Double value; // Temperature in configured unites
937         public String units; // 'C' or 'F'
938         public Double tC; // temperature in deg C
939         public Double tF; // temperature in deg F
940         @SerializedName("is_valid")
941         public Boolean isValid; // whether the internal sensor is operating properly
942     }
943
944     public static class ShellyStatusSensor {
945         // https://shelly-api-docs.shelly.cloud/#h-amp-t-settings
946
947         public static class ShellySensorHum {
948             public Double value; // relative humidity in %
949         }
950
951         public static class ShellySensorBat {
952             public Double value; // estimated remaining battery capacity in %
953             public Double voltage; // battery voltage
954         };
955
956         // Door/Window sensor
957         public static class ShellySensorState {
958             @SerializedName("is_valid")
959             public Boolean isValid; // whether the internal sensor is operating properly
960             public String state; // Shelly Door/Window
961
962             // Shelly Motion
963             public Boolean motion;
964             public Boolean vibration;
965             @SerializedName("timestamp")
966             public Long motionTimestamp;
967             @SerializedName("active")
968             public Boolean motionActive;
969         }
970
971         public static class ShellySensorLux {
972             @SerializedName("is_valid")
973             public Boolean isValid; // whether the internal sensor is operating properly
974             public Double value;
975
976             public String illumination;
977         }
978
979         public static class ShellySensorAccel {
980             public Integer tilt; // Tilt in Â°
981             public Integer vibration; // Whether vibration is detected
982         }
983
984         public static class ShellyMotionSettings {
985             public Integer sensitivity;
986             @SerializedName("blind_time_minutes")
987             public Integer blindTimeMinutes;
988             @SerializedName("pulse_count")
989             public Integer pulseCount;
990             @SerializedName("operating_mode")
991             public Integer operatingMode;
992             public Boolean enabled;
993         }
994
995         public static class ShellyExtTemperature {
996             public static class ShellyShortTemp {
997                 public String hwID; // e.g. "2882379497020381",
998                 public Double tC; // temperature in deg C
999                 public Double tF; // temperature in deg F
1000             }
1001
1002             // Shelly 1/1PM have up to 3 sensors
1003             // for whatever reasons it's not an array, but 3 independent elements
1004             @SerializedName("0")
1005             public ShellyShortTemp sensor1;
1006             @SerializedName("1")
1007             public ShellyShortTemp sensor2;
1008             @SerializedName("2")
1009             public ShellyShortTemp sensor3;
1010             @SerializedName("3")
1011             public ShellyShortTemp sensor4;
1012             @SerializedName("4")
1013             public ShellyShortTemp sensor5;
1014         }
1015
1016         public static class ShellyExtHumidity {
1017             public static class ShellyShortHum {
1018                 public Double hum; // Humidity reading of sensor 0, percent
1019             }
1020
1021             public ShellyExtHumidity() {
1022             }
1023
1024             public ShellyExtHumidity(double hum) {
1025                 sensor1 = new ShellyShortHum();
1026                 sensor1.hum = hum;
1027             }
1028
1029             @SerializedName("0")
1030             public ShellyShortHum sensor1;
1031         }
1032
1033         public static class ShellyExtVoltage {
1034             public static class ShellyShortVoltage {
1035                 public Double voltage;
1036             }
1037
1038             public ShellyExtVoltage() {
1039             }
1040
1041             public ShellyExtVoltage(double voltage) {
1042                 sensor1 = new ShellyShortVoltage();
1043                 sensor1.voltage = voltage;
1044             }
1045
1046             @SerializedName("0")
1047             public ShellyShortVoltage sensor1;
1048         }
1049
1050         public static class ShellyExtDigitalInput {
1051             public static class ShellyShortDigitalInput {
1052                 public Boolean state;
1053             }
1054
1055             public ShellyExtDigitalInput() {
1056             }
1057
1058             public ShellyExtDigitalInput(boolean state) {
1059                 sensor1 = new ShellyShortDigitalInput();
1060                 sensor1.state = state;
1061             }
1062
1063             @SerializedName("0")
1064             public ShellyShortDigitalInput sensor1;
1065         }
1066
1067         public static class ShellyExtAnalogInput {
1068             public static class ShellyShortAnalogInput {
1069                 public Double percent;
1070             }
1071
1072             public ShellyExtAnalogInput() {
1073             }
1074
1075             public ShellyExtAnalogInput(double percent) {
1076                 sensor1 = new ShellyShortAnalogInput();
1077                 sensor1.percent = percent;
1078             }
1079
1080             @SerializedName("0")
1081             public ShellyShortAnalogInput sensor1;
1082         }
1083
1084         public static class ShellyADC {
1085             public Double voltage;
1086         }
1087
1088         public static class ShellyExtSwitchSettings {
1089             public static class ShellyExtSwitchSettingsInput {
1090                 @SerializedName("relay_num")
1091                 public Integer relayNum;
1092             }
1093
1094             @SerializedName("0")
1095             public ShellyExtSwitchSettingsInput input0;
1096         }
1097
1098         public static class ShellyExtSwitchStatus {
1099             public static class ShellyExtSwitchStatusInput {
1100                 public Integer input;
1101             }
1102
1103             @SerializedName("0")
1104             public ShellyExtSwitchStatusInput input0;
1105         }
1106
1107         public ShellySensorTmp tmp;
1108         public ShellySensorHum hum;
1109         public ShellySensorLux lux;
1110         public ShellySensorAccel accel;
1111         public ShellySensorBat bat;
1112         @SerializedName("sensor")
1113         public ShellySensorState sensor;
1114         public Boolean smoke; // SHelly Smoke
1115         public Boolean flood; // Shelly Flood: true = flood condition detected
1116         public Boolean mute; // mute enabled/disabled
1117         @SerializedName("rain_sensor")
1118         public Boolean rainSensor; // Shelly Flood: true=in rain mode
1119
1120         public Boolean motion; // Shelly Sense: true=motion detected
1121         public Boolean charger; // Shelly Sense, TRV: true=charger connected
1122
1123         @SerializedName("act_reasons")
1124         public List<Object> actReasons; // HT/Smoke/Flood: list of reasons which woke up the device
1125
1126         @SerializedName("sensor_error")
1127         public String sensorError; // 1.5.7: Only displayed in case of error
1128
1129         // FW 1.7: Shelly Gas
1130         @SerializedName("gas_sensor")
1131         public ShellyStatusGasSensor gasSensor;
1132         @SerializedName("concentration")
1133         public ShellyStatusGasConcentration concentration;
1134         public ArrayList<ShellyStatusValve> valves;
1135
1136         // FW 1.7 Button
1137         @SerializedName("connect_retries")
1138         public Integer connectRetries;
1139         public ArrayList<ShellyInputState> inputs; // Firmware 1.5.6+
1140
1141         // Shelly UNI FW 1.9+
1142         public ArrayList<ShellyADC> adcs;
1143
1144         // Shelly TRV
1145         public Boolean calibrated;
1146         public ArrayList<ShellyThermnostat> thermostats;
1147     }
1148
1149     public static class ShellySettingsSmoke {
1150         @SerializedName("temperature_units")
1151         public String temperatureUnits; // Either 'C' or 'F'
1152         @SerializedName("temperature_threshold")
1153         public Integer temperatureThreshold; // Temperature delta (in configured degree units) which triggers an update
1154         @SerializedName("sleep_mode_period")
1155         public Integer sleepModePeriod; // Periodic update period in hours, between 1 and 24
1156     }
1157
1158     // Shelly Gas
1159     // "gas_sensor":{"sensor_state":"normal","self_test_state":"not_completed","alarm_state":"none"},
1160     // "concentration":{"ppm":0,"is_valid":true},
1161     public static class ShellyStatusGasSensor {
1162         @SerializedName("sensor_state")
1163         public String sensorState;
1164         @SerializedName("self_test_state")
1165         public String selfTestState;
1166         @SerializedName("alarm_state")
1167         public String alarmState;
1168     }
1169
1170     public static class ShellyStatusGasConcentration {
1171         public Integer ppm;
1172         @SerializedName("is_valid")
1173         public Boolean isValid;
1174     }
1175
1176     public static class ShellyStatusValve {
1177         public String state; // closed/opened/not_connected/failure/closing/opening/checking
1178     }
1179
1180     public static class ShellySettingsLight {
1181         public Integer red; // red brightness, 0..255, applies in mode="color"
1182         public Integer green; // green brightness, 0..255, applies in mode="color"
1183         public Integer blue; // blue brightness, 0..255, applies in mode="color"
1184         public Integer white; // white brightness, 0..255, applies in mode="color"
1185         public Integer gain; // gain for all channels, 0..100, applies in mode="color"
1186         public Integer temp; // color temperature in K, 3000..6500, applies in mode="white"
1187         public Integer brightness; // brightness, 0..100, applies in mode="white"
1188         public Integer effect; // Currently applied effect, description: 0: Off, 1: Meteor Shower, 2: Gradual
1189                                // Change, 3: Breath,
1190                                // 4: Flash, 5: On/Off Gradual, 6: Red/Green Change
1191         @SerializedName("default_state")
1192         public String defaultState; // one of on, off or last
1193         @SerializedName("auto_on")
1194         public Double autoOn; // see above
1195         @SerializedName("auto_off")
1196         public Double autoOff; // see above
1197
1198         public Integer dcpower; // RGW2:Set to true for 24 V power supply, false for 12 V
1199
1200         // Shelly Dimmer
1201         public String mode;
1202         public Boolean ison;
1203     }
1204
1205     public static class ShellySettingsNightMode { // FW1.5.7+
1206         public Integer enabled;
1207         @SerializedName("start_time")
1208         public String startTime;
1209         @SerializedName("end_time")
1210         public String endTime;
1211         public Integer brightness;
1212     }
1213
1214     public static class ShellyStatusLightChannel {
1215         public Boolean ison;
1216         public Double power;
1217         public Boolean overpower;
1218         @SerializedName("has_timer")
1219         public Boolean hasTimer;
1220         @SerializedName("timer_started")
1221         public Integer timerStarted;
1222         @SerializedName("timer_duration")
1223         public Integer timerDuration;
1224         @SerializedName("timer_remaining")
1225         public Integer timerRemaining;
1226
1227         public Integer red; // red brightness, 0..255, applies in mode="color"
1228         public Integer green; // green brightness, 0..255, applies in mode="color"
1229         public Integer blue; // blue brightness, 0..255, applies in mode="color"
1230         public Integer white; // white brightness, 0..255, applies in mode="color"
1231         public Integer gain; // gain for all channels, 0..100, applies in mode="color"
1232         public Integer temp; // color temperature in K, 3000..6500, applies in mode="white"
1233         public Integer brightness; // brightness, 0..100, applies in mode="white"
1234         public Integer effect; // Currently applied effect, description: 0: Off, 1: Meteor Shower, 2: Gradual
1235                                // Change, 3: Breath,
1236     }
1237
1238     public static class ShellyStatusLight {
1239         public Boolean ison; // Whether output channel is on or off
1240         public Integer input;
1241
1242         public ArrayList<ShellyStatusLightChannel> lights;
1243         public ArrayList<ShellySettingsMeter> meters;
1244     }
1245
1246     public static class ShellySenseKeyCode {
1247         String id; // ID of the stored IR code into Shelly Sense.
1248         String name; // Short description or name of the stored IR code.
1249     }
1250
1251     public static class ShellySendKeyList {
1252         @SerializedName("key_codes")
1253         public ArrayList<ShellySenseKeyCode> keyCodes;
1254     }
1255
1256     /**
1257      * Shelly Dimmer returns light[]. However, the structure doesn't match the lights[] of a Bulb/RGBW2.
1258      * The tag lights[] will be replaced with dimmers[] so this could be mapped to a different Gson structure.
1259      * The function requires that it's only called when the device is a dimmer - on get settings and get status
1260      *
1261      * @param json Input Json as received by the API
1262      * @return Modified Json
1263      */
1264     public static String fixDimmerJson(String json) {
1265         return !json.contains("\"lights\":[") ? json
1266                 : json.replaceFirst(java.util.regex.Pattern.quote("\"lights\":["), "\"dimmers\":[");
1267     }
1268
1269     /**
1270      * Convert Shelly Button events into OH button states
1271      *
1272      * @param eventType S/SS/SSS or L
1273      * @return OH button states
1274      */
1275     public static String mapButtonEvent(String eventType) {
1276         // decode different codings
1277         // 0..2: CoAP
1278         // S/SS/SSS/L: CoAP for Button and xi3
1279         // shortpush/double_shortpush/triple_shortpush/longpush: REST
1280         switch (eventType) {
1281             case "0":
1282                 return CommonTriggerEvents.RELEASED;
1283             case "1":
1284             case SHELLY_BTNEVENT_1SHORTPUSH:
1285             case SHELLY_EVENT_SHORTPUSH:
1286                 return CommonTriggerEvents.SHORT_PRESSED;
1287             case SHELLY_BTNEVENT_2SHORTPUSH:
1288             case SHELLY_EVENT_DOUBLE_SHORTPUSH:
1289                 return CommonTriggerEvents.DOUBLE_PRESSED;
1290             case SHELLY_BTNEVENT_3SHORTPUSH:
1291             case SHELLY_EVENT_TRIPLE_SHORTPUSH:
1292                 return "TRIPLE_PRESSED";
1293             case "2":
1294             case SHELLY_BTNEVENT_LONGPUSH:
1295             case SHELLY_EVENT_LONGPUSH:
1296                 return CommonTriggerEvents.LONG_PRESSED;
1297             case SHELLY_BTNEVENT_SHORTLONGPUSH:
1298             case SHELLY_EVENT_SHORT_LONGTPUSH:
1299                 return "SHORT_LONG_PRESSED";
1300             case SHELLY_BTNEVENT_LONGSHORTPUSH:
1301             case SHELLY_EVENT_LONG_SHORTPUSH:
1302                 return "LONG_SHORT_PRESSED";
1303             default:
1304                 return "";
1305         }
1306     }
1307 }