private String inferKey(DiscoveryResult discoveryResult, String lastSegment) { return "discovery." + discoveryResult.getThingUID().getAsString().replaceAll(":", ".") + "." + lastSegment; }
private String inferKey(DiscoveryResult discoveryResult, String lastSegment) { return "discovery." + discoveryResult.getThingUID().getAsString().replaceAll(":", ".") + "." + lastSegment; }
public static Predicate<DiscoveryResult> forThingUID(@Nullable ThingUID thingUID) { return r -> thingUID != null && thingUID.equals(r.getThingUID()); }
@Override public void run() { long now = new Date().getTime(); for (DiscoveryResult result : inbox.getAll()) { if (isResultExpired(result, now)) { logger.debug("Inbox entry for thing {} is expired and will be removed", result.getThingUID()); remove(result.getThingUID()); } } }
@Override public void run() { long now = new Date().getTime(); for (DiscoveryResult result : inbox.getAll()) { if (isResultExpired(result, now)) { logger.debug("Inbox entry for thing {} is expired and will be removed", result.getThingUID()); remove(result.getThingUID()); } } }
private void ignoreInInbox(String bindingId, String representationValue) { List<DiscoveryResult> results = inbox.stream().filter(withRepresentationPropertyValue(representationValue)) .filter(withBindingId(bindingId)).collect(Collectors.toList()); if (results.size() == 1) { logger.debug("Auto-ignoring the inbox entry for the representation value {}", representationValue); inbox.setFlag(results.get(0).getThingUID(), DiscoveryResultFlag.IGNORED); } }
private void ignoreInInbox(ThingTypeUID thingtypeUID, String representationValue) { List<DiscoveryResult> results = inbox.stream().filter(withRepresentationPropertyValue(representationValue)) .filter(forThingTypeUID(thingtypeUID)).collect(Collectors.toList()); if (results.size() == 1) { logger.debug("Auto-ignoring the inbox entry for the representation value {}", representationValue); inbox.setFlag(results.get(0).getThingUID(), DiscoveryResultFlag.IGNORED); } }
private void removeFromInbox(ThingTypeUID thingtypeUID, String representationValue) { List<DiscoveryResult> results = inbox.stream().filter(withRepresentationPropertyValue(representationValue)) .filter(forThingTypeUID(thingtypeUID)).filter(withFlag(DiscoveryResultFlag.IGNORED)) .collect(Collectors.toList()); if (results.size() == 1) { logger.debug("Removing the ignored result from the inbox for the representation value {}", representationValue); inbox.remove(results.get(0).getThingUID()); } }
private void removeFromInbox(String bindingId, String representationValue) { List<DiscoveryResult> results = inbox.stream().filter(withRepresentationPropertyValue(representationValue)) .filter(withBindingId(bindingId)).filter(withFlag(DiscoveryResultFlag.IGNORED)) .collect(Collectors.toList()); if (results.size() == 1) { logger.debug("Removing the ignored result from the inbox for the representation value {}", representationValue); inbox.remove(results.get(0).getThingUID()); } }
private List<ThingUID> getResultsForBridge(ThingUID bridgeUID) { List<ThingUID> thingsForBridge = new ArrayList<>(); for (DiscoveryResult result : discoveryResultStorage.getValues()) { if (bridgeUID.equals(result.getBridgeUID())) { thingsForBridge.add(result.getThingUID()); } } return thingsForBridge; }
private List<ThingUID> getResultsForBridge(ThingUID bridgeUID) { List<ThingUID> thingsForBridge = new ArrayList<>(); for (DiscoveryResult result : discoveryResultStorage.getValues()) { if (bridgeUID.equals(result.getBridgeUID())) { thingsForBridge.add(result.getThingUID()); } } return thingsForBridge; }
@Override public void deactivate() { super.deactivate(); inbox.stream().filter(thing -> { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); return BluetoothBindingConstants.SUPPORTED_THING_TYPES.contains(thingTypeUID); }).forEach(thing -> inbox.remove(thing.getThingUID())); }
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) protected void addInboxAutoApprovePredicate(InboxAutoApprovePredicate inboxAutoApprovePredicate) { inboxAutoApprovePredicates.add(inboxAutoApprovePredicate); for (DiscoveryResult result : inbox.getAll()) { if (result.getFlag().equals(DiscoveryResultFlag.NEW) && inboxAutoApprovePredicate.test(result)) { inbox.approve(result.getThingUID(), result.getLabel()); } } }
private void approveAllInboxEntries() { for (DiscoveryResult result : inbox.getAll()) { if (result.getFlag().equals(DiscoveryResultFlag.NEW)) { inbox.approve(result.getThingUID(), result.getLabel()); } } }
private void autoApproveInboxEntries() { for (DiscoveryResult result : inbox.getAll()) { if (result.getFlag().equals(DiscoveryResultFlag.NEW)) { if (alwaysAutoApprove || isToBeAutoApproved(result)) { inbox.approve(result.getThingUID(), result.getLabel()); } } } }
private DiscoveryResult createDiscoveryResultWithUsbProperties(DiscoveryResult result, UsbSerialDeviceInformation usbSerialDeviceInformation) { Map<String, Object> resultProperties = new HashMap<>(result.getProperties()); resultProperties.put(THING_PROPERTY_USB_VENDOR_ID, usbSerialDeviceInformation.getVendorId()); resultProperties.put(THING_PROPERTY_USB_PRODUCT_ID, usbSerialDeviceInformation.getProductId()); return DiscoveryResultBuilder.create(result.getThingUID()).withProperties(resultProperties) .withBridge(result.getBridgeUID()).withTTL(result.getTimeToLive()).withLabel(result.getLabel()) .withRepresentationProperty(result.getRepresentationProperty()).build(); } }
/** * Creates an inbox updated event. * * @param discoveryResult the discovery result * @return the created inbox updated event * @throws IllegalArgumentException if discoveryResult is null */ public static InboxUpdatedEvent createUpdatedEvent(DiscoveryResult discoveryResult) { assertValidArgument(discoveryResult); String topic = buildTopic(INBOX_UPDATED_EVENT_TOPIC, discoveryResult.getThingUID().getAsString()); DiscoveryResultDTO resultDTO = map(discoveryResult); String payload = serializePayload(resultDTO); return new InboxUpdatedEvent(topic, payload, resultDTO); }
/** * Creates an inbox removed event. * * @param discoveryResult the discovery result * @return the created inbox removed event * @throws IllegalArgumentException if discoveryResult is null */ public static InboxRemovedEvent createRemovedEvent(DiscoveryResult discoveryResult) { assertValidArgument(discoveryResult); String topic = buildTopic(INBOX_REMOVED_EVENT_TOPIC, discoveryResult.getThingUID().getAsString()); DiscoveryResultDTO resultDTO = map(discoveryResult); String payload = serializePayload(resultDTO); return new InboxRemovedEvent(topic, payload, resultDTO); }
/** * Maps discovery result into discovery result data transfer object. * * @param discoveryResult the discovery result * @return the discovery result data transfer object */ public static DiscoveryResultDTO map(DiscoveryResult discoveryResult) { ThingUID thingUID = discoveryResult.getThingUID(); ThingUID bridgeUID = discoveryResult.getBridgeUID(); return new DiscoveryResultDTO(thingUID.toString(), bridgeUID != null ? bridgeUID.toString() : null, discoveryResult.getThingTypeUID().toString(), discoveryResult.getLabel(), discoveryResult.getFlag(), discoveryResult.getProperties(), discoveryResult.getRepresentationProperty()); }
/** * Maps discovery result into discovery result data transfer object. * * @param discoveryResult the discovery result * @return the discovery result data transfer object */ public static DiscoveryResultDTO map(DiscoveryResult discoveryResult) { ThingUID thingUID = discoveryResult.getThingUID(); ThingUID bridgeUID = discoveryResult.getBridgeUID(); return new DiscoveryResultDTO(thingUID.toString(), bridgeUID != null ? bridgeUID.toString() : null, discoveryResult.getThingTypeUID().toString(), discoveryResult.getLabel(), discoveryResult.getFlag(), discoveryResult.getProperties(), discoveryResult.getRepresentationProperty()); }