]> git.basschouten.com Git - openhab-addons.git/blob
e9089c8c4b6423d008ff8555c23422adcd0942fe
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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 Master panels
17  *
18  * @author Laurent Garnier - Initial contribution
19  */
20 public enum PowermasterSensorType {
21
22     SENSOR_TYPE_1((byte) 0x01, "Motion"),
23     SENSOR_TYPE_2((byte) 0x04, "Camera"),
24     SENSOR_TYPE_3((byte) 0x16, "Smoke"),
25     SENSOR_TYPE_4((byte) 0x1A, "Temperature"),
26     SENSOR_TYPE_5((byte) 0x2A, "Magnet"),
27     SENSOR_TYPE_6((byte) 0xFE, "Wired");
28
29     private byte code;
30     private String label;
31
32     private PowermasterSensorType(byte code, String label) {
33         this.code = code;
34         this.label = label;
35     }
36
37     /**
38      * @return the code identifying the sensor type
39      */
40     public byte getCode() {
41         return code;
42     }
43
44     /**
45      * @return the label associated to the sensor type
46      */
47     public String getLabel() {
48         return label;
49     }
50
51     /**
52      * Get the ENUM value from its identifying code
53      *
54      * @param code the identifying code
55      *
56      * @return the corresponding ENUM value
57      *
58      * @throws IllegalArgumentException if no ENUM value corresponds to this code
59      */
60     public static PowermasterSensorType fromCode(byte code) throws IllegalArgumentException {
61         for (PowermasterSensorType sensorType : PowermasterSensorType.values()) {
62             if (sensorType.getCode() == code) {
63                 return sensorType;
64             }
65         }
66
67         throw new IllegalArgumentException("Invalid code: " + code);
68     }
69 }