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