[draytonwiser] MDNS Fixes (#9806)

1. Fixes #8786 invalid uid on discovered hub
2. Resolve issue on startup in OH3 discovery result without address

Signed-off-by: James Melville <jamesmelville@gmail.com>
This commit is contained in:
James Melville 2021-01-13 10:54:27 +00:00 committed by GitHub
parent db8dc5d94b
commit e9b1e35eb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -19,6 +19,7 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern;
import javax.jmdns.ServiceInfo; import javax.jmdns.ServiceInfo;
@ -45,6 +46,7 @@ import org.slf4j.LoggerFactory;
public class DraytonWiserMDNSDiscoveryParticipant implements MDNSDiscoveryParticipant { public class DraytonWiserMDNSDiscoveryParticipant implements MDNSDiscoveryParticipant {
private final Logger logger = LoggerFactory.getLogger(DraytonWiserMDNSDiscoveryParticipant.class); private final Logger logger = LoggerFactory.getLogger(DraytonWiserMDNSDiscoveryParticipant.class);
private final Pattern findIllegalChars = Pattern.compile("[^A-Za-z0-9_-]");
@Override @Override
public Set<ThingTypeUID> getSupportedThingTypeUIDs() { public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
@ -69,10 +71,12 @@ public class DraytonWiserMDNSDiscoveryParticipant implements MDNSDiscoveryPartic
if (addresses.length > 0 && addresses[0] != null) { if (addresses.length > 0 && addresses[0] != null) {
properties.put(PROP_ADDRESS, addresses[0].getHostAddress()); properties.put(PROP_ADDRESS, addresses[0].getHostAddress());
properties.put(REFRESH_INTERVAL, DEFAULT_REFRESH_SECONDS); properties.put(REFRESH_INTERVAL, DEFAULT_REFRESH_SECONDS);
return DiscoveryResultBuilder.create(uid).withProperties(properties)
.withRepresentationProperty(PROP_ADDRESS).withLabel("Heat Hub - " + service.getName())
.build();
} }
return DiscoveryResultBuilder.create(uid).withProperties(properties)
.withRepresentationProperty(PROP_ADDRESS).withLabel("Heat Hub - " + service.getName()).build();
} }
} }
return null; return null;
@ -83,7 +87,7 @@ public class DraytonWiserMDNSDiscoveryParticipant implements MDNSDiscoveryPartic
if (service.getType() != null && service.getType().equals(getServiceType()) if (service.getType() != null && service.getType().equals(getServiceType())
&& service.getName().contains("WiserHeat")) { && service.getName().contains("WiserHeat")) {
logger.trace("Discovered a Drayton Wiser Heat Hub thing with name '{}'", service.getName()); logger.trace("Discovered a Drayton Wiser Heat Hub thing with name '{}'", service.getName());
return new ThingUID(THING_TYPE_BRIDGE, service.getName()); return new ThingUID(THING_TYPE_BRIDGE, findIllegalChars.matcher(service.getName()).replaceAll(""));
} }
return null; return null;
} }