2 * Copyright (c) 2010-2022 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.BridgeCommunicationProtocol;
17 import org.openhab.binding.velux.internal.bridge.common.GetHouseStatus;
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.openhab.binding.velux.internal.things.VeluxProduct;
23 import org.openhab.binding.velux.internal.things.VeluxProduct.ProductBridgeIndex;
24 import org.openhab.binding.velux.internal.things.VeluxProductName;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * Protocol specific bridge communication supported by the Velux bridge:
30 * <B>Retrieve House Status</B>
32 * Common Message semantic: Communication from the bridge and storing returned information within the class itself.
34 * As 3rd level class it defines informations how to receive answer through the
35 * {@link org.openhab.binding.velux.internal.bridge.VeluxBridgeProvider VeluxBridgeProvider}
36 * as described by the interface {@link org.openhab.binding.velux.internal.bridge.slip.SlipBridgeCommunicationProtocol
37 * SlipBridgeCommunicationProtocol}.
39 * Methods in addition to the mentioned interface:
41 * <LI>{@link #getNtfNodeID} to retrieve the node identifier which has been changed.</LI>
42 * <LI>{@link #getNtfState} to retrieve the state of the node which has been changed.</LI>
43 * <LI>{@link #getNtfCurrentPosition} to retrieve the actual position of this node.</LI>
44 * <LI>{@link #getNtfTarget} to retrieve the target position of this node.</LI>
47 * NOTE: the class does NOT define a request as it only works as receiver.
49 * @see BridgeCommunicationProtocol
50 * @see SlipBridgeCommunicationProtocol
52 * @author Guenther Schreiner - Initial contribution.
55 public class SCgetHouseStatus extends GetHouseStatus
56 implements BridgeCommunicationProtocol, SlipBridgeCommunicationProtocol {
57 private final Logger logger = LoggerFactory.getLogger(SCgetHouseStatus.class);
59 private static final String DESCRIPTION = "Retrieve House Status";
60 private static final Command COMMAND = Command.GW_OPENHAB_RECEIVEONLY;
63 * ===========================================================
67 @SuppressWarnings("unused")
68 private byte[] requestData = new byte[0];
71 * ===========================================================
75 private boolean success = false;
76 private boolean finished = false;
78 private Command creatorCommand = Command.UNDEFTYPE;
79 private VeluxProduct product = VeluxProduct.UNKNOWN;
82 * ===========================================================
83 * Methods required for interface {@link SlipBridgeCommunicationProtocol}.
87 public String name() {
92 public CommandNumber getRequestCommand() {
93 logger.debug("getRequestCommand() returns {} ({}).", COMMAND.name(), COMMAND.getCommand());
94 return COMMAND.getCommand();
98 public byte[] getRequestDataAsArrayOfBytes() {
103 public void setResponse(short responseCommand, byte[] thisResponseData, boolean isSequentialEnforced) {
104 KLF200Response.introLogging(logger, responseCommand, thisResponseData);
107 Packet responseData = new Packet(thisResponseData);
108 Command responseCmd = Command.get(responseCommand);
109 switch (responseCmd) {
110 case GW_NODE_STATE_POSITION_CHANGED_NTF:
111 if (!KLF200Response.isLengthValid(logger, responseCommand, thisResponseData, 20)) {
114 int ntfNodeID = responseData.getOneByteValue(0);
115 int ntfState = responseData.getOneByteValue(1);
116 int ntfCurrentPosition = responseData.getTwoByteValue(2);
117 int ntfTarget = responseData.getTwoByteValue(4);
118 FunctionalParameters ntfFunctionalParameters = FunctionalParameters.readArray(responseData, 6);
119 int ntfRemainingTime = responseData.getTwoByteValue(14);
120 int ntfTimeStamp = responseData.getFourByteValue(16);
122 if (logger.isTraceEnabled()) {
123 logger.trace("setResponse(): ntfNodeID={}.", ntfNodeID);
124 logger.trace("setResponse(): ntfState={}.", ntfState);
125 logger.trace("setResponse(): ntfCurrentPosition={}.", String.format("0x%04X", ntfCurrentPosition));
126 logger.trace("setResponse(): ntfTarget={}.", String.format("0x%04X", ntfTarget));
127 logger.trace("setResponse(): ntfFunctionalParameters={} (returns null).", ntfFunctionalParameters);
128 logger.trace("setResponse(): ntfRemainingTime={}.", ntfRemainingTime);
129 logger.trace("setResponse(): ntfTimeStamp={}.", ntfTimeStamp);
132 // this BCP returns wrong functional parameters on some (e.g. Somfy) devices so return null instead
133 ntfFunctionalParameters = null;
135 // create notification product with the returned values
136 product = new VeluxProduct(VeluxProductName.UNKNOWN, new ProductBridgeIndex(ntfNodeID), ntfState,
137 ntfCurrentPosition, ntfTarget, ntfFunctionalParameters, creatorCommand);
143 KLF200Response.errorLogging(logger, responseCommand);
145 KLF200Response.outroLogging(logger, success, finished);
149 public boolean isCommunicationFinished() {
154 public boolean isCommunicationSuccessful() {
159 * ===========================================================
160 * Methods in addition to the interface {@link BridgeCommunicationProtocol}
163 public VeluxProduct getProduct() {
164 logger.trace("getProduct(): returning {}.", product);
169 * Change the command id that identifies the API on which 'product' will be created.
171 * @param creatorCommand the API that will be used to create the product instance.
174 public SCgetHouseStatus setCreatorCommand(Command creatorCommand) {
175 this.creatorCommand = creatorCommand;