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