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