]> git.basschouten.com Git - openhab-addons.git/blob
3423ae6851e1b05682a923d33200bdad71ff992a
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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 import org.eclipse.jdt.annotation.Nullable;
17
18 /**
19  * A class to store the settings of a zone
20  *
21  * @author Laurent Garnier - Initial contribution
22  */
23 @NonNullByDefault
24 public class PowermaxZoneSettings {
25
26     // Note: PowermaxStatusMessage contains hardcoded references to some of these strings
27
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" };
31
32     private static final String[] ZONE_CHIMES = { "Off", "Melody", "Zone" };
33
34     private final @Nullable String chime;
35     private final boolean[] partitions;
36
37     private @Nullable String name;
38     private @Nullable String type;
39     private @Nullable String sensorType;
40     private boolean alwaysInAlarm;
41
42     public PowermaxZoneSettings(@Nullable String name, byte type, byte chime, @Nullable String sensorType,
43             boolean[] partitions) {
44         this.name = name;
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)
50                 || (type == 14));
51     }
52
53     /**
54      * @return the zone name
55      */
56     public String getName() {
57         String localName = name;
58         return (localName == null) ? "Unknown" : localName;
59     }
60
61     /**
62      * Set the zone name
63      *
64      * @param name the zone name
65      */
66     public void setName(@Nullable String name) {
67         this.name = name;
68     }
69
70     /**
71      * @return the zone type
72      */
73     public String getType() {
74         String localType = type;
75         return (localType == null) ? "Unknown" : localType;
76     }
77
78     /**
79      * Set the zone type
80      *
81      * @param type the zone type as an internal code
82      */
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)
86                 || (type == 14));
87     }
88
89     public String getChime() {
90         String localChime = chime;
91         return (localChime == null) ? "Unknown" : localChime;
92     }
93
94     /**
95      * @return the sensor type of this zone
96      */
97     public String getSensorType() {
98         String localSensorType = sensorType;
99         return (localSensorType == null) ? "Unknown" : localSensorType;
100     }
101
102     /**
103      * Set the sensor type of this zone
104      *
105      * @param sensorType the sensor type
106      */
107     public void setSensorType(String sensorType) {
108         this.sensorType = sensorType;
109     }
110
111     /**
112      * @return true if the sensor type of this zone is a motion sensor
113      */
114     public boolean isMotionSensor() {
115         return PowermaxSensorType.MOTION_SENSOR_1.getLabel().equalsIgnoreCase(getSensorType());
116     }
117
118     /**
119      * @param number the partition number (first partition is number 1)
120      *
121      * @return true if the zone is attached to this partition; false if not
122      */
123     public boolean isInPartition(int number) {
124         return ((number <= 0) || (number > partitions.length)) ? false : partitions[number - 1];
125     }
126
127     /**
128      * @return true if the zone type is always in alarm; false if not
129      */
130     public boolean isAlwaysInAlarm() {
131         return alwaysInAlarm;
132     }
133 }