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