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