]> git.basschouten.com Git - openhab-addons.git/blob
af792871d5837bb57f3f0981a74f758f8dc18e60
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.tapocontrol.internal.constants;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16
17 /**
18  * The {@link TapoErrorCode} enum lists known errorcodes can be received or thrown by binding
19  *
20  * @author Christian Wild - Initial contribution
21  */
22 @NonNullByDefault
23 public enum TapoErrorCode {
24     NO_ERROR(0),
25     ERR_UNKNOWN(-1, TapoErrorType.UNKNOWN),
26     ERR_API_SESSION_TIMEOUT(9999, TapoErrorType.COMMUNICATION_RETRY),
27     ERR_API_NULL_TRANSPORT(1000),
28     ERR_API_REQUEST(1002),
29     ERR_API_HAND_SHAKE_FAILED(1100, TapoErrorType.COMMUNICATION_RETRY),
30     ERR_API_LOGIN_FAILED(1111),
31     ERR_API_HTTP_TRANSPORT_FAILED(1112),
32     ERR_API_MULTI_REQUEST_FAILED(1200),
33     ERR_API_JSON_DECODE_FAIL(-1003),
34     ERR_API_JSON_ENCODE_FAIL(-1004),
35     ERR_API_AES_DECODE_FAIL(-1005),
36     ERR_API_REQUEST_LEN_ERROR(-1006),
37     ERR_API_CLOUD_FAILED(-1007),
38     ERR_API_PARAMS(-1008),
39     ERR_API_RSA_KEY_LENGTH(-1010),
40     ERR_API_SESSION_PARAM(-1101),
41     ERR_API_QUICK_SETUP(-1201),
42     ERR_API_DEVICE(-1301),
43     ERR_API_DEVICE_NEXT_EVENT(-1302),
44     ERR_API_FIRMWARE(-1401),
45     ERR_API_FIRMWARE_VER_ERROR(-1402),
46     ERR_API_LOGIN(-1501),
47     ERR_API_TIME(-1601),
48     ERR_API_TIME_SYS(-1602),
49     ERR_API_TIME_SAVE(-1603),
50     ERR_API_WIRELESS(-1701),
51     ERR_API_WIRELESS_UNSUPPORTED(-1702),
52     ERR_API_SCHEDULE(-1801),
53     ERR_API_SCHEDULE_FULL(-1802),
54     ERR_API_SCHEDULE_CONFLICT(-1803),
55     ERR_API_SCHEDULE_SAVE(-1804),
56     ERR_API_SCHEDULE_INDEX(-1805),
57     ERR_API_COUNTDOWN(-1901),
58     ERR_API_COUNTDOWN_CONFLICT(-1902),
59     ERR_API_COUNTDOWN_SAVE(-1903),
60     ERR_API_ANTITHEFT(-2001),
61     ERR_API_ANTITHEFT_CONFLICT(-2002),
62     ERR_API_ANTITHEFT_SAVE(-2003),
63     ERR_API_ACCOUNT(-2101),
64     ERR_API_STAT(-2201),
65     ERR_API_STAT_SAVE(-2202),
66     ERR_API_DST(-2301),
67     ERR_API_DST_SAVE(-2302),
68
69     // List of Cloud-ErrorCodes
70     ERR_CLOUD_API_RATE(-20004),
71     ERR_CLOUD_CREDENTIALS(-20601),
72     ERR_CLOUD_JSON_FORMAT(-10100),
73     ERR_CLOUD_METHOD_MISSING(-20103),
74     ERR_CLOUD_PARAMETER_MISSING(-20104),
75     ERR_CLOUD_TOKEN_EXPIRED(-20651),
76
77     // List of Binding-ErrorCodes
78     ERR_BINDING_HTTP_RESPONSE(9001, TapoErrorType.COMMUNICATION_ERROR),
79     ERR_BINDING_COOKIE(9002, TapoErrorType.COMMUNICATION_ERROR),
80     ERR_BINDING_CREDENTIALS(9003, TapoErrorType.CONFIGURATION_ERROR),
81     ERR_BINDING_DEVICE_OFFLINE(9009, TapoErrorType.COMMUNICATION_ERROR),
82     ERR_BINDING_CONNECT_TIMEOUT(9010, TapoErrorType.COMMUNICATION_ERROR),
83
84     // List of Binding-Config-ErrorCodes
85     ERR_CONFIG_IP(10001, TapoErrorType.CONFIGURATION_ERROR), // ip not set
86     ERR_CONFIG_CREDENTIALS(10002, TapoErrorType.CONFIGURATION_ERROR), // credentials not set
87     ERR_CONFIG_NO_BRIDGE(10003, TapoErrorType.CONFIGURATION_ERROR); // no bridge configured
88
89     private Integer code;
90     private TapoErrorType errorType;
91
92     /* set code */
93     private TapoErrorCode(Integer code) {
94         this.code = code;
95         this.errorType = TapoErrorType.GENERAL;
96     }
97
98     private TapoErrorCode(Integer code, TapoErrorType errorType) {
99         this.code = code;
100         this.errorType = errorType;
101     }
102
103     /* get vlaues */
104     public Integer getCode() {
105         return this.code;
106     }
107
108     public TapoErrorType getType() {
109         return this.errorType;
110     }
111
112     public static TapoErrorCode fromCode(int errorCode) {
113         for (TapoErrorCode e : TapoErrorCode.values()) {
114             if (e.code.equals(errorCode)) {
115                 return e;
116             }
117         }
118         return ERR_UNKNOWN;
119     }
120 }