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.binding.velux.internal.VeluxBindingConstants;
17 import org.openhab.binding.velux.internal.bridge.common.GetLANConfig;
18 import org.openhab.core.library.types.OnOffType;
19 import org.openhab.core.library.types.StringType;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * The {@link VeluxBridgeLANConfig} represents a complete set of transactions
25 * for retrieving the network configuration of the <B>Velux</B> bridge.
27 * It provides the following methods:
29 * <LI>{@link #retrieve} for retrieval of information.
30 * <LI>{@link #getChannel} for accessing the retrieved information.
33 * @see VeluxBridgeProvider
35 * @author Guenther Schreiner - Initial contribution
38 public class VeluxBridgeLANConfig {
39 private final Logger logger = LoggerFactory.getLogger(VeluxBridgeLANConfig.class);
41 // Type definitions, class-internal variables
44 * IP Network configuration, consisting of:
46 * <li>isRetrieved (boolean flag),
54 public class Channel {
55 public boolean isRetrieved = false;
56 public StringType openHABipAddress = new StringType(VeluxBindingConstants.UNKNOWN);
57 public StringType openHABsubnetMask = new StringType(VeluxBindingConstants.UNKNOWN);
58 public StringType openHABdefaultGW = new StringType(VeluxBindingConstants.UNKNOWN);
59 public OnOffType openHABenabledDHCP = OnOffType.OFF;
62 private Channel channel;
64 // Constructor methods
69 * Initializes the internal data structure {@link #channel} of Velux LAN information,
70 * which is publicly accessible via the method {@link #getChannel()}.
72 public VeluxBridgeLANConfig() {
73 logger.trace("VeluxBridgeLANConfig(constructor) called.");
74 channel = new Channel();
77 // Class access methods
80 * Provide access to the internal structure of LAN information.
82 * @return a channel describing the overall actual LAN information.
84 public Channel getChannel() {
89 * Complete workflow for retrieving the network configuration, consisting of Login into bridge, querying
90 * the network configuration and logout from bridge based on a well-prepared environment of a
91 * {@link VeluxBridgeProvider}, where the results are stored within as well in
92 * {@link VeluxBridgeLANConfig#channel}.
94 * @param bridge Initialized Velux bridge handler.
95 * @return <b>channel</b> of type {@link VeluxBridgeLANConfig.Channel} describing the overall result of this
98 public Channel retrieve(VeluxBridge bridge) {
99 logger.trace("retrieve() called.");
101 GetLANConfig bcp = bridge.bridgeAPI().getLANConfig();
102 if (bridge.bridgeCommunicate(bcp) && bcp.isCommunicationSuccessful()) {
103 logger.trace("retrieve() found successfully configuration {}.", bcp.getLANConfig());
104 channel.openHABipAddress = new StringType(bcp.getLANConfig().getIpAddress());
105 channel.openHABsubnetMask = new StringType(bcp.getLANConfig().getSubnetMask());
106 channel.openHABdefaultGW = new StringType(bcp.getLANConfig().getDefaultGW());
107 channel.openHABenabledDHCP = bcp.getLANConfig().getDHCP() ? OnOffType.ON : OnOffType.OFF;
108 channel.isRetrieved = true;
110 channel.isRetrieved = false;
111 logger.trace("retrieve() finished with failure.");