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.homematic.internal.common;
15 import java.nio.charset.Charset;
16 import java.nio.charset.StandardCharsets;
18 import org.openhab.binding.homematic.internal.model.HmChannel;
19 import org.openhab.binding.homematic.internal.model.HmGatewayInfo;
20 import org.openhab.binding.homematic.internal.model.HmInterface;
23 * The main gateway config class.
25 * @author Gerhard Riegler - Initial contribution
27 public class HomematicConfig {
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;
61 private int callbackRegTimeout;
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 XML-RPC callback host port.
94 public int getXmlCallbackPort() {
95 return xmlCallbackPort;
99 * Sets the XML-RPC callback host port.
101 public void setXmlCallbackPort(int xmlCallbackPort) {
102 this.xmlCallbackPort = xmlCallbackPort;
106 * Returns the BIN-RPC callback host port.
108 public int getBinCallbackPort() {
109 return binCallbackPort;
113 * Sets the BIN-RPC callback host port.
115 public void setBinCallbackPort(int binCallbackPort) {
116 this.binCallbackPort = binCallbackPort;
120 * Sets timeout for callback registration.
122 public void setCallbackRegTimeout(int timeout) {
123 this.callbackRegTimeout = timeout;
127 * Returns timeout for callback registrations.
129 public int getCallbackRegTimeout() {
130 return callbackRegTimeout;
134 * Returns the HmGatewayInfo.
136 public HmGatewayInfo getGatewayInfo() {
141 * Sets the HmGatewayInfo.
143 public void setGatewayInfo(HmGatewayInfo gatewayInfo) {
144 this.gatewayInfo = gatewayInfo;
148 * Returns the max alive time of a socket connection to a Homematic gateway in seconds.
150 public int getSocketMaxAlive() {
151 return socketMaxAlive;
155 * Sets the max alive time of a socket connection to a Homematic gateway in seconds.
157 public void setSocketMaxAlive(int socketMaxAlive) {
158 this.socketMaxAlive = socketMaxAlive;
162 * Returns the timeout for the communication to a Homematic gateway in seconds.
164 public int getTimeout() {
169 * Sets the timeout for the communication to a Homematic gateway in seconds.
171 public void setTimeout(int timeout) {
172 this.timeout = timeout;
176 * Returns the time to live for discovery results of a Homematic gateway in seconds.
178 public long getDiscoveryTimeToLive() {
179 return discoveryTimeToLive;
183 * Sets the time to live for discovery results of a Homematic gateway in seconds.
185 public void setDiscoveryTimeToLive(long discoveryTimeToLive) {
186 this.discoveryTimeToLive = discoveryTimeToLive;
190 * Returns the HmGatewayType.
192 public String getGatewayType() {
197 * Sets the HmGatewayType.
199 public void setGatewayType(String gatewayType) {
200 this.gatewayType = gatewayType;
204 * Returns time in seconds that the controller will be in install mode when
205 * a device discovery is initiated
207 * @return time in seconds that the controller remains in install mode
209 public int getInstallModeDuration() {
210 return installModeDuration;
214 * Sets installModeDuration
216 * @param installModeDuration time in seconds that the controller remains in
219 public void setInstallModeDuration(int installModeDuration) {
220 this.installModeDuration = installModeDuration;
224 * Returns if devices are unpaired from the gateway when their corresponding things are removed
226 * @return <i>true</i> if devices are unpaired from the gateway when their corresponding things are removed
228 public boolean isUnpairOnDeletion() {
229 return unpairOnDeletion;
233 * Sets unpairOnDeletion
235 * @param unpairOnDeletion if set to <i>true</i>, devices are unpaired from the gateway when their corresponding
238 public void setUnpairOnDeletion(boolean unpairOnDeletion) {
239 this.unpairOnDeletion = unpairOnDeletion;
243 * Returns if devices are factory reset when their corresponding things are removed
245 * @return <i>true</i> if devices are factory reset when their corresponding things are removed
247 public boolean isFactoryResetOnDeletion() {
248 return factoryResetOnDeletion;
252 * Sets factoryResetOnDeletion
254 * @param factoryResetOnDeletion if set to <i>true</i>, devices are factory reset when their corresponding things
257 public void setFactoryResetOnDeletion(boolean factoryResetOnDeletion) {
258 this.factoryResetOnDeletion = factoryResetOnDeletion;
262 * Returns the TclRegaScript url.
264 public String getTclRegaUrl() {
265 return "http://" + gatewayAddress + ":8181/tclrega.exe";
269 * Returns the Homematic gateway port of the channel.
271 public int getRpcPort(HmChannel channel) {
272 return getRpcPort(channel.getDevice().getHmInterface());
276 * Returns the Homematic gateway port of the interfaces.
278 public int getRpcPort(HmInterface hmInterface) {
279 if (HmInterface.WIRED.equals(hmInterface)) {
280 return getWiredPort();
281 } else if (HmInterface.HMIP.equals(hmInterface)) {
282 return getHmIpPort();
283 } else if (HmInterface.CUXD.equals(hmInterface)) {
284 return getCuxdPort();
285 } else if (HmInterface.GROUP.equals(hmInterface)) {
286 return getGroupPort();
293 * Returns the port of the RF daemon.
295 private int getRfPort() {
296 return rfPort == 0 ? DEFAULT_PORT_RF : rfPort;
300 * Returns the port of the wired daemon.
302 private int getWiredPort() {
303 return wiredPort == 0 ? DEFAULT_PORT_WIRED : wiredPort;
307 * Returns the port of the HmIp daemon.
309 private int getHmIpPort() {
310 return hmIpPort == 0 ? DEFAULT_PORT_HMIP : hmIpPort;
314 * Returns the port of the CUxD daemon.
316 private int getCuxdPort() {
317 return cuxdPort == 0 ? DEFAULT_PORT_CUXD : cuxdPort;
321 * Returns the port of the group daemon.
323 public int getGroupPort() {
324 return groupPort == 0 ? DEFAULT_PORT_GROUP : groupPort;
328 * Returns true, if a wired port is configured.
330 public boolean hasWiredPort() {
331 return wiredPort != 0;
335 * Returns true, if a hmIp port is configured.
337 public boolean hasHmIpPort() {
338 return hmIpPort != 0;
342 * Returns true, if a cuxd port is configured.
344 public boolean hasCuxdPort() {
345 return cuxdPort != 0;
349 * Returns true, if a group port is configured.
351 public boolean hasGroupPort() {
352 return groupPort != 0;
356 * Returns true, if a RF port is configured.
358 public boolean hasRfPort() {
363 * Returns the encoding that is suitable on requests to and responds from the Homematic gateway.
365 public Charset getEncoding() {
366 if (gatewayInfo != null && gatewayInfo.isHomegear()) {
367 return StandardCharsets.UTF_8;
369 return StandardCharsets.ISO_8859_1;
374 * Returns the buffers size used for the communication with the Homematic gateway.
376 public int getBufferSize() {
381 * Returns true, if the configured gatewayType is CCU.
383 public boolean isCCUType() {
384 return gatewayType.equalsIgnoreCase(HomematicConfig.GATEWAY_TYPE_CCU);
388 * Returns true, if the configured gatewayType is NoCCU.
390 public boolean isNoCCUType() {
391 return gatewayType.equalsIgnoreCase(HomematicConfig.GATEWAY_TYPE_NOCCU);
395 public String toString() {
396 return String.format("""
397 %s[gatewayAddress=%s,callbackHost=%s,xmlCallbackPort=%d,binCallbackPort=%d,\
398 gatewayType=%s,rfPort=%d,wiredPort=%d,hmIpPort=%d,cuxdPort=%d,groupPort=%d,timeout=%d,\
399 discoveryTimeToLive=%d,installModeDuration=%d,socketMaxAlive=%d]\
400 """, getClass().getSimpleName(), gatewayAddress, callbackHost, xmlCallbackPort, binCallbackPort,
401 gatewayType, getRfPort(), getWiredPort(), getHmIpPort(), getCuxdPort(), getGroupPort(), timeout,
402 discoveryTimeToLive, installModeDuration, socketMaxAlive);