]> git.basschouten.com Git - openhab-addons.git/blob
104d10115b64a9914259a3d0bc068d4d63a993a6
[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.state.PowermaxPanelType;
18 import org.openhab.binding.powermax.internal.state.PowermaxState;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 /**
23  * A class for INFO message handling
24  *
25  * @author Laurent Garnier - Initial contribution
26  */
27 @NonNullByDefault
28 public class PowermaxInfoMessage extends PowermaxBaseMessage {
29
30     private final Logger logger = LoggerFactory.getLogger(PowermaxInfoMessage.class);
31
32     /**
33      * Constructor
34      *
35      * @param message
36      *            the received message as a buffer of bytes
37      */
38     public PowermaxInfoMessage(byte[] message) {
39         super(message);
40     }
41
42     @Override
43     protected @Nullable PowermaxState handleMessageInternal(@Nullable PowermaxCommManager commManager) {
44         if (commManager == null) {
45             return null;
46         }
47
48         PowermaxState updatedState = commManager.createNewState();
49
50         byte[] message = getRawData();
51         byte panelTypeNr = message[7];
52         String panelTypeStr;
53
54         PowermaxPanelType panelType = null;
55         try {
56             panelType = PowermaxPanelType.fromCode(panelTypeNr);
57             panelTypeStr = panelType.toString();
58         } catch (IllegalArgumentException e) {
59             panelType = null;
60             panelTypeStr = "UNKNOWN";
61         }
62
63         debug("Panel type", panelTypeNr, panelTypeStr);
64
65         logger.debug("Reading panel settings");
66         updatedState.downloadMode.setValue(true);
67         commManager.sendMessage(PowermaxSendType.DL_PANELFW);
68         commManager.sendMessage(PowermaxSendType.DL_SERIAL);
69         commManager.sendMessage(PowermaxSendType.DL_ZONESTR);
70         commManager.sendSetTime();
71         if ((panelType != null) && panelType.isPowerMaster()) {
72             commManager.sendMessage(PowermaxSendType.DL_MR_SIRKEYZON);
73         }
74         commManager.sendMessage(PowermaxSendType.START);
75         commManager.sendMessage(PowermaxSendType.EXIT);
76
77         return updatedState;
78     }
79 }