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