From 45ec538a4076eafd60a96af9b28052e8c6ad72a2 Mon Sep 17 00:00:00 2001 From: Martin Herbst Date: Sun, 4 Apr 2021 19:04:37 +0200 Subject: [PATCH] [homematic] Some fixes and support for new device versions (#10438) * Removed method that was already marked as deprecated Signed-off-by: Martin Herbst * Handle HM-ES-TX-WM with firmware version >= 2.0 as different device The device provides different data points (channels) depending on the firmware version. Therefore devices with a firmware version >= 2.0 are handled as a different device. Fixes #9793 Signed-off-by: Martin Herbst * Don't change uninitialized thing state automatically to online Signed-off-by: Martin Herbst * Listen to all network interfaces instead of limiting it to only one This also makes the specification of a separate bind address superfluous. Fixes #9855 Fixes #10075 Signed-off-by: Martin Herbst * Add support for HmIP-eTRV-C-2 device The event messages received for this device are not correctly formatted and thus some special treatment for at least one data point is required. Signed-off-by: Martin Herbst * Spotless formatting applied Signed-off-by: Martin Herbst --- .../org.openhab.binding.homematic/README.md | 3 -- .../internal/common/HomematicConfig.java | 33 +++---------------- .../communicator/parser/CommonRpcParser.java | 4 +++ .../server/BinRpcNetworkService.java | 2 +- .../communicator/server/XmlRpcServer.java | 2 +- .../handler/HomematicBridgeHandler.java | 3 -- .../handler/HomematicThingHandler.java | 2 ++ .../internal/misc/HomematicConstants.java | 1 + .../homematic/internal/model/HmDevice.java | 13 ++++++-- .../internal/type/MetadataUtils.java | 4 ++- .../main/resources/OH-INF/thing/bridge.xml | 5 --- .../resources/homematic/batteries.properties | 2 ++ .../homematic/extra-descriptions.properties | 2 ++ .../extra-descriptions_de.properties | 2 ++ 14 files changed, 33 insertions(+), 45 deletions(-) diff --git a/bundles/org.openhab.binding.homematic/README.md b/bundles/org.openhab.binding.homematic/README.md index d0724f662fe..7d2e06ba52d 100644 --- a/bundles/org.openhab.binding.homematic/README.md +++ b/bundles/org.openhab.binding.homematic/README.md @@ -130,9 +130,6 @@ Hint for the binding to identify the gateway type (auto|ccu|noccu) (default = "a - **callbackHost** Callback network address of the system runtime, default is auto-discovery -- **bindAddress** -The address the XML-/BINRPC server binds to, default is value of "callbackHost" - - **xmlCallbackPort** Callback port of the binding's XML-RPC server, default is 9125 and counts up for each additional bridge diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/common/HomematicConfig.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/common/HomematicConfig.java index f8ca3f7bc06..9936668541d 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/common/HomematicConfig.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/common/HomematicConfig.java @@ -46,7 +46,6 @@ public class HomematicConfig { private int groupPort; private String callbackHost; - private String bindAddress; private int xmlCallbackPort; private int binCallbackPort; @@ -88,30 +87,6 @@ public class HomematicConfig { this.callbackHost = callbackHost; } - /** - * Returns the bind address. - */ - public String getBindAddress() { - return bindAddress; - } - - /** - * Sets the bind address. - */ - public void setBindAddress(String bindAddress) { - this.bindAddress = bindAddress; - } - - /** - * Sets the callback host port. - * - * @deprecated use setBinCallbackPort - */ - @Deprecated - public void setCallbackPort(int callbackPort) { - this.binCallbackPort = callbackPort; - } - /** * Returns the XML-RPC callback host port. */ @@ -404,11 +379,11 @@ public class HomematicConfig { @Override public String toString() { return String.format( - "%s[gatewayAddress=%s,callbackHost=%s,bindAddress=%s,xmlCallbackPort=%d,binCallbackPort=%d," + "%s[gatewayAddress=%s,callbackHost=%s,xmlCallbackPort=%d,binCallbackPort=%d," + "gatewayType=%s,rfPort=%d,wiredPort=%d,hmIpPort=%d,cuxdPort=%d,groupPort=%d,timeout=%d," + "discoveryTimeToLive=%d,installModeDuration=%d,socketMaxAlive=%d]", - getClass().getSimpleName(), gatewayAddress, callbackHost, bindAddress, xmlCallbackPort, binCallbackPort, - gatewayType, getRfPort(), getWiredPort(), getHmIpPort(), getCuxdPort(), getGroupPort(), timeout, - discoveryTimeToLive, installModeDuration, socketMaxAlive); + getClass().getSimpleName(), gatewayAddress, callbackHost, xmlCallbackPort, binCallbackPort, gatewayType, + getRfPort(), getWiredPort(), getHmIpPort(), getCuxdPort(), getGroupPort(), timeout, discoveryTimeToLive, + installModeDuration, socketMaxAlive); } } diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/CommonRpcParser.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/CommonRpcParser.java index 2196ea2ce21..1c2179e4281 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/CommonRpcParser.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/parser/CommonRpcParser.java @@ -16,6 +16,7 @@ import java.io.IOException; import java.util.Objects; import org.eclipse.jdt.annotation.NonNull; +import org.openhab.binding.homematic.internal.misc.HomematicConstants; import org.openhab.binding.homematic.internal.misc.MiscUtils; import org.openhab.binding.homematic.internal.model.HmDatapoint; import org.openhab.binding.homematic.internal.model.HmParamsetType; @@ -179,6 +180,9 @@ public abstract class CommonRpcParser implements RpcParser { if (dp.getUnit() == null && dp.getName() != null && dp.getName().startsWith("RSSI_")) { dp.setUnit("dBm"); } + // Bypass: For at least one device the CCU does not send a unit together with the value + if (dp.getUnit() == null && dp.getName().startsWith(HomematicConstants.DATAPOINT_NAME_OPERATING_VOLTAGE)) + dp.setUnit("V"); HmValueType valueType = HmValueType.parse(type); if (valueType == null || valueType == HmValueType.UNKNOWN) { diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/server/BinRpcNetworkService.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/server/BinRpcNetworkService.java index b01817fb2ea..8d69f3c6f65 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/server/BinRpcNetworkService.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/server/BinRpcNetworkService.java @@ -47,7 +47,7 @@ public class BinRpcNetworkService implements Runnable { serverSocket = new ServerSocket(); serverSocket.setReuseAddress(true); - serverSocket.bind(new InetSocketAddress(config.getBindAddress(), config.getBinCallbackPort())); + serverSocket.bind(new InetSocketAddress(config.getBinCallbackPort())); this.rpcResponseHandler = new RpcResponseHandler(listener) { diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/server/XmlRpcServer.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/server/XmlRpcServer.java index 375363561f7..a6b2171098f 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/server/XmlRpcServer.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/communicator/server/XmlRpcServer.java @@ -79,7 +79,7 @@ public class XmlRpcServer implements RpcServer { public void start() throws IOException { logger.debug("Initializing XML-RPC server at port {}", config.getXmlCallbackPort()); - InetSocketAddress callbackAddress = new InetSocketAddress(config.getBindAddress(), config.getXmlCallbackPort()); + InetSocketAddress callbackAddress = new InetSocketAddress(config.getXmlCallbackPort()); xmlRpcHTTPD = new Server(callbackAddress); xmlRpcHTTPD.setHandler(jettyResponseHandler); diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicBridgeHandler.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicBridgeHandler.java index dd69e1b5e7c..a7f49b0f5a0 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicBridgeHandler.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicBridgeHandler.java @@ -213,9 +213,6 @@ public class HomematicBridgeHandler extends BaseBridgeHandler implements Homemat if (homematicConfig.getCallbackHost() == null) { homematicConfig.setCallbackHost(this.ipv4Address); } - if (homematicConfig.getBindAddress() == null) { - homematicConfig.setBindAddress(homematicConfig.getCallbackHost()); - } if (homematicConfig.getXmlCallbackPort() == 0) { homematicConfig.setXmlCallbackPort(portPool.getNextPort()); } else { diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandler.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandler.java index 05bcf0048d8..ae09a2d2b79 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandler.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandler.java @@ -417,6 +417,8 @@ public class HomematicThingHandler extends BaseThingHandler { loadHomematicChannelValues(device.getChannel(0)); ThingStatus oldStatus = thing.getStatus(); + if (oldStatus == ThingStatus.UNINITIALIZED) + return; ThingStatus newStatus = ThingStatus.ONLINE; ThingStatusDetail newDetail = ThingStatusDetail.NONE; diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/misc/HomematicConstants.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/misc/HomematicConstants.java index bebcb052405..d1560204afb 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/misc/HomematicConstants.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/misc/HomematicConstants.java @@ -83,6 +83,7 @@ public class HomematicConstants { public static final String DATAPOINT_NAME_CALIBRATION = "CALIBRATION"; public static final String DATAPOINT_NAME_LOWBAT_IP = "LOW_BAT"; public static final String DATAPOINT_NAME_CHANNEL_FUNCTION = "CHANNEL_FUNCTION"; + public static final String DATAPOINT_NAME_OPERATING_VOLTAGE = "OPERATING_VOLTAGE"; public static final String VIRTUAL_DATAPOINT_NAME_BATTERY_TYPE = "BATTERY_TYPE"; public static final String VIRTUAL_DATAPOINT_NAME_DELETE_DEVICE_MODE = "DELETE_DEVICE_MODE"; diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmDevice.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmDevice.java index abd814f5beb..36626549a19 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmDevice.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/model/HmDevice.java @@ -19,6 +19,8 @@ import java.util.List; import java.util.Objects; import org.openhab.binding.homematic.internal.misc.MiscUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Object that represents a Homematic device. @@ -26,6 +28,8 @@ import org.openhab.binding.homematic.internal.misc.MiscUtils; * @author Gerhard Riegler - Initial contribution */ public class HmDevice { + private final Logger logger = LoggerFactory.getLogger(HmDevice.class); + public static final String TYPE_GATEWAY_EXTRAS = "GATEWAY-EXTRAS"; public static final String ADDRESS_GATEWAY_EXTRAS = "GWE00000000"; @@ -43,10 +47,15 @@ public class HmDevice { String firmware) { this.address = address; this.hmInterface = hmInterface; - this.type = type; + this.firmware = firmware; + if ("HM-ES-TX-WM".equals(type) && Float.valueOf(firmware) > 2.0) { + logger.debug("Found HM-ES-TX-WM with firmware version > 2.0, creating virtual type"); + this.type = type + "2"; + } else { + this.type = type; + } this.gatewayId = gatewayId; this.homegearId = homegearId; - this.firmware = firmware; } /** diff --git a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/MetadataUtils.java b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/MetadataUtils.java index 75e182667e8..f288b839639 100644 --- a/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/MetadataUtils.java +++ b/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/type/MetadataUtils.java @@ -331,6 +331,9 @@ public class MetadataUtils { return ITEM_TYPE_NUMBER + ":Energy"; case "m3": return ITEM_TYPE_NUMBER + ":Volume"; + case "": + if (dpName.startsWith(DATAPOINT_NAME_OPERATING_VOLTAGE)) + return ITEM_TYPE_NUMBER + ":ElectricPotential"; case "s": case "min": case "minutes": @@ -338,7 +341,6 @@ public class MetadataUtils { case "month": case "year": case "100%": - case "": default: return ITEM_TYPE_NUMBER; } diff --git a/bundles/org.openhab.binding.homematic/src/main/resources/OH-INF/thing/bridge.xml b/bundles/org.openhab.binding.homematic/src/main/resources/OH-INF/thing/bridge.xml index cd8d9b8bd17..468b5aa6704 100644 --- a/bundles/org.openhab.binding.homematic/src/main/resources/OH-INF/thing/bridge.xml +++ b/bundles/org.openhab.binding.homematic/src/main/resources/OH-INF/thing/bridge.xml @@ -37,11 +37,6 @@ Callback network address of the runtime, default is auto-discovery - - network-address - - The address the XML-/BINRPC server binds to, default is callbackHost - Callback port of the binding's XML-RPC server. If no value is specified, xmlCallbackPort starts with diff --git a/bundles/org.openhab.binding.homematic/src/main/resources/homematic/batteries.properties b/bundles/org.openhab.binding.homematic/src/main/resources/homematic/batteries.properties index 3cebb5a73e1..2aa2c6c1aef 100644 --- a/bundles/org.openhab.binding.homematic/src/main/resources/homematic/batteries.properties +++ b/bundles/org.openhab.binding.homematic/src/main/resources/homematic/batteries.properties @@ -82,6 +82,8 @@ HmIP-WTH=2x AAA/Micro/LR03 HmIP-WRC2=2x AAA/Micro/LR03 HmIP-eTRV=2x AA/Mignon/LR06 HmIP-eTRV-B=2x AA/Mignon/LR06 +HmIP-eTRV-C=2x AA/Mignon/LR06 +HmIP-eTRV-C-2=2x AA/Mignon/LR06 HmIP-SMI=2x AA/Mignon/LR06 HmIP-SPI=2x AA/Mignon/LR06 HmIP-SPDR=2x AA/Mignon/LR06 diff --git a/bundles/org.openhab.binding.homematic/src/main/resources/homematic/extra-descriptions.properties b/bundles/org.openhab.binding.homematic/src/main/resources/homematic/extra-descriptions.properties index a8b345d2378..75630cfa14e 100644 --- a/bundles/org.openhab.binding.homematic/src/main/resources/homematic/extra-descriptions.properties +++ b/bundles/org.openhab.binding.homematic/src/main/resources/homematic/extra-descriptions.properties @@ -4,6 +4,7 @@ HM-LC-Sw1-Pl-2=Wireless Switch Actuator 1-channel, socket adapter HM-Sec-SD-2=Wireless Smoke Detector HM-WDS30-OT2-SM-2=Wireless Differential Temperature Sensor HM-Sen-MDIR-O-2=Wireless Motion Detector, outdoor +HM-ES-TX-WM2=Wireless Transmitter for Energy Meter Sensor Version 2 # MAX! BC-RT-TRX-CyN=MAX! Radiator thermostat basic @@ -30,6 +31,7 @@ HMIP-eTRV=Homematic IP Radiator thermostat HMIP-eTRV-2=Homematic IP Radiator thermostat HMIP-eTRV-B=Homematic IP Radiator thermostat basic HMIP-eTRV-C=Homematic IP Radiator thermostat compact +HmIP-eTRV-C-2=Homematic IP Radiator thermostat compact HmIP-SMI=Homematic IP motion detector with brightness sensor HmIP-SMO=Homematic IP motion detector with brightness sensor - outdoor HmIP-KRC4=Homematic IP Key Ring Remote Control - 4 buttons diff --git a/bundles/org.openhab.binding.homematic/src/main/resources/homematic/extra-descriptions_de.properties b/bundles/org.openhab.binding.homematic/src/main/resources/homematic/extra-descriptions_de.properties index 92ab34f0597..9a6b4893223 100644 --- a/bundles/org.openhab.binding.homematic/src/main/resources/homematic/extra-descriptions_de.properties +++ b/bundles/org.openhab.binding.homematic/src/main/resources/homematic/extra-descriptions_de.properties @@ -4,6 +4,7 @@ HM-LC-Sw1-Pl-2=Funk-Schaltaktor 1-fach, Zwischenstecker HM-Sec-SD-2=Funk-Rauchmelder HM-WDS30-OT2-SM-2=Funk-Temperaturdifferenzsensor HM-Sen-MDIR-O-2=Funk-Bewegungsmelder außen +HM-ES-TX-WM2=Funk-Sender für Energiezähler-Sensor Version 2 # MAX! BC-RT-TRX-CyN=MAX! Heizkörperthermostat Basic @@ -30,6 +31,7 @@ HMIP-eTRV=Homematic IP Heizk HMIP-eTRV-2=Homematic IP Heizkörperthermostat HMIP-eTRV-B=Homematic IP Heizkörperthermostat Basis HMIP-eTRV-C=Homematic IP Heizkörperthermostat kompakt +HmIP-eTRV-C-2=Homematic IP Heizkörperthermostat kompakt HmIP-SMI=Homematic IP Bewegungsmelder mit Dämmerungssensor HmIP-SMO=Homematic IP Bewegungsmelder mit Dämmerungssensor außen HmIP-KRC4=Homematic IP Schlüsselbundfernbedienung - 4 Tasten