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;
62 private HmGatewayInfo gatewayInfo;
65 * Returns the Homematic gateway address.
67 public String getGatewayAddress() {
68 return gatewayAddress;
72 * Sets the Homematic gateway address.
74 public void setGatewayAddress(String gatewayAddress) {
75 this.gatewayAddress = gatewayAddress;
79 * Returns the callback host address.
81 public String getCallbackHost() {
86 * Sets the callback host address.
88 public void setCallbackHost(String callbackHost) {
89 this.callbackHost = callbackHost;
93 * Returns the bind address.
95 public String getBindAddress() {
100 * Sets the bind address.
102 public void setBindAddress(String bindAddress) {
103 this.bindAddress = bindAddress;
107 * Sets the callback host port.
109 * @deprecated use setBinCallbackPort
112 public void setCallbackPort(int callbackPort) {
113 this.binCallbackPort = callbackPort;
117 * Returns the XML-RPC callback host port.
119 public int getXmlCallbackPort() {
120 return xmlCallbackPort;
124 * Sets the XML-RPC callback host port.
126 public void setXmlCallbackPort(int xmlCallbackPort) {
127 this.xmlCallbackPort = xmlCallbackPort;
131 * Returns the BIN-RPC callback host port.
133 public int getBinCallbackPort() {
134 return binCallbackPort;
138 * Sets the BIN-RPC callback host port.
140 public void setBinCallbackPort(int binCallbackPort) {
141 this.binCallbackPort = binCallbackPort;
145 * Returns the HmGatewayInfo.
147 public HmGatewayInfo getGatewayInfo() {
152 * Sets the HmGatewayInfo.
154 public void setGatewayInfo(HmGatewayInfo gatewayInfo) {
155 this.gatewayInfo = gatewayInfo;
159 * Returns the max alive time of a socket connection to a Homematic gateway in seconds.
161 public int getSocketMaxAlive() {
162 return socketMaxAlive;
166 * Sets the max alive time of a socket connection to a Homematic gateway in seconds.
168 public void setSocketMaxAlive(int socketMaxAlive) {
169 this.socketMaxAlive = socketMaxAlive;
173 * Returns the timeout for the communication to a Homematic gateway in seconds.
175 public int getTimeout() {
180 * Sets the timeout for the communication to a Homematic gateway in seconds.
182 public void setTimeout(int timeout) {
183 this.timeout = timeout;
187 * Returns the time to live for discovery results of a Homematic gateway in seconds.
189 public long getDiscoveryTimeToLive() {
190 return discoveryTimeToLive;
194 * Sets the time to live for discovery results of a Homematic gateway in seconds.
196 public void setDiscoveryTimeToLive(long discoveryTimeToLive) {
197 this.discoveryTimeToLive = discoveryTimeToLive;
201 * Returns the HmGatewayType.
203 public String getGatewayType() {
208 * Sets the HmGatewayType.
210 public void setGatewayType(String gatewayType) {
211 this.gatewayType = gatewayType;
215 * Returns time in seconds that the controller will be in install mode when
216 * a device discovery is initiated
218 * @return time in seconds that the controller remains in install mode
220 public int getInstallModeDuration() {
221 return installModeDuration;
225 * Sets installModeDuration
227 * @param installModeDuration time in seconds that the controller remains in
230 public void setInstallModeDuration(int installModeDuration) {
231 this.installModeDuration = installModeDuration;
235 * Returns if devices are unpaired from the gateway when their corresponding things are removed
237 * @return <i>true</i> if devices are unpaired from the gateway when their corresponding things are removed
239 public boolean isUnpairOnDeletion() {
240 return unpairOnDeletion;
244 * Sets unpairOnDeletion
246 * @param unpairOnDeletion if set to <i>true</i>, devices are unpaired from the gateway when their corresponding
249 public void setUnpairOnDeletion(boolean unpairOnDeletion) {
250 this.unpairOnDeletion = unpairOnDeletion;
254 * Returns if devices are factory reset when their corresponding things are removed
256 * @return <i>true</i> if devices are factory reset when their corresponding things are removed
258 public boolean isFactoryResetOnDeletion() {
259 return factoryResetOnDeletion;
263 * Sets factoryResetOnDeletion
265 * @param factoryResetOnDeletion if set to <i>true</i>, devices are factory reset when their corresponding things
268 public void setFactoryResetOnDeletion(boolean factoryResetOnDeletion) {
269 this.factoryResetOnDeletion = factoryResetOnDeletion;
273 * Returns the TclRegaScript url.
275 public String getTclRegaUrl() {
276 return "http://" + gatewayAddress + ":8181/tclrega.exe";
280 * Returns the Homematic gateway port of the channel.
282 public int getRpcPort(HmChannel channel) {
283 return getRpcPort(channel.getDevice().getHmInterface());
287 * Returns the Homematic gateway port of the interfaces.
289 public int getRpcPort(HmInterface hmInterface) {
290 if (HmInterface.WIRED.equals(hmInterface)) {
291 return getWiredPort();
292 } else if (HmInterface.HMIP.equals(hmInterface)) {
293 return getHmIpPort();
294 } else if (HmInterface.CUXD.equals(hmInterface)) {
295 return getCuxdPort();
296 } else if (HmInterface.GROUP.equals(hmInterface)) {
297 return getGroupPort();
304 * Returns the port of the RF daemon.
306 private int getRfPort() {
307 return rfPort == 0 ? DEFAULT_PORT_RF : rfPort;
311 * Returns the port of the wired daemon.
313 private int getWiredPort() {
314 return wiredPort == 0 ? DEFAULT_PORT_WIRED : wiredPort;
318 * Returns the port of the HmIp daemon.
320 private int getHmIpPort() {
321 return hmIpPort == 0 ? DEFAULT_PORT_HMIP : hmIpPort;
325 * Returns the port of the CUxD daemon.
327 private int getCuxdPort() {
328 return cuxdPort == 0 ? DEFAULT_PORT_CUXD : cuxdPort;
332 * Returns the port of the group daemon.
334 public int getGroupPort() {
335 return groupPort == 0 ? DEFAULT_PORT_GROUP : groupPort;
339 * Returns true, if a wired port is configured.
341 public boolean hasWiredPort() {
342 return wiredPort != 0;
346 * Returns true, if a hmIp port is configured.
348 public boolean hasHmIpPort() {
349 return hmIpPort != 0;
353 * Returns true, if a cuxd port is configured.
355 public boolean hasCuxdPort() {
356 return cuxdPort != 0;
360 * Returns true, if a group port is configured.
362 public boolean hasGroupPort() {
363 return groupPort != 0;
367 * Returns true, if a RF port is configured.
369 public boolean hasRfPort() {
374 * Returns the encoding that is suitable on requests to & responds from the Homematic gateway.
376 public String getEncoding() {
377 if (gatewayInfo != null && gatewayInfo.isHomegear()) {
385 * Returns true, if the configured gatewayType is CCU.
387 public boolean isCCUType() {
388 return gatewayType.equalsIgnoreCase(HomematicConfig.GATEWAY_TYPE_CCU);
392 * Returns true, if the configured gatewayType is NoCCU.
394 public boolean isNoCCUType() {
395 return gatewayType.equalsIgnoreCase(HomematicConfig.GATEWAY_TYPE_NOCCU);
399 public String toString() {
400 ToStringBuilder tsb = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
401 tsb.append("gatewayAddress", gatewayAddress).append("callbackHost", callbackHost)
402 .append("bindAddress", bindAddress).append("xmlCallbackPort", xmlCallbackPort)
403 .append("binCallbackPort", binCallbackPort).append("gatewayType", gatewayType)
404 .append("rfPort", getRfPort()).append("wiredPort", getWiredPort()).append("hmIpPort", getHmIpPort())
405 .append("cuxdPort", getCuxdPort()).append("groupPort", getGroupPort()).append("timeout", timeout)
406 .append("discoveryTimeToLive", discoveryTimeToLive).append("installModeDuration", installModeDuration)
407 .append("socketMaxAlive", socketMaxAlive);
408 return tsb.toString();