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.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),
53 public class Channel {
54 public boolean isRetrieved = false;
55 public StringType openHABipAddress = new StringType(VeluxBindingConstants.UNKNOWN);
56 public StringType openHABsubnetMask = new StringType(VeluxBindingConstants.UNKNOWN);
57 public StringType openHABdefaultGW = new StringType(VeluxBindingConstants.UNKNOWN);
58 public OnOffType openHABenabledDHCP = OnOffType.OFF;
61 private Channel channel;
63 // Constructor methods
68 * Initializes the internal data structure {@link #channel} of Velux LAN information,
69 * which is publicly accessible via the method {@link #getChannel()}.
71 public VeluxBridgeLANConfig() {
72 logger.trace("VeluxBridgeLANConfig(constructor) called.");
73 channel = new Channel();
76 // Class access methods
79 * Provide access to the internal structure of LAN information.
81 * @return a channel describing the overall actual LAN information.
83 public Channel getChannel() {
88 * Complete workflow for retrieving the network configuration, consisting of Login into bridge, querying
89 * the network configuration and logout from bridge based on a well-prepared environment of a
90 * {@link VeluxBridgeProvider}, where the results are stored within as well in
91 * {@link VeluxBridgeLANConfig#channel}.
93 * @param bridge Initialized Velux bridge handler.
94 * @return <b>channel</b> of type {@link VeluxBridgeLANConfig.Channel} describing the overall result of this
97 public Channel retrieve(VeluxBridge bridge) {
98 logger.trace("retrieve() called.");
100 GetLANConfig bcp = bridge.bridgeAPI().getLANConfig();
101 if (bridge.bridgeCommunicate(bcp) && bcp.isCommunicationSuccessful()) {
102 logger.trace("retrieve() found successfully configuration {}.", bcp.getLANConfig());
103 channel.openHABipAddress = new StringType(bcp.getLANConfig().getIpAddress());
104 channel.openHABsubnetMask = new StringType(bcp.getLANConfig().getSubnetMask());
105 channel.openHABdefaultGW = new StringType(bcp.getLANConfig().getDefaultGW());
106 channel.openHABenabledDHCP = bcp.getLANConfig().getDHCP() ? OnOffType.ON : OnOffType.OFF;
107 channel.isRetrieved = true;
109 channel.isRetrieved = false;
110 logger.trace("retrieve() finished with failure.");