]> git.basschouten.com Git - openhab-addons.git/blob
a9cadab83429c60cc0ac8ce0f518e55dbfca8506
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.powermax.internal.message;
14
15 /**
16  * All defined trouble types
17  *
18  * @author Laurent Garnier - Initial contribution
19  */
20 public enum PowermaxTroubleType {
21
22     TROUBLE_TYPE_1(0x0A, "Communication"),
23     TROUBLE_TYPE_2(0x0F, "General"),
24     TROUBLE_TYPE_3(0x29, "Battery"),
25     TROUBLE_TYPE_4(0x2B, "Power"),
26     TROUBLE_TYPE_5(0x2D, "Battery"),
27     TROUBLE_TYPE_6(0x2F, "Jamming"),
28     TROUBLE_TYPE_7(0x31, "Communication"),
29     TROUBLE_TYPE_8(0x33, "Telephone"),
30     TROUBLE_TYPE_9(0x36, "Power"),
31     TROUBLE_TYPE_10(0x38, "Battery"),
32     TROUBLE_TYPE_11(0x3B, "Battery"),
33     TROUBLE_TYPE_12(0x3C, "Battery"),
34     TROUBLE_TYPE_13(0x40, "Battery"),
35     TROUBLE_TYPE_14(0x43, "Battery");
36
37     private int code;
38     private String label;
39
40     private PowermaxTroubleType(int code, String label) {
41         this.code = code;
42         this.label = label;
43     }
44
45     /**
46      * @return the code identifying the trouble type
47      */
48     public int getCode() {
49         return code;
50     }
51
52     /**
53      * @return the label associated to the trouble type
54      */
55     public String getLabel() {
56         return label;
57     }
58
59     /**
60      * Get the ENUM value from its identifying code
61      *
62      * @param code the identifying code
63      *
64      * @return the corresponding ENUM value
65      *
66      * @throws IllegalArgumentException if no ENUM value corresponds to this code
67      */
68     public static PowermaxTroubleType fromCode(int code) throws IllegalArgumentException {
69         for (PowermaxTroubleType troubleType : PowermaxTroubleType.values()) {
70             if (troubleType.getCode() == code) {
71                 return troubleType;
72             }
73         }
74
75         throw new IllegalArgumentException("Invalid code: " + code);
76     }
77 }