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.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 #getProduct} to retrieve product type.</LI>
42 * <LI>{@link #setCreatorCommand} to set the command id that identifies the API on which 'product' will be created.</LI>
45 * NOTE: the class does NOT define a request as it only works as receiver.
47 * @see BridgeCommunicationProtocol
48 * @see SlipBridgeCommunicationProtocol
50 * @author Guenther Schreiner - Initial contribution.
53 public class SCgetHouseStatus extends GetHouseStatus
54 implements BridgeCommunicationProtocol, SlipBridgeCommunicationProtocol {
55 private final Logger logger = LoggerFactory.getLogger(SCgetHouseStatus.class);
57 private static final String DESCRIPTION = "Retrieve House Status";
58 private static final Command COMMAND = Command.GW_OPENHAB_RECEIVEONLY;
61 * ===========================================================
65 @SuppressWarnings("unused")
66 private byte[] requestData = new byte[0];
69 * ===========================================================
73 private boolean success = false;
74 private boolean finished = false;
76 private Command creatorCommand = Command.UNDEFTYPE;
77 private VeluxProduct product = VeluxProduct.UNKNOWN;
80 * ===========================================================
81 * Methods required for interface {@link SlipBridgeCommunicationProtocol}.
85 public String name() {
90 public CommandNumber getRequestCommand() {
91 logger.debug("getRequestCommand() returns {} ({}).", COMMAND.name(), COMMAND.getCommand());
92 return COMMAND.getCommand();
96 public byte[] getRequestDataAsArrayOfBytes() {
101 public void setResponse(short responseCommand, byte[] thisResponseData, boolean isSequentialEnforced) {
102 KLF200Response.introLogging(logger, responseCommand, thisResponseData);
105 Packet responseData = new Packet(thisResponseData);
106 Command responseCmd = Command.get(responseCommand);
107 switch (responseCmd) {
108 case GW_NODE_STATE_POSITION_CHANGED_NTF:
109 if (!KLF200Response.isLengthValid(logger, responseCommand, thisResponseData, 20)) {
112 int ntfNodeID = responseData.getOneByteValue(0);
113 int ntfState = responseData.getOneByteValue(1);
114 int ntfCurrentPosition = responseData.getTwoByteValue(2);
115 int ntfTarget = responseData.getTwoByteValue(4);
116 FunctionalParameters ntfFunctionalParameters = FunctionalParameters.readArray(responseData, 6);
117 int ntfRemainingTime = responseData.getTwoByteValue(14);
118 int ntfTimeStamp = responseData.getFourByteValue(16);
120 if (logger.isTraceEnabled()) {
121 logger.trace("setResponse(): ntfNodeID={}.", ntfNodeID);
122 logger.trace("setResponse(): ntfState={}.", ntfState);
123 logger.trace("setResponse(): ntfCurrentPosition={}.", String.format("0x%04X", ntfCurrentPosition));
124 logger.trace("setResponse(): ntfTarget={}.", String.format("0x%04X", ntfTarget));
125 logger.trace("setResponse(): ntfFunctionalParameters={} (returns null).", ntfFunctionalParameters);
126 logger.trace("setResponse(): ntfRemainingTime={}.", ntfRemainingTime);
127 logger.trace("setResponse(): ntfTimeStamp={}.", ntfTimeStamp);
130 // this BCP returns wrong functional parameters on some (e.g. Somfy) devices so return null instead
131 ntfFunctionalParameters = null;
133 // create notification product with the returned values
134 product = new VeluxProduct(VeluxProductName.UNKNOWN, new ProductBridgeIndex(ntfNodeID), ntfState,
135 ntfCurrentPosition, ntfTarget, ntfFunctionalParameters, creatorCommand);
141 KLF200Response.errorLogging(logger, responseCommand);
143 KLF200Response.outroLogging(logger, success, finished);
147 public boolean isCommunicationFinished() {
152 public boolean isCommunicationSuccessful() {
157 * ===========================================================
158 * Methods in addition to the interface {@link BridgeCommunicationProtocol}
161 public VeluxProduct getProduct() {
162 logger.trace("getProduct(): returning {}.", product);
167 * Change the command id that identifies the API on which 'product' will be created.
169 * @param creatorCommand the API that will be used to create the product instance.
172 public SCgetHouseStatus setCreatorCommand(Command creatorCommand) {
173 this.creatorCommand = creatorCommand;