]> git.basschouten.com Git - openhab-addons.git/blob
d5802e5394c61266f92196a03a3bf7baa5ea8187
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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 /**
16  * A class to store the settings of a zone
17  *
18  * @author Laurent Garnier - Initial contribution
19  */
20 public class PowermaxZoneSettings {
21
22     // Note: PowermaxStatusMessage contains hardcoded references to some of these strings
23
24     private static final String[] ZONE_TYPES = { "Non-Alarm", "Emergency", "Flood", "Gas", "Delay 1", "Delay 2",
25             "Interior-Follow", "Perimeter", "Perimeter-Follow", "24 Hours Silent", "24 Hours Audible", "Fire",
26             "Interior", "Home Delay", "Temperature", "Outdoor" };
27
28     private static final String[] ZONE_CHIMES = { "Off", "Melody", "Zone" };
29
30     private String name;
31     private String type;
32     private String chime;
33     private String sensorType;
34     private boolean[] partitions;
35     private boolean alwaysInAlarm;
36
37     public PowermaxZoneSettings(String name, byte type, byte chime, String sensorType, boolean[] partitions) {
38         this.name = name;
39         this.type = ((type & 0x000000FF) < ZONE_TYPES.length) ? ZONE_TYPES[type & 0x000000FF] : null;
40         this.chime = ((chime & 0x000000FF) < ZONE_CHIMES.length) ? ZONE_CHIMES[chime & 0x000000FF] : null;
41         this.sensorType = sensorType;
42         this.partitions = partitions;
43         this.alwaysInAlarm = ((type == 2) || (type == 3) || (type == 9) || (type == 10) || (type == 11)
44                 || (type == 14));
45     }
46
47     /**
48      * @return the zone name
49      */
50     public String getName() {
51         return (name == null) ? "Unknown" : name;
52     }
53
54     /**
55      * Set the zone name
56      *
57      * @param name the zone name
58      */
59     public void setName(String name) {
60         this.name = name;
61     }
62
63     /**
64      * @return the zone type
65      */
66     public String getType() {
67         return (type == null) ? "Unknown" : type;
68     }
69
70     /**
71      * Set the zone type
72      *
73      * @param type the zone type as an internal code
74      */
75     public void setType(byte type) {
76         this.type = ((type & 0x000000FF) < ZONE_TYPES.length) ? ZONE_TYPES[type & 0x000000FF] : null;
77         this.alwaysInAlarm = ((type == 2) || (type == 3) || (type == 9) || (type == 10) || (type == 11)
78                 || (type == 14));
79     }
80
81     public String getChime() {
82         return (chime == null) ? "Unknown" : chime;
83     }
84
85     /**
86      * @return the sensor type of this zone
87      */
88     public String getSensorType() {
89         return (sensorType == null) ? "Unknown" : sensorType;
90     }
91
92     /**
93      * Set the sensor type of this zone
94      *
95      * @param sensorType the sensor type
96      */
97     public void setSensorType(String sensorType) {
98         this.sensorType = sensorType;
99     }
100
101     /**
102      * @return true if the sensor type of this zone is a motion sensor
103      */
104     public boolean isMotionSensor() {
105         return PowermaxSensorType.MOTION_SENSOR_1.getLabel().equalsIgnoreCase(getSensorType());
106     }
107
108     /**
109      * @param number the partition number (first partition is number 1)
110      *
111      * @return true if the zone is attached to this partition; false if not
112      */
113     public boolean isInPartition(int number) {
114         return ((number <= 0) || (number > partitions.length)) ? false : partitions[number - 1];
115     }
116
117     /**
118      * @return true if the zone type is always in alarm; false if not
119      */
120     public boolean isAlwaysInAlarm() {
121         return alwaysInAlarm;
122     }
123 }