]> git.basschouten.com Git - openhab-addons.git/blob
38f9940616c6d9295e79e563fcff0586f7b012d6
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.shelly.internal.api2;
14
15 import java.util.ArrayList;
16
17 import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult;
18 import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2RpcBaseMessage.Shelly2RpcMessageError;
19
20 import com.google.gson.annotations.SerializedName;
21
22 /**
23  * {@link Shelly2ApiJsonDTO} wraps the Shelly REST API and provides various low level function to access the device api
24  * (not
25  * cloud api).
26  *
27  * @author Markus Michels - Initial contribution
28  */
29 public class Shelly2ApiJsonDTO {
30     public static final String SHELLYRPC_METHOD_CLASS_SHELLY = "Shelly";
31     public static final String SHELLYRPC_METHOD_CLASS_SWITCH = "Switch";
32
33     public static final String SHELLYRPC_METHOD_GETDEVCONFIG = "GetDeviceInfo";
34     public static final String SHELLYRPC_METHOD_GETSYSCONFIG = "GetSysConfig"; // only sys
35     public static final String SHELLYRPC_METHOD_GETCONFIG = "GetConfig"; // sys + components
36     public static final String SHELLYRPC_METHOD_GETSYSSTATUS = "GetSysStatus"; // only sys
37     public static final String SHELLYRPC_METHOD_GETSTATUS = "GetStatus"; // sys + components
38     public static final String SHELLYRPC_METHOD_REBOOT = "Shelly.Reboot";
39     public static final String SHELLYRPC_METHOD_RESET = "Shelly.FactoryReset";
40     public static final String SHELLYRPC_METHOD_CHECKUPD = "Shelly.CheckForUpdate";
41     public static final String SHELLYRPC_METHOD_UPDATE = "Shelly.Update";
42     public static final String SHELLYRPC_METHOD_AUTHSET = "Shelly.SetAuth";
43     public static final String SHELLYRPC_METHOD_SWITCH_STATUS = "Switch.GetStatus";
44     public static final String SHELLYRPC_METHOD_SWITCH_SET = "Switch.Set";
45     public static final String SHELLYRPC_METHOD_SWITCH_SETCONFIG = "Switch.SetConfig";
46     public static final String SHELLYRPC_METHOD_COVER_SETPOS = "Cover.GoToPosition";
47     public static final String SHELLY2_COVER_CMD_OPEN = "Open";
48     public static final String SHELLY2_COVER_CMD_CLOSE = "Close";
49     public static final String SHELLY2_COVER_CMD_STOP = "Stop";
50     public static final String SHELLYRPC_METHOD_LIGHT_STATUS = "Light.GetStatus";
51     public static final String SHELLYRPC_METHOD_LIGHT_SET = "Light.Set";
52     public static final String SHELLYRPC_METHOD_LIGHT_SETCONFIG = "Light.SetConfig";
53     public static final String SHELLYRPC_METHOD_LED_SETCONFIG = "WD_UI.SetConfig";
54     public static final String SHELLYRPC_METHOD_WIFIGETCONG = "Wifi.GetConfig";
55     public static final String SHELLYRPC_METHOD_WIFISETCONG = "Wifi.SetConfig";
56     public static final String SHELLYRPC_METHOD_ETHGETCONG = "Eth.GetConfig";
57     public static final String SHELLYRPC_METHOD_ETHSETCONG = "Eth.SetConfig";
58     public static final String SHELLYRPC_METHOD_BLEGETCONG = "BLE.GetConfig";
59     public static final String SHELLYRPC_METHOD_BLESETCONG = "BLE.SetConfig";
60     public static final String SHELLYRPC_METHOD_CLOUDSET = "Cloud.SetConfig";
61     public static final String SHELLYRPC_METHOD_WSGETCONFIG = "WS.GetConfig";
62     public static final String SHELLYRPC_METHOD_WSSETCONFIG = "WS.SetConfig";
63     public static final String SHELLYRPC_METHOD_EMDATARESET = "EMData.DeleteAllData";
64     public static final String SHELLYRPC_METHOD_EM1DATARESET = "EM1Data.DeleteAllData";
65     public static final String SHELLYRPC_METHOD_SMOKE_SETCONFIG = "Smoke.SetConfig";
66     public static final String SHELLYRPC_METHOD_SMOKE_MUTE = "Smoke.Mute";
67     public static final String SHELLYRPC_METHOD_SCRIPT_LIST = "Script.List";
68     public static final String SHELLYRPC_METHOD_SCRIPT_SETCONFIG = "Script.SetConfig";
69     public static final String SHELLYRPC_METHOD_SCRIPT_GETSTATUS = "Script.GetStatus";
70     public static final String SHELLYRPC_METHOD_SCRIPT_DELETE = "Script.Delete";
71     public static final String SHELLYRPC_METHOD_SCRIPT_CREATE = "Script.Create";
72     public static final String SHELLYRPC_METHOD_SCRIPT_GETCODE = "Script.GetCode";
73     public static final String SHELLYRPC_METHOD_SCRIPT_PUTCODE = "Script.PutCode";
74     public static final String SHELLYRPC_METHOD_SCRIPT_START = "Script.Start";
75     public static final String SHELLYRPC_METHOD_SCRIPT_STOP = "Script.Stop";
76
77     public static final String SHELLYRPC_METHOD_NOTIFYSTATUS = "NotifyStatus"; // inbound status
78     public static final String SHELLYRPC_METHOD_NOTIFYFULLSTATUS = "NotifyFullStatus"; // inbound status from bat device
79     public static final String SHELLYRPC_METHOD_NOTIFYEVENT = "NotifyEvent"; // inbound event
80
81     // Component types
82     public static final String SHELLY2_PROFILE_RELAY = "switch";
83     public static final String SHELLY2_PROFILE_ROLLER = "cover";
84
85     // Button types/modes
86     public static final String SHELLY2_BTNT_MOMENTARY = "momentary";
87     public static final String SHELLY2_BTNT_FLIP = "flip";
88     public static final String SHELLY2_BTNT_FOLLOW = "follow";
89     public static final String SHELLY2_BTNT_DETACHED = "detached";
90
91     // Input types
92     public static final String SHELLY2_INPUTT_SWITCH = "switch";
93     public static final String SHELLY2_INPUTT_BUTTON = "button";
94     public static final String SHELLY2_INPUTT_ANALOG = "analog"; // Shelly Addon: analogous input
95
96     // Switcm modes
97     public static final String SHELLY2_API_MODE_DETACHED = "detached";
98     public static final String SHELLY2_API_MODE_FOLLOW = "follow";
99
100     // Initial switch states
101     public static final String SHELLY2_API_ISTATE_ON = "on";
102     public static final String SHELLY2_API_ISTATE_OFF = "off";
103     public static final String SHELLY2_API_ISTATE_FOLLOWLAST = "restore_last";
104     public static final String SHELLY2_API_ISTATE_MATCHINPUT = "match_input";
105
106     // Cover/Roller modes
107     public static final String SHELLY2_RMODE_SINGLE = "single";
108     public static final String SHELLY2_RMODE_DUAL = "dual";
109     public static final String SHELLY2_RMODE_DETACHED = "detached";
110
111     public static final String SHELLY2_RSTATE_OPENING = "opening";
112     public static final String SHELLY2_RSTATE_OPEN = "open";
113     public static final String SHELLY2_RSTATE_CLOSING = "closing";
114     public static final String SHELLY2_RSTATE_CLOSED = "closed";
115     public static final String SHELLY2_RSTATE_STOPPED = "stopped";
116     public static final String SHELLY2_RSTATE_CALIB = "calibrating";
117
118     // Event notifications
119     public static final String SHELLY2_EVENT_BTNUP = "btn_up";
120     public static final String SHELLY2_EVENT_BTNDOWN = "btn_down";
121     public static final String SHELLY2_EVENT_1PUSH = "single_push";
122     public static final String SHELLY2_EVENT_2PUSH = "double_push";
123     public static final String SHELLY2_EVENT_3PUSH = "triple_push";
124     public static final String SHELLY2_EVENT_LPUSH = "long_push";
125     public static final String SHELLY2_EVENT_SLPUSH = "short_long_push";
126     public static final String SHELLY2_EVENT_LSPUSH = "long_short_push";
127
128     public static final String SHELLY2_EVENT_SLEEP = "sleep";
129     public static final String SHELLY2_EVENT_CFGCHANGED = "config_changed";
130     public static final String SHELLY2_EVENT_OTASTART = "ota_begin";
131     public static final String SHELLY2_EVENT_OTAPROGRESS = "ota_progress";
132     public static final String SHELLY2_EVENT_OTADONE = "ota_success";
133     public static final String SHELLY2_EVENT_WIFICONNFAILED = "sta_connect_fail";
134     public static final String SHELLY2_EVENT_WIFIDISCONNECTED = "sta_disconnected";
135
136     // BLU events
137     public static final String SHELLY2_BLU_GWSCRIPT = "oh-blu-scanner.js";
138     public static final String SHELLY2_EVENT_BLUPREFIX = "oh-blu.";
139     public static final String SHELLY2_EVENT_BLUSCAN = SHELLY2_EVENT_BLUPREFIX + "scan_result";
140     public static final String SHELLY2_EVENT_BLUDATA = SHELLY2_EVENT_BLUPREFIX + "data";
141
142     // Error Codes
143     public static final String SHELLY2_ERROR_OVERPOWER = "overpower";
144     public static final String SHELLY2_ERROR_OVERTEMP = "overtemp";
145     public static final String SHELLY2_ERROR_OVERVOLTAGE = "overvoltage";
146
147     // Wakeup reasons (e.g. Plus HT)
148     public static final String SHELLY2_WAKEUPO_BOOT_POWERON = "poweron";
149     public static final String SHELLY2_WAKEUPO_BOOT_RESTART = "software_restart";
150     public static final String SHELLY2_WAKEUPO_BOOT_WAKEUP = "deepsleep_wake";
151     public static final String SHELLY2_WAKEUPO_BOOT_INTERNAL = "internal";
152     public static final String SHELLY2_WAKEUPO_BOOT_UNKNOWN = "unknown";
153
154     public static final String SHELLY2_WAKEUPOCAUSE_BUTTON = "button";
155     public static final String SHELLY2_WAKEUPOCAUSE_USB = "usb";
156     public static final String SHELLY2_WAKEUPOCAUSE_PERIODIC = "periodic";
157     public static final String SHELLY2_WAKEUPOCAUSE_UPDATE = "status_update";
158     public static final String SHELLY2_WAKEUPOCAUSE_UNDEFINED = "undefined";
159
160     // Dimmer US: LED power modes
161     public static final String SHELLY2_POWERLED_ON = "on";
162     public static final String SHELLY2_POWERLED_OFF = "off";
163     public static final String SHELLY2_POWERLED_MATCH = "match_output";
164     public static final String SHELLY2_POWERLED_INVERT = "inverted_output";
165
166     public class Shelly2DevConfigBle {
167         public Boolean enable;
168     }
169
170     public class Shelly2DevConfigEth {
171         public Boolean enable;
172         public String ipv4mode;
173         public String ip;
174         public String netmask;
175         public String gw;
176         public String nameserver;
177     }
178
179     public static class Shelly2DeviceSettings {
180         public String name;
181         public String id;
182         public String mac;
183         public String model;
184         public Integer gen;
185         @SerializedName("fw_id")
186         public String firmware;
187         public String ver;
188         public String app;
189         @SerializedName("auth_en")
190         public Boolean authEnable;
191         @SerializedName("auth_domain")
192         public String authDomain;
193     }
194
195     public static class Shelly2DeviceConfigAp {
196         public static class Shelly2DeviceConfigApRE {
197             public Boolean enable;
198         }
199
200         public Boolean enable;
201         public String ssid;
202         public String password;
203         @SerializedName("is_open")
204         public Boolean isOpen;
205         @SerializedName("range_extender")
206         Shelly2DeviceConfigApRE rangeExtender;
207     }
208
209     public static class Shelly2DeviceConfig {
210         public class Shelly2DeviceConfigSys {
211             public class Shelly2DeviceConfigDevice {
212                 public String name;
213                 public String mac;
214                 @SerializedName("fw_id")
215                 public String fwId;
216                 public String profile;
217                 @SerializedName("eco_mode")
218                 public Boolean ecoMode;
219                 public Boolean discoverable;
220             }
221
222             public class Shelly2DeviceConfigLocation {
223                 public String tz;
224                 public Double lat;
225                 public Double lon;
226             }
227
228             public class Shelly2DeviceConfigSntp {
229                 public String server;
230             }
231
232             public class Shelly2DeviceConfigSleep {
233                 @SerializedName("wakeup_period")
234                 public Integer wakeupPeriod;
235             }
236
237             public class Shelly2DeviceConfigDebug {
238                 public class Shelly2DeviceConfigDebugMqtt {
239                     public Boolean enable;
240                 }
241
242                 public class Shelly2DeviceConfigDebugWebSocket {
243                     public Boolean enable;
244                 }
245
246                 public class Shelly2DeviceConfigDebugUdp {
247                     public String addr;
248                 }
249
250                 public Shelly2DeviceConfigDebugMqtt mqtt;
251                 public Shelly2DeviceConfigDebugWebSocket websocket;
252                 public Shelly2DeviceConfigDebugUdp udp;
253             }
254
255             public class Shelly2DeviceConfigUiData {
256                 public String cover; // hold comma seperated list of roller favorites
257             }
258
259             public class Shelly2DeviceConfigRpcUdp {
260                 @SerializedName("dst_addr")
261                 public String dstAddr;
262                 @SerializedName("listenPort")
263                 public String listenPort;
264             }
265
266             @SerializedName("cfg_rev")
267             public Integer cfgRevision;
268             public Shelly2DeviceConfigDevice device;
269             public Shelly2DeviceConfigLocation location;
270             public Shelly2DeviceConfigSntp sntp;
271             public Shelly2DeviceConfigSleep sleep;
272             public Shelly2DeviceConfigDebug debug;
273             @SerializedName("ui_data")
274             public Shelly2DeviceConfigUiData uiData;
275             @SerializedName("rpc_udp")
276             public Shelly2DeviceConfigRpcUdp rpcUdp;
277         }
278
279         public class Shelly2DevConfigInput {
280             public Integer id;
281             public String name;
282             public String type;
283             public Boolean invert;
284             @SerializedName("factory_reset")
285             public Boolean factoryReset;
286             @SerializedName("report_thr")
287             public Double reportTreshold; // only for type analog
288         }
289
290         public class Shelly2DevConfigSwitch {
291             public Integer id;
292             public String name;
293
294             @SerializedName("in_mode")
295             public String mode;
296
297             @SerializedName("initial_state")
298             public String initialState;
299             @SerializedName("auto_on")
300             public Boolean autoOn;
301             @SerializedName("auto_on_delay")
302             public Double autoOnDelay;
303             @SerializedName("auto_off")
304             public Boolean autoOff;
305             @SerializedName("auto_off_delay")
306             public Double autoOffDelay;
307             @SerializedName("power_limit")
308             public Integer powerLimit;
309             @SerializedName("voltage_limit")
310             public Integer voltageLimit;
311             @SerializedName("current_limit")
312             public Double currentLimit;
313         }
314
315         public static class Shelly2DevConfigEm {
316             public Integer id;
317             public String name;
318             @SerializedName("blink_mode_selector")
319             public String blinkModeSelector;
320             @SerializedName("phase_selector")
321             public String phase_selector;
322             @SerializedName("monitor_phase_sequence")
323             public Boolean monitorPhaseSequence;
324         }
325
326         public class Shelly2DevConfigPm1 {
327             public Integer id;
328             public String name;
329         }
330
331         public class Shelly2DevConfigCover {
332             public class Shelly2DeviceConfigCoverMotor {
333                 @SerializedName("idle_power_thr")
334                 public Double idle_powerThr;
335             }
336
337             public class Shelly2DeviceConfigCoverSafetySwitch {
338                 public Boolean enable;
339                 public String direction;
340                 public String action;
341                 @SerializedName("allowed_move")
342                 public String allowedMove;
343             }
344
345             public class Shelly2DeviceConfigCoverObstructionDetection {
346                 public Boolean enable;
347                 public String direction;
348                 public String action;
349                 @SerializedName("power_thr")
350                 public Integer powerThr;
351                 public Double holdoff;
352             }
353
354             public String id;
355             public String name;
356             public Shelly2DeviceConfigCoverMotor motor;
357             @SerializedName("maxtime_open")
358             public Double maxtimeOpen;
359             @SerializedName("maxtime_close")
360             public Double maxtimeClose;
361             @SerializedName("initial_state")
362             public String initialState;
363             @SerializedName("invert_directions")
364             public Boolean invertDirections;
365             @SerializedName("in_mode")
366             public String inMode;
367             @SerializedName("swap_inputs")
368             public Boolean swapInputs;
369             @SerializedName("safety_switch")
370             public Shelly2DeviceConfigCoverSafetySwitch safetySwitch;
371             @SerializedName("power_limit")
372             public Integer powerLimit;
373             @SerializedName("voltage_limit")
374             public Integer voltageLimit;
375             @SerializedName("current_limit")
376             public Double currentLimit;
377             @SerializedName("obstruction_detection")
378             public Shelly2DeviceConfigCoverObstructionDetection obstructionDetection;
379         }
380
381         public static class Shelly2ConfigSmoke {
382             public Integer id;
383             public Boolean alarm;
384             public Boolean mute;
385         }
386
387         public static class Shelly2GetConfigLight {
388             public static class Shelly2GetConfigLightDefault {
389                 public Integer brightness;
390             }
391
392             public static class Shelly2GetConfigLightNightMode {
393                 public boolean enable;
394                 public Integer brightness;
395             }
396
397             public Integer id;
398             public String name;
399             @SerializedName("initial_state")
400             public String initialState;
401             @SerializedName("auto_on")
402             public Boolean autoOn;
403             @SerializedName("auto_off")
404             public Boolean autoOff;
405             @SerializedName("auto_on_delay")
406             public Double autoOnDelay;
407             @SerializedName("auto_off_delay")
408             public Double autoOffDelay;
409             @SerializedName("default")
410             public Shelly2GetConfigLightDefault defaultCfg;
411             @SerializedName("night_mode")
412             public Shelly2GetConfigLightNightMode nightMode;
413         }
414
415         public class Shelly2DeviceConfigLed {
416             @SerializedName("sys_led_enable")
417             public Boolean sysLedEnable;
418             @SerializedName("power_led")
419             public String powerLed;
420         }
421
422         public static class Shelly2GetConfigResult {
423
424             public class Shelly2DevConfigCloud {
425                 public Boolean enable;
426                 public String server;
427             }
428
429             public class Shelly2DevConfigMqtt {
430                 public Boolean enable;
431                 public String server;
432                 public String user;
433                 @SerializedName("topic_prefix:0")
434                 public String topicPrefix;
435                 @SerializedName("rpc_ntf")
436                 public String rpcNtf;
437                 @SerializedName("status_ntf")
438                 public String statusNtf;
439             }
440
441             public Shelly2DevConfigBle ble;
442             public Shelly2DevConfigEth eth;
443             public Shelly2DevConfigCloud cloud;
444             public Shelly2DevConfigMqtt mqtt;
445             public Shelly2DeviceConfigSys sys;
446             public Shelly2DeviceConfigWiFi wifi;
447             @SerializedName("wd_ui")
448             public Shelly2DeviceConfigLed led;
449
450             @SerializedName("input:0")
451             public Shelly2DevConfigInput input0;
452             @SerializedName("input:1")
453             public Shelly2DevConfigInput input1;
454             @SerializedName("input:2")
455             public Shelly2DevConfigInput input2;
456             @SerializedName("input:3")
457             public Shelly2DevConfigInput input3;
458
459             @SerializedName("switch:0")
460             public Shelly2DevConfigSwitch switch0;
461             @SerializedName("switch:1")
462             public Shelly2DevConfigSwitch switch1;
463             @SerializedName("switch:2")
464             public Shelly2DevConfigSwitch switch2;
465             @SerializedName("switch:3")
466             public Shelly2DevConfigSwitch switch3;
467             @SerializedName("switch:100")
468             public Shelly2DevConfigSwitch switch100; // Pro 3EM Add-On
469
470             @SerializedName("em:0")
471             public Shelly2DevConfigEm em0;
472             @SerializedName("em1:0")
473             public Shelly2DevConfigEm em10;
474             @SerializedName("em1:1")
475             public Shelly2DevConfigEm em11;
476             @SerializedName("pm1:0")
477             public Shelly2DevConfigPm1 pm10;
478
479             @SerializedName("cover:0")
480             public Shelly2DevConfigCover cover0;
481
482             @SerializedName("light:0")
483             public Shelly2GetConfigLight light0;
484
485             @SerializedName("smoke:0")
486             public Shelly2ConfigSmoke smoke0;
487         }
488
489         public class Shelly2DeviceConfigSta {
490             public String ssid;
491             public String password;
492             @SerializedName("is_open")
493             public Boolean isOpen;
494             public Boolean enable;
495             public String ipv4mode;
496             public String ip;
497             public String netmask;
498             public String gw;
499             public String nameserver;
500         }
501
502         public class Shelly2DeviceConfigRoam {
503             @SerializedName("rssi_thr")
504             public Integer rssiThr;
505             public Integer interval;
506         }
507
508         public class Shelly2DeviceConfigWiFi {
509             public Shelly2DeviceConfigAp ap;
510             public Shelly2DeviceConfigSta sta;
511             public Shelly2DeviceConfigSta sta1;
512             public Shelly2DeviceConfigRoam roam;
513         }
514
515         public String id;
516         public String src;
517         public Shelly2GetConfigResult result;
518     }
519
520     public static class Shelly2DeviceStatus {
521         public class Shelly2InputStatus {
522             public Integer id;
523             public Boolean state;
524             public Double percent; // analog input only
525             public ArrayList<String> errors;// shown only if at least one error is present.
526         }
527
528         public static class Shelly2DeviceStatusLight {
529             public Integer id;
530             public String source;
531             public Boolean output;
532             public Double brightness;
533             @SerializedName("timer_started_at")
534             public Double timerStartedAt;
535             @SerializedName("timer_duration")
536             public Integer timerDuration;
537         }
538
539         public static class Shelly2DeviceStatusResult {
540             public class Shelly2DeviceStatusBle {
541
542             }
543
544             public class Shelly2DeviceStatusCloud {
545                 public Boolean connected;
546             }
547
548             public class Shelly2DeviceStatusMqqt {
549                 public Boolean connected;
550             }
551
552             public class Shelly2CoverStatus {
553                 public Integer id;
554                 public String source;
555                 public String state;
556                 public Double apower;
557                 public Double voltage;
558                 public Double current;
559                 public Double pf;
560                 public Shelly2Energy aenergy;
561                 @SerializedName("current_pos")
562                 public Integer currentPos;
563                 @SerializedName("target_pos")
564                 public Integer targetPos;
565                 @SerializedName("move_timeout")
566                 public Double moveTimeout;
567                 @SerializedName("move_started_at")
568                 public Double moveStartedAt;
569                 @SerializedName("pos_control")
570                 public Boolean posControl;
571                 public Shelly2DeviceStatusTemp temperature;
572                 public ArrayList<String> errors;
573             }
574
575             public class Shelly2DeviceStatusHumidity {
576                 public Integer id;
577                 public Double rh;
578             }
579
580             public class Shelly2DeviceStatusIlluminance {
581                 public Integer id;
582                 public Double lux;
583                 public String illumination;
584             }
585
586             public class Shelly2DeviceStatusVoltage {
587                 public Integer id;
588                 public Double voltage;
589             }
590
591             public class Shelly2DeviceStatusTempId extends Shelly2DeviceStatusTemp {
592                 public Integer id;
593             }
594
595             public static class Shelly2DeviceStatusPower {
596                 public static class Shelly2DeviceStatusBattery {
597                     @SerializedName("V")
598                     public Double volt;
599                     public Double percent;
600                 }
601
602                 public static class Shelly2DeviceStatusCharger {
603                     public Boolean present;
604                 }
605
606                 public Integer id;
607                 public Shelly2DeviceStatusBattery battery;
608                 public Shelly2DeviceStatusCharger external;
609             }
610
611             public static class Shelly2DeviceStatusEm {
612                 public Integer id;
613
614                 @SerializedName("a_current")
615                 public Double aCurrent;
616                 @SerializedName("a_voltage")
617                 public Double aVoltage;
618                 @SerializedName("a_act_power")
619                 public Double aActPower;
620                 @SerializedName("a_aprt_power")
621                 public Double aAprtPower;
622                 @SerializedName("a_pf")
623                 public Double aPF;
624
625                 @SerializedName("b_current")
626                 public Double bCurrent;
627                 @SerializedName("b_voltage")
628                 public Double bVoltage;
629                 @SerializedName("b_act_power")
630                 public Double bActPower;
631                 @SerializedName("b_aprt_power")
632                 public Double bAprtPower;
633                 @SerializedName("b_pf")
634                 public Double bPF;
635
636                 @SerializedName("c_current")
637                 public Double cCurrent;
638                 @SerializedName("c_voltage")
639                 public Double cVoltage;
640                 @SerializedName("c_act_power")
641                 public Double cActPower;
642                 @SerializedName("c_aprt_power")
643                 public Double cAprtPower;
644                 @SerializedName("c_pf")
645                 public Double cPF;
646
647                 @SerializedName("n_current")
648                 public Double nCurrent;
649
650                 @SerializedName("total_current")
651                 public Double totalCurrent;
652                 @SerializedName("total_act_power")
653                 public Double totalActPower;
654                 @SerializedName("total_aprt_power")
655                 public Double totalAprtPower;
656             }
657
658             public static class Shelly2DeviceStatusEmData {
659                 public Integer id;
660                 public String[] errors;
661             }
662
663             public class Shelly2DeviceStatusSmoke {
664                 public Integer id;
665                 public Boolean alarm;
666                 public Boolean mute;
667             }
668
669             public Shelly2DeviceStatusBle ble;
670             public Shelly2DeviceStatusCloud cloud;
671             public Shelly2DeviceStatusMqqt mqtt;
672             public Shelly2DeviceStatusSys sys;
673             public Shelly2DeviceStatusSysWiFi wifi;
674
675             @SerializedName("input:0")
676             public Shelly2InputStatus input0;
677             @SerializedName("input:1")
678             public Shelly2InputStatus input1;
679             @SerializedName("input:2")
680             public Shelly2InputStatus input2;
681             @SerializedName("input:3")
682             public Shelly2InputStatus input3;
683             @SerializedName("input:100")
684             public Shelly2InputStatus input100; // Digital Input from Add-On
685
686             @SerializedName("switch:0")
687             public Shelly2RelayStatus switch0;
688             @SerializedName("switch:1")
689             public Shelly2RelayStatus switch1;
690             @SerializedName("switch:2")
691             public Shelly2RelayStatus switch2;
692             @SerializedName("switch:3")
693             public Shelly2RelayStatus switch3;
694             @SerializedName("switch:100")
695             public Shelly2RelayStatus switch100; // Pro 3EM Add-On
696
697             @SerializedName("pm1:0")
698             public Shelly2RelayStatus pm10;
699
700             @SerializedName("em:0")
701             public Shelly2DeviceStatusEm em0;
702             @SerializedName("emdata:0")
703             public Shelly2DeviceStatusEmData emdata0;
704             @SerializedName("em1:0")
705             public Shelly2StatusEm1 em10;
706             @SerializedName("em1:1")
707             public Shelly2StatusEm1 em11;
708             @SerializedName("em1data:0")
709             public Shelly2DeviceStatusEmData em1data0;
710
711             @SerializedName("cover:0")
712             public Shelly2CoverStatus cover0;
713
714             @SerializedName("light:0")
715             public Shelly2DeviceStatusLight light0;
716
717             @SerializedName("temperature:0")
718             public Shelly2DeviceStatusTempId temperature0;
719             @SerializedName("temperature:100")
720             public Shelly2DeviceStatusTempId temperature100;
721             @SerializedName("temperature:101")
722             public Shelly2DeviceStatusTempId temperature101;
723             @SerializedName("temperature:102")
724             public Shelly2DeviceStatusTempId temperature102;
725             @SerializedName("temperature:103")
726             public Shelly2DeviceStatusTempId temperature103;
727             @SerializedName("temperature:104")
728             public Shelly2DeviceStatusTempId temperature104;
729
730             @SerializedName("humidity:0")
731             public Shelly2DeviceStatusHumidity humidity0;
732             @SerializedName("humidity:100")
733             public Shelly2DeviceStatusHumidity humidity100;
734
735             @SerializedName("illuminance:0")
736             Shelly2DeviceStatusIlluminance illuminance0;
737
738             @SerializedName("smoke:0")
739             public Shelly2DeviceStatusSmoke smoke0;
740
741             @SerializedName("voltmeter:100")
742             public Shelly2DeviceStatusVoltage voltmeter100;
743
744             @SerializedName("devicepower:0")
745             public Shelly2DeviceStatusPower devicepower0;
746         }
747
748         public class Shelly2DeviceStatusSys {
749             public class Shelly2DeviceStatusSysAvlUpdate {
750                 public class Shelly2DeviceStatusSysUpdate {
751                     public String version;
752                 }
753
754                 public Shelly2DeviceStatusSysUpdate stable;
755                 public Shelly2DeviceStatusSysUpdate beta;
756             }
757
758             public class Shelly2DeviceStatusWakeup {
759                 public String boot;
760                 public String cause;
761             }
762
763             public String mac;
764             @SerializedName("restart_required")
765             public Boolean restartRequired;
766             public String time;
767             public Long unixtime;
768             public Long uptime;
769             @SerializedName("ram_size")
770             public Long ramSize;
771             @SerializedName("ram_free")
772             public Long ramFree;
773             @SerializedName("fs_size")
774             public Long fsSize;
775             @SerializedName("fs_free")
776             public Long fsFree;
777             @SerializedName("cfg_rev")
778             public Integer cfg_rev;
779             @SerializedName("available_updates")
780             public Shelly2DeviceStatusSysAvlUpdate availableUpdates;
781             @SerializedName("webhook_rev")
782             public Integer webHookRev;
783             @SerializedName("wakeup_reason")
784             public Shelly2DeviceStatusWakeup wakeUpReason;
785             @SerializedName("wakeup_period")
786             public Integer wakeupPeriod;
787         }
788
789         public class Shelly2DeviceStatusSysWiFi {
790             @SerializedName("sta_ip")
791             public String staIP;
792             public String status;
793             public String ssid;
794             public Integer rssi;
795             @SerializedName("ap_client_count")
796             public Integer apClientCount;
797         }
798
799         public String id;
800         public String src;
801         public Shelly2DeviceStatusResult result;
802     }
803
804     public static class Shelly2RelayStatus {
805         public Integer id;
806         public String source;
807         public Boolean output;
808         @SerializedName("timer_started_at")
809         public Double timerStartetAt;
810         @SerializedName("timer_duration")
811         public Integer timerDuration;
812         public Double apower;
813         public Double voltage;
814         public Double current;
815         public Double pf;
816         public Shelly2Energy aenergy;
817         public Shelly2DeviceStatusTemp temperature;
818         public String[] errors;
819     }
820
821     public static class Shelly2Pm1Status {
822         public Integer id;
823         public String source;
824         public Boolean output;
825         @SerializedName("timer_started_at")
826         public Double timerStartetAt;
827         @SerializedName("timer_duration")
828         public Integer timerDuration;
829         public Double apower;
830         public Double voltage;
831         public Double current;
832         public Double pf;
833         public Shelly2Energy aenergy;
834         public Shelly2DeviceStatusTemp temperature;
835         public String[] errors;
836     }
837
838     public static class Shelly2StatusEm1 {
839         public Integer id;
840         public Double current;
841         public Double voltage;
842         @SerializedName("act_power")
843         public Double actPower;
844         @SerializedName("aprt_power")
845         public Double aptrPower;
846         public Double pf;
847         public String calibration;
848         public ArrayList<String> errors;
849     }
850
851     public static class Shelly2DeviceStatusTemp {
852         public Double tC;
853         public Double tF;
854     }
855
856     public static class Shelly2Energy {
857         // "switch:1":{"id":1,"aenergy":{"total":0.003,"by_minute":[0.000,0.000,0.000],"minute_ts":1619910239}}}}
858         public Double total;
859         @SerializedName("by_minute")
860         public Double[] byMinute;
861         @SerializedName("minute_ts")
862         public Long minuteTs;
863     }
864
865     public static class Shelly2ConfigParms {
866         public String name;
867         public Boolean enable;
868         public String server;
869         @SerializedName("ssl_ca")
870         public String sslCA;
871
872         // WiFi.SetConfig
873         public Shelly2DeviceConfigAp ap;
874
875         // Switch.SetConfig
876         @SerializedName("auto_on")
877         public Boolean autoOn;
878         @SerializedName("auto_on_delay")
879         public Double autoOnDelay;
880         @SerializedName("auto_off")
881         public Boolean autoOff;
882         @SerializedName("auto_off_delay")
883         public Double autoOffDelay;
884
885         // WD_UI.SetConfig
886         @SerializedName("sys_led_enable")
887         public Boolean sysLedEnable;
888         @SerializedName("power_led")
889         public String powerLed;
890     }
891
892     public static class Shelly2RpcRequest {
893         public Integer id = 0;
894         public String method;
895
896         public static class Shelly2RpcRequestParams {
897             public Integer id = 1;
898
899             // Cover
900             public Integer pos;
901             public Boolean on;
902
903             // Dimmer / Light
904             public Integer brightness;
905             @SerializedName("toggle_after")
906             public Integer toggleAfter;
907
908             // Shelly.SetAuth
909             public String user;
910             public String realm;
911             public String ha1;
912
913             // Shelly.Update
914             public String stage;
915             public String url;
916
917             // Cloud.SetConfig
918             public Shelly2ConfigParms config;
919
920             // Script
921             public String name;
922
923             public Shelly2RpcRequestParams withConfig() {
924                 config = new Shelly2ConfigParms();
925                 return this;
926             }
927         }
928
929         public Shelly2RpcRequestParams params = new Shelly2RpcRequestParams();
930
931         public Shelly2RpcRequest() {
932         }
933
934         public Shelly2RpcRequest withMethod(String method) {
935             this.method = method;
936             return this;
937         }
938
939         public Shelly2RpcRequest withId(int id) {
940             params.id = id;
941             return this;
942         }
943
944         public Shelly2RpcRequest withPos(int pos) {
945             params.pos = pos;
946             return this;
947         }
948
949         public Shelly2RpcRequest withName(String name) {
950             params.name = name;
951             return this;
952         }
953     }
954
955     public static class Shelly2WsConfigResponse {
956         public Integer id;
957         public String src;
958
959         public static class Shelly2WsConfigResult {
960             @SerializedName("restart_required")
961             public Boolean restartRequired;
962         }
963
964         public Shelly2WsConfigResult result;
965     }
966
967     public static class ShellyScriptListResponse {
968         public static class ShellyScriptListEntry {
969             public Integer id;
970             public String name;
971             public Boolean enable;
972             public Boolean running;
973         }
974
975         public ArrayList<ShellyScriptListEntry> scripts;
976     }
977
978     public static class ShellyScriptResponse {
979         public Integer id;
980         public Boolean running;
981         public Integer len;
982         public String data;
983     }
984
985     public static class ShellyScriptPutCodeParams {
986         public Integer id;
987         public String code;
988         public Boolean append;
989     }
990
991     public static class Shelly2RpcBaseMessage {
992         // Basic message format, e.g.
993         // {"id":1,"src":"localweb528","method":"Shelly.GetConfig"}
994         public class Shelly2RpcMessageError {
995             public Integer code;
996             public String message;
997         }
998
999         public Integer id;
1000         public String src;
1001         public String dst;
1002         public String component;
1003         public String method;
1004         public Object params;
1005         public String event;
1006         public Object result;
1007         public Shelly2AuthRequest auth;
1008         public Shelly2RpcMessageError error;
1009     }
1010
1011     public static class Shelly2RpcNotifyStatus {
1012         public static class Shelly2NotifyStatus extends Shelly2DeviceStatusResult {
1013             public Double ts;
1014         }
1015
1016         public Integer id;
1017         public String src;
1018         public String dst;
1019         public String method;
1020         public Shelly2NotifyStatus params;
1021         public Shelly2NotifyStatus result;
1022         public Shelly2RpcMessageError error;
1023     }
1024
1025     public static String SHELLY2_AUTHTTYPE_DIGEST = "digest";
1026     public static String SHELLY2_AUTHTTYPE_STRING = "string";
1027     public static String SHELLY2_AUTHALG_SHA256 = "SHA-256";
1028     // = ':auth:'+HexHash("dummy_method:dummy_uri");
1029     public static String SHELLY2_AUTH_NOISE = "6370ec69915103833b5222b368555393393f098bfbfbb59f47e0590af135f062";
1030
1031     public static class Shelly2AuthRequest {
1032         public String username;
1033         public Long nonce;
1034         public Long cnonce;
1035         public Integer nc;
1036         public String realm;
1037         public String algorithm;
1038         public String response;
1039         @SerializedName("auth_type")
1040         public String authType;
1041     }
1042
1043     public static class Shelly2AuthResponse { // on 401 message contains the auth info
1044         @SerializedName("auth_type")
1045         public String authType;
1046         public Long nonce;
1047         public Integer nc;
1048         public String realm;
1049         public String algorithm;
1050     }
1051
1052     // BTHome samples
1053     // BLU Button 1
1054     // {"component":"script:2", "id":2, "event":"oh-blu.scan_result",
1055     // "data":{"addr":"bc:02:6e:c3:a6:c7","rssi":-62,"tx_power":-128}, "ts":1682877414.21}
1056     // {"component":"script:2", "id":2, "event":"oh-blu.data",
1057     // "data":{"encryption":false,"BTHome_version":2,"pid":205,"Battery":100,"Button":1,"addr":"b4:35:22:fd:b3:81","rssi":-68},
1058     // "ts":1682877399.22}
1059     //
1060     // BLU Door Window
1061     // {"component":"script:2", "id":2, "event":"oh-blu.scan_result",
1062     // "data":{"addr":"bc:02:6e:c3:a6:c7","rssi":-62,"tx_power":-128}, "ts":1682877414.21}
1063     // {"component":"script:2", "id":2, "event":"oh-blu.data",
1064     // "data":{"encryption":false,"BTHome_version":2,"pid":38,"Battery":100,"Illuminance":0,"Window":1,"Rotation":0,"addr":"bc:02:6e:c3:a6:c7","rssi":-62},
1065     // "ts":1682877414.25}
1066
1067     public class Shelly2NotifyEventMessage {
1068         public String addr;
1069         public String name;
1070         public Boolean encryption;
1071         @SerializedName("BTHome_version")
1072         public Integer bthVersion;
1073         public Integer pid;
1074         @SerializedName("Battery")
1075         public Integer battery;
1076         @SerializedName("Button")
1077         public Integer buttonEvent;
1078         @SerializedName("Illuminance")
1079         public Integer illuminance;
1080         @SerializedName("Window")
1081         public Integer windowState;
1082         @SerializedName("Rotation")
1083         public Double rotation;
1084
1085         public Integer rssi;
1086         public Integer tx_power;
1087     }
1088
1089     public class Shelly2NotifyEvent {
1090         public Integer id;
1091         public Double ts;
1092         public String component;
1093         public String event;
1094         public Shelly2NotifyEventMessage data;
1095         public String msg;
1096         public Integer reason;
1097         @SerializedName("cfg_rev")
1098         public Integer cfgRev;
1099     }
1100
1101     public class Shelly2NotifyEventData {
1102         public Double ts;
1103         public ArrayList<Shelly2NotifyEvent> events;
1104     }
1105
1106     public static class Shelly2RpcNotifyEvent {
1107         public String src;
1108         public Double ts;
1109         public Shelly2NotifyEventData params;
1110     }
1111 }