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