]> git.basschouten.com Git - openhab-addons.git/blob
b97ae47587813f39c708e3be8cbe000f463e675c
[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 arm modes
17  *
18  * @author Laurent Garnier - Initial contribution
19  */
20 public enum PowermaxArmMode {
21
22     DISARMED(0, "Disarmed", "Disarmed", false, (byte) 0x00, false),
23     HOME_EXIT_DELAY(1, "Home Exit Delay", "ExitDelay", false, (byte) 0xFF, false),
24     AWAY_EXIT_DELAY(2, "Away Exit Delay", "ExitDelay", false, (byte) 0xFF, false),
25     ENTRY_DELAY(3, "Entry Delay", "EntryDelay", true, (byte) 0xFF, false),
26     ARMED_HOME(4, "Armed Home", "Stay", true, (byte) 0x04, false),
27     ARMED_AWAY(5, "Armed Away", "Armed", true, (byte) 0x05, false),
28     USER_TEST(6, "User Test", "UserTest", false, (byte) 0xFF, false),
29     DOWNLOADING(7, "Downloading", "NotReady", false, (byte) 0xFF, false),
30     PROGRAMMING(8, "Programming", "NotReady", false, (byte) 0xFF, false),
31     INSTALLER(9, "Installer", "NotReady", false, (byte) 0xFF, false),
32     HOME_BYPASS(10, "Home Bypass", "Force", true, (byte) 0xFF, false),
33     AWAY_BYPASS(11, "Away Bypass", "Force", true, (byte) 0xFF, false),
34     READY(12, "Ready", "Ready", false, (byte) 0xFF, false),
35     NOT_READY(13, "Not Ready", "NotReady", false, (byte) 0xFF, false),
36     ARMED_NIGHT(14, "Armed Night", "Night", true, (byte) 0x04, false),
37     ARMED_NIGHT_INSTANT(15, "Armed Night Instant", "NightInstant", true, (byte) 0x14, false),
38     DISARMED_INSTANT(16, "Disarmed Instant", "DisarmedInstant", false, (byte) 0xFF, false),
39     HOME_INSTANT_EXIT_DELAY(17, "Home Instant Exit Delay", "ExitDelay", false, (byte) 0xFF, false),
40     AWAY_INSTANT_EXIT_DELAY(18, "Away Instant Exit Delay", "ExitDelay", false, (byte) 0xFF, false),
41     ENTRY_DELAY_INSTANT(19, "Entry Delay Instant", "EntryDelay", true, (byte) 0xFF, false),
42     ARMED_HOME_INSTANT(20, "Armed Home Instant", "StayInstant", true, (byte) 0x14, false),
43     ARMED_AWAY_INSTANT(21, "Armed Away Instant", "ArmedInstant", true, (byte) 0x15, false);
44
45     private int code;
46     private String name;
47     private String shortName;
48     private boolean armed;
49     private byte commandCode;
50     private boolean allowedCommand;
51
52     private PowermaxArmMode(int code, String name, String shortName, boolean armed, byte commandCode,
53             boolean allowedCommand) {
54         this.code = code;
55         this.name = name;
56         this.shortName = shortName;
57         this.armed = armed;
58         this.commandCode = commandCode;
59         this.allowedCommand = allowedCommand;
60     }
61
62     /**
63      * @return the code identifying the mode
64      */
65     public int getCode() {
66         return code;
67     }
68
69     /**
70      * @return the full mode name
71      */
72     public String getName() {
73         return name;
74     }
75
76     /**
77      * @return the short name
78      */
79     public String getShortName() {
80         return shortName;
81     }
82
83     /**
84      * @return true if the mode is considered as armed
85      */
86     public boolean isArmed() {
87         return armed;
88     }
89
90     /**
91      * @return the command code
92      */
93     public byte getCommandCode() {
94         return commandCode;
95     }
96
97     /**
98      * @return true if the mode is an allowed command
99      */
100     public boolean isAllowedCommand() {
101         return allowedCommand;
102     }
103
104     /**
105      * Set whether the mode is an allowed command or not
106      * To be allowed, the mode must have a valid command code.
107      *
108      * @param allowedCommand true if the mode must be an allowed command
109      */
110     public void setAllowedCommand(boolean allowedCommand) {
111         this.allowedCommand = getCommandCode() == 0xFF ? false : allowedCommand;
112     }
113
114     /**
115      * Get the ENUM value from its code
116      *
117      * @param code the code identifying the mode
118      *
119      * @return the corresponding ENUM value
120      *
121      * @throws IllegalArgumentException if no ENUM value corresponds to this code
122      */
123     public static PowermaxArmMode fromCode(int code) throws IllegalArgumentException {
124         for (PowermaxArmMode mode : PowermaxArmMode.values()) {
125             if (mode.getCode() == code) {
126                 return mode;
127             }
128         }
129
130         throw new IllegalArgumentException("Invalid code: " + code);
131     }
132
133     /**
134      * Get the ENUM value from its name
135      *
136      * @param name the full mode name
137      *
138      * @return the corresponding ENUM value
139      *
140      * @throws IllegalArgumentException if no ENUM value corresponds to this name
141      */
142     public static PowermaxArmMode fromName(String name) throws IllegalArgumentException {
143         for (PowermaxArmMode mode : PowermaxArmMode.values()) {
144             if (mode.getName().equalsIgnoreCase(name)) {
145                 return mode;
146             }
147         }
148
149         throw new IllegalArgumentException("Invalid name: " + name);
150     }
151
152     /**
153      * Get the ENUM value from its short name
154      *
155      * @param shortName the mode short name
156      *
157      * @return the first corresponding ENUM value
158      *
159      * @throws IllegalArgumentException if no ENUM value corresponds to this short name
160      */
161     public static PowermaxArmMode fromShortName(String shortName) throws IllegalArgumentException {
162         for (PowermaxArmMode mode : PowermaxArmMode.values()) {
163             if (mode.getShortName().equalsIgnoreCase(shortName)) {
164                 return mode;
165             }
166         }
167
168         throw new IllegalArgumentException("Invalid short name: " + shortName);
169     }
170 }