]> git.basschouten.com Git - openhab-addons.git/blob
c51e8993092d43a1c26cd659737b82c9aafc09b9
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.velux.internal.VeluxBindingConstants;
18 import org.openhab.binding.velux.internal.bridge.common.GetWLANConfig;
19 import org.openhab.binding.velux.internal.bridge.slip.utils.Packet;
20 import org.openhab.binding.velux.internal.things.VeluxGwWLAN;
21 import org.openhab.binding.velux.internal.things.VeluxKLFAPI.Command;
22 import org.openhab.binding.velux.internal.things.VeluxKLFAPI.CommandNumber;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 /**
27  * Protocol specific bridge communication supported by the Velux bridge:
28  * <B>Retrieve WLAN configuration</B>
29  * <P>
30  * Common Message semantic: Communication with the bridge and (optionally) storing returned information within the class
31  * itself.
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 #getWLANConfig} to retrieve the current WLAN configuration.</LI>
40  * </UL>
41  *
42  * @see GetWLANConfig
43  * @see SlipBridgeCommunicationProtocol
44  *
45  *
46  * @author Guenther Schreiner - Initial contribution.
47  */
48 @NonNullByDefault
49 class SCgetWLANConfig extends GetWLANConfig implements SlipBridgeCommunicationProtocol {
50     private final Logger logger = LoggerFactory.getLogger(SCgetWLANConfig.class);
51
52     private static final String DESCRIPTION = "Retrieve WLAN configuration";
53     private static final Command COMMAND = Command.GW_GET_NETWORK_SETUP_REQ;
54
55     /*
56      * Message Objects
57      */
58
59     private byte[] requestData = new byte[0];
60     private short responseCommand;
61     @SuppressWarnings("unused")
62     private byte @Nullable [] responseData;
63
64     /*
65      * ===========================================================
66      * Constructor Method
67      */
68
69     public SCgetWLANConfig() {
70         logger.trace("SCgetWLANConfig(constructor) called.");
71         requestData = new byte[1];
72     }
73
74     /*
75      * ===========================================================
76      * Methods required for interface {@link SlipBridgeCommunicationProtocol}.
77      */
78
79     @Override
80     public String name() {
81         return DESCRIPTION;
82     }
83
84     @Override
85     public CommandNumber getRequestCommand() {
86         return COMMAND.getCommand();
87     }
88
89     @Override
90     public byte[] getRequestDataAsArrayOfBytes() {
91         return requestData;
92     }
93
94     @Override
95     public void setResponse(short thisResponseCommand, byte[] thisResponseData, boolean isSequentialEnforced) {
96         logger.trace("setResponseCommand({}, {}) called.", thisResponseCommand, new Packet(thisResponseData));
97         responseCommand = thisResponseCommand;
98         responseData = thisResponseData;
99     }
100
101     @Override
102     public boolean isCommunicationFinished() {
103         return true;
104     }
105
106     @Override
107     public boolean isCommunicationSuccessful() {
108         return (responseCommand == Command.GW_GET_NETWORK_SETUP_CFM.getShort());
109     }
110
111     /*
112      * ===========================================================
113      * Methods in addition to interface {@link BridgeCommunicationProtocol}.
114      */
115
116     @Override
117     public VeluxGwWLAN getWLANConfig() {
118         logger.trace("getWLANConfig() called.");
119         // Enhancement idea: Velux should provide an enhanced API.
120         return new VeluxGwWLAN(VeluxBindingConstants.UNKNOWN, VeluxBindingConstants.UNKNOWN);
121     }
122 }