2 * Copyright (c) 2010-2023 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.
50 class SCsetSceneVelocity extends SetSceneVelocity implements SlipBridgeCommunicationProtocol {
51 private final Logger logger = LoggerFactory.getLogger(SCsetSceneVelocity.class);
53 private static final String DESCRIPTION = "Modify Velocity of an Actuator";
54 private static final Command COMMAND = Command.GW_SET_NODE_VELOCITY_REQ;
57 * ===========================================================
58 * Message Content Parameters
61 private int reqNodeID = -1;
62 private int reqNodeVelocity = -1;
65 * ===========================================================
69 private byte[] requestData = new byte[0];
72 * ===========================================================
76 private boolean success = false;
77 private boolean finished = false;
80 * ===========================================================
81 * Methods required for interface {@link BridgeCommunicationProtocol}.
85 public String name() {
90 public CommandNumber getRequestCommand() {
93 logger.debug("getRequestCommand() returns {}.", COMMAND.getCommand());
94 return COMMAND.getCommand();
98 public byte[] getRequestDataAsArrayOfBytes() {
99 Packet request = new Packet(new byte[2]);
100 request.setOneByteValue(0, reqNodeID);
101 request.setOneByteValue(1, reqNodeVelocity);
102 requestData = request.toByteArray();
103 logger.trace("getRequestDataAsArrayOfBytes() data is {}.", new Packet(requestData).toString());
108 public void setResponse(short responseCommand, byte[] thisResponseData, boolean isSequentialEnforced) {
109 KLF200Response.introLogging(logger, responseCommand, thisResponseData);
112 Packet responseData = new Packet(thisResponseData);
113 switch (Command.get(responseCommand)) {
114 case GW_SET_NODE_VELOCITY_CFM:
116 if (!KLF200Response.isLengthValid(logger, responseCommand, thisResponseData, 3)) {
119 int cfmStatus = responseData.getOneByteValue(0);
122 logger.trace("setResponse(): returned status: Error - Wink is rejected.");
125 logger.trace("setResponse(): returned status: OK – Wink is accepted.");
129 logger.warn("setResponse({}): returned status={} (Reserved/unknown).",
130 Command.get(responseCommand).toString(), cfmStatus);
136 KLF200Response.errorLogging(logger, responseCommand);
139 KLF200Response.outroLogging(logger, success, finished);
143 public boolean isCommunicationFinished() {
148 public boolean isCommunicationSuccessful() {
153 * ===========================================================
154 * Methods in addition to the interface {@link BridgeCommunicationProtocol}
155 * and the abstract class {@link RunProductIdentification}
159 * Constructor Addon Method.
161 * Passes the intended Actuator Identifier towards this class for building the request lateron.
163 * @param actuatorId as type int describing the scene to be processed.
164 * @param silent as type boolean describing the silence mode of this node.
165 * @return <b>this</b> of type {@link SCsetSceneVelocity} as class itself.
168 public SCsetSceneVelocity setMode(int actuatorId, boolean silent) {
169 logger.trace("setProductId({},{}) called.", actuatorId, silent);
170 this.reqNodeID = actuatorId;
171 this.reqNodeVelocity = silent ? VeluxProductVelocity.SILENT.getVelocity()
172 : VeluxProductVelocity.FAST.getVelocity();