]> git.basschouten.com Git - openhab-addons.git/blob
672f9e3b8cc962a52d5957a8f064e935a80d0ee4
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.shelly.internal.api2;
14
15 import java.util.ArrayList;
16
17 import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult;
18 import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2RpcBaseMessage.Shelly2RpcMessageError;
19
20 import com.google.gson.annotations.SerializedName;
21
22 /**
23  * {@link Shelly2ApiJsonDTO} wraps the Shelly REST API and provides various low level function to access the device api
24  * (not
25  * cloud api).
26  *
27  * @author Markus Michels - Initial contribution
28  */
29 public class Shelly2ApiJsonDTO {
30     public static final String SHELLYRPC_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_ROLLER = "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 Integer gen;
187         @SerializedName("fw_id")
188         public String firmware;
189         public String ver;
190         public String app;
191         @SerializedName("auth_en")
192         public Boolean authEnable;
193         @SerializedName("auth_domain")
194         public String authDomain;
195     }
196
197     public static class Shelly2DeviceConfigAp {
198         public static class Shelly2DeviceConfigApRE {
199             public Boolean enable;
200         }
201
202         public Boolean enable;
203         public String ssid;
204         public String password;
205         @SerializedName("is_open")
206         public Boolean isOpen;
207         @SerializedName("range_extender")
208         Shelly2DeviceConfigApRE rangeExtender;
209     }
210
211     public static class Shelly2DeviceConfig {
212         public class Shelly2DeviceConfigSys {
213             public class Shelly2DeviceConfigDevice {
214                 public String name;
215                 public String mac;
216                 @SerializedName("fw_id")
217                 public String fwId;
218                 public String profile;
219                 @SerializedName("eco_mode")
220                 public Boolean ecoMode;
221                 public Boolean discoverable;
222             }
223
224             public class Shelly2DeviceConfigLocation {
225                 public String tz;
226                 public Double lat;
227                 public Double lon;
228             }
229
230             public class Shelly2DeviceConfigSntp {
231                 public String server;
232             }
233
234             public class Shelly2DeviceConfigSleep {
235                 @SerializedName("wakeup_period")
236                 public Integer wakeupPeriod;
237             }
238
239             public class Shelly2DeviceConfigDebug {
240                 public class Shelly2DeviceConfigDebugMqtt {
241                     public Boolean enable;
242                 }
243
244                 public class Shelly2DeviceConfigDebugWebSocket {
245                     public Boolean enable;
246                 }
247
248                 public class Shelly2DeviceConfigDebugUdp {
249                     public String addr;
250                 }
251
252                 public Shelly2DeviceConfigDebugMqtt mqtt;
253                 public Shelly2DeviceConfigDebugWebSocket websocket;
254                 public Shelly2DeviceConfigDebugUdp udp;
255             }
256
257             public class Shelly2DeviceConfigUiData {
258                 public String cover; // hold comma seperated list of roller favorites
259             }
260
261             public class Shelly2DeviceConfigRpcUdp {
262                 @SerializedName("dst_addr")
263                 public String dstAddr;
264                 @SerializedName("listenPort")
265                 public String listenPort;
266             }
267
268             @SerializedName("cfg_rev")
269             public Integer cfgRevision;
270             public Shelly2DeviceConfigDevice device;
271             public Shelly2DeviceConfigLocation location;
272             public Shelly2DeviceConfigSntp sntp;
273             public Shelly2DeviceConfigSleep sleep;
274             public Shelly2DeviceConfigDebug debug;
275             @SerializedName("ui_data")
276             public Shelly2DeviceConfigUiData uiData;
277             @SerializedName("rpc_udp")
278             public Shelly2DeviceConfigRpcUdp rpcUdp;
279         }
280
281         public class Shelly2DevConfigInput {
282             public Integer id;
283             public String name;
284             public String type;
285             public Boolean invert;
286             @SerializedName("factory_reset")
287             public Boolean factoryReset;
288             @SerializedName("report_thr")
289             public Double reportTreshold; // only for type analog
290         }
291
292         public class Shelly2DevConfigSwitch {
293             public Integer id;
294             public String name;
295
296             @SerializedName("in_mode")
297             public String mode;
298
299             @SerializedName("initial_state")
300             public String initialState;
301             @SerializedName("auto_on")
302             public Boolean autoOn;
303             @SerializedName("auto_on_delay")
304             public Double autoOnDelay;
305             @SerializedName("auto_off")
306             public Boolean autoOff;
307             @SerializedName("auto_off_delay")
308             public Double autoOffDelay;
309             @SerializedName("power_limit")
310             public Integer powerLimit;
311             @SerializedName("voltage_limit")
312             public Integer voltageLimit;
313             @SerializedName("current_limit")
314             public Double currentLimit;
315         }
316
317         public static class Shelly2DevConfigEm {
318             public Integer id;
319             public String name;
320             @SerializedName("blink_mode_selector")
321             public String blinkModeSelector;
322             @SerializedName("phase_selector")
323             public String phase_selector;
324             @SerializedName("monitor_phase_sequence")
325             public Boolean monitorPhaseSequence;
326         }
327
328         public class Shelly2DevConfigPm1 {
329             public Integer id;
330             public String name;
331         }
332
333         public class Shelly2DevConfigCover {
334             public class Shelly2DeviceConfigCoverMotor {
335                 @SerializedName("idle_power_thr")
336                 public Double idle_powerThr;
337             }
338
339             public class Shelly2DeviceConfigCoverSafetySwitch {
340                 public Boolean enable;
341                 public String direction;
342                 public String action;
343                 @SerializedName("allowed_move")
344                 public String allowedMove;
345             }
346
347             public class Shelly2DeviceConfigCoverObstructionDetection {
348                 public Boolean enable;
349                 public String direction;
350                 public String action;
351                 @SerializedName("power_thr")
352                 public Integer powerThr;
353                 public Double holdoff;
354             }
355
356             public String id;
357             public String name;
358             public Shelly2DeviceConfigCoverMotor motor;
359             @SerializedName("maxtime_open")
360             public Double maxtimeOpen;
361             @SerializedName("maxtime_close")
362             public Double maxtimeClose;
363             @SerializedName("initial_state")
364             public String initialState;
365             @SerializedName("invert_directions")
366             public Boolean invertDirections;
367             @SerializedName("in_mode")
368             public String inMode;
369             @SerializedName("swap_inputs")
370             public Boolean swapInputs;
371             @SerializedName("safety_switch")
372             public Shelly2DeviceConfigCoverSafetySwitch safetySwitch;
373             @SerializedName("power_limit")
374             public Integer powerLimit;
375             @SerializedName("voltage_limit")
376             public Integer voltageLimit;
377             @SerializedName("current_limit")
378             public Double currentLimit;
379             @SerializedName("obstruction_detection")
380             public Shelly2DeviceConfigCoverObstructionDetection obstructionDetection;
381         }
382
383         public static class Shelly2ConfigSmoke {
384             public Integer id;
385             public Boolean alarm;
386             public Boolean mute;
387         }
388
389         public static class Shelly2GetConfigLight {
390             public static class Shelly2GetConfigLightDefault {
391                 public Integer brightness;
392             }
393
394             public static class Shelly2GetConfigLightNightMode {
395                 public boolean enable;
396                 public Integer brightness;
397             }
398
399             public Integer id;
400             public String name;
401             @SerializedName("initial_state")
402             public String initialState;
403             @SerializedName("auto_on")
404             public Boolean autoOn;
405             @SerializedName("auto_off")
406             public Boolean autoOff;
407             @SerializedName("auto_on_delay")
408             public Double autoOnDelay;
409             @SerializedName("auto_off_delay")
410             public Double autoOffDelay;
411             @SerializedName("default")
412             public Shelly2GetConfigLightDefault defaultCfg;
413             @SerializedName("night_mode")
414             public Shelly2GetConfigLightNightMode nightMode;
415         }
416
417         public class Shelly2DeviceConfigLed {
418             @SerializedName("sys_led_enable")
419             public Boolean sysLedEnable;
420             @SerializedName("power_led")
421             public String powerLed;
422         }
423
424         public static class Shelly2GetConfigResult {
425
426             public class Shelly2DevConfigCloud {
427                 public Boolean enable;
428                 public String server;
429             }
430
431             public class Shelly2DevConfigMqtt {
432                 public Boolean enable;
433                 public String server;
434                 public String user;
435                 @SerializedName("topic_prefix:0")
436                 public String topicPrefix;
437                 @SerializedName("rpc_ntf")
438                 public String rpcNtf;
439                 @SerializedName("status_ntf")
440                 public String statusNtf;
441             }
442
443             public Shelly2DevConfigBle ble;
444             public Shelly2DevConfigEth eth;
445             public Shelly2DevConfigCloud cloud;
446             public Shelly2DevConfigMqtt mqtt;
447             public Shelly2DeviceConfigSys sys;
448             public Shelly2DeviceConfigWiFi wifi;
449             @SerializedName("wd_ui")
450             public Shelly2DeviceConfigLed led;
451
452             @SerializedName("input:0")
453             public Shelly2DevConfigInput input0;
454             @SerializedName("input:1")
455             public Shelly2DevConfigInput input1;
456             @SerializedName("input:2")
457             public Shelly2DevConfigInput input2;
458             @SerializedName("input:3")
459             public Shelly2DevConfigInput input3;
460
461             @SerializedName("switch:0")
462             public Shelly2DevConfigSwitch switch0;
463             @SerializedName("switch:1")
464             public Shelly2DevConfigSwitch switch1;
465             @SerializedName("switch:2")
466             public Shelly2DevConfigSwitch switch2;
467             @SerializedName("switch:3")
468             public Shelly2DevConfigSwitch switch3;
469             @SerializedName("switch:100")
470             public Shelly2DevConfigSwitch switch100; // Pro 3EM Add-On
471
472             @SerializedName("em:0")
473             public Shelly2DevConfigEm em0;
474             @SerializedName("em1:0")
475             public Shelly2DevConfigEm em10;
476             @SerializedName("em1:1")
477             public Shelly2DevConfigEm em11;
478             @SerializedName("pm1:0")
479             public Shelly2DevConfigPm1 pm10;
480
481             @SerializedName("cover:0")
482             public Shelly2DevConfigCover cover0;
483
484             @SerializedName("light:0")
485             public Shelly2GetConfigLight light0;
486
487             @SerializedName("smoke:0")
488             public Shelly2ConfigSmoke smoke0;
489         }
490
491         public class Shelly2DeviceConfigSta {
492             public String ssid;
493             public String password;
494             @SerializedName("is_open")
495             public Boolean isOpen;
496             public Boolean enable;
497             public String ipv4mode;
498             public String ip;
499             public String netmask;
500             public String gw;
501             public String nameserver;
502         }
503
504         public class Shelly2DeviceConfigRoam {
505             @SerializedName("rssi_thr")
506             public Integer rssiThr;
507             public Integer interval;
508         }
509
510         public class Shelly2DeviceConfigWiFi {
511             public Shelly2DeviceConfigAp ap;
512             public Shelly2DeviceConfigSta sta;
513             public Shelly2DeviceConfigSta sta1;
514             public Shelly2DeviceConfigRoam roam;
515         }
516
517         public String id;
518         public String src;
519         public Shelly2GetConfigResult result;
520     }
521
522     public static class Shelly2DeviceStatus {
523         public class Shelly2InputStatus {
524             public Integer id;
525             public Boolean state;
526             public Double percent; // analog input only
527             public ArrayList<String> errors;// shown only if at least one error is present.
528         }
529
530         public static class Shelly2DeviceStatusLight {
531             public Integer id;
532             public String source;
533             public Boolean output;
534             public Double brightness;
535             @SerializedName("timer_started_at")
536             public Double timerStartedAt;
537             @SerializedName("timer_duration")
538             public Integer timerDuration;
539         }
540
541         public static class Shelly2DeviceStatusResult {
542             public class Shelly2DeviceStatusBle {
543
544             }
545
546             public class Shelly2DeviceStatusCloud {
547                 public Boolean connected;
548             }
549
550             public class Shelly2DeviceStatusMqqt {
551                 public Boolean connected;
552             }
553
554             public class Shelly2CoverStatus {
555                 public Integer id;
556                 public String source;
557                 public String state;
558                 public Double apower;
559                 public Double voltage;
560                 public Double current;
561                 public Double pf;
562                 public Shelly2Energy aenergy;
563                 @SerializedName("current_pos")
564                 public Integer currentPos;
565                 @SerializedName("target_pos")
566                 public Integer targetPos;
567                 @SerializedName("move_timeout")
568                 public Double moveTimeout;
569                 @SerializedName("move_started_at")
570                 public Double moveStartedAt;
571                 @SerializedName("pos_control")
572                 public Boolean posControl;
573                 public Shelly2DeviceStatusTemp temperature;
574                 public ArrayList<String> errors;
575             }
576
577             public class Shelly2DeviceStatusHumidity {
578                 public Integer id;
579                 public Double rh;
580             }
581
582             public class Shelly2DeviceStatusIlluminance {
583                 public Integer id;
584                 public Double lux;
585                 public String illumination;
586             }
587
588             public class Shelly2DeviceStatusVoltage {
589                 public Integer id;
590                 public Double voltage;
591             }
592
593             public class Shelly2DeviceStatusTempId extends Shelly2DeviceStatusTemp {
594                 public Integer id;
595             }
596
597             public static class Shelly2DeviceStatusPower {
598                 public static class Shelly2DeviceStatusBattery {
599                     @SerializedName("V")
600                     public Double volt;
601                     public Double percent;
602                 }
603
604                 public static class Shelly2DeviceStatusCharger {
605                     public Boolean present;
606                 }
607
608                 public Integer id;
609                 public Shelly2DeviceStatusBattery battery;
610                 public Shelly2DeviceStatusCharger external;
611             }
612
613             public static class Shelly2DeviceStatusEm {
614                 public Integer id;
615
616                 @SerializedName("a_current")
617                 public Double aCurrent;
618                 @SerializedName("a_voltage")
619                 public Double aVoltage;
620                 @SerializedName("a_act_power")
621                 public Double aActPower;
622                 @SerializedName("a_aprt_power")
623                 public Double aAprtPower;
624                 @SerializedName("a_pf")
625                 public Double aPF;
626
627                 @SerializedName("b_current")
628                 public Double bCurrent;
629                 @SerializedName("b_voltage")
630                 public Double bVoltage;
631                 @SerializedName("b_act_power")
632                 public Double bActPower;
633                 @SerializedName("b_aprt_power")
634                 public Double bAprtPower;
635                 @SerializedName("b_pf")
636                 public Double bPF;
637
638                 @SerializedName("c_current")
639                 public Double cCurrent;
640                 @SerializedName("c_voltage")
641                 public Double cVoltage;
642                 @SerializedName("c_act_power")
643                 public Double cActPower;
644                 @SerializedName("c_aprt_power")
645                 public Double cAprtPower;
646                 @SerializedName("c_pf")
647                 public Double cPF;
648
649                 @SerializedName("n_current")
650                 public Double nCurrent;
651
652                 @SerializedName("total_current")
653                 public Double totalCurrent;
654                 @SerializedName("total_act_power")
655                 public Double totalActPower;
656                 @SerializedName("total_aprt_power")
657                 public Double totalAprtPower;
658             }
659
660             public static class Shelly2DeviceStatusEmData {
661                 public Integer id;
662                 public String[] errors;
663             }
664
665             public class Shelly2DeviceStatusSmoke {
666                 public Integer id;
667                 public Boolean alarm;
668                 public Boolean mute;
669             }
670
671             public Shelly2DeviceStatusBle ble;
672             public Shelly2DeviceStatusCloud cloud;
673             public Shelly2DeviceStatusMqqt mqtt;
674             public Shelly2DeviceStatusSys sys;
675             public Shelly2DeviceStatusSysWiFi wifi;
676
677             @SerializedName("input:0")
678             public Shelly2InputStatus input0;
679             @SerializedName("input:1")
680             public Shelly2InputStatus input1;
681             @SerializedName("input:2")
682             public Shelly2InputStatus input2;
683             @SerializedName("input:3")
684             public Shelly2InputStatus input3;
685             @SerializedName("input:100")
686             public Shelly2InputStatus input100; // Digital Input from Add-On
687
688             @SerializedName("switch:0")
689             public Shelly2RelayStatus switch0;
690             @SerializedName("switch:1")
691             public Shelly2RelayStatus switch1;
692             @SerializedName("switch:2")
693             public Shelly2RelayStatus switch2;
694             @SerializedName("switch:3")
695             public Shelly2RelayStatus switch3;
696             @SerializedName("switch:100")
697             public Shelly2RelayStatus switch100; // Pro 3EM Add-On
698
699             @SerializedName("pm1:0")
700             public Shelly2RelayStatus pm10;
701
702             @SerializedName("em:0")
703             public Shelly2DeviceStatusEm em0;
704             @SerializedName("emdata:0")
705             public Shelly2DeviceStatusEmData emdata0;
706             @SerializedName("em1:0")
707             public Shelly2StatusEm1 em10;
708             @SerializedName("em1:1")
709             public Shelly2StatusEm1 em11;
710             @SerializedName("em1data:0")
711             public Shelly2DeviceStatusEmData em1data0;
712
713             @SerializedName("cover:0")
714             public Shelly2CoverStatus cover0;
715
716             @SerializedName("light:0")
717             public Shelly2DeviceStatusLight light0;
718
719             @SerializedName("temperature:0")
720             public Shelly2DeviceStatusTempId temperature0;
721             @SerializedName("temperature:100")
722             public Shelly2DeviceStatusTempId temperature100;
723             @SerializedName("temperature:101")
724             public Shelly2DeviceStatusTempId temperature101;
725             @SerializedName("temperature:102")
726             public Shelly2DeviceStatusTempId temperature102;
727             @SerializedName("temperature:103")
728             public Shelly2DeviceStatusTempId temperature103;
729             @SerializedName("temperature:104")
730             public Shelly2DeviceStatusTempId temperature104;
731
732             @SerializedName("humidity:0")
733             public Shelly2DeviceStatusHumidity humidity0;
734             @SerializedName("humidity:100")
735             public Shelly2DeviceStatusHumidity humidity100;
736
737             @SerializedName("illuminance:0")
738             Shelly2DeviceStatusIlluminance illuminance0;
739
740             @SerializedName("smoke:0")
741             public Shelly2DeviceStatusSmoke smoke0;
742
743             @SerializedName("voltmeter:100")
744             public Shelly2DeviceStatusVoltage voltmeter100;
745
746             @SerializedName("devicepower:0")
747             public Shelly2DeviceStatusPower devicepower0;
748         }
749
750         public class Shelly2DeviceStatusSys {
751             public class Shelly2DeviceStatusSysAvlUpdate {
752                 public class Shelly2DeviceStatusSysUpdate {
753                     public String version;
754                 }
755
756                 public Shelly2DeviceStatusSysUpdate stable;
757                 public Shelly2DeviceStatusSysUpdate beta;
758             }
759
760             public class Shelly2DeviceStatusWakeup {
761                 public String boot;
762                 public String cause;
763             }
764
765             public String mac;
766             @SerializedName("restart_required")
767             public Boolean restartRequired;
768             public String time;
769             public Long unixtime;
770             public Long uptime;
771             @SerializedName("ram_size")
772             public Long ramSize;
773             @SerializedName("ram_free")
774             public Long ramFree;
775             @SerializedName("fs_size")
776             public Long fsSize;
777             @SerializedName("fs_free")
778             public Long fsFree;
779             @SerializedName("cfg_rev")
780             public Integer cfg_rev;
781             @SerializedName("available_updates")
782             public Shelly2DeviceStatusSysAvlUpdate availableUpdates;
783             @SerializedName("webhook_rev")
784             public Integer webHookRev;
785             @SerializedName("wakeup_reason")
786             public Shelly2DeviceStatusWakeup wakeUpReason;
787             @SerializedName("wakeup_period")
788             public Integer wakeupPeriod;
789         }
790
791         public class Shelly2DeviceStatusSysWiFi {
792             @SerializedName("sta_ip")
793             public String staIP;
794             public String status;
795             public String ssid;
796             public Integer rssi;
797             @SerializedName("ap_client_count")
798             public Integer apClientCount;
799         }
800
801         public String id;
802         public String src;
803         public Shelly2DeviceStatusResult result;
804     }
805
806     public static class Shelly2RelayStatus {
807         public Integer id;
808         public String source;
809         public Boolean output;
810         @SerializedName("timer_started_at")
811         public Double timerStartetAt;
812         @SerializedName("timer_duration")
813         public Integer timerDuration;
814         public Double apower;
815         public Double voltage;
816         public Double current;
817         public Double pf;
818         public Shelly2Energy aenergy;
819         public Shelly2DeviceStatusTemp temperature;
820         public String[] errors;
821     }
822
823     public static class Shelly2Pm1Status {
824         public Integer id;
825         public String source;
826         public Boolean output;
827         @SerializedName("timer_started_at")
828         public Double timerStartetAt;
829         @SerializedName("timer_duration")
830         public Integer timerDuration;
831         public Double apower;
832         public Double voltage;
833         public Double current;
834         public Double pf;
835         public Shelly2Energy aenergy;
836         public Shelly2DeviceStatusTemp temperature;
837         public String[] errors;
838     }
839
840     public static class Shelly2StatusEm1 {
841         public Integer id;
842         public Double current;
843         public Double voltage;
844         @SerializedName("act_power")
845         public Double actPower;
846         @SerializedName("aprt_power")
847         public Double aptrPower;
848         public Double pf;
849         public String calibration;
850         public ArrayList<String> errors;
851     }
852
853     public static class Shelly2DeviceStatusTemp {
854         public Double tC;
855         public Double tF;
856     }
857
858     public static class Shelly2Energy {
859         // "switch:1":{"id":1,"aenergy":{"total":0.003,"by_minute":[0.000,0.000,0.000],"minute_ts":1619910239}}}}
860         public Double total;
861         @SerializedName("by_minute")
862         public Double[] byMinute;
863         @SerializedName("minute_ts")
864         public Long minuteTs;
865     }
866
867     public static class Shelly2ConfigParms {
868         public String name;
869         public Boolean enable;
870         public String server;
871         @SerializedName("ssl_ca")
872         public String sslCA;
873
874         // WiFi.SetConfig
875         public Shelly2DeviceConfigAp ap;
876
877         // Switch.SetConfig
878         @SerializedName("auto_on")
879         public Boolean autoOn;
880         @SerializedName("auto_on_delay")
881         public Double autoOnDelay;
882         @SerializedName("auto_off")
883         public Boolean autoOff;
884         @SerializedName("auto_off_delay")
885         public Double autoOffDelay;
886
887         // WD_UI.SetConfig
888         @SerializedName("sys_led_enable")
889         public Boolean sysLedEnable;
890         @SerializedName("power_led")
891         public String powerLed;
892     }
893
894     public static class Shelly2RpcRequest {
895         public Integer id = 0;
896         public String method;
897
898         public static class Shelly2RpcRequestParams {
899             public Integer id = 1;
900
901             // Cover
902             public Integer pos;
903             public Boolean on;
904
905             // Dimmer / Light
906             public Integer brightness;
907             @SerializedName("toggle_after")
908             public Integer toggleAfter;
909
910             // Shelly.SetAuth
911             public String user;
912             public String realm;
913             public String ha1;
914
915             // Shelly.Update
916             public String stage;
917             public String url;
918
919             // Cloud.SetConfig
920             public Shelly2ConfigParms config;
921
922             // Script
923             public String name;
924
925             public Shelly2RpcRequestParams withConfig() {
926                 config = new Shelly2ConfigParms();
927                 return this;
928             }
929         }
930
931         public Shelly2RpcRequestParams params = new Shelly2RpcRequestParams();
932
933         public Shelly2RpcRequest() {
934         }
935
936         public Shelly2RpcRequest withMethod(String method) {
937             this.method = method;
938             return this;
939         }
940
941         public Shelly2RpcRequest withId(int id) {
942             params.id = id;
943             return this;
944         }
945
946         public Shelly2RpcRequest withPos(int pos) {
947             params.pos = pos;
948             return this;
949         }
950
951         public Shelly2RpcRequest withName(String name) {
952             params.name = name;
953             return this;
954         }
955     }
956
957     public static class Shelly2WsConfigResponse {
958         public Integer id;
959         public String src;
960
961         public static class Shelly2WsConfigResult {
962             @SerializedName("restart_required")
963             public Boolean restartRequired;
964         }
965
966         public Shelly2WsConfigResult result;
967     }
968
969     public static class ShellyScriptListResponse {
970         public static class ShellyScriptListEntry {
971             public Integer id;
972             public String name;
973             public Boolean enable;
974             public Boolean running;
975         }
976
977         public ArrayList<ShellyScriptListEntry> scripts;
978     }
979
980     public static class ShellyScriptResponse {
981         public Integer id;
982         public Boolean running;
983         public Integer len;
984         public String data;
985     }
986
987     public static class ShellyScriptPutCodeParams {
988         public Integer id;
989         public String code;
990         public Boolean append;
991     }
992
993     public static class Shelly2RpcBaseMessage {
994         // Basic message format, e.g.
995         // {"id":1,"src":"localweb528","method":"Shelly.GetConfig"}
996         public class Shelly2RpcMessageError {
997             public Integer code;
998             public String message;
999         }
1000
1001         public Integer id;
1002         public String src;
1003         public String dst;
1004         public String component;
1005         public String method;
1006         public Object params;
1007         public String event;
1008         public Object result;
1009         public Shelly2AuthRsp auth;
1010         public Shelly2RpcMessageError error;
1011     }
1012
1013     public static class Shelly2RpcNotifyStatus {
1014         public static class Shelly2NotifyStatus extends Shelly2DeviceStatusResult {
1015             public Double ts;
1016         }
1017
1018         public Integer id;
1019         public String src;
1020         public String dst;
1021         public String method;
1022         public Shelly2NotifyStatus params;
1023         public Shelly2NotifyStatus result;
1024         public Shelly2RpcMessageError error;
1025     }
1026
1027     public static String SHELLY2_AUTHDEF_USER = "admin";
1028     public static String SHELLY2_AUTHTTYPE_DIGEST = "digest";
1029     public static String SHELLY2_AUTHTTYPE_STRING = "string";
1030     public static String SHELLY2_AUTHALG_SHA256 = "SHA-256";
1031     // = ':auth:'+HexHash("dummy_method:dummy_uri");
1032     public static String SHELLY2_AUTH_NOISE = "6370ec69915103833b5222b368555393393f098bfbfbb59f47e0590af135f062";
1033
1034     public static class Shelly2AuthChallenge { // on 401 message contains the auth info
1035         @SerializedName("auth_type")
1036         public String authType;
1037         public String nonce;
1038         public String nc;
1039         public String realm;
1040         public String algorithm;
1041     }
1042
1043     public static class Shelly2AuthRsp {
1044         public String username;
1045         public String nonce;
1046         public String cnonce;
1047         public String nc;
1048         public String realm;
1049         public String algorithm;
1050         public String response;
1051         @SerializedName("auth_type")
1052         public String authType;
1053     }
1054
1055     // BTHome samples
1056     // BLU Button 1
1057     // {"component":"script:2", "id":2, "event":"oh-blu.scan_result",
1058     // "data":{"addr":"bc:02:6e:c3:a6:c7","rssi":-62,"tx_power":-128}, "ts":1682877414.21}
1059     // {"component":"script:2", "id":2, "event":"oh-blu.data",
1060     // "data":{"encryption":false,"BTHome_version":2,"pid":205,"Battery":100,"Button":1,"addr":"b4:35:22:fd:b3:81","rssi":-68},
1061     // "ts":1682877399.22}
1062     //
1063     // BLU Door Window
1064     // {"component":"script:2", "id":2, "event":"oh-blu.scan_result",
1065     // "data":{"addr":"bc:02:6e:c3:a6:c7","rssi":-62,"tx_power":-128}, "ts":1682877414.21}
1066     // {"component":"script:2", "id":2, "event":"oh-blu.data",
1067     // "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},
1068     // "ts":1682877414.25}
1069
1070     public class Shelly2NotifyEventMessage {
1071         public String addr;
1072         public String name;
1073         public Boolean encryption;
1074         @SerializedName("BTHome_version")
1075         public Integer bthVersion;
1076         public Integer pid;
1077         @SerializedName("Battery")
1078         public Integer battery;
1079         @SerializedName("Button")
1080         public Integer buttonEvent;
1081         @SerializedName("Illuminance")
1082         public Integer illuminance;
1083         @SerializedName("Window")
1084         public Integer windowState;
1085         @SerializedName("Rotation")
1086         public Double rotation;
1087
1088         public Integer rssi;
1089         public Integer tx_power;
1090     }
1091
1092     public class Shelly2NotifyEvent {
1093         public Integer id;
1094         public Double ts;
1095         public String component;
1096         public String event;
1097         public Shelly2NotifyEventMessage data;
1098         public String msg;
1099         public Integer reason;
1100         @SerializedName("cfg_rev")
1101         public Integer cfgRev;
1102     }
1103
1104     public class Shelly2NotifyEventData {
1105         public Double ts;
1106         public ArrayList<Shelly2NotifyEvent> events;
1107     }
1108
1109     public static class Shelly2RpcNotifyEvent {
1110         public String src;
1111         public Double ts;
1112         public Shelly2NotifyEventData params;
1113     }
1114 }