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;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.velux.internal.VeluxBindingConstants;
17 import org.openhab.binding.velux.internal.bridge.common.GetDeviceStatus;
18 import org.openhab.binding.velux.internal.things.VeluxGwState;
19 import org.openhab.core.library.types.StringType;
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.
51 public class Channel {
52 public boolean isRetrieved = false;
53 public StringType gwState = new StringType(VeluxBindingConstants.UNKNOWN);
54 public StringType gwStateDescription = new StringType(VeluxBindingConstants.UNKNOWN);
57 private Channel channel;
59 // Constructor methods
64 * Initializes the internal data structure {@link #channel} of Velux actuators/products,
65 * which is publicly accessible via the method {@link #getChannel()}.
67 public VeluxBridgeDeviceStatus() {
68 logger.trace("VeluxBridgeDeviceStatus(constructor) called.");
69 channel = new Channel();
72 // Class access methods
75 * Provide access to the internal structure of the device status.
77 * @return a channel describing the overall actual device status.
79 public Channel getChannel() {
84 * Complete workflow for retrieving the firmware version, consisting of Login into bridge, querying the firmware
85 * version and logout from bridge based on a well-prepared environment of a {@link VeluxBridgeProvider}, where the
86 * results are stored in {@link VeluxBridgeDeviceStatus#channel}.
88 * @param bridge Initialized Velux bridge handler.
89 * @return <b>channel</b> of type {@link VeluxBridgeDeviceStatus.Channel} describing the overall result of this
92 public Channel retrieve(VeluxBridge bridge) {
93 logger.trace("retrieve() called. About to query device status.");
94 GetDeviceStatus bcp = bridge.bridgeAPI().getDeviceStatus();
95 if (bridge.bridgeCommunicate(bcp) && bcp.isCommunicationSuccessful()) {
96 VeluxGwState state = bcp.getState();
97 channel.gwState = new StringType(state.toString());
98 channel.gwStateDescription = new StringType(state.toDescription());
99 channel.isRetrieved = true;
100 logger.trace("retrieve() finished successfully with result {}.", state.toDescription());
102 channel.isRetrieved = false;
103 logger.trace("retrieve() finished with failure.");