2 * Copyright (c) 2010-2022 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;
16 import org.eclipse.jdt.annotation.Nullable;
19 * A class to store the settings of a zone
21 * @author Laurent Garnier - Initial contribution
24 public class PowermaxZoneSettings {
26 // Note: PowermaxStatusMessage contains hardcoded references to some of these strings
28 private static final String[] ZONE_TYPES = { "Non-Alarm", "Emergency", "Flood", "Gas", "Delay 1", "Delay 2",
29 "Interior-Follow", "Perimeter", "Perimeter-Follow", "24 Hours Silent", "24 Hours Audible", "Fire",
30 "Interior", "Home Delay", "Temperature", "Outdoor" };
32 private static final String[] ZONE_CHIMES = { "Off", "Melody", "Zone" };
34 private final @Nullable String chime;
35 private final boolean[] partitions;
37 private @Nullable String name;
38 private @Nullable String type;
39 private @Nullable String sensorType;
40 private boolean alwaysInAlarm;
42 public PowermaxZoneSettings(@Nullable String name, byte type, byte chime, @Nullable String sensorType,
43 boolean[] partitions) {
45 this.type = ((type & 0x000000FF) < ZONE_TYPES.length) ? ZONE_TYPES[type & 0x000000FF] : null;
46 this.chime = ((chime & 0x000000FF) < ZONE_CHIMES.length) ? ZONE_CHIMES[chime & 0x000000FF] : null;
47 this.sensorType = sensorType;
48 this.partitions = partitions;
49 this.alwaysInAlarm = ((type == 2) || (type == 3) || (type == 9) || (type == 10) || (type == 11)
54 * @return the zone name
56 public String getName() {
57 String localName = name;
58 return (localName == null) ? "Unknown" : localName;
64 * @param name the zone name
66 public void setName(@Nullable String name) {
71 * @return the zone type
73 public String getType() {
74 String localType = type;
75 return (localType == null) ? "Unknown" : localType;
81 * @param type the zone type as an internal code
83 public void setType(byte type) {
84 this.type = ((type & 0x000000FF) < ZONE_TYPES.length) ? ZONE_TYPES[type & 0x000000FF] : null;
85 this.alwaysInAlarm = ((type == 2) || (type == 3) || (type == 9) || (type == 10) || (type == 11)
89 public String getChime() {
90 String localChime = chime;
91 return (localChime == null) ? "Unknown" : localChime;
95 * @return the sensor type of this zone
97 public String getSensorType() {
98 String localSensorType = sensorType;
99 return (localSensorType == null) ? "Unknown" : localSensorType;
103 * Set the sensor type of this zone
105 * @param sensorType the sensor type
107 public void setSensorType(String sensorType) {
108 this.sensorType = sensorType;
112 * @return true if the sensor type of this zone is a motion sensor
114 public boolean isMotionSensor() {
115 return PowermaxSensorType.MOTION_SENSOR_1.getLabel().equalsIgnoreCase(getSensorType());
119 * @param number the partition number (first partition is number 1)
121 * @return true if the zone is attached to this partition; false if not
123 public boolean isInPartition(int number) {
124 return ((number <= 0) || (number > partitions.length)) ? false : partitions[number - 1];
128 * @return true if the zone type is always in alarm; false if not
130 public boolean isAlwaysInAlarm() {
131 return alwaysInAlarm;