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.bridge.common.SetSceneVelocity;
17 import org.openhab.binding.velux.internal.bridge.slip.utils.KLF200Response;
18 import org.openhab.binding.velux.internal.bridge.slip.utils.Packet;
19 import org.openhab.binding.velux.internal.things.VeluxKLFAPI.Command;
20 import org.openhab.binding.velux.internal.things.VeluxKLFAPI.CommandNumber;
21 import org.openhab.binding.velux.internal.things.VeluxProductVelocity;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * Protocol specific bridge communication supported by the Velux bridge:
27 * <B>Modify Velocity of an Actuator</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 #setMode} to define the new silence mode of the intended actuator.</LI>
42 * @see SetSceneVelocity
43 * @see SlipBridgeCommunicationProtocol
45 * @author Guenther Schreiner - Initial contribution.
47 // ToDo: THIS MESSAGE EXCHANGE IS AN UNDOCUMENTED FEATURE. Check the updated Velux doc against this implementation.
49 class SCsetSceneVelocity extends SetSceneVelocity implements SlipBridgeCommunicationProtocol {
50 private final Logger logger = LoggerFactory.getLogger(SCsetSceneVelocity.class);
52 private static final String DESCRIPTION = "Modify Velocity of an Actuator";
53 private static final Command COMMAND = Command.GW_SET_NODE_VELOCITY_REQ;
56 * ===========================================================
57 * Message Content Parameters
60 private int reqNodeID = -1;
61 private int reqNodeVelocity = -1;
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 BridgeCommunicationProtocol}.
84 public String name() {
89 public CommandNumber getRequestCommand() {
92 logger.debug("getRequestCommand() returns {}.", COMMAND.getCommand());
93 return COMMAND.getCommand();
97 public byte[] getRequestDataAsArrayOfBytes() {
98 Packet request = new Packet(new byte[2]);
99 request.setOneByteValue(0, reqNodeID);
100 request.setOneByteValue(1, reqNodeVelocity);
101 requestData = request.toByteArray();
102 logger.trace("getRequestDataAsArrayOfBytes() data is {}.", new Packet(requestData).toString());
107 public void setResponse(short responseCommand, byte[] thisResponseData, boolean isSequentialEnforced) {
108 KLF200Response.introLogging(logger, responseCommand, thisResponseData);
111 Packet responseData = new Packet(thisResponseData);
112 switch (Command.get(responseCommand)) {
113 case GW_SET_NODE_VELOCITY_CFM:
115 if (!KLF200Response.isLengthValid(logger, responseCommand, thisResponseData, 3)) {
118 int cfmStatus = responseData.getOneByteValue(0);
121 logger.trace("setResponse(): returned status: Error - Wink is rejected.");
124 logger.trace("setResponse(): returned status: OK – Wink is accepted.");
128 logger.warn("setResponse({}): returned status={} (Reserved/unknown).",
129 Command.get(responseCommand).toString(), cfmStatus);
135 KLF200Response.errorLogging(logger, responseCommand);
138 KLF200Response.outroLogging(logger, success, finished);
142 public boolean isCommunicationFinished() {
147 public boolean isCommunicationSuccessful() {
152 * ===========================================================
153 * Methods in addition to the interface {@link BridgeCommunicationProtocol}
154 * and the abstract class {@link RunProductIdentification}
158 * Constructor Addon Method.
160 * Passes the intended Actuator Identifier towards this class for building the request lateron.
162 * @param actuatorId as type int describing the scene to be processed.
163 * @param silent as type boolean describing the silence mode of this node.
164 * @return <b>this</b> of type {@link SCsetSceneVelocity} as class itself.
167 public SCsetSceneVelocity setMode(int actuatorId, boolean silent) {
168 logger.trace("setProductId({},{}) called.", actuatorId, silent);
169 this.reqNodeID = actuatorId;
170 this.reqNodeVelocity = silent ? VeluxProductVelocity.SILENT.getVelocity()
171 : VeluxProductVelocity.FAST.getVelocity();