]> git.basschouten.com Git - openhab-addons.git/blob
4ab622b54237e8e2dee0d5aed51260309de7a500
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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     @NonNullByDefault
52     public class Channel {
53         public boolean isRetrieved = false;
54         public StringType openHABwlanSSID = new StringType(VeluxBindingConstants.UNKNOWN);
55         public StringType openHABwlanPassword = new StringType(VeluxBindingConstants.UNKNOWN);
56     }
57
58     private Channel channel;
59
60     // Constructor methods
61
62     /**
63      * Constructor.
64      * <P>
65      * Initializes the internal data structure {@link #channel} of Velux WLAN information,
66      * which is publicly accessible via the method {@link #getChannel()}.
67      */
68     public VeluxBridgeWLANConfig() {
69         logger.trace("VeluxBridgeWLANConfig(constructor) called.");
70         channel = new Channel();
71     }
72
73     // Class access methods
74
75     /**
76      * Provide access to the internal structure of WLAN information.
77      *
78      * @return a channel describing the overall WLAN situation.
79      */
80     public Channel getChannel() {
81         return channel;
82     }
83
84     /**
85      * Complete workflow for retrieving the wireless network configuration, consisting of Login into bridge, querying
86      * the network configuration and logout from bridge based on a well-prepared environment of a
87      * {@link VeluxBridgeProvider}, where the results are stored within {@link VeluxBridgeWLANConfig#channel}.
88      *
89      * @param bridge Initialized Velux bridge handler.
90      * @return <b>channel</b> - or null -
91      *         of type {@link VeluxBridgeWLANConfig.Channel} describing the overall result of this interaction.
92      */
93     public Channel retrieve(VeluxBridge bridge) {
94         logger.trace("retrieve() called.");
95
96         GetWLANConfig bcp = bridge.bridgeAPI().getWLANConfig();
97         if (bridge.bridgeCommunicate(bcp) && bcp.isCommunicationSuccessful()) {
98             logger.trace("retrieve() found successfully configuration {}.", bcp.getWLANConfig());
99             channel.openHABwlanSSID = new StringType(bcp.getWLANConfig().getSSID());
100             channel.openHABwlanPassword = new StringType(bcp.getWLANConfig().getPassword());
101             channel.isRetrieved = true;
102         } else {
103             channel.isRetrieved = false;
104             logger.trace("retrieve() finished with failure.");
105         }
106         return channel;
107     }
108 }