use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class HueBridgeNupnpDiscoveryOSGITest method validBridgesAreDiscovered.
@Test
public void validBridgesAreDiscovered() {
List<DiscoveryResult> oldResults = inbox.stream().filter(forThingTypeUID(BRIDGE_THING_TYPE_UID)).collect(Collectors.toList());
for (final DiscoveryResult oldResult : oldResults) {
inbox.remove(oldResult.getThingUID());
}
sut = new ConfigurableBridgeNupnpDiscoveryMock();
registerService(sut, DiscoveryService.class.getName());
discoveryResult = validBridgeDiscoveryResult;
final Map<ThingUID, DiscoveryResult> results = new HashMap<>();
registerDiscoveryListener(new DiscoveryListener() {
@Override
public void thingDiscovered(DiscoveryService source, DiscoveryResult result) {
results.put(result.getThingUID(), result);
}
@Override
public void thingRemoved(DiscoveryService source, ThingUID thingUID) {
}
@Override
public Collection<ThingUID> removeOlderResults(DiscoveryService source, long timestamp, Collection<ThingTypeUID> thingTypeUIDs, ThingUID bridgeUID) {
return null;
}
});
sut.startScan();
waitForAssert(() -> {
assertThat(results.size(), is(2));
assertThat(results.get(BRIDGE_THING_UID_1), is(notNullValue()));
checkDiscoveryResult(results.get(BRIDGE_THING_UID_1), ip1, sn1);
assertThat(results.get(BRIDGE_THING_UID_2), is(notNullValue()));
checkDiscoveryResult(results.get(BRIDGE_THING_UID_2), ip2, sn2);
final List<DiscoveryResult> inboxResults = inbox.stream().filter(forThingTypeUID(BRIDGE_THING_TYPE_UID)).collect(Collectors.toList());
assertTrue(inboxResults.size() >= 2);
assertThat(inboxResults.stream().filter(result -> result.getThingUID().equals(BRIDGE_THING_UID_1)).findFirst().orElse(null), is(notNullValue()));
assertThat(inboxResults.stream().filter(result -> result.getThingUID().equals(BRIDGE_THING_UID_2)).findFirst().orElse(null), is(notNullValue()));
});
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class HueBridgeDiscoveryParticipantOSGITest method validDiscoveryResult.
@Test
public void validDiscoveryResult() {
final DiscoveryResult result = discoveryParticipant.createResult(hueDevice);
assertThat(result.getFlag(), is(DiscoveryResultFlag.NEW));
assertThat(result.getThingUID(), is(new ThingUID("hue:bridge:serial123")));
assertThat(result.getThingTypeUID(), is(THING_TYPE_BRIDGE));
assertThat(result.getBridgeUID(), is(nullValue()));
assertThat(result.getProperties().get(HOST), is("1.2.3.4"));
assertThat(result.getProperties().get(SERIAL_NUMBER), is("serial123"));
assertThat(result.getRepresentationProperty(), is(SERIAL_NUMBER));
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class FSInternetRadioDiscoveryParticipant method getThingUID.
/**
* If <code>device</code> is a supported device, a unique thing ID (e.g. serial number) must be returned. Further
* supported devices should be added here, based on the available UPnP information.
*/
@Override
public ThingUID getThingUID(RemoteDevice device) {
final DeviceDetails details = device.getDetails();
if (details != null) {
final ManufacturerDetails manufacturerDetails = details.getManufacturerDetails();
final String manufacturer = manufacturerDetails == null ? null : manufacturerDetails.getManufacturer();
final ModelDetails modelDetails = details.getModelDetails();
if (modelDetails != null) {
// check manufacturer and model number
final String modelNumber = modelDetails.getModelNumber();
if (modelNumber != null) {
if (manufacturer != null) {
final Set<String> supportedRadios = SUPPORTED_RADIO_MODELS.get(manufacturer.trim().toUpperCase());
if (supportedRadios != null && supportedRadios.contains(modelNumber.toUpperCase())) {
return new ThingUID(THING_TYPE_RADIO, details.getSerialNumber());
}
}
// check model name and number
final String modelName = modelDetails.getModelName();
if (modelName != null) {
final Set<String> supportedRadios = SUPPORTED_RADIO_MODELS.get(modelName.trim().toUpperCase());
if (supportedRadios != null && supportedRadios.contains(modelNumber.toUpperCase())) {
return new ThingUID(THING_TYPE_RADIO, details.getSerialNumber());
}
}
}
}
// maybe we can add further indicators, whether the device is a supported one
}
// device not supported
return null;
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class HueBridgeDiscoveryParticipant method createResult.
@Override
@Nullable
public 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(SERIAL_NUMBER, device.getDetails().getSerialNumber());
DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(device.getDetails().getFriendlyName()).withRepresentationProperty(SERIAL_NUMBER).build();
return result;
} else {
return null;
}
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class HueLightDiscoveryService method getThingUID.
@Nullable
private ThingUID getThingUID(FullLight light) {
ThingUID bridgeUID = hueBridgeHandler.getThing().getUID();
ThingTypeUID thingTypeUID = getThingTypeUID(light);
if (thingTypeUID != null && getSupportedThingTypes().contains(thingTypeUID)) {
return new ThingUID(thingTypeUID, bridgeUID, light.getId());
} else {
return null;
}
}
Aggregations