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