Search in sources :

Example 61 with ThingUID

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);
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) BluetoothDiscoveryParticipant(org.eclipse.smarthome.binding.bluetooth.discovery.BluetoothDiscoveryParticipant) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ThingUID(org.eclipse.smarthome.core.thing.ThingUID)

Example 62 with ThingUID

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;
    }
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID)

Example 63 with ThingUID

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));
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 64 with ThingUID

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));
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser) Test(org.junit.Test)

Example 65 with ThingUID

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));
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser) Test(org.junit.Test)

Aggregations

ThingUID (org.eclipse.smarthome.core.thing.ThingUID)99 DiscoveryResult (org.eclipse.smarthome.config.discovery.DiscoveryResult)29 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)27 Thing (org.eclipse.smarthome.core.thing.Thing)26 Test (org.junit.Test)25 HashMap (java.util.HashMap)21 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)14 ApiOperation (io.swagger.annotations.ApiOperation)10 ApiResponses (io.swagger.annotations.ApiResponses)10 Path (javax.ws.rs.Path)9 JsonObject (com.google.gson.JsonObject)8 JsonParser (com.google.gson.JsonParser)7 RolesAllowed (javax.annotation.security.RolesAllowed)7 Locale (java.util.Locale)6 Nullable (org.eclipse.jdt.annotation.Nullable)6 Consumes (javax.ws.rs.Consumes)5 Configuration (org.eclipse.smarthome.config.core.Configuration)5 Collection (java.util.Collection)4 GET (javax.ws.rs.GET)4 InboxPredicates.forThingUID (org.eclipse.smarthome.config.discovery.inbox.InboxPredicates.forThingUID)4