]> git.basschouten.com Git - openhab-addons.git/blob
e873b41063786ec95b547e48420b41a86239569b
[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.state;
14
15 /**
16  * All defined sensor types for all panels except Master panels
17  *
18  * @author Laurent Garnier - Initial contribution
19  */
20 public enum PowermaxSensorType {
21
22     MOTION_SENSOR_1((byte) 0x03, "Motion"),
23     MOTION_SENSOR_2((byte) 0x04, "Motion"),
24     MAGNET_SENSOR_1((byte) 0x05, "Magnet"),
25     MAGNET_SENSOR_2((byte) 0x06, "Magnet"),
26     MAGNET_SENSOR_3((byte) 0x07, "Magnet"),
27     SMOKE_SENSOR((byte) 0x0A, "Smoke"),
28     GAS_SENSOR((byte) 0x0B, "Gas"),
29     MOTION_SENSOR_3((byte) 0x0C, "Motion"),
30     WIRED_SENSOR((byte) 0x0F, "Wired");
31
32     private byte code;
33     private String label;
34
35     private PowermaxSensorType(byte code, String label) {
36         this.code = code;
37         this.label = label;
38     }
39
40     /**
41      * @return the code identifying the sensor type
42      */
43     public byte getCode() {
44         return code;
45     }
46
47     /**
48      * @return the label associated to the sensor type
49      */
50     public String getLabel() {
51         return label;
52     }
53
54     /**
55      * Get the ENUM value from its identifying code
56      *
57      * @param code the identifying code
58      *
59      * @return the corresponding ENUM value
60      *
61      * @throws IllegalArgumentException if no ENUM value corresponds to this code
62      */
63     public static PowermaxSensorType fromCode(byte code) throws IllegalArgumentException {
64         for (PowermaxSensorType sensorType : PowermaxSensorType.values()) {
65             if (sensorType.getCode() == code) {
66                 return sensorType;
67             }
68         }
69
70         throw new IllegalArgumentException("Invalid code: " + code);
71     }
72 }