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