org.eclipse.smarthome.config.discovery.DiscoveryResult Java Examples
The following examples show how to use
org.eclipse.smarthome.config.discovery.DiscoveryResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AutomaticInboxProcessorTest.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Test public void testThingWentOnline() { inbox.add(DiscoveryResultBuilder.create(THING_UID).withProperty(DEVICE_ID_KEY, DEVICE_ID) .withRepresentationProperty(DEVICE_ID_KEY).build()); List<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)) .collect(Collectors.toList()); assertThat(results.size(), is(1)); assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID))); when(thingRegistry.get(THING_UID)).thenReturn(thing); when(thingStatusInfoChangedEvent.getStatusInfo()) .thenReturn(new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null)); when(thingStatusInfoChangedEvent.getThingUID()).thenReturn(THING_UID); automaticInboxProcessor.receive(thingStatusInfoChangedEvent); results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).collect(Collectors.toList()); assertThat(results.size(), is(0)); results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).collect(Collectors.toList()); assertThat(results.size(), is(1)); assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID))); }
Example #2
Source File: LIRCRemoteDiscoveryService.java From smarthome with Eclipse Public License 2.0 | 6 votes |
private void addRemote(ThingUID bridge, String remote) { ThingTypeUID uid = LIRCBindingConstants.THING_TYPE_REMOTE; ThingUID thingUID = new ThingUID(uid, bridge, remote); if (thingUID != null) { if (discoveryServiceCallback != null && discoveryServiceCallback.getExistingDiscoveryResult(thingUID) != null) { // Ignore this remote as we already know about it logger.debug("Remote {}: Already known.", remote); return; } logger.trace("Remote {}: Discovered new remote.", remote); Map<String, Object> properties = new HashMap<>(1); properties.put(LIRCBindingConstants.PROPERTY_REMOTE, remote); DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withLabel(remote) .withBridge(bridge).withProperties(properties).build(); thingDiscovered(discoveryResult); } }
Example #3
Source File: InboxOSGITest.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Test public void assertThatDiscoveryResultIsAddedToInboxWhenThingWithDifferentUIDexists() { assertThat(inbox.getAll().size(), is(0)); ThingTypeUID thingTypeUID = new ThingTypeUID("dummyBindingId2", "dummyThingType"); ThingUID thingUID = new ThingUID(thingTypeUID, "dummyThingId"); managedThingProvider.add(ThingBuilder.create(thingTypeUID, "dummyThingId").build()); Map<String, Object> props = new HashMap<>(); props.put("property1", "property1value1"); props.put("property2", "property2value1"); DiscoveryResult discoveryResult = new DiscoveryResultImpl(thingTypeUID, thingUID, null, null, null, "DummyLabel1", DEFAULT_TTL); inbox.add(discoveryResult); assertThat(inbox.getAll().size(), is(0)); }
Example #4
Source File: BlukiiDiscoveryParticipant.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Override public DiscoveryResult createResult(@NonNull BluetoothDevice device) { ThingUID thingUID = getThingUID(device); if (thingUID != null) { String label = "Blukii SmartBeacon"; Map<String, Object> properties = new HashMap<>(); properties.put(BluetoothBindingConstants.CONFIGURATION_ADDRESS, device.getAddress().toString()); properties.put(Thing.PROPERTY_VENDOR, "Schneider Schreibgeräte GmbH"); Integer txPower = device.getTxPower(); if (txPower != null) { properties.put(BluetoothBindingConstants.PROPERTY_TXPOWER, Integer.toString(txPower)); } // Create the discovery result and add to the inbox return DiscoveryResultBuilder.create(thingUID).withProperties(properties) .withRepresentationProperty(BluetoothBindingConstants.CONFIGURATION_ADDRESS) .withBridge(device.getAdapter().getUID()).withLabel(label).build(); } else { return null; } }
Example #5
Source File: AutomaticInboxProcessorTest.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Test public void testThingWithOtherBindingIDButSameRepresentationPropertyIsDiscovered() { // insert thing with thing type THING_TYPE_UID3 and representation property value DEVICE_ID in registry when(thingRegistry.get(THING_UID)).thenReturn(thing); when(thingRegistry.stream()).thenReturn(Stream.of(thing)); // Add discovery result with thing type THING_TYPE_UID3 and representation property value DEVICE_ID inbox.add(DiscoveryResultBuilder.create(THING_UID3).withProperty(DEVICE_ID_KEY, DEVICE_ID) .withRepresentationProperty(DEVICE_ID_KEY).build()); // Do NOT ignore this discovery result because it has a different binding ID List<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)) .collect(Collectors.toList()); assertThat(results.size(), is(0)); // Then there is a discovery result which is NEW results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).collect(Collectors.toList()); assertThat(results.size(), is(1)); assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID3))); }
Example #6
Source File: InboxConsoleCommandExtension.java From smarthome with Eclipse Public License 2.0 | 6 votes |
private void clearInboxEntries(Console console, List<DiscoveryResult> discoveryResults) { if (discoveryResults.isEmpty()) { console.println("No inbox entries found."); } for (DiscoveryResult discoveryResult : discoveryResults) { ThingTypeUID thingTypeUID = discoveryResult.getThingTypeUID(); ThingUID thingUID = discoveryResult.getThingUID(); String label = discoveryResult.getLabel(); DiscoveryResultFlag flag = discoveryResult.getFlag(); ThingUID bridgeId = discoveryResult.getBridgeUID(); Map<String, Object> properties = discoveryResult.getProperties(); console.println(String.format("REMOVED [%s]: %s [label=%s, thingId=%s, bridgeId=%s, properties=%s]", flag.name(), thingTypeUID, label, thingUID, bridgeId, properties)); inbox.remove(thingUID); } }
Example #7
Source File: TradfriDiscoveryServiceTest.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Before public void setUp() { initMocks(this); when(handler.getThing()).thenReturn(BridgeBuilder.create(GATEWAY_TYPE_UID, "1").build()); discovery = new TradfriDiscoveryService(handler); listener = new DiscoveryListener() { @Override public void thingRemoved(DiscoveryService source, ThingUID thingUID) { } @Override public void thingDiscovered(DiscoveryService source, DiscoveryResult result) { discoveryResult = result; } @Override public Collection<ThingUID> removeOlderResults(DiscoveryService source, long timestamp, Collection<ThingTypeUID> thingTypeUIDs, ThingUID bridgeUID) { return null; } }; discovery.addDiscoveryListener(listener); }
Example #8
Source File: UpnpDiscoveryService.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Deprecated @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) protected void addUpnpDiscoveryParticipant_old( org.eclipse.smarthome.config.discovery.UpnpDiscoveryParticipant participant) { this.oldParticipants.add(participant); if (upnpService != null) { Collection<RemoteDevice> devices = upnpService.getRegistry().getRemoteDevices(); for (RemoteDevice device : devices) { DiscoveryResult result = participant.createResult(device); if (result != null) { thingDiscovered(result); } } } }
Example #9
Source File: SonyAudioDiscoveryParticipant.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Override public DiscoveryResult createResult(RemoteDevice device) { DiscoveryResult result = null; ThingUID thingUid = getThingUID(device); if (thingUid != null) { String label = StringUtils.isEmpty(device.getDetails().getFriendlyName()) ? device.getDisplayString() : device.getDetails().getFriendlyName(); String host = device.getIdentity().getDescriptorURL().getHost(); int port = device.getIdentity().getDescriptorURL().getPort(); String path = device.getIdentity().getDescriptorURL().getPath(); try { Map<String, Object> properties = getDescription(host, port, path); properties.put(SonyAudioBindingConstants.HOST_PARAMETER, device.getIdentity().getDescriptorURL().getHost()); result = DiscoveryResultBuilder.create(thingUid).withLabel(label).withProperties(properties).build(); } catch (IOException e) { return null; } } return result; }
Example #10
Source File: PersistentInbox.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Override public synchronized boolean remove(@Nullable ThingUID thingUID) throws IllegalStateException { if (thingUID != null) { DiscoveryResult discoveryResult = get(thingUID); if (discoveryResult != null) { if (!isInRegistry(thingUID)) { removeResultsForBridge(thingUID); } resultDiscovererMap.remove(discoveryResult); this.discoveryResultStorage.remove(thingUID.toString()); notifyListeners(discoveryResult, EventType.removed); return true; } } return false; }
Example #11
Source File: FSInternetRadioDiscoveryParticipant.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Override public DiscoveryResult createResult(RemoteDevice device) { final ThingUID uid = getThingUID(device); if (uid != null) { final Map<String, Object> properties = new HashMap<>(1); final String ip = getIp(device); if (ip != null) { properties.put(CONFIG_PROPERTY_IP, ip); // add manufacturer and model, if provided final String manufacturer = getManufacturer(device); if (manufacturer != null) { properties.put(PROPERTY_MANUFACTURER, manufacturer); } final String model = getModel(device); if (model != null) { properties.put(PROPERTY_MODEL, model); } final DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties) .withLabel(device.getDisplayString()).build(); return result; } } return null; }
Example #12
Source File: PersistentInbox.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Override public @Nullable Collection<ThingUID> removeOlderResults(DiscoveryService source, long timestamp, @Nullable Collection<ThingTypeUID> thingTypeUIDs, @Nullable ThingUID bridgeUID) { HashSet<ThingUID> removedThings = new HashSet<>(); for (DiscoveryResult discoveryResult : getAll()) { Class<?> discoverer = resultDiscovererMap.get(discoveryResult); if (thingTypeUIDs != null && thingTypeUIDs.contains(discoveryResult.getThingTypeUID()) && discoveryResult.getTimestamp() < timestamp && (discoverer == null || source.getClass() == discoverer)) { ThingUID thingUID = discoveryResult.getThingUID(); if (bridgeUID == null || bridgeUID.equals(discoveryResult.getBridgeUID())) { removedThings.add(thingUID); remove(thingUID); logger.debug("Removed {} from inbox because it was older than {}", thingUID, new Date(timestamp)); } } } return removedThings; }
Example #13
Source File: PersistentInboxTest.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Test public void testEmittedUpdatedResultIsReadFromStorage() { DiscoveryResult result = DiscoveryResultBuilder.create(THING_UID).withProperty("foo", 3).build(); EventPublisher eventPublisher = mock(EventPublisher.class); inbox.setEventPublisher(eventPublisher); when(storage.get(THING_UID.toString())) // .thenReturn(result) // .thenReturn(DiscoveryResultBuilder.create(THING_UID).withProperty("foo", "bar").build()); inbox.add(result); // 1st call checks existence of the result in the storage (returns the original result) // 2nd call retrieves the stored instance before the event gets emitted // (modified due to storage mock configuration) verify(storage, times(2)).get(THING_UID.toString()); ArgumentCaptor<InboxUpdatedEvent> eventCaptor = ArgumentCaptor.forClass(InboxUpdatedEvent.class); verify(eventPublisher).post(eventCaptor.capture()); assertThat(eventCaptor.getValue().getDiscoveryResult().properties, hasEntry("foo", "bar")); }
Example #14
Source File: AutomaticInboxProcessorTest.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Test public void testInboxHasBeenChanged() { inbox.stream().map(DiscoveryResult::getThingUID).forEach(t -> inbox.remove(t)); assertThat(inbox.getAll().size(), is(0)); when(thingRegistry.get(THING_UID)).thenReturn(thing); when(thingRegistry.stream()).thenReturn(Stream.of(thing)); inbox.add(DiscoveryResultBuilder.create(THING_UID2).withProperty(DEVICE_ID_KEY, DEVICE_ID) .withRepresentationProperty(DEVICE_ID_KEY).build()); List<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)) .collect(Collectors.toList()); assertThat(results.size(), is(0)); results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).collect(Collectors.toList()); assertThat(results.size(), is(1)); assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID2))); }
Example #15
Source File: DiscoveryServiceRegistryImpl.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Override public synchronized void thingDiscovered(final DiscoveryService source, final DiscoveryResult result) { synchronized (cachedResults) { cachedResults.computeIfAbsent(source, unused -> new HashSet<>()).add(result); } for (final DiscoveryListener listener : this.listeners) { try { AccessController.doPrivileged(new PrivilegedAction<@Nullable Void>() { @Override public @Nullable Void run() { listener.thingDiscovered(source, result); return null; } }); } catch (Exception ex) { logger.error("Cannot notify the DiscoveryListener {} on Thing discovered event!", listener.getClass().getName(), ex); } } }
Example #16
Source File: HueBridgeDiscoveryParticipant.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Override public @Nullable DiscoveryResult createResult(RemoteDevice device) { ThingUID uid = getThingUID(device); if (uid != null) { Map<String, Object> properties = new HashMap<>(2); properties.put(HOST, device.getDetails().getBaseURL().getHost()); properties.put(PROPERTY_SERIAL_NUMBER, device.getDetails().getSerialNumber()); DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties) .withLabel(device.getDetails().getFriendlyName()).withRepresentationProperty(PROPERTY_SERIAL_NUMBER) .build(); return result; } else { return null; } }
Example #17
Source File: WemoDiscoveryParticipant.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Override public DiscoveryResult createResult(RemoteDevice device) { ThingUID uid = getThingUID(device); if (uid != null) { Map<String, Object> properties = new HashMap<>(2); String label = "WeMo Device"; try { label = device.getDetails().getFriendlyName(); } catch (Exception e) { // ignore and use default label } properties.put(UDN, device.getIdentity().getUdn().getIdentifierString()); DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(label) .withRepresentationProperty(UDN).build(); logger.debug("Created a DiscoveryResult for device '{}' with UDN '{}'", device.getDetails().getFriendlyName(), device.getIdentity().getUdn().getIdentifierString()); return result; } else { return null; } }
Example #18
Source File: AutomaticInboxProcessor.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Override public void thingAdded(Inbox inbox, DiscoveryResult result) { if (autoIgnore) { String value = getRepresentationValue(result); if (value != null) { Thing thing = thingRegistry.stream() .filter(t -> Objects.equals(value, getRepresentationPropertyValueForThing(t))) .filter(t -> Objects.equals(t.getThingTypeUID(), result.getThingTypeUID())).findFirst() .orElse(null); if (thing != null) { logger.debug("Auto-ignoring the inbox entry for the representation value {}", value); inbox.setFlag(result.getThingUID(), DiscoveryResultFlag.IGNORED); } } } if (alwaysAutoApprove || isToBeAutoApproved(result)) { inbox.approve(result.getThingUID(), result.getLabel()); } }
Example #19
Source File: HomegearDiscoveryParticipant.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override public DiscoveryResult createResult(RemoteDevice device) { ThingUID uid = getThingUID(device); if (uid != null) { DeviceDetails details = device.getDetails(); Map<String, Object> properties = new HashMap<>(3); properties.put("gatewayAddress", details.getBaseURL().getHost()); logger.debug("Discovered a Homegear gateway with serial number '{}'", details.getSerialNumber()); return DiscoveryResultBuilder.create(uid).withProperties(properties) .withLabel(details.getModelDetails().getModelNumber()).build(); } return null; }
Example #20
Source File: DynamicThingUpdateOSGITest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void assertNotNUpdatedWithSameConfig() { managedThingProvider.add(ThingBuilder.create(THING_TYPE_UID, THING_ID).build()); DiscoveryResult discoveryResult = new DiscoveryResultImpl(THING_TYPE_UID, THING_UID, null, Collections.emptyMap(), null, "DummyLabel", DEFAULT_TTL); inbox.add(discoveryResult); assertEquals(0, inbox.getAll().size()); verify(thingHandler, never()).thingUpdated(any()); }
Example #21
Source File: HueBridgeNupnpDiscovery.java From smarthome with Eclipse Public License 2.0 | 5 votes |
/** * Discover available Hue Bridges and then add them in the discovery inbox */ private void discoverHueBridges() { for (BridgeJsonParameters bridge : getBridgeList()) { if (isReachableAndValidHueBridge(bridge)) { String host = bridge.getInternalIpAddress(); String serialNumber = bridge.getId().substring(0, 6) + bridge.getId().substring(10); ThingUID uid = new ThingUID(THING_TYPE_BRIDGE, serialNumber); DiscoveryResult result = DiscoveryResultBuilder.create(uid) .withProperties(buildProperties(host, serialNumber)) .withLabel(LABEL_PATTERN.replace("IP", host)).withRepresentationProperty(PROPERTY_SERIAL_NUMBER) .build(); thingDiscovered(result); } } }
Example #22
Source File: SceneDiscoveryService.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private void onSceneAddedInternal(InternalScene scene) { logger.debug("{}", scene.getSceneType()); if (scene.getSceneType().equals(sceneType)) { if (!ignoredScene(scene.getSceneID()) && !ignoreGroup(scene.getGroupID())) { ThingUID thingUID = getThingUID(scene); if (thingUID != null) { ThingUID bridgeUID = bridgeHandler.getThing().getUID(); Map<String, Object> properties = new HashMap<>(); properties.put(ZONE_ID, scene.getZoneID()); properties.put(GROUP_ID, scene.getGroupID()); if (SceneEnum.containsScene(scene.getSceneID())) { properties.put(SCENE_ID, SceneEnum.getScene(scene.getSceneID()).toString()); } else { logger.debug("discovered scene: name '{}' with id {} have an invalid scene-ID", scene.getSceneName(), scene.getID()); } DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withProperties(properties) .withBridge(bridgeUID).withLabel(scene.getSceneName()).build(); thingDiscovered(discoveryResult); } else { logger.debug("discovered unsupported scene: name '{}' with id {}", scene.getSceneName(), scene.getID()); } } } }
Example #23
Source File: InboxOSGITest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void assertThatGetAllIncludesPreviouslyUpdatedDiscoveryResult() { ThingTypeUID thingTypeUID = new ThingTypeUID("dummyBindingId", "dummyThingType"); ThingUID thingUID = new ThingUID(thingTypeUID, "dummyThingId"); List<DiscoveryResult> allDiscoveryResults = inbox.getAll(); assertThat(allDiscoveryResults.size(), is(0)); Map<String, Object> props = new HashMap<>(); props.put("property1", "property1value1"); props.put("property2", "property2value1"); DiscoveryResult discoveryResult = new DiscoveryResultImpl(thingTypeUID, thingUID, null, props, "property1", "DummyLabel1", DEFAULT_TTL); assertTrue(addDiscoveryResult(discoveryResult)); props.clear(); props.put("property2", "property2value2"); props.put("property3", "property3value1"); discoveryResult = new DiscoveryResultImpl(thingTypeUID, thingUID, null, props, "property3", "DummyLabel2", DEFAULT_TTL); assertTrue(addDiscoveryResult(discoveryResult)); allDiscoveryResults = inbox.getAll(); assertThat(allDiscoveryResults.size(), is(1)); DiscoveryResult actualDiscoveryResult = allDiscoveryResults.get(0); assertThat(actualDiscoveryResult.getThingUID(), is(thingUID)); assertThat(actualDiscoveryResult.getThingTypeUID(), is(thingTypeUID)); assertThat(actualDiscoveryResult.getBindingId(), is("dummyBindingId")); assertThat(actualDiscoveryResult.getFlag(), is(DiscoveryResultFlag.NEW)); assertThat(actualDiscoveryResult.getLabel(), is("DummyLabel2")); assertThat(actualDiscoveryResult.getProperties().size(), is(2)); assertThat(actualDiscoveryResult.getProperties().get("property2"), is("property2value2")); assertThat(actualDiscoveryResult.getProperties().get("property3"), is("property3value1")); assertThat(actualDiscoveryResult.getRepresentationProperty(), is("property3")); }
Example #24
Source File: ZonePlayerDiscoveryParticipant.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override public DiscoveryResult createResult(RemoteDevice device) { ThingUID uid = getThingUID(device); if (uid != null) { String roomName = getSonosRoomName(device); if (roomName != null) { Map<String, Object> properties = new HashMap<>(3); String label = "Sonos device"; try { label = device.getDetails().getModelDetails().getModelName(); } catch (Exception e) { // ignore and use default label } label += " (" + roomName + ")"; properties.put(ZonePlayerConfiguration.UDN, device.getIdentity().getUdn().getIdentifierString()); properties.put(SonosBindingConstants.IDENTIFICATION, roomName); DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(label) .withRepresentationProperty(ZonePlayerConfiguration.UDN).build(); logger.debug("Created a DiscoveryResult for device '{}' with UDN '{}'", device.getDetails().getFriendlyName(), device.getIdentity().getUdn().getIdentifierString()); return result; } } return null; }
Example #25
Source File: DynamicThingUpdateOSGITest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void assertAdded() { managedThingProvider.add(ThingBuilder.create(THING_TYPE_UID, THING_ID).build()); DiscoveryResult discoveryResult = new DiscoveryResultImpl(THING_TYPE_UID, THING_UID2, null, Collections.emptyMap(), null, "DummyLabel", DEFAULT_TTL); inbox.add(discoveryResult); assertEquals(1, inbox.getAll().size()); }
Example #26
Source File: OwDiscoveryService.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override public void startScan() { bridgeUID = owBridgeHandler.getThing().getUID(); scanDirectory("/"); // remove duplicates owDiscoveryItems.entrySet().removeIf(s -> associatedSensors.contains(s.getKey())); // make discovery results for (OwDiscoveryItem owDiscoveryItem : owDiscoveryItems.values()) { owDiscoveryItem.checkSensorType(); try { ThingTypeUID thingTypeUID = owDiscoveryItem.getThingTypeUID(); String normalizedId = owDiscoveryItem.getNormalizedSensorId(); ThingUID thingUID = new ThingUID(thingTypeUID, bridgeUID, normalizedId); logger.debug("created thing UID {} for sensor {}, type {}", thingUID, owDiscoveryItem.getSensorId(), owDiscoveryItem.getSensorType()); Map<String, Object> properties = new HashMap<>(); properties.put(PROPERTY_MODELID, owDiscoveryItem.getSensorType().toString()); properties.put(PROPERTY_VENDOR, owDiscoveryItem.getVendor()); properties.put(CONFIG_ID, owDiscoveryItem.getSensorId().getFullPath()); DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withThingType(thingTypeUID) .withProperties(properties).withBridge(bridgeUID).withLabel(owDiscoveryItem.getLabel()).build(); thingDiscovered(discoveryResult); } catch (OwException e) { logger.info("sensor-id {}: {}", owDiscoveryItem.getSensorId(), e.getMessage()); } } }
Example #27
Source File: AutomaticInboxProcessor.java From smarthome with Eclipse Public License 2.0 | 5 votes |
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()); } }
Example #28
Source File: AutomaticInboxProcessor.java From smarthome with Eclipse Public License 2.0 | 5 votes |
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); } }
Example #29
Source File: InboxOSGITest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void assertThatGetAllIncludesPreviouslyAddedDiscoveryResult() { ThingTypeUID thingTypeUID = new ThingTypeUID("dummyBindingId", "dummyThingType"); ThingUID thingUID = new ThingUID(thingTypeUID, "thingId"); List<DiscoveryResult> allDiscoveryResults = inbox.getAll(); assertThat(allDiscoveryResults.size(), is(0)); Map<String, Object> props = new HashMap<>(); props.put("property1", "property1value1"); props.put("property2", "property2value1"); DiscoveryResult discoveryResult = new DiscoveryResultImpl(thingTypeUID, thingUID, null, props, "property1", "DummyLabel1", DEFAULT_TTL); assertTrue(addDiscoveryResult(discoveryResult)); allDiscoveryResults = inbox.getAll(); assertThat(allDiscoveryResults.size(), is(1)); DiscoveryResult actualDiscoveryResult = allDiscoveryResults.get(0); assertThat(actualDiscoveryResult.getThingUID(), is(thingUID)); assertThat(actualDiscoveryResult.getThingTypeUID(), is(thingTypeUID)); assertThat(actualDiscoveryResult.getBindingId(), is("dummyBindingId")); assertThat(actualDiscoveryResult.getFlag(), is(DiscoveryResultFlag.NEW)); assertThat(actualDiscoveryResult.getLabel(), is("DummyLabel1")); assertThat(actualDiscoveryResult.getProperties().size(), is(2)); assertThat(actualDiscoveryResult.getProperties().get("property1"), is("property1value1")); assertThat(actualDiscoveryResult.getProperties().get("property2"), is("property2value1")); assertThat(actualDiscoveryResult.getRepresentationProperty(), is("property1")); }
Example #30
Source File: IpCameraDiscoveryService.java From IpCamera with Eclipse Public License 2.0 | 5 votes |
public void newCameraFound(String brand, String hostname, int onvifPort) { ThingTypeUID thingtypeuid = new ThingTypeUID("ipcamera", brand); ThingUID thingUID = new ThingUID(thingtypeuid, hostname.replace(".", "")); DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID) .withProperty(CONFIG_IPADDRESS, hostname).withProperty(CONFIG_ONVIF_PORT, onvifPort) .withLabel(brand + " Camera @" + hostname).build(); thingDiscovered(discoveryResult); }