use of org.eclipse.smarthome.core.thing.ThingUID 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.core.thing.ThingUID in project smarthome by eclipse.
the class ZoneTemperatureControlDiscoveryService method getThingUID.
private ThingUID getThingUID(TemperatureControlStatus tempControlStatus) {
ThingTypeUID thingTypeUID = new ThingTypeUID(BINDING_ID, thingTypeID);
if (getSupportedThingTypes().contains(thingTypeUID)) {
String thingID = tempControlStatus.getZoneID().toString();
ThingUID thingUID = new ThingUID(thingTypeUID, bridgeUID, thingID);
return thingUID;
} else {
return null;
}
}
use of org.eclipse.smarthome.core.thing.ThingUID 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.core.thing.ThingUID in project smarthome by eclipse.
the class TradfriDiscoveryServiceTest method validDiscoveryResultWhiteLightWSWithIncompleteJson.
@Test
public void validDiscoveryResultWhiteLightWSWithIncompleteJson() {
// We do not always receive a COLOR = "5706" attribute, even the light supports it - but the gateway does not
// seem to have this information, if the bulb is unreachable.
String json = "{\"9001\":\"TRADFRI bulb E27 WS opal 980lm\",\"9002\":1492955148,\"9020\":1506968670,\"9003\":65537,\"3311\":[{\"9003\":0}],\"9054\":0,\"5750\":2,\"9019\":0,\"3\":{\"0\":\"IKEA of Sweden\",\"1\":\"TRADFRI bulb E27 WS opal 980lm\",\"2\":\"\",\"3\":\"1.2.217\",\"6\":1}}";
JsonObject data = new JsonParser().parse(json).getAsJsonObject();
discovery.onUpdate("65537", data);
assertNotNull(discoveryResult);
assertThat(discoveryResult.getFlag(), is(DiscoveryResultFlag.NEW));
assertThat(discoveryResult.getThingUID(), is(new ThingUID("tradfri:0220:1:65537")));
assertThat(discoveryResult.getThingTypeUID(), is(THING_TYPE_COLOR_TEMP_LIGHT));
assertThat(discoveryResult.getBridgeUID(), is(GATEWAY_THING_UID));
assertThat(discoveryResult.getProperties().get(CONFIG_ID), is(65537));
assertThat(discoveryResult.getRepresentationProperty(), is(CONFIG_ID));
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class TradfriDiscoveryServiceTest method validDiscoveryResultWirelessDimmer.
@Test
public void validDiscoveryResultWirelessDimmer() {
String json = "{\"9001\":\"TRADFRI wireless dimmer\",\"9002\":1492843083,\"9020\":1506977986,\"9003\":65536,\"9054\":0,\"5750\":0,\"9019\":1,\"3\":{\"0\":\"IKEA of Sweden\",\"1\":\"TRADFRI wireless dimmer\",\"2\":\"\",\"3\":\"1.2.214\",\"6\":3,\"9\":47},\"15009\":[{\"9003\":0}]}";
JsonObject data = new JsonParser().parse(json).getAsJsonObject();
discovery.onUpdate("65536", data);
assertNotNull(discoveryResult);
assertThat(discoveryResult.getFlag(), is(DiscoveryResultFlag.NEW));
assertThat(discoveryResult.getThingUID(), is(new ThingUID("tradfri:0820:1:65536")));
assertThat(discoveryResult.getThingTypeUID(), is(THING_TYPE_DIMMER));
assertThat(discoveryResult.getBridgeUID(), is(GATEWAY_THING_UID));
assertThat(discoveryResult.getProperties().get(CONFIG_ID), is(65536));
assertThat(discoveryResult.getRepresentationProperty(), is(CONFIG_ID));
}
Aggregations