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;
15 import static org.apache.commons.lang.StringUtils.isNotBlank;
17 import java.lang.reflect.Field;
19 import org.apache.commons.lang.StringUtils;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.binding.velux.internal.config.VeluxBridgeConfiguration;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * <B>Class for Velux binding which validates the bridge configuration parameters.</B>
30 * <li>{@link #VeluxBinding constructor}</li>
31 * <li>{@link #checked }</li>
34 * @author Guenther Schreiner - Initial contribution
35 * @author Joachim Sauer (@Saua) - fix for isBulkRetrievalEnabled, isSequentialEnforced
38 public class VeluxBinding extends VeluxBridgeConfiguration {
39 private final Logger logger = LoggerFactory.getLogger(getClass());
48 * initializes the interface towards the Velux bridge. Furthermore, the checked configuration can be retrieved by
49 * the method {@link #checked checked}.
51 * @param uncheckedConfiguration
52 * The configuration of type {@link VeluxBridgeConfiguration}
53 * which shall be checked.
55 public VeluxBinding(@Nullable VeluxBridgeConfiguration uncheckedConfiguration) {
56 logger.trace("VeluxBinding(constructor) called.");
57 if (logger.isTraceEnabled()) {
58 for (Field field : VeluxBridgeConfiguration.class.getFields()) {
59 if (!StringUtils.capitalize(field.getName()).contentEquals(field.getName())) {
60 logger.trace("VeluxBinding(): FYI: a potential configuration string is '{}'.", field.getName());
64 if (uncheckedConfiguration == null) {
65 logger.debug("No configuration found, using default values.");
67 logger.trace("VeluxBinding(): checking {}.", VeluxBridgeConfiguration.BRIDGE_PROTOCOL);
68 if (isNotBlank(uncheckedConfiguration.protocol)) {
69 this.protocol = uncheckedConfiguration.protocol;
71 logger.trace("VeluxBinding(): checking {}.", VeluxBridgeConfiguration.BRIDGE_IPADDRESS);
72 if (isNotBlank(uncheckedConfiguration.ipAddress)) {
73 this.ipAddress = uncheckedConfiguration.ipAddress;
75 logger.trace("VeluxBinding(): checking {}.", VeluxBridgeConfiguration.BRIDGE_TCPPORT);
76 if ((uncheckedConfiguration.tcpPort > 0) && (uncheckedConfiguration.tcpPort <= 65535)) {
77 this.tcpPort = uncheckedConfiguration.tcpPort;
79 logger.trace("VeluxBinding(): checking {}.", VeluxBridgeConfiguration.BRIDGE_PASSWORD);
80 if (isNotBlank(uncheckedConfiguration.password)) {
81 this.password = uncheckedConfiguration.password;
83 logger.trace("VeluxBinding(): checking {}.", VeluxBridgeConfiguration.BRIDGE_TIMEOUT_MSECS);
84 if ((uncheckedConfiguration.timeoutMsecs > 0) && (uncheckedConfiguration.timeoutMsecs <= 10000)) {
85 this.timeoutMsecs = uncheckedConfiguration.timeoutMsecs;
87 logger.trace("VeluxBinding(): checking {}.", VeluxBridgeConfiguration.BRIDGE_RETRIES);
88 if ((uncheckedConfiguration.retries >= 0) && (uncheckedConfiguration.retries <= 10)) {
89 this.retries = uncheckedConfiguration.retries;
91 logger.trace("VeluxBinding(): checking {}.", VeluxBridgeConfiguration.BRIDGE_REFRESH_MSECS);
92 if ((uncheckedConfiguration.refreshMSecs > 0) && (uncheckedConfiguration.refreshMSecs <= 10000)) {
93 this.refreshMSecs = uncheckedConfiguration.refreshMSecs;
95 this.isBulkRetrievalEnabled = uncheckedConfiguration.isBulkRetrievalEnabled;
96 this.isSequentialEnforced = uncheckedConfiguration.isSequentialEnforced;
97 this.isProtocolTraceEnabled = uncheckedConfiguration.isProtocolTraceEnabled;
100 logger.trace("VeluxBinding(constructor) done.");
104 * Access method returning a validated configuration.
106 * @return bridgeConfiguration of type {@link VeluxBridgeConfiguration
107 * VeluxBridgeConfiguration}.
109 public VeluxBridgeConfiguration checked() {
110 logger.trace("checked() called.");
111 logger.debug("{}Config[{}={},{}={},{}={},{}={},{}={},{}={},{}={},{}={},{}={},{}={}]",
112 VeluxBindingConstants.BINDING_ID, VeluxBridgeConfiguration.BRIDGE_PROTOCOL, protocol,
113 VeluxBridgeConfiguration.BRIDGE_IPADDRESS, this.ipAddress, VeluxBridgeConfiguration.BRIDGE_TCPPORT,
114 tcpPort, VeluxBridgeConfiguration.BRIDGE_PASSWORD, password.replaceAll(".", "*"),
115 VeluxBridgeConfiguration.BRIDGE_TIMEOUT_MSECS, timeoutMsecs, VeluxBridgeConfiguration.BRIDGE_RETRIES,
116 retries, VeluxBridgeConfiguration.BRIDGE_REFRESH_MSECS, refreshMSecs,
117 VeluxBridgeConfiguration.BRIDGE_IS_BULK_RETRIEVAL_ENABLED, isBulkRetrievalEnabled,
118 VeluxBridgeConfiguration.BRIDGE_IS_SEQUENTIAL_ENFORCED, isSequentialEnforced,
119 VeluxBridgeConfiguration.BRIDGE_PROTOCOL_TRACE_ENABLED, isProtocolTraceEnabled);
120 logger.trace("checked() done.");