]> git.basschouten.com Git - openhab-addons.git/blob
664eb42807fc02168ff663fc7161f71054a5ac42
[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_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 Shelly2InputStatus {
525             public Integer id;
526             public Boolean state;
527             public Double percent; // analog input only
528             public ArrayList<String> errors;// shown only if at least one error is present.
529         }
530
531         public static class Shelly2DeviceStatusLight {
532             public Integer id;
533             public String source;
534             public Boolean output;
535             public Double brightness;
536             @SerializedName("timer_started_at")
537             public Double timerStartedAt;
538             @SerializedName("timer_duration")
539             public Integer timerDuration;
540         }
541
542         public static class Shelly2DeviceStatusResult {
543             public class Shelly2DeviceStatusBle {
544
545             }
546
547             public class Shelly2DeviceStatusCloud {
548                 public Boolean connected;
549             }
550
551             public class Shelly2DeviceStatusMqqt {
552                 public Boolean connected;
553             }
554
555             public class Shelly2CoverStatus {
556                 public Integer id;
557                 public String source;
558                 public String state;
559                 public Double apower;
560                 public Double voltage;
561                 public Double current;
562                 public Double pf;
563                 public Shelly2Energy aenergy;
564                 @SerializedName("current_pos")
565                 public Integer currentPos;
566                 @SerializedName("target_pos")
567                 public Integer targetPos;
568                 @SerializedName("move_timeout")
569                 public Double moveTimeout;
570                 @SerializedName("move_started_at")
571                 public Double moveStartedAt;
572                 @SerializedName("pos_control")
573                 public Boolean posControl;
574                 public Shelly2DeviceStatusTemp temperature;
575                 public ArrayList<String> errors;
576             }
577
578             public class Shelly2DeviceStatusHumidity {
579                 public Integer id;
580                 public Double rh;
581             }
582
583             public class Shelly2DeviceStatusIlluminance {
584                 public Integer id;
585                 public Double lux;
586                 public String illumination;
587             }
588
589             public class Shelly2DeviceStatusVoltage {
590                 public Integer id;
591                 public Double voltage;
592             }
593
594             public class Shelly2DeviceStatusTempId extends Shelly2DeviceStatusTemp {
595                 public Integer id;
596             }
597
598             public static class Shelly2DeviceStatusPower {
599                 public static class Shelly2DeviceStatusBattery {
600                     @SerializedName("V")
601                     public Double volt;
602                     public Double percent;
603                 }
604
605                 public static class Shelly2DeviceStatusCharger {
606                     public Boolean present;
607                 }
608
609                 public Integer id;
610                 public Shelly2DeviceStatusBattery battery;
611                 public Shelly2DeviceStatusCharger external;
612             }
613
614             public static class Shelly2DeviceStatusEm {
615                 public Integer id;
616
617                 @SerializedName("a_current")
618                 public Double aCurrent;
619                 @SerializedName("a_voltage")
620                 public Double aVoltage;
621                 @SerializedName("a_act_power")
622                 public Double aActPower;
623                 @SerializedName("a_aprt_power")
624                 public Double aAprtPower;
625                 @SerializedName("a_pf")
626                 public Double aPF;
627
628                 @SerializedName("b_current")
629                 public Double bCurrent;
630                 @SerializedName("b_voltage")
631                 public Double bVoltage;
632                 @SerializedName("b_act_power")
633                 public Double bActPower;
634                 @SerializedName("b_aprt_power")
635                 public Double bAprtPower;
636                 @SerializedName("b_pf")
637                 public Double bPF;
638
639                 @SerializedName("c_current")
640                 public Double cCurrent;
641                 @SerializedName("c_voltage")
642                 public Double cVoltage;
643                 @SerializedName("c_act_power")
644                 public Double cActPower;
645                 @SerializedName("c_aprt_power")
646                 public Double cAprtPower;
647                 @SerializedName("c_pf")
648                 public Double cPF;
649
650                 @SerializedName("n_current")
651                 public Double nCurrent;
652
653                 @SerializedName("total_current")
654                 public Double totalCurrent;
655                 @SerializedName("total_act_power")
656                 public Double totalActPower;
657                 @SerializedName("total_aprt_power")
658                 public Double totalAprtPower;
659             }
660
661             public static class Shelly2DeviceStatusEmData {
662                 public Integer id;
663                 public String[] errors;
664             }
665
666             public class Shelly2DeviceStatusSmoke {
667                 public Integer id;
668                 public Boolean alarm;
669                 public Boolean mute;
670             }
671
672             public Shelly2DeviceStatusBle ble;
673             public Shelly2DeviceStatusCloud cloud;
674             public Shelly2DeviceStatusMqqt mqtt;
675             public Shelly2DeviceStatusSys sys;
676             public Shelly2DeviceStatusSysWiFi wifi;
677
678             @SerializedName("input:0")
679             public Shelly2InputStatus input0;
680             @SerializedName("input:1")
681             public Shelly2InputStatus input1;
682             @SerializedName("input:2")
683             public Shelly2InputStatus input2;
684             @SerializedName("input:3")
685             public Shelly2InputStatus input3;
686             @SerializedName("input:100")
687             public Shelly2InputStatus input100; // Digital Input from Add-On
688
689             @SerializedName("switch:0")
690             public Shelly2RelayStatus switch0;
691             @SerializedName("switch:1")
692             public Shelly2RelayStatus switch1;
693             @SerializedName("switch:2")
694             public Shelly2RelayStatus switch2;
695             @SerializedName("switch:3")
696             public Shelly2RelayStatus switch3;
697             @SerializedName("switch:100")
698             public Shelly2RelayStatus switch100; // Pro 3EM Add-On
699
700             @SerializedName("pm1:0")
701             public Shelly2RelayStatus pm10;
702
703             @SerializedName("em:0")
704             public Shelly2DeviceStatusEm em0;
705             @SerializedName("emdata:0")
706             public Shelly2DeviceStatusEmData emdata0;
707             @SerializedName("em1:0")
708             public Shelly2StatusEm1 em10;
709             @SerializedName("em1:1")
710             public Shelly2StatusEm1 em11;
711             @SerializedName("em1data:0")
712             public Shelly2DeviceStatusEmData em1data0;
713
714             @SerializedName("cover:0")
715             public Shelly2CoverStatus cover0;
716
717             @SerializedName("light:0")
718             public Shelly2DeviceStatusLight light0;
719
720             @SerializedName("temperature:0")
721             public Shelly2DeviceStatusTempId temperature0;
722             @SerializedName("temperature:100")
723             public Shelly2DeviceStatusTempId temperature100;
724             @SerializedName("temperature:101")
725             public Shelly2DeviceStatusTempId temperature101;
726             @SerializedName("temperature:102")
727             public Shelly2DeviceStatusTempId temperature102;
728             @SerializedName("temperature:103")
729             public Shelly2DeviceStatusTempId temperature103;
730             @SerializedName("temperature:104")
731             public Shelly2DeviceStatusTempId temperature104;
732
733             @SerializedName("humidity:0")
734             public Shelly2DeviceStatusHumidity humidity0;
735             @SerializedName("humidity:100")
736             public Shelly2DeviceStatusHumidity humidity100;
737
738             @SerializedName("illuminance:0")
739             Shelly2DeviceStatusIlluminance illuminance0;
740
741             @SerializedName("smoke:0")
742             public Shelly2DeviceStatusSmoke smoke0;
743
744             @SerializedName("voltmeter:100")
745             public Shelly2DeviceStatusVoltage voltmeter100;
746
747             @SerializedName("devicepower:0")
748             public Shelly2DeviceStatusPower devicepower0;
749         }
750
751         public class Shelly2DeviceStatusSys {
752             public class Shelly2DeviceStatusSysAvlUpdate {
753                 public class Shelly2DeviceStatusSysUpdate {
754                     public String version;
755                 }
756
757                 public Shelly2DeviceStatusSysUpdate stable;
758                 public Shelly2DeviceStatusSysUpdate beta;
759             }
760
761             public class Shelly2DeviceStatusWakeup {
762                 public String boot;
763                 public String cause;
764             }
765
766             public String mac;
767             @SerializedName("restart_required")
768             public Boolean restartRequired;
769             public String time;
770             public Long unixtime;
771             public Long uptime;
772             @SerializedName("ram_size")
773             public Long ramSize;
774             @SerializedName("ram_free")
775             public Long ramFree;
776             @SerializedName("fs_size")
777             public Long fsSize;
778             @SerializedName("fs_free")
779             public Long fsFree;
780             @SerializedName("cfg_rev")
781             public Integer cfg_rev;
782             @SerializedName("available_updates")
783             public Shelly2DeviceStatusSysAvlUpdate availableUpdates;
784             @SerializedName("webhook_rev")
785             public Integer webHookRev;
786             @SerializedName("wakeup_reason")
787             public Shelly2DeviceStatusWakeup wakeUpReason;
788             @SerializedName("wakeup_period")
789             public Integer wakeupPeriod;
790         }
791
792         public class Shelly2DeviceStatusSysWiFi {
793             @SerializedName("sta_ip")
794             public String staIP;
795             public String status;
796             public String ssid;
797             public Integer rssi;
798             @SerializedName("ap_client_count")
799             public Integer apClientCount;
800         }
801
802         public String id;
803         public String src;
804         public Shelly2DeviceStatusResult result;
805     }
806
807     public static class Shelly2RelayStatus {
808         public Integer id;
809         public String source;
810         public Boolean output;
811         @SerializedName("timer_started_at")
812         public Double timerStartetAt;
813         @SerializedName("timer_duration")
814         public Integer timerDuration;
815         public Double apower;
816         public Double voltage;
817         public Double current;
818         public Double pf;
819         public Shelly2Energy aenergy;
820         public Shelly2DeviceStatusTemp temperature;
821         public String[] errors;
822     }
823
824     public static class Shelly2Pm1Status {
825         public Integer id;
826         public String source;
827         public Boolean output;
828         @SerializedName("timer_started_at")
829         public Double timerStartetAt;
830         @SerializedName("timer_duration")
831         public Integer timerDuration;
832         public Double apower;
833         public Double voltage;
834         public Double current;
835         public Double pf;
836         public Shelly2Energy aenergy;
837         public Shelly2DeviceStatusTemp temperature;
838         public String[] errors;
839     }
840
841     public static class Shelly2StatusEm1 {
842         public Integer id;
843         public Double current;
844         public Double voltage;
845         @SerializedName("act_power")
846         public Double actPower;
847         @SerializedName("aprt_power")
848         public Double aptrPower;
849         public Double pf;
850         public String calibration;
851         public ArrayList<String> errors;
852     }
853
854     public static class Shelly2DeviceStatusTemp {
855         public Double tC;
856         public Double tF;
857     }
858
859     public static class Shelly2Energy {
860         // "switch:1":{"id":1,"aenergy":{"total":0.003,"by_minute":[0.000,0.000,0.000],"minute_ts":1619910239}}}}
861         public Double total;
862         @SerializedName("by_minute")
863         public Double[] byMinute;
864         @SerializedName("minute_ts")
865         public Long minuteTs;
866     }
867
868     public static class Shelly2ConfigParms {
869         public String name;
870         public Boolean enable;
871         public String server;
872         @SerializedName("ssl_ca")
873         public String sslCA;
874
875         // WiFi.SetConfig
876         public Shelly2DeviceConfigAp ap;
877
878         // Switch.SetConfig
879         @SerializedName("auto_on")
880         public Boolean autoOn;
881         @SerializedName("auto_on_delay")
882         public Double autoOnDelay;
883         @SerializedName("auto_off")
884         public Boolean autoOff;
885         @SerializedName("auto_off_delay")
886         public Double autoOffDelay;
887
888         // WD_UI.SetConfig
889         @SerializedName("sys_led_enable")
890         public Boolean sysLedEnable;
891         @SerializedName("power_led")
892         public String powerLed;
893     }
894
895     public static class Shelly2RpcRequest {
896         public Integer id = 0;
897         public String method;
898
899         public static class Shelly2RpcRequestParams {
900             public Integer id = 1;
901
902             // Cover
903             public Integer pos;
904             public Boolean on;
905
906             // Dimmer / Light
907             public Integer brightness;
908             @SerializedName("toggle_after")
909             public Integer toggleAfter;
910
911             // Shelly.SetAuth
912             public String user;
913             public String realm;
914             public String ha1;
915
916             // Shelly.Update
917             public String stage;
918             public String url;
919
920             // Cloud.SetConfig
921             public Shelly2ConfigParms config;
922
923             // Script
924             public String name;
925
926             public Shelly2RpcRequestParams withConfig() {
927                 config = new Shelly2ConfigParms();
928                 return this;
929             }
930         }
931
932         public Shelly2RpcRequestParams params = new Shelly2RpcRequestParams();
933
934         public Shelly2RpcRequest() {
935         }
936
937         public Shelly2RpcRequest withMethod(String method) {
938             this.method = method;
939             return this;
940         }
941
942         public Shelly2RpcRequest withId(int id) {
943             params.id = id;
944             return this;
945         }
946
947         public Shelly2RpcRequest withPos(int pos) {
948             params.pos = pos;
949             return this;
950         }
951
952         public Shelly2RpcRequest withName(String name) {
953             params.name = name;
954             return this;
955         }
956     }
957
958     public static class Shelly2WsConfigResponse {
959         public Integer id;
960         public String src;
961
962         public static class Shelly2WsConfigResult {
963             @SerializedName("restart_required")
964             public Boolean restartRequired;
965         }
966
967         public Shelly2WsConfigResult result;
968     }
969
970     public static class ShellyScriptListResponse {
971         public static class ShellyScriptListEntry {
972             public Integer id;
973             public String name;
974             public Boolean enable;
975             public Boolean running;
976         }
977
978         public ArrayList<ShellyScriptListEntry> scripts;
979     }
980
981     public static class ShellyScriptResponse {
982         public Integer id;
983         public Boolean running;
984         public Integer len;
985         public String data;
986     }
987
988     public static class ShellyScriptPutCodeParams {
989         public Integer id;
990         public String code;
991         public Boolean append;
992     }
993
994     public static class Shelly2RpcBaseMessage {
995         // Basic message format, e.g.
996         // {"id":1,"src":"localweb528","method":"Shelly.GetConfig"}
997         public class Shelly2RpcMessageError {
998             public Integer code;
999             public String message;
1000         }
1001
1002         public Integer id;
1003         public String src;
1004         public String dst;
1005         public String component;
1006         public String method;
1007         public Object params;
1008         public String event;
1009         public Object result;
1010         public Shelly2AuthRsp auth;
1011         public Shelly2RpcMessageError error;
1012     }
1013
1014     public static class Shelly2RpcNotifyStatus {
1015         public static class Shelly2NotifyStatus extends Shelly2DeviceStatusResult {
1016             public Double ts;
1017         }
1018
1019         public Integer id;
1020         public String src;
1021         public String dst;
1022         public String method;
1023         public Shelly2NotifyStatus params;
1024         public Shelly2NotifyStatus result;
1025         public Shelly2RpcMessageError error;
1026     }
1027
1028     public static String SHELLY2_AUTHDEF_USER = "admin";
1029     public static String SHELLY2_AUTHTTYPE_DIGEST = "digest";
1030     public static String SHELLY2_AUTHTTYPE_STRING = "string";
1031     public static String SHELLY2_AUTHALG_SHA256 = "SHA-256";
1032     // = ':auth:'+HexHash("dummy_method:dummy_uri");
1033     public static String SHELLY2_AUTH_NOISE = "6370ec69915103833b5222b368555393393f098bfbfbb59f47e0590af135f062";
1034
1035     public static class Shelly2AuthChallenge { // on 401 message contains the auth info
1036         @SerializedName("auth_type")
1037         public String authType;
1038         public String nonce;
1039         public String nc;
1040         public String realm;
1041         public String algorithm;
1042     }
1043
1044     public static class Shelly2AuthRsp {
1045         public String username;
1046         public String nonce;
1047         public String cnonce;
1048         public String nc;
1049         public String realm;
1050         public String algorithm;
1051         public String response;
1052         @SerializedName("auth_type")
1053         public String authType;
1054     }
1055
1056     // BTHome samples
1057     // BLU Button 1
1058     // {"component":"script:2", "id":2, "event":"oh-blu.scan_result",
1059     // "data":{"addr":"bc:02:6e:c3:a6:c7","rssi":-62,"tx_power":-128}, "ts":1682877414.21}
1060     // {"component":"script:2", "id":2, "event":"oh-blu.data",
1061     // "data":{"encryption":false,"BTHome_version":2,"pid":205,"Battery":100,"Button":1,"addr":"b4:35:22:fd:b3:81","rssi":-68},
1062     // "ts":1682877399.22}
1063     //
1064     // BLU Door Window
1065     // {"component":"script:2", "id":2, "event":"oh-blu.scan_result",
1066     // "data":{"addr":"bc:02:6e:c3:a6:c7","rssi":-62,"tx_power":-128}, "ts":1682877414.21}
1067     // {"component":"script:2", "id":2, "event":"oh-blu.data",
1068     // "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},
1069     // "ts":1682877414.25}
1070
1071     public class Shelly2NotifyEventMessage {
1072         public String addr;
1073         public String name;
1074         public Boolean encryption;
1075         @SerializedName("BTHome_version")
1076         public Integer bthVersion;
1077         public Integer pid;
1078         @SerializedName("Battery")
1079         public Integer battery;
1080         @SerializedName("Button")
1081         public Integer buttonEvent;
1082         @SerializedName("Illuminance")
1083         public Integer illuminance;
1084         @SerializedName("Window")
1085         public Integer windowState;
1086         @SerializedName("Rotation")
1087         public Double rotation;
1088         @SerializedName("Motion")
1089         public Integer motionState;
1090         @SerializedName("Temperature")
1091         public Double temperature;
1092
1093         public Integer rssi;
1094         public Integer tx_power;
1095     }
1096
1097     public class Shelly2NotifyEvent {
1098         public Integer id;
1099         public Double ts;
1100         public String component;
1101         public String event;
1102         public Shelly2NotifyEventMessage data;
1103         public String msg;
1104         public Integer reason;
1105         @SerializedName("cfg_rev")
1106         public Integer cfgRev;
1107     }
1108
1109     public class Shelly2NotifyEventData {
1110         public Double ts;
1111         public ArrayList<Shelly2NotifyEvent> events;
1112     }
1113
1114     public static class Shelly2RpcNotifyEvent {
1115         public String src;
1116         public Double ts;
1117         public Shelly2NotifyEventData params;
1118     }
1119 }