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.GetWLANConfig;
18 import org.openhab.core.library.types.StringType;
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:
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);
57 private Channel channel;
59 // Constructor methods
64 * Initializes the internal data structure {@link #channel} of Velux WLAN information,
65 * which is publicly accessible via the method {@link #getChannel()}.
67 public VeluxBridgeWLANConfig() {
68 logger.trace("VeluxBridgeWLANConfig(constructor) called.");
69 channel = new Channel();
72 // Class access methods
75 * Provide access to the internal structure of WLAN information.
77 * @return a channel describing the overall WLAN situation.
79 public Channel getChannel() {
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}.
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.
92 public Channel retrieve(VeluxBridge bridge) {
93 logger.trace("retrieve() called.");
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;
102 channel.isRetrieved = false;
103 logger.trace("retrieve() finished with failure.");