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