2 * Copyright (c) 2010-2021 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.homematic.internal.common;
15 import org.apache.commons.lang.builder.ToStringBuilder;
16 import org.apache.commons.lang.builder.ToStringStyle;
17 import org.openhab.binding.homematic.internal.model.HmChannel;
18 import org.openhab.binding.homematic.internal.model.HmGatewayInfo;
19 import org.openhab.binding.homematic.internal.model.HmInterface;
22 * The main gateway config class.
24 * @author Gerhard Riegler - Initial contribution
26 public class HomematicConfig {
27 private static final String ISO_ENCODING = "ISO-8859-1";
28 private static final String UTF_ENCODING = "UTF-8";
30 private static final String GATEWAY_TYPE_AUTO = "AUTO";
31 private static final String GATEWAY_TYPE_CCU = "CCU";
32 private static final String GATEWAY_TYPE_NOCCU = "NOCCU";
34 private static final int DEFAULT_PORT_RF = 2001;
35 private static final int DEFAULT_PORT_WIRED = 2000;
36 private static final int DEFAULT_PORT_HMIP = 2010;
37 private static final int DEFAULT_PORT_CUXD = 8701;
38 private static final int DEFAULT_PORT_GROUP = 9292;
39 public static final int DEFAULT_INSTALL_MODE_DURATION = 60;
41 private String gatewayAddress;
42 private String gatewayType = GATEWAY_TYPE_AUTO;
45 private int wiredPort;
48 private int groupPort;
50 private String callbackHost;
51 private String bindAddress;
52 private int xmlCallbackPort;
53 private int binCallbackPort;
55 private int socketMaxAlive = 900;
56 private int timeout = 15;
57 private int installModeDuration = DEFAULT_INSTALL_MODE_DURATION;
58 private long discoveryTimeToLive = -1;
59 private boolean unpairOnDeletion = false;
60 private boolean factoryResetOnDeletion = false;
61 private int bufferSize = 2048;
63 private HmGatewayInfo gatewayInfo;
66 * Returns the Homematic gateway address.
68 public String getGatewayAddress() {
69 return gatewayAddress;
73 * Sets the Homematic gateway address.
75 public void setGatewayAddress(String gatewayAddress) {
76 this.gatewayAddress = gatewayAddress;
80 * Returns the callback host address.
82 public String getCallbackHost() {
87 * Sets the callback host address.
89 public void setCallbackHost(String callbackHost) {
90 this.callbackHost = callbackHost;
94 * Returns the bind address.
96 public String getBindAddress() {
101 * Sets the bind address.
103 public void setBindAddress(String bindAddress) {
104 this.bindAddress = bindAddress;
108 * Sets the callback host port.
110 * @deprecated use setBinCallbackPort
113 public void setCallbackPort(int callbackPort) {
114 this.binCallbackPort = callbackPort;
118 * Returns the XML-RPC callback host port.
120 public int getXmlCallbackPort() {
121 return xmlCallbackPort;
125 * Sets the XML-RPC callback host port.
127 public void setXmlCallbackPort(int xmlCallbackPort) {
128 this.xmlCallbackPort = xmlCallbackPort;
132 * Returns the BIN-RPC callback host port.
134 public int getBinCallbackPort() {
135 return binCallbackPort;
139 * Sets the BIN-RPC callback host port.
141 public void setBinCallbackPort(int binCallbackPort) {
142 this.binCallbackPort = binCallbackPort;
146 * Returns the HmGatewayInfo.
148 public HmGatewayInfo getGatewayInfo() {
153 * Sets the HmGatewayInfo.
155 public void setGatewayInfo(HmGatewayInfo gatewayInfo) {
156 this.gatewayInfo = gatewayInfo;
160 * Returns the max alive time of a socket connection to a Homematic gateway in seconds.
162 public int getSocketMaxAlive() {
163 return socketMaxAlive;
167 * Sets the max alive time of a socket connection to a Homematic gateway in seconds.
169 public void setSocketMaxAlive(int socketMaxAlive) {
170 this.socketMaxAlive = socketMaxAlive;
174 * Returns the timeout for the communication to a Homematic gateway in seconds.
176 public int getTimeout() {
181 * Sets the timeout for the communication to a Homematic gateway in seconds.
183 public void setTimeout(int timeout) {
184 this.timeout = timeout;
188 * Returns the time to live for discovery results of a Homematic gateway in seconds.
190 public long getDiscoveryTimeToLive() {
191 return discoveryTimeToLive;
195 * Sets the time to live for discovery results of a Homematic gateway in seconds.
197 public void setDiscoveryTimeToLive(long discoveryTimeToLive) {
198 this.discoveryTimeToLive = discoveryTimeToLive;
202 * Returns the HmGatewayType.
204 public String getGatewayType() {
209 * Sets the HmGatewayType.
211 public void setGatewayType(String gatewayType) {
212 this.gatewayType = gatewayType;
216 * Returns time in seconds that the controller will be in install mode when
217 * a device discovery is initiated
219 * @return time in seconds that the controller remains in install mode
221 public int getInstallModeDuration() {
222 return installModeDuration;
226 * Sets installModeDuration
228 * @param installModeDuration time in seconds that the controller remains in
231 public void setInstallModeDuration(int installModeDuration) {
232 this.installModeDuration = installModeDuration;
236 * Returns if devices are unpaired from the gateway when their corresponding things are removed
238 * @return <i>true</i> if devices are unpaired from the gateway when their corresponding things are removed
240 public boolean isUnpairOnDeletion() {
241 return unpairOnDeletion;
245 * Sets unpairOnDeletion
247 * @param unpairOnDeletion if set to <i>true</i>, devices are unpaired from the gateway when their corresponding
250 public void setUnpairOnDeletion(boolean unpairOnDeletion) {
251 this.unpairOnDeletion = unpairOnDeletion;
255 * Returns if devices are factory reset when their corresponding things are removed
257 * @return <i>true</i> if devices are factory reset when their corresponding things are removed
259 public boolean isFactoryResetOnDeletion() {
260 return factoryResetOnDeletion;
264 * Sets factoryResetOnDeletion
266 * @param factoryResetOnDeletion if set to <i>true</i>, devices are factory reset when their corresponding things
269 public void setFactoryResetOnDeletion(boolean factoryResetOnDeletion) {
270 this.factoryResetOnDeletion = factoryResetOnDeletion;
274 * Returns the TclRegaScript url.
276 public String getTclRegaUrl() {
277 return "http://" + gatewayAddress + ":8181/tclrega.exe";
281 * Returns the Homematic gateway port of the channel.
283 public int getRpcPort(HmChannel channel) {
284 return getRpcPort(channel.getDevice().getHmInterface());
288 * Returns the Homematic gateway port of the interfaces.
290 public int getRpcPort(HmInterface hmInterface) {
291 if (HmInterface.WIRED.equals(hmInterface)) {
292 return getWiredPort();
293 } else if (HmInterface.HMIP.equals(hmInterface)) {
294 return getHmIpPort();
295 } else if (HmInterface.CUXD.equals(hmInterface)) {
296 return getCuxdPort();
297 } else if (HmInterface.GROUP.equals(hmInterface)) {
298 return getGroupPort();
305 * Returns the port of the RF daemon.
307 private int getRfPort() {
308 return rfPort == 0 ? DEFAULT_PORT_RF : rfPort;
312 * Returns the port of the wired daemon.
314 private int getWiredPort() {
315 return wiredPort == 0 ? DEFAULT_PORT_WIRED : wiredPort;
319 * Returns the port of the HmIp daemon.
321 private int getHmIpPort() {
322 return hmIpPort == 0 ? DEFAULT_PORT_HMIP : hmIpPort;
326 * Returns the port of the CUxD daemon.
328 private int getCuxdPort() {
329 return cuxdPort == 0 ? DEFAULT_PORT_CUXD : cuxdPort;
333 * Returns the port of the group daemon.
335 public int getGroupPort() {
336 return groupPort == 0 ? DEFAULT_PORT_GROUP : groupPort;
340 * Returns true, if a wired port is configured.
342 public boolean hasWiredPort() {
343 return wiredPort != 0;
347 * Returns true, if a hmIp port is configured.
349 public boolean hasHmIpPort() {
350 return hmIpPort != 0;
354 * Returns true, if a cuxd port is configured.
356 public boolean hasCuxdPort() {
357 return cuxdPort != 0;
361 * Returns true, if a group port is configured.
363 public boolean hasGroupPort() {
364 return groupPort != 0;
368 * Returns true, if a RF port is configured.
370 public boolean hasRfPort() {
375 * Returns the encoding that is suitable on requests to & responds from the Homematic gateway.
377 public String getEncoding() {
378 if (gatewayInfo != null && gatewayInfo.isHomegear()) {
386 * Returns the buffers size used for the communication with the Homematic gateway.
388 public int getBufferSize() {
393 * Returns true, if the configured gatewayType is CCU.
395 public boolean isCCUType() {
396 return gatewayType.equalsIgnoreCase(HomematicConfig.GATEWAY_TYPE_CCU);
400 * Returns true, if the configured gatewayType is NoCCU.
402 public boolean isNoCCUType() {
403 return gatewayType.equalsIgnoreCase(HomematicConfig.GATEWAY_TYPE_NOCCU);
407 public String toString() {
408 ToStringBuilder tsb = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
409 tsb.append("gatewayAddress", gatewayAddress).append("callbackHost", callbackHost)
410 .append("bindAddress", bindAddress).append("xmlCallbackPort", xmlCallbackPort)
411 .append("binCallbackPort", binCallbackPort).append("gatewayType", gatewayType)
412 .append("rfPort", getRfPort()).append("wiredPort", getWiredPort()).append("hmIpPort", getHmIpPort())
413 .append("cuxdPort", getCuxdPort()).append("groupPort", getGroupPort()).append("timeout", timeout)
414 .append("discoveryTimeToLive", discoveryTimeToLive).append("installModeDuration", installModeDuration)
415 .append("socketMaxAlive", socketMaxAlive);
416 return tsb.toString();