2 * Copyright (c) 2010-2023 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;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
18 * All defined arm modes
20 * @author Laurent Garnier - Initial contribution
23 public enum PowermaxArmMode {
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);
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;
55 private PowermaxArmMode(int code, String name, String shortName, boolean armed, byte commandCode,
56 boolean allowedCommand) {
59 this.shortName = shortName;
61 this.commandCode = commandCode;
62 this.allowedCommand = allowedCommand;
66 * @return the code identifying the mode
68 public int getCode() {
73 * @return the full mode name
75 public String getName() {
80 * @return the short name
82 public String getShortName() {
87 * @return true if the mode is considered as armed
89 public boolean isArmed() {
94 * @return the command code
96 public byte getCommandCode() {
101 * @return true if the mode is an allowed command
103 public boolean isAllowedCommand() {
104 return allowedCommand;
108 * Set whether the mode is an allowed command or not
109 * To be allowed, the mode must have a valid command code.
111 * @param allowedCommand true if the mode must be an allowed command
113 public void setAllowedCommand(boolean allowedCommand) {
114 this.allowedCommand = getCommandCode() == 0xFF ? false : allowedCommand;
118 * Get the ENUM value from its code
120 * @param code the code identifying the mode
122 * @return the corresponding ENUM value
124 * @throws IllegalArgumentException if no ENUM value corresponds to this code
126 public static PowermaxArmMode fromCode(int code) throws IllegalArgumentException {
127 for (PowermaxArmMode mode : PowermaxArmMode.values()) {
128 if (mode.getCode() == code) {
133 throw new IllegalArgumentException("Invalid code: " + code);
137 * Get the ENUM value from its name
139 * @param name the full mode name
141 * @return the corresponding ENUM value
143 * @throws IllegalArgumentException if no ENUM value corresponds to this name
145 public static PowermaxArmMode fromName(String name) throws IllegalArgumentException {
146 for (PowermaxArmMode mode : PowermaxArmMode.values()) {
147 if (mode.getName().equalsIgnoreCase(name)) {
152 throw new IllegalArgumentException("Invalid name: " + name);
156 * Get the ENUM value from its short name
158 * @param shortName the mode short name
160 * @return the first corresponding ENUM value
162 * @throws IllegalArgumentException if no ENUM value corresponds to this short name
164 public static PowermaxArmMode fromShortName(String shortName) throws IllegalArgumentException {
165 for (PowermaxArmMode mode : PowermaxArmMode.values()) {
166 if (mode.getShortName().equalsIgnoreCase(shortName)) {
171 throw new IllegalArgumentException("Invalid short name: " + shortName);