]> git.basschouten.com Git - openhab-addons.git/blob
ada033471da65e872c93860af665228898dbe7fb
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.velux.internal.bridge;
14
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;
22
23 /**
24  * The {@link VeluxBridgeDeviceStatus} represents a complete set of transactions
25  * for querying device status on the <B>Velux</B> bridge.
26  * <P>
27  * It therefore provides a method
28  * <UL>
29  * <LI>{@link #retrieve} for starting the detection.
30  * <LI>{@link #getChannel} for accessing the retrieved information.
31  * </UL>
32  *
33  * @see VeluxBridgeProvider
34  *
35  * @author Guenther Schreiner - Initial contribution
36  */
37 @NonNullByDefault
38 public class VeluxBridgeDeviceStatus {
39     private final Logger logger = LoggerFactory.getLogger(VeluxBridgeDeviceStatus.class);
40
41     // Type definitions, class-internal variables
42
43     /**
44      * Bridge information consisting of:
45      * <ul>
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.
49      * </ul>
50      */
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);
55     }
56
57     private Channel channel;
58
59     // Constructor methods
60
61     /**
62      * Constructor.
63      * <P>
64      * Initializes the internal data structure {@link #channel} of Velux actuators/products,
65      * which is publicly accessible via the method {@link #getChannel()}.
66      */
67     public VeluxBridgeDeviceStatus() {
68         logger.trace("VeluxBridgeDeviceStatus(constructor) called.");
69         channel = new Channel();
70     }
71
72     // Class access methods
73
74     /**
75      * Provide access to the internal structure of the device status.
76      *
77      * @return a channel describing the overall actual device status.
78      */
79     public Channel getChannel() {
80         return channel;
81     }
82
83     /**
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}.
87      *
88      * @param bridge Initialized Velux bridge handler.
89      * @return <b>channel</b> of type {@link VeluxBridgeDeviceStatus.Channel} describing the overall result of this
90      *         interaction.
91      */
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());
101         } else {
102             channel.isRetrieved = false;
103             logger.trace("retrieve() finished with failure.");
104         }
105         return channel;
106     }
107 }