Skip to content

Commit

Permalink
[suggested addon finder] fix check for null properties
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
  • Loading branch information
andrewfg committed Oct 31, 2023
1 parent 2bfa9d1 commit e5ceb8c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,16 @@ public Set<AddonInfo> getSuggestedAddons() {
addonCandidates.forEach(candidate -> {
candidate.getDiscoveryMethods().stream().filter(method -> SERVICE_TYPE.equals(method.getServiceType()))
.forEach(method -> {
Map<String, Pattern> matchProperties = method.getMatchProperties().stream().collect(
Map<String, Pattern> map = method.getMatchProperties().stream().collect(
Collectors.toMap(property -> property.getName(), property -> property.getPattern()));

services.values().stream().forEach(service -> {
if (method.getMdnsServiceType().equals(service.getType())
&& propertyMatches(matchProperties, NAME, service.getName())) {
List<String> serviceProperties = Collections.list(service.getPropertyNames());
if (serviceProperties.containsAll(matchProperties.keySet())
&& serviceProperties.stream().allMatch(name -> propertyMatches(matchProperties,
name, service.getPropertyString(name)))) {
result.add(candidate);
logger.debug("Addon '{}' will be suggested (via mDNS)", candidate.getUID());
}
&& propertyMatches(map, NAME, service.getName())
&& map.keySet().stream().filter(name -> !NAME.equals(name)).allMatch(
name -> propertyMatches(map, name, service.getPropertyString(name)))) {
result.add(candidate);
logger.debug("Addon '{}' will be suggested (via mDNS)", candidate.getUID());
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ public Set<AddonInfo> getSuggestedAddons() {
addonCandidates.forEach(candidate -> {
candidate.getDiscoveryMethods().stream().filter(method -> SERVICE_TYPE.equals(method.getServiceType()))
.forEach(method -> {
Map<String, Pattern> matchProperties = method.getMatchProperties().stream().collect(
Map<String, Pattern> map = method.getMatchProperties().stream().collect(
Collectors.toMap(property -> property.getName(), property -> property.getPattern()));

Set<String> propNames = new HashSet<>(matchProperties.keySet());
Set<String> propNames = new HashSet<>(map.keySet());
propNames.removeAll(SUPPORTED_PROPERTIES);
if (!propNames.isEmpty()) {
logger.warn("Addon '{}' addon.xml file contains unsupported 'match-property' [{}]",
Expand Down Expand Up @@ -184,15 +184,15 @@ public Set<AddonInfo> getSuggestedAddons() {
}
}

if (propertyMatches(matchProperties, DEVICE_TYPE, deviceType)
&& propertyMatches(matchProperties, MANUFACTURER, manufacturer)
&& propertyMatches(matchProperties, MANUFACTURER_URL, manufacturerURL)
&& propertyMatches(matchProperties, MODEL_NAME, modelName)
&& propertyMatches(matchProperties, MODEL_NUMBER, modelNumber)
&& propertyMatches(matchProperties, MODEL_DESCRIPTION, modelDescription)
&& propertyMatches(matchProperties, MODEL_URL, modelURL)
&& propertyMatches(matchProperties, SERIAL_NUMBER, serialNumber)
&& propertyMatches(matchProperties, FRIENDLY_NAME, friendlyName)) {
if (propertyMatches(map, DEVICE_TYPE, deviceType)
&& propertyMatches(map, MANUFACTURER, manufacturer)
&& propertyMatches(map, MANUFACTURER_URL, manufacturerURL)
&& propertyMatches(map, MODEL_NAME, modelName)
&& propertyMatches(map, MODEL_NUMBER, modelNumber)
&& propertyMatches(map, MODEL_DESCRIPTION, modelDescription)
&& propertyMatches(map, MODEL_URL, modelURL)
&& propertyMatches(map, SERIAL_NUMBER, serialNumber)
&& propertyMatches(map, FRIENDLY_NAME, friendlyName)) {
result.add(candidate);
logger.debug("Addon '{}' will be suggested (via UPnP)", candidate.getUID());
}
Expand Down

0 comments on commit e5ceb8c

Please sign in to comment.