2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.shelly.internal.api2;
15 import java.util.ArrayList;
17 import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult;
18 import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2RpcBaseMessage.Shelly2RpcMessageError;
20 import com.google.gson.annotations.SerializedName;
23 * {@link Shelly2ApiJsonDTO} wraps the Shelly REST API and provides various low level function to access the device api
27 * @author Markus Michels - Initial contribution
29 public class Shelly2ApiJsonDTO {
30 public static final String SHELLYRPC_METHOD_CLASS_SHELLY = "Shelly";
31 public static final String SHELLYRPC_METHOD_CLASS_SWITCH = "Switch";
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_WIFIGETCONG = "Wifi.GetConfig";
51 public static final String SHELLYRPC_METHOD_WIFISETCONG = "Wifi.SetConfig";
52 public static final String SHELLYRPC_METHOD_ETHGETCONG = "Eth.GetConfig";
53 public static final String SHELLYRPC_METHOD_ETHSETCONG = "Eth.SetConfig";
54 public static final String SHELLYRPC_METHOD_BLEGETCONG = "BLE.GetConfig";
55 public static final String SHELLYRPC_METHOD_BLESETCONG = "BLE.SetConfig";
56 public static final String SHELLYRPC_METHOD_CLOUDSET = "Cloud.SetConfig";
57 public static final String SHELLYRPC_METHOD_WSGETCONFIG = "WS.GetConfig";
58 public static final String SHELLYRPC_METHOD_WSSETCONFIG = "WS.SetConfig";
60 public static final String SHELLYRPC_METHOD_NOTIFYSTATUS = "NotifyStatus"; // inbound status
61 public static final String SHELLYRPC_METHOD_NOTIFYFULLSTATUS = "NotifyFullStatus"; // inbound status from bat device
62 public static final String SHELLYRPC_METHOD_NOTIFYEVENT = "NotifyEvent"; // inbound event
65 public static final String SHELLY2_PROFILE_RELAY = "switch";
66 public static final String SHELLY2_PROFILE_ROLLER = "cover";
69 public static final String SHELLY2_BTNT_MOMENTARY = "momentary";
70 public static final String SHELLY2_BTNT_FLIP = "flip";
71 public static final String SHELLY2_BTNT_FOLLOW = "follow";
72 public static final String SHELLY2_BTNT_DETACHED = "detached";
75 public static final String SHELLY2_INPUTT_SWITCH = "switch";
76 public static final String SHELLY2_INPUTT_BUTTON = "button";
79 public static final String SHELLY2_API_MODE_DETACHED = "detached";
80 public static final String SHELLY2_API_MODE_FOLLOW = "follow";
82 // Initial switch states
83 public static final String SHELLY2_API_ISTATE_ON = "on";
84 public static final String SHELLY2_API_ISTATE_OFF = "off";
85 public static final String SHELLY2_API_ISTATE_FOLLOWLAST = "restore_last";
86 public static final String SHELLY2_API_ISTATE_MATCHINPUT = "match_input";
89 public static final String SHELLY2_RMODE_SINGLE = "single";
90 public static final String SHELLY2_RMODE_DUAL = "dual";
91 public static final String SHELLY2_RMODE_DETACHED = "detached";
93 public static final String SHELLY2_RSTATE_OPENING = "opening";
94 public static final String SHELLY2_RSTATE_OPEN = "open";
95 public static final String SHELLY2_RSTATE_CLOSING = "closing";
96 public static final String SHELLY2_RSTATE_CLOSED = "closed";
97 public static final String SHELLY2_RSTATE_STOPPED = "stopped";
98 public static final String SHELLY2_RSTATE_CALIB = "calibrating";
100 // Event notifications
101 public static final String SHELLY2_EVENT_BTNUP = "btn_up";
102 public static final String SHELLY2_EVENT_BTNDOWN = "btn_down";
103 public static final String SHELLY2_EVENT_1PUSH = "single_push";
104 public static final String SHELLY2_EVENT_2PUSH = "double_push";
105 public static final String SHELLY2_EVENT_3PUSH = "triple_push";
106 public static final String SHELLY2_EVENT_LPUSH = "long_push";
107 public static final String SHELLY2_EVENT_SLPUSH = "short_long_push";
108 public static final String SHELLY2_EVENT_LSPUSH = "long_short_push";
110 public static final String SHELLY2_EVENT_SLEEP = "sleep";
111 public static final String SHELLY2_EVENT_CFGCHANGED = "config_changed";
112 public static final String SHELLY2_EVENT_OTASTART = "ota_begin";
113 public static final String SHELLY2_EVENT_OTAPROGRESS = "ota_progress";
114 public static final String SHELLY2_EVENT_OTADONE = "ota_success";
115 public static final String SHELLY2_EVENT_WIFICONNFAILED = "sta_connect_fail";
116 public static final String SHELLY2_EVENT_WIFIDISCONNECTED = "sta_disconnected";
119 public static final String SHELLY2_ERROR_OVERPOWER = "overpower";
120 public static final String SHELLY2_ERROR_OVERTEMP = "overtemp";
121 public static final String SHELLY2_ERROR_OVERVOLTAGE = "overvoltage";
123 // Wakeup reasons (e.g. Plus HT)
124 public static final String SHELLY2_WAKEUPO_BOOT_POWERON = "poweron";
125 public static final String SHELLY2_WAKEUPO_BOOT_RESTART = "software_restart";
126 public static final String SHELLY2_WAKEUPO_BOOT_WAKEUP = "deepsleep_wake";
127 public static final String SHELLY2_WAKEUPO_BOOT_INTERNAL = "internal";
128 public static final String SHELLY2_WAKEUPO_BOOT_UNKNOWN = "unknown";
130 public static final String SHELLY2_WAKEUPOCAUSE_BUTTON = "button";
131 public static final String SHELLY2_WAKEUPOCAUSE_USB = "usb";
132 public static final String SHELLY2_WAKEUPOCAUSE_PERIODIC = "periodic";
133 public static final String SHELLY2_WAKEUPOCAUSE_UPDATE = "status_update";
134 public static final String SHELLY2_WAKEUPOCAUSE_UNDEFINED = "undefined";
136 public class Shelly2DevConfigBle {
137 public Boolean enable;
140 public class Shelly2DevConfigEth {
141 public Boolean enable;
142 public String ipv4mode;
144 public String netmask;
146 public String nameserver;
149 public static class Shelly2DeviceSettings {
155 @SerializedName("fw_id")
156 public String firmware;
159 @SerializedName("auth_en")
160 public Boolean authEnable;
161 @SerializedName("auth_domain")
162 public String authDomain;
165 public static class Shelly2DeviceConfigAp {
166 public static class Shelly2DeviceConfigApRE {
167 public Boolean enable;
170 public Boolean enable;
172 public String password;
173 @SerializedName("is_open")
174 public Boolean isOpen;
175 @SerializedName("range_extender")
176 Shelly2DeviceConfigApRE rangeExtender;
179 public static class Shelly2DeviceConfig {
180 public class Shelly2DeviceConfigSys {
181 public class Shelly2DeviceConfigDevice {
184 @SerializedName("fw_id")
186 public String profile;
187 @SerializedName("eco_mode")
188 public Boolean ecoMode;
189 public Boolean discoverable;
192 public class Shelly2DeviceConfigLocation {
198 public class Shelly2DeviceConfigSntp {
199 public String server;
202 public class Shelly2DeviceConfigSleep {
203 @SerializedName("wakeup_period")
204 public Integer wakeupPeriod;
207 public class Shelly2DeviceConfigDebug {
208 public class Shelly2DeviceConfigDebugMqtt {
209 public Boolean enable;
212 public class Shelly2DeviceConfigDebugWebSocket {
213 public Boolean enable;
216 public class Shelly2DeviceConfigDebugUdp {
220 public Shelly2DeviceConfigDebugMqtt mqtt;
221 public Shelly2DeviceConfigDebugWebSocket websocket;
222 public Shelly2DeviceConfigDebugUdp udp;
225 public class Shelly2DeviceConfigUiData {
226 public String cover; // hold comma seperated list of roller favorites
229 public class Shelly2DeviceConfigRpcUdp {
230 @SerializedName("dst_addr")
231 public String dstAddr;
232 @SerializedName("listenPort")
233 public String listenPort;
236 @SerializedName("cfg_rev")
237 public Integer cfgRevision;
238 public Shelly2DeviceConfigDevice device;
239 public Shelly2DeviceConfigLocation location;
240 public Shelly2DeviceConfigSntp sntp;
241 public Shelly2DeviceConfigSleep sleep;
242 public Shelly2DeviceConfigDebug debug;
243 @SerializedName("ui_data")
244 public Shelly2DeviceConfigUiData uiData;
245 @SerializedName("rpc_udp")
246 public Shelly2DeviceConfigRpcUdp rpcUdp;
249 public class Shelly2DevConfigInput {
253 public Boolean invert;
254 @SerializedName("factory_reset")
255 public Boolean factoryReset;
258 public class Shelly2DevConfigSwitch {
262 @SerializedName("in_mode")
265 @SerializedName("initial_state")
266 public String initialState;
267 @SerializedName("auto_on")
268 public Boolean autoOn;
269 @SerializedName("auto_on_delay")
270 public Double autoOnDelay;
271 @SerializedName("auto_off")
272 public Boolean autoOff;
273 @SerializedName("auto_off_delay")
274 public Double autoOffDelay;
275 @SerializedName("power_limit")
276 public Integer powerLimit;
277 @SerializedName("voltage_limit")
278 public Integer voltageLimit;
279 @SerializedName("current_limit")
280 public Double currentLimit;
283 public class Shelly2DevConfigCover {
284 public class Shelly2DeviceConfigCoverMotor {
285 @SerializedName("idle_power_thr")
286 public Double idle_powerThr;
289 public class Shelly2DeviceConfigCoverSafetySwitch {
290 public Boolean enable;
291 public String direction;
292 public String action;
293 @SerializedName("allowed_move")
294 public String allowedMove;
297 public class Shelly2DeviceConfigCoverObstructionDetection {
298 public Boolean enable;
299 public String direction;
300 public String action;
301 @SerializedName("power_thr")
302 public Integer powerThr;
303 public Double holdoff;
308 public Shelly2DeviceConfigCoverMotor motor;
309 @SerializedName("maxtime_open")
310 public Double maxtimeOpen;
311 @SerializedName("maxtime_close")
312 public Double maxtimeClose;
313 @SerializedName("initial_state")
314 public String initialState;
315 @SerializedName("invert_directions")
316 public Boolean invertDirections;
317 @SerializedName("in_mode")
318 public String inMode;
319 @SerializedName("swap_inputs")
320 public Boolean swapInputs;
321 @SerializedName("safety_switch")
322 public Shelly2DeviceConfigCoverSafetySwitch safetySwitch;
323 @SerializedName("power_limit")
324 public Integer powerLimit;
325 @SerializedName("voltage_limit")
326 public Integer voltageLimit;
327 @SerializedName("current_limit")
328 public Double currentLimit;
329 @SerializedName("obstruction_detection")
330 public Shelly2DeviceConfigCoverObstructionDetection obstructionDetection;
333 public static class Shelly2GetConfigResult {
335 public class Shelly2DevConfigCloud {
336 public Boolean enable;
337 public String server;
340 public class Shelly2DevConfigMqtt {
341 public Boolean enable;
342 public String server;
344 @SerializedName("topic_prefix:0")
345 public String topicPrefix;
346 @SerializedName("rpc_ntf")
347 public String rpcNtf;
348 @SerializedName("status_ntf")
349 public String statusNtf;
352 public Shelly2DevConfigBle ble;
353 public Shelly2DevConfigEth eth;
354 public Shelly2DevConfigCloud cloud;
355 public Shelly2DevConfigMqtt mqtt;
356 public Shelly2DeviceConfigSys sys;
357 public Shelly2DeviceConfigWiFi wifi;
359 @SerializedName("input:0")
360 public Shelly2DevConfigInput input0;
361 @SerializedName("input:1")
362 public Shelly2DevConfigInput input1;
363 @SerializedName("input:2")
364 public Shelly2DevConfigInput input2;
365 @SerializedName("input:3")
366 public Shelly2DevConfigInput input3;
368 @SerializedName("switch:0")
369 public Shelly2DevConfigSwitch switch0;
370 @SerializedName("switch:1")
371 public Shelly2DevConfigSwitch switch1;
372 @SerializedName("switch:2")
373 public Shelly2DevConfigSwitch switch2;
374 @SerializedName("switch:3")
375 public Shelly2DevConfigSwitch switch3;
377 @SerializedName("cover:0")
378 public Shelly2DevConfigCover cover0;
381 public class Shelly2DeviceConfigSta {
383 public String password;
384 @SerializedName("is_open")
385 public Boolean isOpen;
386 public Boolean enable;
387 public String ipv4mode;
389 public String netmask;
391 public String nameserver;
394 public class Shelly2DeviceConfigRoam {
395 @SerializedName("rssi_thr")
396 public Integer rssiThr;
397 public Integer interval;
400 public class Shelly2DeviceConfigWiFi {
401 public Shelly2DeviceConfigAp ap;
402 public Shelly2DeviceConfigSta sta;
403 public Shelly2DeviceConfigSta sta1;
404 public Shelly2DeviceConfigRoam roam;
409 public Shelly2GetConfigResult result;
412 public static class Shelly2DeviceStatus {
413 public class Shelly2InputStatus {
415 public Boolean state;
418 public static class Shelly2DeviceStatusResult {
419 public class Shelly2DeviceStatusBle {
423 public class Shelly2DeviceStatusCloud {
424 public Boolean connected;
427 public class Shelly2DeviceStatusMqqt {
428 public Boolean connected;
431 public class Shelly2CoverStatus {
433 public String source;
435 public Double apower;
436 public Double voltage;
437 public Double current;
439 public Shelly2Energy aenergy;
440 @SerializedName("current_pos")
441 public Integer currentPos;
442 @SerializedName("target_pos")
443 public Integer targetPos;
444 @SerializedName("move_timeout")
445 public Double moveTimeout;
446 @SerializedName("move_started_at")
447 public Double moveStartedAt;
448 @SerializedName("pos_control")
449 public Boolean posControl;
450 public Shelly2DeviceStatusTemp temperature;
451 public ArrayList<String> errors;
454 public class Shelly2DeviceStatusHumidity {
459 public class Shelly2DeviceStatusTempId extends Shelly2DeviceStatusTemp {
463 public static class Shelly2DeviceStatusPower {
464 public static class Shelly2DeviceStatusBattery {
467 public Double percent;
470 public static class Shelly2DeviceStatusCharger {
471 public Boolean present;
475 public Shelly2DeviceStatusBattery battery;
476 public Shelly2DeviceStatusCharger external;
479 public Shelly2DeviceStatusBle ble;
480 public Shelly2DeviceStatusCloud cloud;
481 public Shelly2DeviceStatusMqqt mqtt;
482 public Shelly2DeviceStatusSys sys;
483 public Shelly2DeviceStatusSysWiFi wifi;
485 @SerializedName("input:0")
486 public Shelly2InputStatus input0;
487 @SerializedName("input:1")
488 public Shelly2InputStatus input1;
489 @SerializedName("input:2")
490 public Shelly2InputStatus input2;
491 @SerializedName("input:3")
492 public Shelly2InputStatus input3;
494 @SerializedName("switch:0")
495 public Shelly2RelayStatus switch0;
496 @SerializedName("switch:1")
497 public Shelly2RelayStatus switch1;
498 @SerializedName("switch:2")
499 public Shelly2RelayStatus switch2;
500 @SerializedName("switch:3")
501 public Shelly2RelayStatus switch3;
503 @SerializedName("cover:0")
504 public Shelly2CoverStatus cover0;
506 @SerializedName("humidity:0")
507 public Shelly2DeviceStatusHumidity humidity0;
508 @SerializedName("temperature:0")
509 public Shelly2DeviceStatusTempId temperature0;
510 @SerializedName("devicepower:0")
511 public Shelly2DeviceStatusPower devicepower0;
514 public class Shelly2DeviceStatusSys {
515 public class Shelly2DeviceStatusSysAvlUpdate {
516 public class Shelly2DeviceStatusSysUpdate {
517 public String version;
520 public Shelly2DeviceStatusSysUpdate stable;
521 public Shelly2DeviceStatusSysUpdate beta;
524 public class Shelly2DeviceStatusWakeup {
530 @SerializedName("restart_required")
531 public Boolean restartRequired;
533 public Long unixtime;
535 @SerializedName("ram_size")
537 @SerializedName("ram_free")
539 @SerializedName("fs_size")
541 @SerializedName("fs_free")
543 @SerializedName("cfg_rev")
544 public Integer cfg_rev;
545 @SerializedName("available_updates")
546 public Shelly2DeviceStatusSysAvlUpdate availableUpdates;
547 @SerializedName("webhook_rev")
548 public Integer webHookRev;
549 @SerializedName("wakeup_reason")
550 public Shelly2DeviceStatusWakeup wakeUpReason;
551 @SerializedName("wakeup_period")
552 public Integer wakeupPeriod;
555 public class Shelly2DeviceStatusSysWiFi {
556 @SerializedName("sta_ip")
558 public String status;
561 @SerializedName("ap_client_count")
562 public Integer apClientCount;
567 public Shelly2DeviceStatusResult result;
570 public static class Shelly2RelayStatus {
572 public String source;
573 public Boolean output;
574 @SerializedName("timer_started_at")
575 public Double timerStartetAt;
576 @SerializedName("timer_duration")
577 public Integer timerDuration;
578 public Double apower;
579 public Double voltage;
580 public Double current;
582 public Shelly2Energy aenergy;
583 public Shelly2DeviceStatusTemp temperature;
584 public String[] errors;
587 public static class Shelly2DeviceStatusTemp {
592 public static class Shelly2Energy {
593 // "switch:1":{"id":1,"aenergy":{"total":0.003,"by_minute":[0.000,0.000,0.000],"minute_ts":1619910239}}}}
595 @SerializedName("by_minute")
596 public Double[] byMinute;
597 @SerializedName("minute_ts")
598 public Long minuteTs;
601 public static class Shelly2ConfigParms {
603 public Boolean enable;
604 public String server;
605 @SerializedName("ssl_ca")
609 public Shelly2DeviceConfigAp ap;
612 @SerializedName("auto_on")
613 public Boolean autoOn;
614 @SerializedName("auto_on_delay")
615 public Double autoOnDelay;
616 @SerializedName("auto_off")
617 public Boolean autoOff;
618 @SerializedName("auto_off_delay")
619 public Double autoOffDelay;
622 public static class Shelly2RpcRequest {
623 public Integer id = 0;
624 public String method;
626 public static class Shelly2RpcRequestParams {
627 public Integer id = 1;
643 public Shelly2ConfigParms config;
645 public Shelly2RpcRequestParams withConfig() {
646 config = new Shelly2ConfigParms();
651 public Shelly2RpcRequestParams params = new Shelly2RpcRequestParams();
653 public Shelly2RpcRequest() {
656 public Shelly2RpcRequest withMethod(String method) {
657 this.method = method;
661 public Shelly2RpcRequest withId(int id) {
666 public Shelly2RpcRequest withPos(int pos) {
672 public static class Shelly2WsConfigResponse {
676 public static class Shelly2WsConfigResult {
677 @SerializedName("restart_required")
678 public Boolean restartRequired;
681 public Shelly2WsConfigResult result;
684 public static class Shelly2RpcBaseMessage {
685 // Basic message format, e.g.
686 // {"id":1,"src":"localweb528","method":"Shelly.GetConfig"}
687 public class Shelly2RpcMessageError {
689 public String message;
695 public String method;
696 public Object params;
697 public Object result;
698 public Shelly2AuthRequest auth;
699 public Shelly2RpcMessageError error;
702 public static class Shelly2RpcNotifyStatus {
703 public static class Shelly2NotifyStatus extends Shelly2DeviceStatusResult {
710 public String method;
711 public Shelly2NotifyStatus params;
712 public Shelly2NotifyStatus result;
713 public Shelly2RpcMessageError error;
716 public static String SHELLY2_AUTHTTYPE_DIGEST = "digest";
717 public static String SHELLY2_AUTHTTYPE_STRING = "string";
718 public static String SHELLY2_AUTHALG_SHA256 = "SHA-256";
719 // = ':auth:'+HexHash("dummy_method:dummy_uri");
720 public static String SHELLY2_AUTH_NOISE = "6370ec69915103833b5222b368555393393f098bfbfbb59f47e0590af135f062";
722 public static class Shelly2AuthRequest {
723 public String username;
728 public String algorithm;
729 public String response;
730 @SerializedName("auth_type")
731 public String authType;
734 public static class Shelly2AuthResponse { // on 401 message contains the auth info
735 @SerializedName("auth_type")
736 public String authType;
740 public String algorithm;
743 public class Shelly2NotifyEvent {
746 public String component;
749 public Integer reason;
750 @SerializedName("cfg_rev")
751 public Integer cfgRev;
754 public class Shelly2NotifyEventData {
756 public ArrayList<Shelly2NotifyEvent> events;
759 public static class Shelly2RpcNotifyEvent {
761 Shelly2NotifyEventData params;