From 0e4e3a5e9014bd91eaf1d0913add4b84971511d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Dywicki?= Date: Fri, 9 Nov 2018 18:57:37 +0100 Subject: [PATCH] Fix discovery of 3rd party devices + type mapping to existing WMBusHandlerFactory. --- .../binding/wmbus/WMBusBindingConstants.java | 16 ++++------------ .../discovery/WMBusDiscoveryService2.java | 13 ++++++++----- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/org.openhab.binding.wmbus/src/main/java/org/openhab/binding/wmbus/WMBusBindingConstants.java b/org.openhab.binding.wmbus/src/main/java/org/openhab/binding/wmbus/WMBusBindingConstants.java index b527859..cd09582 100644 --- a/org.openhab.binding.wmbus/src/main/java/org/openhab/binding/wmbus/WMBusBindingConstants.java +++ b/org.openhab.binding.wmbus/src/main/java/org/openhab/binding/wmbus/WMBusBindingConstants.java @@ -121,18 +121,10 @@ public class WMBusBindingConstants { public static final String PROPERTY_DEVICE_ADDRESS = "address"; public static final String PROPERTY_WMBUS_MESSAGE = "wmBusMessage"; - public static final Map WMBUS_TYPE_MAP = new ImmutableMap.Builder() - .put("68TCH97255", THING_TYPE_NAME_TECHEM_HKV) // unsure, - // whether they work - .put("68TCH105255", THING_TYPE_NAME_TECHEM_HKV) - // another techem - .put("68TCH116255", THING_TYPE_NAME_TECHEM_HKV) // unsure, - // whether they work - .put("68TCH118255", THING_TYPE_NAME_TECHEM_HKV) // find out, if they work - .put("68KAM484", THING_TYPE_NAME_KAMSTRUP_MULTICAL_302).put("68LSE264", THING_TYPE_NAME_QUNDIS_QHEAT_5) - .put("68QDS227", THING_TYPE_NAME_QUNDIS_QWATER_5_5).put("68QDS528", THING_TYPE_NAME_QUNDIS_QCALORIC_5_5) - .put("68EFE04", THING_TYPE_NAME_ENGELMANN_SENSOSTAR).put("68ARF33", THING_TYPE_NAME_ADEUNIS_GAS_METER_3) - .build(); + public static final Map WMBUS_TYPE_MAP = new ImmutableMap.Builder() + .put("68KAM484", THING_TYPE_KAMSTRUP_MULTICAL_302).put("68LSE264", THING_TYPE_QUNDIS_QHEAT_5) + .put("68QDS227", THING_TYPE_QUNDIS_QWATER_5_5).put("68QDS528", THING_TYPE_QUNDIS_QCALORIC_5_5) + .put("68EFE04", THING_TYPE_ENGELMANN_SENSOSTAR).put("68ARF33", THING_TYPE_ADEUNIS_GAS_METER_3).build(); /** * Generic device types which are supported by binding. diff --git a/org.openhab.binding.wmbus/src/main/java/org/openhab/binding/wmbus/internal/discovery/WMBusDiscoveryService2.java b/org.openhab.binding.wmbus/src/main/java/org/openhab/binding/wmbus/internal/discovery/WMBusDiscoveryService2.java index 43da19f..9e9ee99 100644 --- a/org.openhab.binding.wmbus/src/main/java/org/openhab/binding/wmbus/internal/discovery/WMBusDiscoveryService2.java +++ b/org.openhab.binding.wmbus/src/main/java/org/openhab/binding/wmbus/internal/discovery/WMBusDiscoveryService2.java @@ -137,7 +137,7 @@ private void deviceDiscovered(WMBusAdapter adapter, WMBusDevice device) { // valves and other standard accessory excluding repeaters and other special things. SecondaryAddress secondaryAddress = device.getOriginalMessage().getSecondaryAddress(); if (!WMBusBindingConstants.SUPPORTED_DEVICE_TYPES.contains(secondaryAddress.getDeviceType()) - || !device.getDeviceId().matches("[a-zA-Z0-9]")) { + || !device.getDeviceId().matches("^[a-zA-Z0-9]+$")) { logger.info("Discarded discovery of device {} which is unsupported by binding: {}", device.getDeviceType(), secondaryAddress); return; @@ -158,13 +158,16 @@ private void deviceDiscovered(WMBusAdapter adapter, WMBusDevice device) { label += " (" + manufacturer + ")"; } - ThingUID thingUID = new ThingUID(WMBusBindingConstants.THING_TYPE_METER, address); + ThingTypeUID typeUID = WMBusBindingConstants.WMBUS_TYPE_MAP.getOrDefault(device.getDeviceType(), + WMBusBindingConstants.THING_TYPE_METER); + + ThingUID thingUID = new ThingUID(typeUID, address); // Create the discovery result and add to the inbox DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withProperties(properties) - // .withRepresentationProperty(WMBusBindingConstants.PROPERTY_DEVICE_ID) - .withBridge(adapter.getUID()).withThingType(WMBusBindingConstants.THING_TYPE_METER).withLabel(label) - .build(); + .withRepresentationProperty(WMBusBindingConstants.PROPERTY_DEVICE_ID).withBridge(adapter.getUID()) + .withThingType(typeUID).withLabel(label).build(); + thingDiscovered(discoveryResult); }