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