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.openhab.binding.homematic.internal.model.HmChannel;
16 import org.openhab.binding.homematic.internal.model.HmGatewayInfo;
17 import org.openhab.binding.homematic.internal.model.HmInterface;
20 * The main gateway config class.
22 * @author Gerhard Riegler - Initial contribution
24 public class HomematicConfig {
25 private static final String ISO_ENCODING = "ISO-8859-1";
26 private static final String UTF_ENCODING = "UTF-8";
28 private static final String GATEWAY_TYPE_AUTO = "AUTO";
29 private static final String GATEWAY_TYPE_CCU = "CCU";
30 private static final String GATEWAY_TYPE_NOCCU = "NOCCU";
32 private static final int DEFAULT_PORT_RF = 2001;
33 private static final int DEFAULT_PORT_WIRED = 2000;
34 private static final int DEFAULT_PORT_HMIP = 2010;
35 private static final int DEFAULT_PORT_CUXD = 8701;
36 private static final int DEFAULT_PORT_GROUP = 9292;
37 public static final int DEFAULT_INSTALL_MODE_DURATION = 60;
39 private String gatewayAddress;
40 private String gatewayType = GATEWAY_TYPE_AUTO;
43 private int wiredPort;
46 private int groupPort;
48 private String callbackHost;
49 private int xmlCallbackPort;
50 private int binCallbackPort;
52 private int socketMaxAlive = 900;
53 private int timeout = 15;
54 private int installModeDuration = DEFAULT_INSTALL_MODE_DURATION;
55 private long discoveryTimeToLive = -1;
56 private boolean unpairOnDeletion = false;
57 private boolean factoryResetOnDeletion = false;
58 private int bufferSize = 2048;
60 private HmGatewayInfo gatewayInfo;
63 * Returns the Homematic gateway address.
65 public String getGatewayAddress() {
66 return gatewayAddress;
70 * Sets the Homematic gateway address.
72 public void setGatewayAddress(String gatewayAddress) {
73 this.gatewayAddress = gatewayAddress;
77 * Returns the callback host address.
79 public String getCallbackHost() {
84 * Sets the callback host address.
86 public void setCallbackHost(String callbackHost) {
87 this.callbackHost = callbackHost;
91 * Returns the XML-RPC callback host port.
93 public int getXmlCallbackPort() {
94 return xmlCallbackPort;
98 * Sets the XML-RPC callback host port.
100 public void setXmlCallbackPort(int xmlCallbackPort) {
101 this.xmlCallbackPort = xmlCallbackPort;
105 * Returns the BIN-RPC callback host port.
107 public int getBinCallbackPort() {
108 return binCallbackPort;
112 * Sets the BIN-RPC callback host port.
114 public void setBinCallbackPort(int binCallbackPort) {
115 this.binCallbackPort = binCallbackPort;
119 * Returns the HmGatewayInfo.
121 public HmGatewayInfo getGatewayInfo() {
126 * Sets the HmGatewayInfo.
128 public void setGatewayInfo(HmGatewayInfo gatewayInfo) {
129 this.gatewayInfo = gatewayInfo;
133 * Returns the max alive time of a socket connection to a Homematic gateway in seconds.
135 public int getSocketMaxAlive() {
136 return socketMaxAlive;
140 * Sets the max alive time of a socket connection to a Homematic gateway in seconds.
142 public void setSocketMaxAlive(int socketMaxAlive) {
143 this.socketMaxAlive = socketMaxAlive;
147 * Returns the timeout for the communication to a Homematic gateway in seconds.
149 public int getTimeout() {
154 * Sets the timeout for the communication to a Homematic gateway in seconds.
156 public void setTimeout(int timeout) {
157 this.timeout = timeout;
161 * Returns the time to live for discovery results of a Homematic gateway in seconds.
163 public long getDiscoveryTimeToLive() {
164 return discoveryTimeToLive;
168 * Sets the time to live for discovery results of a Homematic gateway in seconds.
170 public void setDiscoveryTimeToLive(long discoveryTimeToLive) {
171 this.discoveryTimeToLive = discoveryTimeToLive;
175 * Returns the HmGatewayType.
177 public String getGatewayType() {
182 * Sets the HmGatewayType.
184 public void setGatewayType(String gatewayType) {
185 this.gatewayType = gatewayType;
189 * Returns time in seconds that the controller will be in install mode when
190 * a device discovery is initiated
192 * @return time in seconds that the controller remains in install mode
194 public int getInstallModeDuration() {
195 return installModeDuration;
199 * Sets installModeDuration
201 * @param installModeDuration time in seconds that the controller remains in
204 public void setInstallModeDuration(int installModeDuration) {
205 this.installModeDuration = installModeDuration;
209 * Returns if devices are unpaired from the gateway when their corresponding things are removed
211 * @return <i>true</i> if devices are unpaired from the gateway when their corresponding things are removed
213 public boolean isUnpairOnDeletion() {
214 return unpairOnDeletion;
218 * Sets unpairOnDeletion
220 * @param unpairOnDeletion if set to <i>true</i>, devices are unpaired from the gateway when their corresponding
223 public void setUnpairOnDeletion(boolean unpairOnDeletion) {
224 this.unpairOnDeletion = unpairOnDeletion;
228 * Returns if devices are factory reset when their corresponding things are removed
230 * @return <i>true</i> if devices are factory reset when their corresponding things are removed
232 public boolean isFactoryResetOnDeletion() {
233 return factoryResetOnDeletion;
237 * Sets factoryResetOnDeletion
239 * @param factoryResetOnDeletion if set to <i>true</i>, devices are factory reset when their corresponding things
242 public void setFactoryResetOnDeletion(boolean factoryResetOnDeletion) {
243 this.factoryResetOnDeletion = factoryResetOnDeletion;
247 * Returns the TclRegaScript url.
249 public String getTclRegaUrl() {
250 return "http://" + gatewayAddress + ":8181/tclrega.exe";
254 * Returns the Homematic gateway port of the channel.
256 public int getRpcPort(HmChannel channel) {
257 return getRpcPort(channel.getDevice().getHmInterface());
261 * Returns the Homematic gateway port of the interfaces.
263 public int getRpcPort(HmInterface hmInterface) {
264 if (HmInterface.WIRED.equals(hmInterface)) {
265 return getWiredPort();
266 } else if (HmInterface.HMIP.equals(hmInterface)) {
267 return getHmIpPort();
268 } else if (HmInterface.CUXD.equals(hmInterface)) {
269 return getCuxdPort();
270 } else if (HmInterface.GROUP.equals(hmInterface)) {
271 return getGroupPort();
278 * Returns the port of the RF daemon.
280 private int getRfPort() {
281 return rfPort == 0 ? DEFAULT_PORT_RF : rfPort;
285 * Returns the port of the wired daemon.
287 private int getWiredPort() {
288 return wiredPort == 0 ? DEFAULT_PORT_WIRED : wiredPort;
292 * Returns the port of the HmIp daemon.
294 private int getHmIpPort() {
295 return hmIpPort == 0 ? DEFAULT_PORT_HMIP : hmIpPort;
299 * Returns the port of the CUxD daemon.
301 private int getCuxdPort() {
302 return cuxdPort == 0 ? DEFAULT_PORT_CUXD : cuxdPort;
306 * Returns the port of the group daemon.
308 public int getGroupPort() {
309 return groupPort == 0 ? DEFAULT_PORT_GROUP : groupPort;
313 * Returns true, if a wired port is configured.
315 public boolean hasWiredPort() {
316 return wiredPort != 0;
320 * Returns true, if a hmIp port is configured.
322 public boolean hasHmIpPort() {
323 return hmIpPort != 0;
327 * Returns true, if a cuxd port is configured.
329 public boolean hasCuxdPort() {
330 return cuxdPort != 0;
334 * Returns true, if a group port is configured.
336 public boolean hasGroupPort() {
337 return groupPort != 0;
341 * Returns true, if a RF port is configured.
343 public boolean hasRfPort() {
348 * Returns the encoding that is suitable on requests to & responds from the Homematic gateway.
350 public String getEncoding() {
351 if (gatewayInfo != null && gatewayInfo.isHomegear()) {
359 * Returns the buffers size used for the communication with the Homematic gateway.
361 public int getBufferSize() {
366 * Returns true, if the configured gatewayType is CCU.
368 public boolean isCCUType() {
369 return gatewayType.equalsIgnoreCase(HomematicConfig.GATEWAY_TYPE_CCU);
373 * Returns true, if the configured gatewayType is NoCCU.
375 public boolean isNoCCUType() {
376 return gatewayType.equalsIgnoreCase(HomematicConfig.GATEWAY_TYPE_NOCCU);
380 public String toString() {
381 return String.format(
382 "%s[gatewayAddress=%s,callbackHost=%s,xmlCallbackPort=%d,binCallbackPort=%d,"
383 + "gatewayType=%s,rfPort=%d,wiredPort=%d,hmIpPort=%d,cuxdPort=%d,groupPort=%d,timeout=%d,"
384 + "discoveryTimeToLive=%d,installModeDuration=%d,socketMaxAlive=%d]",
385 getClass().getSimpleName(), gatewayAddress, callbackHost, xmlCallbackPort, binCallbackPort, gatewayType,
386 getRfPort(), getWiredPort(), getHmIpPort(), getCuxdPort(), getGroupPort(), timeout, discoveryTimeToLive,
387 installModeDuration, socketMaxAlive);