2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.velux.internal.bridge.slip;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.velux.internal.VeluxBindingConstants;
17 import org.openhab.binding.velux.internal.bridge.common.Login;
18 import org.openhab.binding.velux.internal.bridge.slip.utils.KLF200Response;
19 import org.openhab.binding.velux.internal.bridge.slip.utils.Packet;
20 import org.openhab.binding.velux.internal.things.VeluxKLFAPI.Command;
21 import org.openhab.binding.velux.internal.things.VeluxKLFAPI.CommandNumber;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * Protocol specific bridge communication supported by the Velux bridge:
27 * <B>Authenticate / login</B>
29 * Common Message semantic: Communication with the bridge and (optionally) storing returned information within the class
32 * As 3rd level class it defines informations how to send query and receive answer through the
33 * {@link org.openhab.binding.velux.internal.bridge.VeluxBridgeProvider VeluxBridgeProvider}
34 * as described by the interface {@link org.openhab.binding.velux.internal.bridge.slip.SlipBridgeCommunicationProtocol
35 * SlipBridgeCommunicationProtocol}.
37 * Methods in addition to the mentioned interface:
39 * <LI>{@link #setPassword(String)} to define the authentication reqPassword to be used.</LI>
40 * <LI>{@link #getAuthToken()} to retrieve the authentication reqPassword.</LI>
44 * @see SlipBridgeCommunicationProtocol
47 * @author Guenther Schreiner - Initial contribution.
50 class SClogin extends Login implements SlipBridgeCommunicationProtocol {
51 private final Logger logger = LoggerFactory.getLogger(SClogin.class);
53 private static final String DESCRIPTION = "Authenticate / login";
54 private static final Command COMMAND = Command.GW_PASSWORD_ENTER_REQ;
57 * ===========================================================
58 * Message Content Parameters
61 private String reqPassword = "";
64 * ===========================================================
68 private byte[] requestData = new byte[0];
71 * ===========================================================
75 private boolean success = false;
76 private boolean finished = false;
79 * ===========================================================
80 * Methods required for interface {@link SlipBridgeCommunicationProtocol}.
84 public String name() {
89 public CommandNumber getRequestCommand() {
90 return COMMAND.getCommand();
94 public byte[] getRequestDataAsArrayOfBytes() {
95 requestData = new byte[32];
96 byte[] password = reqPassword.getBytes();
97 System.arraycopy(password, 0, requestData, 0, password.length);
102 public void setResponse(short responseCommand, byte[] thisResponseData, boolean isSequentialEnforced) {
103 KLF200Response.introLogging(logger, responseCommand, thisResponseData);
106 Packet responseData = new Packet(thisResponseData);
107 switch (Command.get(responseCommand)) {
108 case GW_PASSWORD_ENTER_CFM:
109 if (!KLF200Response.isLengthValid(logger, responseCommand, thisResponseData, 1)) {
112 int cfmStatus = responseData.getOneByteValue(0);
115 logger.info("{} bridge connection successfully established (login succeeded).",
116 VeluxBindingConstants.BINDING_ID);
117 logger.debug("setResponse(): returned status: The request was successful.");
121 logger.warn("{} bridge connection successfully established but login failed.",
122 VeluxBindingConstants.BINDING_ID);
123 logger.debug("setResponse(): returned status: The request failed.");
126 logger.warn("setResponse(): returned status={} (not defined).", cfmStatus);
132 KLF200Response.errorLogging(logger, responseCommand);
135 KLF200Response.outroLogging(logger, success, finished);
139 public boolean isCommunicationFinished() {
144 public boolean isCommunicationSuccessful() {
149 * ===========================================================
150 * Methods in addition to interface {@link BridgeCommunicationProtocol}.
154 public void setPassword(String thisPassword) {
155 logger.trace("setPassword({}) called.", thisPassword.replaceAll(".", "*"));
156 reqPassword = thisPassword;
161 public String getAuthToken() {
162 logger.trace("getAuthToken() called, returning {}.", reqPassword.replaceAll(".", "*"));