Skip to content

Commit

Permalink
[suggested addon finder] quick fixes for reviewer
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Fiddian-Green <[email protected]>
  • Loading branch information
andrewfg committed Oct 31, 2023
1 parent fd11a99 commit 81c044e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public void close() {
public abstract Set<AddonInfo> getSuggestedAddons();

public void setAddonCandidates(List<AddonInfo> candidates) {
addonCandidates.clear();
addonCandidates.addAll(candidates);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,18 @@ public Set<AddonInfo> getSuggestedAddons() {
addonCandidates.forEach(candidate -> {
candidate.getDiscoveryMethods().stream().filter(method -> SERVICE_TYPE.equals(method.getServiceType()))
.forEach(method -> {
Map<String, Pattern> map = method.getMatchProperties().stream().collect(
Map<String, Pattern> matchProperties = method.getMatchProperties().stream().collect(
Collectors.toMap(property -> property.getName(), property -> property.getPattern()));
services.values().stream().forEach(service -> {
if (method.getMdnsServiceType().equals(service.getType())
&& propertyMatches(map, NAME, service.getName())
&& Collections.list(service.getPropertyNames()).stream().allMatch(
name -> propertyMatches(map, name, service.getPropertyString(name)))) {
result.add(candidate);
logger.debug("Addon '{}' will be suggested (via mDNS)", candidate.getUID());
&& 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());
}
}
});
});
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> map = method.getMatchProperties().stream().collect(
Map<String, Pattern> matchProperties = method.getMatchProperties().stream().collect(
Collectors.toMap(property -> property.getName(), property -> property.getPattern()));

Set<String> propNames = new HashSet<>(map.keySet());
Set<String> propNames = new HashSet<>(matchProperties.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(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)) {
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)) {
result.add(candidate);
logger.debug("Addon '{}' will be suggested (via UPnP)", candidate.getUID());
}
Expand Down

0 comments on commit 81c044e

Please sign in to comment.