]> git.basschouten.com Git - openhab-addons.git/blob
ec4a826d592ec97bfa636c200332ae29633a323c
[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.powermax.internal.message;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.powermax.internal.message.PowermaxMessageConstants.PowermaxSysEvent;
18 import org.openhab.binding.powermax.internal.state.PowermaxState;
19
20 /**
21  * A class for PANEL message handling
22  *
23  * @author Laurent Garnier - Initial contribution
24  */
25 @NonNullByDefault
26 public class PowermaxPanelMessage extends PowermaxBaseMessage {
27
28     /**
29      * Constructor
30      *
31      * @param message
32      *            the received message as a buffer of bytes
33      */
34     public PowermaxPanelMessage(byte[] message) {
35         super(message);
36     }
37
38     @Override
39     protected @Nullable PowermaxState handleMessageInternal(@Nullable PowermaxCommManager commManager) {
40         if (commManager == null) {
41             return null;
42         }
43
44         PowermaxState updatedState = commManager.createNewState();
45
46         byte[] message = getRawData();
47         int msgCnt = message[2] & 0x000000FF;
48
49         debug("Event count", msgCnt);
50
51         for (int i = 1; i <= msgCnt; i++) {
52             byte eventZone = message[2 + 2 * i];
53             byte logEvent = message[3 + 2 * i];
54             int eventType = logEvent & 0x0000007F;
55             PowermaxSysEvent sysEvent = PowermaxMessageConstants.getSystemEvent(eventType);
56             String logEventStr = sysEvent.toString();
57             String logUserStr = commManager.getPanelSettings().getZoneOrUserName(eventZone & 0x000000FF);
58
59             debug("Event " + i + " zone code", eventZone, logUserStr);
60             debug("Event " + i + " event code", eventType, logEventStr);
61
62             if (sysEvent.isAlarm() || sysEvent.isSilentAlarm() || sysEvent.isAlert() || sysEvent.isPanic()
63                     || sysEvent.isTrouble()) {
64                 updatedState.addActiveAlert(eventZone, eventType);
65             }
66
67             if (sysEvent.isAlarm() || (sysEvent.isPanic() && !commManager.getPanelSettings().isSilentPanic())) {
68                 updatedState.ringing.setValue(true);
69                 updatedState.ringingSince.setValue(System.currentTimeMillis());
70             }
71
72             if (sysEvent.isCancel() || sysEvent.isGeneralRestore() || sysEvent.isReset()) {
73                 updatedState.ringing.setValue(false);
74             }
75
76             if (sysEvent.isRestore()) {
77                 updatedState.clearActiveAlert(eventZone, sysEvent.getRestoreFor());
78             }
79
80             if (sysEvent.isGeneralRestore() || sysEvent.isReset()) {
81                 updatedState.clearAllActiveAlerts();
82             }
83
84             if (sysEvent.isReset()) {
85                 updatedState.clearAllActiveAlerts();
86                 updatedState.downloadSetupRequired.setValue(true);
87             }
88         }
89
90         return updatedState;
91     }
92 }