2 * Copyright (c) 2010-2023 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.satel.internal.event;
15 import java.time.LocalDateTime;
16 import java.util.Optional;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
21 * Event class describing basic status bits and current time.
23 * @author Krzysztof Goworek - Initial contribution
26 public class IntegraStatusEvent implements SatelEvent {
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;
38 * Constructs new event.
40 * @param integraTime current Integra date and time
41 * @param statusByte1 status bits, byte #1
42 * @param statusByte2 status bits, byte #2
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);
56 * @return current date and time on connected Integra or <code>Optional.empty()</code> if date/time set in the
59 public Optional<LocalDateTime> getIntegraTime() {
64 * @return <code>true</code> if service mode is enabled
66 public boolean inServiceMode() {
71 * @return <code>true</code> if there are troubles in the system
73 public boolean troublesPresent() {
78 * @return <code>true</code> if the are troubles in the memory
80 public boolean troublesMemory() {
81 return troublesMemory;
85 * @return <code>true</code> if ACU-100 module is present in the system
87 public boolean isAcu100Present() {
92 * @return <code>true</code> if INT-RX module is present in the system
94 public boolean isIntRxPresent() {
99 * @return <code>true</code> if Grade 2 or Grade 3 is enabled in Integra configuration
101 public boolean isGrade23Set() {
106 * @return Integra board type
108 public int getIntegraType() {
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);