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;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.core.library.types.StringType;
17 import org.openhab.binding.velux.internal.VeluxBindingConstants;
18 import org.openhab.binding.velux.internal.bridge.common.GetDeviceStatus;
19 import org.openhab.binding.velux.internal.things.VeluxGwState;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * The {@link VeluxBridgeDeviceStatus} represents a complete set of transactions
25 * for querying device status on the <B>Velux</B> bridge.
27 * It therefore provides a method
29 * <LI>{@link #retrieve} for starting the detection.
30 * <LI>{@link #getChannel} for accessing the retrieved information.
33 * @see VeluxBridgeProvider
35 * @author Guenther Schreiner - Initial contribution
38 public class VeluxBridgeDeviceStatus {
39 private final Logger logger = LoggerFactory.getLogger(VeluxBridgeDeviceStatus.class);
41 // Type definitions, class-internal variables
44 * Bridge information consisting of:
46 * <li>{@link #isRetrieved} describing the retrieval state,
47 * <li>{@link #gwState} containing the brief gateway state,
48 * <li>{@link #gwStateDescription} containing the verbose gateway state.
52 public class Channel {
53 public boolean isRetrieved = false;
54 public StringType gwState = new StringType(VeluxBindingConstants.UNKNOWN);
55 public StringType gwStateDescription = new StringType(VeluxBindingConstants.UNKNOWN);
58 private Channel channel;
60 // Constructor methods
65 * Initializes the internal data structure {@link #channel} of Velux actuators/products,
66 * which is publicly accessible via the method {@link #getChannel()}.
68 public VeluxBridgeDeviceStatus() {
69 logger.trace("VeluxBridgeDeviceStatus(constructor) called.");
70 channel = new Channel();
73 // Class access methods
76 * Provide access to the internal structure of the device status.
78 * @return a channel describing the overall actual device status.
80 public Channel getChannel() {
85 * Complete workflow for retrieving the firmware version, consisting of Login into bridge, querying the firmware
86 * version and logout from bridge based on a well-prepared environment of a {@link VeluxBridgeProvider}, where the
87 * results are stored in {@link VeluxBridgeDeviceStatus#channel}.
89 * @param bridge Initialized Velux bridge handler.
90 * @return <b>channel</b> of type {@link VeluxBridgeDeviceStatus.Channel} describing the overall result of this
93 public Channel retrieve(VeluxBridge bridge) {
94 logger.trace("retrieve() called. About to query device status.");
95 GetDeviceStatus bcp = bridge.bridgeAPI().getDeviceStatus();
96 if (bridge.bridgeCommunicate(bcp) && bcp.isCommunicationSuccessful()) {
97 VeluxGwState state = bcp.getState();
98 channel.gwState = new StringType(state.toString());
99 channel.gwStateDescription = new StringType(state.toDescription());
100 channel.isRetrieved = true;
101 logger.trace("retrieve() finished successfully with result {}.", state.toDescription());
103 channel.isRetrieved = false;
104 logger.trace("retrieve() finished with failure.");