use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.
the class BluetoothDiscoveryService method deviceDiscovered.
private void deviceDiscovered(BluetoothAdapter adapter, BluetoothDevice device) {
for (BluetoothDiscoveryParticipant participant : participants) {
try {
DiscoveryResult result = participant.createResult(device);
if (result != null) {
thingDiscovered(result);
return;
}
} catch (Exception e) {
logger.error("Participant '{}' threw an exception", participant.getClass().getName(), e);
}
}
// We did not find a thing type for this device, so let's treat it as a generic one
String label = device.getName();
if (label == null || label.length() == 0 || label.equals(device.getAddress().toString().replace(':', '-'))) {
label = "Bluetooth Device";
}
Map<String, Object> properties = new HashMap<>();
properties.put(BluetoothBindingConstants.CONFIGURATION_ADDRESS, device.getAddress().toString());
Integer txPower = device.getTxPower();
if (txPower != null && txPower > 0) {
properties.put(BluetoothBindingConstants.PROPERTY_TXPOWER, Integer.toString(txPower));
}
String manufacturer = BluetoothCompanyIdentifiers.get(device.getManufacturerId());
if (manufacturer != null) {
properties.put(Thing.PROPERTY_VENDOR, manufacturer);
label += " (" + manufacturer + ")";
}
ThingUID thingUID = new ThingUID(BluetoothBindingConstants.THING_TYPE_BEACON, adapter.getUID(), device.getAddress().toString().toLowerCase().replace(":", ""));
// Create the discovery result and add to the inbox
DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withProperties(properties).withRepresentationProperty(BluetoothBindingConstants.CONFIGURATION_ADDRESS).withBridge(adapter.getUID()).withLabel(label).build();
thingDiscovered(discoveryResult);
}
use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.
the class TradfriDiscoveryParticipantOSGITest method validDiscoveryResult.
@Test
public void validDiscoveryResult() {
DiscoveryResult result = discoveryParticipant.createResult(tradfriGateway);
assertNotNull(result);
assertThat(result.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is("1.1"));
assertThat(result.getFlag(), is(DiscoveryResultFlag.NEW));
assertThat(result.getThingUID(), is(new ThingUID("tradfri:gateway:gw1234567890ab")));
assertThat(result.getThingTypeUID(), is(GATEWAY_TYPE_UID));
assertThat(result.getBridgeUID(), is(nullValue()));
assertThat(result.getProperties().get(Thing.PROPERTY_VENDOR), is("IKEA of Sweden"));
assertThat(result.getProperties().get(GATEWAY_CONFIG_HOST), is("192.168.0.5"));
assertThat(result.getProperties().get(GATEWAY_CONFIG_PORT), is(1234));
assertThat(result.getRepresentationProperty(), is(GATEWAY_CONFIG_HOST));
}
use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.
the class TradfriDiscoveryServiceTest method setUp.
@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);
}
use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.
the class PersistentInbox method setFlag.
@Override
public void setFlag(ThingUID thingUID, DiscoveryResultFlag flag) {
DiscoveryResult result = get(thingUID);
if (result instanceof DiscoveryResultImpl) {
DiscoveryResultImpl resultImpl = (DiscoveryResultImpl) result;
resultImpl.setFlag((flag == null) ? DiscoveryResultFlag.NEW : flag);
discoveryResultStorage.put(resultImpl.getThingUID().toString(), resultImpl);
notifyListeners(resultImpl, EventType.updated);
} else {
logger.warn("Cannot set flag for result of instance type '{}'", result.getClass().getName());
}
}
use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.
the class PersistentInbox method removeResultsForBridge.
private void removeResultsForBridge(ThingUID bridgeUID) {
for (ThingUID thingUID : getResultsForBridge(bridgeUID)) {
DiscoveryResult discoveryResult = get(thingUID);
if (discoveryResult != null) {
this.discoveryResultStorage.remove(thingUID.toString());
notifyListeners(discoveryResult, EventType.removed);
}
}
}
Aggregations