Search in sources :

Example 56 with ThingTypeUID

use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.

the class ThingTypeResource method getByUID.

@GET
@RolesAllowed({ Role.USER })
@Path("/{thingTypeUID}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets thing type by UID.", response = ThingTypeDTO.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Thing type with provided thingTypeUID does not exist.", response = ThingTypeDTO.class), @ApiResponse(code = 404, message = "No content") })
public Response getByUID(@PathParam("thingTypeUID") @ApiParam(value = "thingTypeUID") String thingTypeUID, @HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = HttpHeaders.ACCEPT_LANGUAGE) String language) {
    Locale locale = LocaleUtil.getLocale(language);
    ThingType thingType = thingTypeRegistry.getThingType(new ThingTypeUID(thingTypeUID), locale);
    if (thingType != null) {
        return Response.ok(convertToThingTypeDTO(thingType, locale)).build();
    } else {
        return Response.noContent().build();
    }
}
Also used : Locale(java.util.Locale) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 57 with ThingTypeUID

use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.

the class HueLightDiscoveryServiceOSGiTest method hueLightRegistration.

@Test
public void hueLightRegistration() {
    FullLight light = new FullLight();
    light.setId("1");
    light.setModelID("LCT001");
    light.setType("Extended color light");
    AsyncResultWrapper<DiscoveryResult> resultWrapper = new AsyncResultWrapper<DiscoveryResult>();
    registerDiscoveryListener(new DiscoveryListener() {

        @Override
        public void thingDiscovered(DiscoveryService source, DiscoveryResult result) {
            resultWrapper.set(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;
        }
    });
    discoveryService.onLightAdded(null, light);
    waitForAssert(() -> {
        assertTrue(resultWrapper.isSet());
    });
    final DiscoveryResult result = resultWrapper.getWrappedObject();
    assertThat(result.getFlag(), is(DiscoveryResultFlag.NEW));
    assertThat(result.getThingUID().toString(), is("hue:0210:testBridge:" + light.getId()));
    assertThat(result.getThingTypeUID(), is(THING_TYPE_EXTENDED_COLOR_LIGHT));
    assertThat(result.getBridgeUID(), is(hueBridge.getUID()));
    assertThat(result.getProperties().get(LIGHT_ID), is(light.getId()));
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) AsyncResultWrapper(org.eclipse.smarthome.test.AsyncResultWrapper) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Collection(java.util.Collection) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) DiscoveryService(org.eclipse.smarthome.config.discovery.DiscoveryService) HueLightDiscoveryService(org.eclipse.smarthome.binding.hue.internal.discovery.HueLightDiscoveryService) DiscoveryListener(org.eclipse.smarthome.config.discovery.DiscoveryListener) AbstractHueOSGiTest(org.eclipse.smarthome.binding.hue.test.AbstractHueOSGiTest) Test(org.junit.Test)

Example 58 with ThingTypeUID

use of org.eclipse.smarthome.core.thing.ThingTypeUID 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()));
    });
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) VolatileStorageService(org.eclipse.smarthome.test.storage.VolatileStorageService) Collection(java.util.Collection) DiscoveryService(org.eclipse.smarthome.config.discovery.DiscoveryService) InboxPredicates.forThingTypeUID(org.eclipse.smarthome.config.discovery.inbox.InboxPredicates.forThingTypeUID) IOException(java.io.IOException) HashMap(java.util.HashMap) Test(org.junit.Test) Collectors(java.util.stream.Collectors) List(java.util.List) DiscoveryListener(org.eclipse.smarthome.config.discovery.DiscoveryListener) Inbox(org.eclipse.smarthome.config.discovery.inbox.Inbox) Map(java.util.Map) HueBindingConstants(org.eclipse.smarthome.binding.hue.HueBindingConstants) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) Assert(org.junit.Assert) DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Before(org.junit.Before) HashMap(java.util.HashMap) DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Collection(java.util.Collection) InboxPredicates.forThingTypeUID(org.eclipse.smarthome.config.discovery.inbox.InboxPredicates.forThingTypeUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) DiscoveryService(org.eclipse.smarthome.config.discovery.DiscoveryService) DiscoveryListener(org.eclipse.smarthome.config.discovery.DiscoveryListener) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 59 with ThingTypeUID

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

Example 60 with ThingTypeUID

use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.

the class HueLightDiscoveryService method onLightAddedInternal.

private void onLightAddedInternal(FullLight light) {
    ThingUID thingUID = getThingUID(light);
    ThingTypeUID thingTypeUID = getThingTypeUID(light);
    String modelId = light.getModelID().replaceAll(HueLightHandler.NORMALIZE_ID_REGEX, "_");
    if (thingUID != null && thingTypeUID != null) {
        ThingUID bridgeUID = hueBridgeHandler.getThing().getUID();
        Map<String, Object> properties = new HashMap<>(1);
        properties.put(LIGHT_ID, light.getId());
        properties.put(MODEL_ID, modelId);
        properties.put(LIGHT_UNIQUE_ID, light.getUniqueID());
        DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withThingType(thingTypeUID).withProperties(properties).withBridge(bridgeUID).withRepresentationProperty(LIGHT_UNIQUE_ID).withLabel(light.getName()).build();
        thingDiscovered(discoveryResult);
    } else {
        logger.debug("discovered unsupported light of type '{}' and model '{}' with id {}", light.getType(), modelId, light.getId());
    }
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) HashMap(java.util.HashMap) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID)

Aggregations

ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)63 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)27 Test (org.junit.Test)27 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)25 Thing (org.eclipse.smarthome.core.thing.Thing)12 DiscoveryResult (org.eclipse.smarthome.config.discovery.DiscoveryResult)11 Locale (java.util.Locale)10 HashMap (java.util.HashMap)9 Collection (java.util.Collection)5 DiscoveryService (org.eclipse.smarthome.config.discovery.DiscoveryService)5 Before (org.junit.Before)5 Configuration (org.eclipse.smarthome.config.core.Configuration)4 DiscoveryListener (org.eclipse.smarthome.config.discovery.DiscoveryListener)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 Nullable (org.eclipse.jdt.annotation.Nullable)3 ThingRegistry (org.eclipse.smarthome.core.thing.ThingRegistry)3 BaseThingHandlerFactory (org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory)3 Firmware (org.eclipse.smarthome.core.thing.binding.firmware.Firmware)3 ArrayList (java.util.ArrayList)2