Skip to content

Commit

Permalink
Fix discovery of 3rd party devices + type mapping to existing WMBusHa…
Browse files Browse the repository at this point in the history
…ndlerFactory.
  • Loading branch information
splatch committed Nov 9, 2018
1 parent 690c9d1 commit 0e4e3a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> WMBUS_TYPE_MAP = new ImmutableMap.Builder<String, String>()
.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<String, ThingTypeUID> WMBUS_TYPE_MAP = new ImmutableMap.Builder<String, ThingTypeUID>()
.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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down

0 comments on commit 0e4e3a5

Please sign in to comment.