2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.powermax.internal.state;
16 * All defined arm modes
18 * @author Laurent Garnier - Initial contribution
20 public enum PowermaxArmMode {
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);
47 private String shortName;
48 private boolean armed;
49 private byte commandCode;
50 private boolean allowedCommand;
52 private PowermaxArmMode(int code, String name, String shortName, boolean armed, byte commandCode,
53 boolean allowedCommand) {
56 this.shortName = shortName;
58 this.commandCode = commandCode;
59 this.allowedCommand = allowedCommand;
63 * @return the code identifying the mode
65 public int getCode() {
70 * @return the full mode name
72 public String getName() {
77 * @return the short name
79 public String getShortName() {
84 * @return true if the mode is considered as armed
86 public boolean isArmed() {
91 * @return the command code
93 public byte getCommandCode() {
98 * @return true if the mode is an allowed command
100 public boolean isAllowedCommand() {
101 return allowedCommand;
105 * Set whether the mode is an allowed command or not
106 * To be allowed, the mode must have a valid command code.
108 * @param allowedCommand true if the mode must be an allowed command
110 public void setAllowedCommand(boolean allowedCommand) {
111 this.allowedCommand = getCommandCode() == 0xFF ? false : allowedCommand;
115 * Get the ENUM value from its code
117 * @param code the code identifying the mode
119 * @return the corresponding ENUM value
121 * @throws IllegalArgumentException if no ENUM value corresponds to this code
123 public static PowermaxArmMode fromCode(int code) throws IllegalArgumentException {
124 for (PowermaxArmMode mode : PowermaxArmMode.values()) {
125 if (mode.getCode() == code) {
130 throw new IllegalArgumentException("Invalid code: " + code);
134 * Get the ENUM value from its name
136 * @param name the full mode name
138 * @return the corresponding ENUM value
140 * @throws IllegalArgumentException if no ENUM value corresponds to this name
142 public static PowermaxArmMode fromName(String name) throws IllegalArgumentException {
143 for (PowermaxArmMode mode : PowermaxArmMode.values()) {
144 if (mode.getName().equalsIgnoreCase(name)) {
149 throw new IllegalArgumentException("Invalid name: " + name);
153 * Get the ENUM value from its short name
155 * @param shortName the mode short name
157 * @return the first corresponding ENUM value
159 * @throws IllegalArgumentException if no ENUM value corresponds to this short name
161 public static PowermaxArmMode fromShortName(String shortName) throws IllegalArgumentException {
162 for (PowermaxArmMode mode : PowermaxArmMode.values()) {
163 if (mode.getShortName().equalsIgnoreCase(shortName)) {
168 throw new IllegalArgumentException("Invalid short name: " + shortName);