2 * Copyright (c) 2010-2023 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 callbackRegistrationRetries;
62 private int callbackRegTimeout;
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 XML-RPC callback host port.
95 public int getXmlCallbackPort() {
96 return xmlCallbackPort;
100 * Sets the XML-RPC callback host port.
102 public void setXmlCallbackPort(int xmlCallbackPort) {
103 this.xmlCallbackPort = xmlCallbackPort;
107 * Returns the BIN-RPC callback host port.
109 public int getBinCallbackPort() {
110 return binCallbackPort;
114 * Sets the BIN-RPC callback host port.
116 public void setBinCallbackPort(int binCallbackPort) {
117 this.binCallbackPort = binCallbackPort;
121 * Sets timeout for callback registration.
123 public void setCallbackRegTimeout(int timeout) {
124 this.callbackRegTimeout = timeout;
128 * Returns timeout for callback registrations.
130 public int getCallbackRegTimeout() {
131 return callbackRegTimeout;
135 * Returns the HmGatewayInfo.
137 public HmGatewayInfo getGatewayInfo() {
142 * Sets the HmGatewayInfo.
144 public void setGatewayInfo(HmGatewayInfo gatewayInfo) {
145 this.gatewayInfo = gatewayInfo;
149 * Returns the max alive time of a socket connection to a Homematic gateway in seconds.
151 public int getSocketMaxAlive() {
152 return socketMaxAlive;
156 * Sets the max alive time of a socket connection to a Homematic gateway in seconds.
158 public void setSocketMaxAlive(int socketMaxAlive) {
159 this.socketMaxAlive = socketMaxAlive;
163 * Returns the timeout for the communication to a Homematic gateway in seconds.
165 public int getTimeout() {
170 * Sets the timeout for the communication to a Homematic gateway in seconds.
172 public void setTimeout(int timeout) {
173 this.timeout = timeout;
177 * Returns the time to live for discovery results of a Homematic gateway in seconds.
179 public long getDiscoveryTimeToLive() {
180 return discoveryTimeToLive;
184 * Sets the time to live for discovery results of a Homematic gateway in seconds.
186 public void setDiscoveryTimeToLive(long discoveryTimeToLive) {
187 this.discoveryTimeToLive = discoveryTimeToLive;
191 * Returns the HmGatewayType.
193 public String getGatewayType() {
198 * Sets the HmGatewayType.
200 public void setGatewayType(String gatewayType) {
201 this.gatewayType = gatewayType;
205 * Returns time in seconds that the controller will be in install mode when
206 * a device discovery is initiated
208 * @return time in seconds that the controller remains in install mode
210 public int getInstallModeDuration() {
211 return installModeDuration;
215 * Sets installModeDuration
217 * @param installModeDuration time in seconds that the controller remains in
220 public void setInstallModeDuration(int installModeDuration) {
221 this.installModeDuration = installModeDuration;
225 * Returns if devices are unpaired from the gateway when their corresponding things are removed
227 * @return <i>true</i> if devices are unpaired from the gateway when their corresponding things are removed
229 public boolean isUnpairOnDeletion() {
230 return unpairOnDeletion;
234 * Sets unpairOnDeletion
236 * @param unpairOnDeletion if set to <i>true</i>, devices are unpaired from the gateway when their corresponding
239 public void setUnpairOnDeletion(boolean unpairOnDeletion) {
240 this.unpairOnDeletion = unpairOnDeletion;
244 * Returns if devices are factory reset when their corresponding things are removed
246 * @return <i>true</i> if devices are factory reset when their corresponding things are removed
248 public boolean isFactoryResetOnDeletion() {
249 return factoryResetOnDeletion;
253 * Sets factoryResetOnDeletion
255 * @param factoryResetOnDeletion if set to <i>true</i>, devices are factory reset when their corresponding things
258 public void setFactoryResetOnDeletion(boolean factoryResetOnDeletion) {
259 this.factoryResetOnDeletion = factoryResetOnDeletion;
263 * Returns the TclRegaScript url.
265 public String getTclRegaUrl() {
266 return "http://" + gatewayAddress + ":8181/tclrega.exe";
270 * Returns the Homematic gateway port of the channel.
272 public int getRpcPort(HmChannel channel) {
273 return getRpcPort(channel.getDevice().getHmInterface());
277 * Returns the Homematic gateway port of the interfaces.
279 public int getRpcPort(HmInterface hmInterface) {
280 if (HmInterface.WIRED.equals(hmInterface)) {
281 return getWiredPort();
282 } else if (HmInterface.HMIP.equals(hmInterface)) {
283 return getHmIpPort();
284 } else if (HmInterface.CUXD.equals(hmInterface)) {
285 return getCuxdPort();
286 } else if (HmInterface.GROUP.equals(hmInterface)) {
287 return getGroupPort();
294 * Returns the port of the RF daemon.
296 private int getRfPort() {
297 return rfPort == 0 ? DEFAULT_PORT_RF : rfPort;
301 * Returns the port of the wired daemon.
303 private int getWiredPort() {
304 return wiredPort == 0 ? DEFAULT_PORT_WIRED : wiredPort;
308 * Returns the port of the HmIp daemon.
310 private int getHmIpPort() {
311 return hmIpPort == 0 ? DEFAULT_PORT_HMIP : hmIpPort;
315 * Returns the port of the CUxD daemon.
317 private int getCuxdPort() {
318 return cuxdPort == 0 ? DEFAULT_PORT_CUXD : cuxdPort;
322 * Returns the port of the group daemon.
324 public int getGroupPort() {
325 return groupPort == 0 ? DEFAULT_PORT_GROUP : groupPort;
329 * Returns true, if a wired port is configured.
331 public boolean hasWiredPort() {
332 return wiredPort != 0;
336 * Returns true, if a hmIp port is configured.
338 public boolean hasHmIpPort() {
339 return hmIpPort != 0;
343 * Returns true, if a cuxd port is configured.
345 public boolean hasCuxdPort() {
346 return cuxdPort != 0;
350 * Returns true, if a group port is configured.
352 public boolean hasGroupPort() {
353 return groupPort != 0;
357 * Returns true, if a RF port is configured.
359 public boolean hasRfPort() {
364 * Returns the encoding that is suitable on requests to & responds from the Homematic gateway.
366 public Charset getEncoding() {
367 if (gatewayInfo != null && gatewayInfo.isHomegear()) {
368 return StandardCharsets.UTF_8;
370 return StandardCharsets.ISO_8859_1;
375 * Returns the buffers size used for the communication with the Homematic gateway.
377 public int getBufferSize() {
382 * Returns true, if the configured gatewayType is CCU.
384 public boolean isCCUType() {
385 return gatewayType.equalsIgnoreCase(HomematicConfig.GATEWAY_TYPE_CCU);
389 * Returns true, if the configured gatewayType is NoCCU.
391 public boolean isNoCCUType() {
392 return gatewayType.equalsIgnoreCase(HomematicConfig.GATEWAY_TYPE_NOCCU);
396 public String toString() {
397 return String.format(
398 "%s[gatewayAddress=%s,callbackHost=%s,xmlCallbackPort=%d,binCallbackPort=%d,"
399 + "gatewayType=%s,rfPort=%d,wiredPort=%d,hmIpPort=%d,cuxdPort=%d,groupPort=%d,timeout=%d,"
400 + "discoveryTimeToLive=%d,installModeDuration=%d,socketMaxAlive=%d]",
401 getClass().getSimpleName(), gatewayAddress, callbackHost, xmlCallbackPort, binCallbackPort, gatewayType,
402 getRfPort(), getWiredPort(), getHmIpPort(), getCuxdPort(), getGroupPort(), timeout, discoveryTimeToLive,
403 installModeDuration, socketMaxAlive);