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