]> git.basschouten.com Git - openhab-addons.git/blob
28afa180e815b2c13325dd4d40ca9eb9eabddd1d
[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.GetWLANConfig;
18 import org.openhab.core.library.types.StringType;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 /**
23  * The {@link VeluxBridgeWLANConfig} represents a complete set of transactions
24  * for retrieving the wireless network configuration of the <B>Velux</B> bridge.
25  * <P>
26  * It provides the following methods:
27  * <UL>
28  * <LI>{@link #retrieve} for retrieval of information.
29  * <LI>{@link #getChannel} for accessing the retrieved information.
30  * </UL>
31  * <P>
32  *
33  * @see VeluxBridgeProvider
34  *
35  * @author Guenther Schreiner - Initial contribution
36  */
37 @NonNullByDefault
38 public class VeluxBridgeWLANConfig {
39     private final Logger logger = LoggerFactory.getLogger(VeluxBridgeWLANConfig.class);
40
41     // Type definitions, class-internal variables
42
43     /**
44      * Wireless network configuration, consisting of:
45      * <ul>
46      * <li>isRetrieved,
47      * <li>wlanSSID,
48      * <li>wlanPassword.
49      * </ul>
50      */
51     public class Channel {
52         public boolean isRetrieved = false;
53         public StringType openHABwlanSSID = new StringType(VeluxBindingConstants.UNKNOWN);
54         public StringType openHABwlanPassword = 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 WLAN information,
65      * which is publicly accessible via the method {@link #getChannel()}.
66      */
67     public VeluxBridgeWLANConfig() {
68         logger.trace("VeluxBridgeWLANConfig(constructor) called.");
69         channel = new Channel();
70     }
71
72     // Class access methods
73
74     /**
75      * Provide access to the internal structure of WLAN information.
76      *
77      * @return a channel describing the overall WLAN situation.
78      */
79     public Channel getChannel() {
80         return channel;
81     }
82
83     /**
84      * Complete workflow for retrieving the wireless network configuration, consisting of Login into bridge, querying
85      * the network configuration and logout from bridge based on a well-prepared environment of a
86      * {@link VeluxBridgeProvider}, where the results are stored within {@link VeluxBridgeWLANConfig#channel}.
87      *
88      * @param bridge Initialized Velux bridge handler.
89      * @return <b>channel</b> - or null -
90      *         of type {@link VeluxBridgeWLANConfig.Channel} describing the overall result of this interaction.
91      */
92     public Channel retrieve(VeluxBridge bridge) {
93         logger.trace("retrieve() called.");
94
95         GetWLANConfig bcp = bridge.bridgeAPI().getWLANConfig();
96         if (bridge.bridgeCommunicate(bcp) && bcp.isCommunicationSuccessful()) {
97             logger.trace("retrieve() found successfully configuration {}.", bcp.getWLANConfig());
98             channel.openHABwlanSSID = new StringType(bcp.getWLANConfig().getSSID());
99             channel.openHABwlanPassword = new StringType(bcp.getWLANConfig().getPassword());
100             channel.isRetrieved = true;
101         } else {
102             channel.isRetrieved = false;
103             logger.trace("retrieve() finished with failure.");
104         }
105         return channel;
106     }
107 }