]> git.basschouten.com Git - openhab-addons.git/blob
0d20886c828f7c32520904924f42d5727c8cda18
[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 Master panels
19  *
20  * @author Laurent Garnier - Initial contribution
21  */
22 @NonNullByDefault
23 public enum PowermasterSensorType {
24
25     SENSOR_TYPE_1((byte) 0x01, "Motion"),
26     SENSOR_TYPE_2((byte) 0x04, "Camera"),
27     SENSOR_TYPE_3((byte) 0x16, "Smoke"),
28     SENSOR_TYPE_4((byte) 0x1A, "Temperature"),
29     SENSOR_TYPE_5((byte) 0x2A, "Magnet"),
30     SENSOR_TYPE_6((byte) 0xFE, "Wired");
31
32     private final byte code;
33     private final String label;
34
35     private PowermasterSensorType(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 PowermasterSensorType fromCode(byte code) throws IllegalArgumentException {
64         for (PowermasterSensorType sensorType : PowermasterSensorType.values()) {
65             if (sensorType.getCode() == code) {
66                 return sensorType;
67             }
68         }
69
70         throw new IllegalArgumentException("Invalid code: " + code);
71     }
72 }