2 * Copyright (c) 2010-2024 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 java.lang.reflect.Field;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.velux.internal.config.VeluxBridgeConfiguration;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * <B>Class for Velux binding which validates the bridge configuration parameters.</B>
27 * <li>{@link #VeluxBinding constructor}</li>
28 * <li>{@link #checked }</li>
31 * @author Guenther Schreiner - Initial contribution
32 * @author Joachim Sauer (@Saua) - fix for isBulkRetrievalEnabled, isSequentialEnforced
35 public class VeluxBinding extends VeluxBridgeConfiguration {
36 private final Logger logger = LoggerFactory.getLogger(getClass());
45 * initializes the interface towards the Velux bridge. Furthermore, the checked configuration can be retrieved by
46 * the method {@link #checked checked}.
48 * @param uncheckedConfiguration
49 * The configuration of type {@link VeluxBridgeConfiguration}
50 * which shall be checked.
52 public VeluxBinding(@Nullable VeluxBridgeConfiguration uncheckedConfiguration) {
53 logger.trace("VeluxBinding(constructor) called.");
54 if (logger.isTraceEnabled()) {
55 for (Field field : VeluxBridgeConfiguration.class.getFields()) {
56 String fName = field.getName();
57 if ((fName.length() > 0) && Character.isUpperCase(fName.charAt(0))) {
58 logger.trace("VeluxBinding(): FYI: a potential configuration string is '{}'.", fName);
62 if (uncheckedConfiguration == null) {
63 logger.debug("No configuration found, using default values.");
65 logger.trace("VeluxBinding(): checking {}.", VeluxBridgeConfiguration.BRIDGE_PROTOCOL);
66 if (!uncheckedConfiguration.protocol.isBlank()) {
67 this.protocol = uncheckedConfiguration.protocol;
69 logger.trace("VeluxBinding(): checking {}.", VeluxBridgeConfiguration.BRIDGE_IPADDRESS);
70 if (!uncheckedConfiguration.ipAddress.isBlank()) {
71 this.ipAddress = uncheckedConfiguration.ipAddress;
73 logger.trace("VeluxBinding(): checking {}.", VeluxBridgeConfiguration.BRIDGE_TCPPORT);
74 if ((uncheckedConfiguration.tcpPort > 0) && (uncheckedConfiguration.tcpPort <= 65535)) {
75 this.tcpPort = uncheckedConfiguration.tcpPort;
77 logger.trace("VeluxBinding(): checking {}.", VeluxBridgeConfiguration.BRIDGE_PASSWORD);
78 if (!uncheckedConfiguration.password.isBlank()) {
79 this.password = uncheckedConfiguration.password;
81 logger.trace("VeluxBinding(): checking {}.", VeluxBridgeConfiguration.BRIDGE_TIMEOUT_MSECS);
82 if ((uncheckedConfiguration.timeoutMsecs >= 500) && (uncheckedConfiguration.timeoutMsecs <= 5000)) {
83 this.timeoutMsecs = uncheckedConfiguration.timeoutMsecs;
85 logger.trace("VeluxBinding(): checking {}.", VeluxBridgeConfiguration.BRIDGE_RETRIES);
86 if ((uncheckedConfiguration.retries >= 0) && (uncheckedConfiguration.retries <= 10)) {
87 this.retries = uncheckedConfiguration.retries;
89 logger.trace("VeluxBinding(): checking {}.", VeluxBridgeConfiguration.BRIDGE_REFRESH_MSECS);
90 if ((uncheckedConfiguration.refreshMSecs >= 1000) && (uncheckedConfiguration.refreshMSecs <= 60000)) {
91 this.refreshMSecs = uncheckedConfiguration.refreshMSecs;
93 this.isBulkRetrievalEnabled = uncheckedConfiguration.isBulkRetrievalEnabled;
94 this.isSequentialEnforced = uncheckedConfiguration.isSequentialEnforced;
95 this.isProtocolTraceEnabled = uncheckedConfiguration.isProtocolTraceEnabled;
98 logger.trace("VeluxBinding(constructor) done.");
102 * Access method returning a validated configuration.
104 * @return bridgeConfiguration of type {@link VeluxBridgeConfiguration
105 * VeluxBridgeConfiguration}.
107 public VeluxBridgeConfiguration checked() {
108 logger.trace("checked() called.");
110 logger.debug("{}Config[{}={},{}={},{}={},{}={},{}={},{}={},{}={},{}={},{}={},{}={}]",
111 VeluxBindingConstants.BINDING_ID,
112 VeluxBridgeConfiguration.BRIDGE_PROTOCOL, protocol,
113 VeluxBridgeConfiguration.BRIDGE_IPADDRESS, this.ipAddress,
114 VeluxBridgeConfiguration.BRIDGE_TCPPORT, tcpPort,
115 VeluxBridgeConfiguration.BRIDGE_PASSWORD, password.replaceAll(".", "*"),
116 VeluxBridgeConfiguration.BRIDGE_TIMEOUT_MSECS, timeoutMsecs,
117 VeluxBridgeConfiguration.BRIDGE_RETRIES, retries,
118 VeluxBridgeConfiguration.BRIDGE_REFRESH_MSECS, refreshMSecs,
119 VeluxBridgeConfiguration.BRIDGE_IS_BULK_RETRIEVAL_ENABLED, isBulkRetrievalEnabled,
120 VeluxBridgeConfiguration.BRIDGE_IS_SEQUENTIAL_ENFORCED, isSequentialEnforced,
121 VeluxBridgeConfiguration.BRIDGE_PROTOCOL_TRACE_ENABLED, isProtocolTraceEnabled);
123 logger.trace("checked() done.");