]> git.basschouten.com Git - openhab-addons.git/blob
c0a548e9df53d2ce839fe4f24310bc415b413259
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.loxone.internal.types;
14
15 /**
16  * Reasons why Miniserver may be not reachable
17  *
18  * @author Pawel Pieczul - initial contribution
19  *
20  */
21 public enum LxErrorCode {
22     /**
23      * No error at all
24      */
25     OK,
26     /**
27      * User name or password incorrect or user not authorized
28      */
29     USER_UNAUTHORIZED,
30     /**
31      * Too many failed login attempts and server's temporary ban of the user
32      */
33     TOO_MANY_FAILED_LOGIN_ATTEMPTS,
34     /**
35      * Communication error with the Miniserv
36      */
37     COMMUNICATION_ERROR,
38     /**
39      * Timeout of user authentication procedure
40      */
41     USER_AUTHENTICATION_TIMEOUT,
42     /**
43      * No activity from Miniserver's client
44      */
45     WEBSOCKET_IDLE_TIMEOUT,
46     /**
47      * Internal error, sign of something wrong with the program
48      */
49     INTERNAL_ERROR,
50     /**
51      * Error code is missing - reason for failure is unknown
52      */
53     ERROR_CODE_MISSING;
54
55     /**
56      * Converts Miniserver status code to enumerated error value
57      *
58      * @param code status code received in message response from the Miniserver
59      * @return converted error code
60      */
61     public static LxErrorCode getErrorCode(Integer code) {
62         if (code == null) {
63             return ERROR_CODE_MISSING;
64         }
65         switch (code) {
66             case 420:
67                 return USER_AUTHENTICATION_TIMEOUT;
68             case 401:
69             case 500:
70                 return USER_UNAUTHORIZED;
71             case 4003:
72                 return TOO_MANY_FAILED_LOGIN_ATTEMPTS;
73             case 1001:
74                 return WEBSOCKET_IDLE_TIMEOUT;
75             case 200:
76                 return OK;
77             default:
78                 return COMMUNICATION_ERROR;
79         }
80     }
81 }