]> git.basschouten.com Git - openhab-addons.git/blob
f58e7248bbd240fc51687da6b981c51d783c5560
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.satel.internal.event;
14
15 import java.time.LocalDateTime;
16 import java.util.Optional;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19
20 /**
21  * Event class describing basic status bits and current time.
22  *
23  * @author Krzysztof Goworek - Initial contribution
24  */
25 @NonNullByDefault
26 public class IntegraStatusEvent implements SatelEvent {
27
28     private Optional<LocalDateTime> integraTime;
29     private boolean serviceMode;
30     private boolean troubles;
31     private boolean acu100Present;
32     private boolean intRxPresent;
33     private boolean troublesMemory;
34     private boolean grade23Set;
35     private byte integraType;
36
37     /**
38      * Constructs new event.
39      *
40      * @param integraTime current Integra date and time
41      * @param statusByte1 status bits, byte #1
42      * @param statusByte2 status bits, byte #2
43      */
44     public IntegraStatusEvent(Optional<LocalDateTime> integraTime, byte statusByte1, byte statusByte2) {
45         this.integraTime = integraTime;
46         this.serviceMode = (statusByte1 & 0x80) != 0;
47         this.troubles = (statusByte1 & 0x40) != 0;
48         this.acu100Present = (statusByte2 & 0x80) != 0;
49         this.intRxPresent = (statusByte2 & 0x40) != 0;
50         this.troublesMemory = (statusByte2 & 0x20) != 0;
51         this.grade23Set = (statusByte2 & 0x10) != 0;
52         this.integraType = (byte) (statusByte2 & 0x0f);
53     }
54
55     /**
56      * @return current date and time on connected Integra or <code>Optional.empty()</code> if date/time set in the
57      *         system is incorrect
58      */
59     public Optional<LocalDateTime> getIntegraTime() {
60         return integraTime;
61     }
62
63     /**
64      * @return <code>true</code> if service mode is enabled
65      */
66     public boolean inServiceMode() {
67         return serviceMode;
68     }
69
70     /**
71      * @return <code>true</code> if there are troubles in the system
72      */
73     public boolean troublesPresent() {
74         return troubles;
75     }
76
77     /**
78      * @return <code>true</code> if the are troubles in the memory
79      */
80     public boolean troublesMemory() {
81         return troublesMemory;
82     }
83
84     /**
85      * @return <code>true</code> if ACU-100 module is present in the system
86      */
87     public boolean isAcu100Present() {
88         return acu100Present;
89     }
90
91     /**
92      * @return <code>true</code> if INT-RX module is present in the system
93      */
94     public boolean isIntRxPresent() {
95         return intRxPresent;
96     }
97
98     /**
99      * @return <code>true</code> if Grade 2 or Grade 3 is enabled in Integra configuration
100      */
101     public boolean isGrade23Set() {
102         return grade23Set;
103     }
104
105     /**
106      * @return Integra board type
107      */
108     public int getIntegraType() {
109         return integraType;
110     }
111
112     @Override
113     public String toString() {
114         return String.format(
115                 "IntegraStatusEvent: type = %d, time = %s, service mode = %b, troubles = %b, troubles memory = %b, ACU-100 = %b, INT-RX = %b, grade 2/3 = %b",
116                 this.integraType, this.integraTime.map(LocalDateTime::toString).orElse("N/A"), this.serviceMode,
117                 this.troubles, this.troublesMemory, this.acu100Present, this.intRxPresent, this.grade23Set);
118     }
119 }