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 String bindAddress;
50 private int xmlCallbackPort;
51 private int binCallbackPort;
53 private int socketMaxAlive = 900;
54 private int timeout = 15;
55 private int installModeDuration = DEFAULT_INSTALL_MODE_DURATION;
56 private long discoveryTimeToLive = -1;
57 private boolean unpairOnDeletion = false;
58 private boolean factoryResetOnDeletion = false;
59 private int bufferSize = 2048;
61 private HmGatewayInfo gatewayInfo;
64 * Returns the Homematic gateway address.
66 public String getGatewayAddress() {
67 return gatewayAddress;
71 * Sets the Homematic gateway address.
73 public void setGatewayAddress(String gatewayAddress) {
74 this.gatewayAddress = gatewayAddress;
78 * Returns the callback host address.
80 public String getCallbackHost() {
85 * Sets the callback host address.
87 public void setCallbackHost(String callbackHost) {
88 this.callbackHost = callbackHost;
92 * Returns the bind address.
94 public String getBindAddress() {
99 * Sets the bind address.
101 public void setBindAddress(String bindAddress) {
102 this.bindAddress = bindAddress;
106 * Sets the callback host port.
108 * @deprecated use setBinCallbackPort
111 public void setCallbackPort(int callbackPort) {
112 this.binCallbackPort = callbackPort;
116 * Returns the XML-RPC callback host port.
118 public int getXmlCallbackPort() {
119 return xmlCallbackPort;
123 * Sets the XML-RPC callback host port.
125 public void setXmlCallbackPort(int xmlCallbackPort) {
126 this.xmlCallbackPort = xmlCallbackPort;
130 * Returns the BIN-RPC callback host port.
132 public int getBinCallbackPort() {
133 return binCallbackPort;
137 * Sets the BIN-RPC callback host port.
139 public void setBinCallbackPort(int binCallbackPort) {
140 this.binCallbackPort = binCallbackPort;
144 * Returns the HmGatewayInfo.
146 public HmGatewayInfo getGatewayInfo() {
151 * Sets the HmGatewayInfo.
153 public void setGatewayInfo(HmGatewayInfo gatewayInfo) {
154 this.gatewayInfo = gatewayInfo;
158 * Returns the max alive time of a socket connection to a Homematic gateway in seconds.
160 public int getSocketMaxAlive() {
161 return socketMaxAlive;
165 * Sets the max alive time of a socket connection to a Homematic gateway in seconds.
167 public void setSocketMaxAlive(int socketMaxAlive) {
168 this.socketMaxAlive = socketMaxAlive;
172 * Returns the timeout for the communication to a Homematic gateway in seconds.
174 public int getTimeout() {
179 * Sets the timeout for the communication to a Homematic gateway in seconds.
181 public void setTimeout(int timeout) {
182 this.timeout = timeout;
186 * Returns the time to live for discovery results of a Homematic gateway in seconds.
188 public long getDiscoveryTimeToLive() {
189 return discoveryTimeToLive;
193 * Sets the time to live for discovery results of a Homematic gateway in seconds.
195 public void setDiscoveryTimeToLive(long discoveryTimeToLive) {
196 this.discoveryTimeToLive = discoveryTimeToLive;
200 * Returns the HmGatewayType.
202 public String getGatewayType() {
207 * Sets the HmGatewayType.
209 public void setGatewayType(String gatewayType) {
210 this.gatewayType = gatewayType;
214 * Returns time in seconds that the controller will be in install mode when
215 * a device discovery is initiated
217 * @return time in seconds that the controller remains in install mode
219 public int getInstallModeDuration() {
220 return installModeDuration;
224 * Sets installModeDuration
226 * @param installModeDuration time in seconds that the controller remains in
229 public void setInstallModeDuration(int installModeDuration) {
230 this.installModeDuration = installModeDuration;
234 * Returns if devices are unpaired from the gateway when their corresponding things are removed
236 * @return <i>true</i> if devices are unpaired from the gateway when their corresponding things are removed
238 public boolean isUnpairOnDeletion() {
239 return unpairOnDeletion;
243 * Sets unpairOnDeletion
245 * @param unpairOnDeletion if set to <i>true</i>, devices are unpaired from the gateway when their corresponding
248 public void setUnpairOnDeletion(boolean unpairOnDeletion) {
249 this.unpairOnDeletion = unpairOnDeletion;
253 * Returns if devices are factory reset when their corresponding things are removed
255 * @return <i>true</i> if devices are factory reset when their corresponding things are removed
257 public boolean isFactoryResetOnDeletion() {
258 return factoryResetOnDeletion;
262 * Sets factoryResetOnDeletion
264 * @param factoryResetOnDeletion if set to <i>true</i>, devices are factory reset when their corresponding things
267 public void setFactoryResetOnDeletion(boolean factoryResetOnDeletion) {
268 this.factoryResetOnDeletion = factoryResetOnDeletion;
272 * Returns the TclRegaScript url.
274 public String getTclRegaUrl() {
275 return "http://" + gatewayAddress + ":8181/tclrega.exe";
279 * Returns the Homematic gateway port of the channel.
281 public int getRpcPort(HmChannel channel) {
282 return getRpcPort(channel.getDevice().getHmInterface());
286 * Returns the Homematic gateway port of the interfaces.
288 public int getRpcPort(HmInterface hmInterface) {
289 if (HmInterface.WIRED.equals(hmInterface)) {
290 return getWiredPort();
291 } else if (HmInterface.HMIP.equals(hmInterface)) {
292 return getHmIpPort();
293 } else if (HmInterface.CUXD.equals(hmInterface)) {
294 return getCuxdPort();
295 } else if (HmInterface.GROUP.equals(hmInterface)) {
296 return getGroupPort();
303 * Returns the port of the RF daemon.
305 private int getRfPort() {
306 return rfPort == 0 ? DEFAULT_PORT_RF : rfPort;
310 * Returns the port of the wired daemon.
312 private int getWiredPort() {
313 return wiredPort == 0 ? DEFAULT_PORT_WIRED : wiredPort;
317 * Returns the port of the HmIp daemon.
319 private int getHmIpPort() {
320 return hmIpPort == 0 ? DEFAULT_PORT_HMIP : hmIpPort;
324 * Returns the port of the CUxD daemon.
326 private int getCuxdPort() {
327 return cuxdPort == 0 ? DEFAULT_PORT_CUXD : cuxdPort;
331 * Returns the port of the group daemon.
333 public int getGroupPort() {
334 return groupPort == 0 ? DEFAULT_PORT_GROUP : groupPort;
338 * Returns true, if a wired port is configured.
340 public boolean hasWiredPort() {
341 return wiredPort != 0;
345 * Returns true, if a hmIp port is configured.
347 public boolean hasHmIpPort() {
348 return hmIpPort != 0;
352 * Returns true, if a cuxd port is configured.
354 public boolean hasCuxdPort() {
355 return cuxdPort != 0;
359 * Returns true, if a group port is configured.
361 public boolean hasGroupPort() {
362 return groupPort != 0;
366 * Returns true, if a RF port is configured.
368 public boolean hasRfPort() {
373 * Returns the encoding that is suitable on requests to & responds from the Homematic gateway.
375 public String getEncoding() {
376 if (gatewayInfo != null && gatewayInfo.isHomegear()) {
384 * Returns the buffers size used for the communication with the Homematic gateway.
386 public int getBufferSize() {
391 * Returns true, if the configured gatewayType is CCU.
393 public boolean isCCUType() {
394 return gatewayType.equalsIgnoreCase(HomematicConfig.GATEWAY_TYPE_CCU);
398 * Returns true, if the configured gatewayType is NoCCU.
400 public boolean isNoCCUType() {
401 return gatewayType.equalsIgnoreCase(HomematicConfig.GATEWAY_TYPE_NOCCU);
405 public String toString() {
406 return String.format(
407 "%s[gatewayAddress=%s,callbackHost=%s,bindAddress=%s,xmlCallbackPort=%d,binCallbackPort=%d,"
408 + "gatewayType=%s,rfPort=%d,wiredPort=%d,hmIpPort=%d,cuxdPort=%d,groupPort=%d,timeout=%d,"
409 + "discoveryTimeToLive=%d,installModeDuration=%d,socketMaxAlive=%d]",
410 getClass().getSimpleName(), gatewayAddress, callbackHost, bindAddress, xmlCallbackPort, binCallbackPort,
411 gatewayType, getRfPort(), getWiredPort(), getHmIpPort(), getCuxdPort(), getGroupPort(), timeout,
412 discoveryTimeToLive, installModeDuration, socketMaxAlive);