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.GetWLANConfig;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * The {@link VeluxBridgeWLANConfig} represents a complete set of transactions
24 * for retrieving the wireless network configuration of the <B>Velux</B> bridge.
26 * It provides the following methods:
28 * <LI>{@link #retrieve} for retrieval of information.
29 * <LI>{@link #getChannel} for accessing the retrieved information.
33 * @see VeluxBridgeProvider
35 * @author Guenther Schreiner - Initial contribution
38 public class VeluxBridgeWLANConfig {
39 private final Logger logger = LoggerFactory.getLogger(VeluxBridgeWLANConfig.class);
41 // Type definitions, class-internal variables
44 * Wireless network configuration, consisting of:
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);
58 private Channel channel;
60 // Constructor methods
65 * Initializes the internal data structure {@link #channel} of Velux WLAN information,
66 * which is publicly accessible via the method {@link #getChannel()}.
68 public VeluxBridgeWLANConfig() {
69 logger.trace("VeluxBridgeWLANConfig(constructor) called.");
70 channel = new Channel();
73 // Class access methods
76 * Provide access to the internal structure of WLAN information.
78 * @return a channel describing the overall WLAN situation.
80 public Channel getChannel() {
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}.
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.
93 public Channel retrieve(VeluxBridge bridge) {
94 logger.trace("retrieve() called.");
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;
103 channel.isRetrieved = false;
104 logger.trace("retrieve() finished with failure.");