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