]> git.basschouten.com Git - openhab-addons.git/blob
64033493fc0ad4c9f919760b6ed4b6017da510ad
[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.velux.internal.bridge.slip;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.velux.internal.bridge.common.RunProductSearch;
17 import org.openhab.binding.velux.internal.bridge.slip.utils.Packet;
18 import org.openhab.binding.velux.internal.things.VeluxGwState;
19 import org.openhab.binding.velux.internal.things.VeluxKLFAPI.Command;
20 import org.openhab.binding.velux.internal.things.VeluxKLFAPI.CommandNumber;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 /**
25  * Protocol specific bridge communication supported by the Velux bridge:
26  * <B>Check for lost Nodes</B>
27  * <P>
28  * Common Message semantic: Communication with the bridge and (optionally) storing returned information within the class
29  * itself.
30  * <P>
31  * Implementing the protocol-independent class {@link RunProductSearch}.
32  * <P>
33  * As 3rd level class it defines informations how to send query and receive answer through the
34  * {@link org.openhab.binding.velux.internal.bridge.VeluxBridgeProvider VeluxBridgeProvider}
35  * as described by the interface {@link SlipBridgeCommunicationProtocol}.
36  * <P>
37  * Methods in addition to the mentioned interface:
38  * <UL>
39  * <LI>{@link SCrunProductSearch#getState} to retrieve the Velux gateway status.</LI>
40  * </UL>
41  *
42  * @see RunProductSearch
43  * @see SlipBridgeCommunicationProtocol
44  *
45  * @author Guenther Schreiner - Initial contribution.
46  */
47 @NonNullByDefault
48 class SCrunProductSearch extends RunProductSearch implements SlipBridgeCommunicationProtocol {
49     private final Logger logger = LoggerFactory.getLogger(SCrunProductSearch.class);
50
51     private static final String DESCRIPTION = "Check for lost Nodes";
52     private static final Command COMMAND = Command.GW_GET_STATE_REQ;
53
54     /*
55      * Message Objects
56      */
57
58     private byte[] requestData = new byte[0];
59     private short responseCommand;
60     private byte[] responseData = new byte[0];
61
62     /*
63      * ===========================================================
64      * Methods required for interface {@link SlipBridgeCommunicationProtocol}.
65      */
66
67     @Override
68     public String name() {
69         return DESCRIPTION;
70     }
71
72     @Override
73     public CommandNumber getRequestCommand() {
74         return COMMAND.getCommand();
75     }
76
77     @Override
78     public byte[] getRequestDataAsArrayOfBytes() {
79         requestData = new byte[0];
80         return requestData;
81     }
82
83     @Override
84     public void setResponse(short thisResponseCommand, byte[] thisResponseData, boolean isSequentialEnforced) {
85         logger.trace("setResponseCommand({}, {}) called.", thisResponseCommand, new Packet(thisResponseData));
86         responseCommand = thisResponseCommand;
87         responseData = thisResponseData;
88     }
89
90     @Override
91     public boolean isCommunicationFinished() {
92         return (responseCommand == Command.GW_GET_STATE_CFM.getShort());
93     }
94
95     @Override
96     public boolean isCommunicationSuccessful() {
97         return (responseCommand == Command.GW_GET_STATE_CFM.getShort());
98     }
99
100     /*
101      * ===========================================================
102      * Methods in addition to interface {@link BridgeCommunicationProtocol}.
103      */
104
105     public VeluxGwState getState() {
106         byte stateValue = responseData[0];
107         byte subStateValue = responseData[1];
108         VeluxGwState thisGwState = new VeluxGwState(stateValue, subStateValue);
109         logger.trace("getState() returns {} ({}).", thisGwState, thisGwState.toDescription());
110         return thisGwState;
111     }
112 }