Search in sources :

Example 51 with ThingUID

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

the class ThingRegistryOSGiTest method assertThatCreateThingDelegatesToRegisteredThingHandlerFactory.

@Test
public void assertThatCreateThingDelegatesToRegisteredThingHandlerFactory() {
    ThingTypeUID expectedThingTypeUID = THING_TYPE_UID;
    ThingUID expectedThingUID = new ThingUID(THING_TYPE_UID, THING1_ID);
    Configuration expectedConfiguration = new Configuration();
    ThingUID expectedBridgeUID = new ThingUID(THING_TYPE_UID, THING2_ID);
    String expectedLabel = "Test Thing";
    AsyncResultWrapper<Thing> thingResultWrapper = new AsyncResultWrapper<Thing>();
    ThingRegistry thingRegistry = getService(ThingRegistry.class);
    ThingHandlerFactory thingHandlerFactory = new BaseThingHandlerFactory() {

        @Override
        public boolean supportsThingType(@NonNull ThingTypeUID thingTypeUID) {
            return true;
        }

        @Override
        @Nullable
        protected ThingHandler createHandler(@NonNull Thing thing) {
            return null;
        }

        @Override
        @Nullable
        public Thing createThing(@NonNull ThingTypeUID thingTypeUID, @NonNull Configuration configuration, @Nullable ThingUID thingUID, @Nullable ThingUID bridgeUID) {
            assertThat(thingTypeUID, is(expectedThingTypeUID));
            assertThat(configuration, is(expectedConfiguration));
            assertThat(thingUID, is(expectedThingUID));
            assertThat(bridgeUID, is(expectedBridgeUID));
            Thing thing = ThingBuilder.create(thingTypeUID, thingUID.getId()).withBridge(bridgeUID).build();
            thingResultWrapper.set(thing);
            return thing;
        }
    };
    registerThingHandlerFactory(thingHandlerFactory);
    Thing thing = thingRegistry.createThingOfType(expectedThingTypeUID, expectedThingUID, expectedBridgeUID, expectedLabel, expectedConfiguration);
    waitForAssert(() -> {
        assertTrue(thingResultWrapper.isSet());
    });
    assertThat(thing, is(thingResultWrapper.getWrappedObject()));
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) BaseThingHandlerFactory(org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory) AsyncResultWrapper(org.eclipse.smarthome.test.AsyncResultWrapper) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) NonNull(org.eclipse.jdt.annotation.NonNull) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) BaseThingHandlerFactory(org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory) ThingHandlerFactory(org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory) Thing(org.eclipse.smarthome.core.thing.Thing) Nullable(org.eclipse.jdt.annotation.Nullable) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 52 with ThingUID

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

the class ThingRegistryOSGiTest method assertThatThingRegistryThrowsExceptionForConfigUpdateOfNonExistingThing.

@Test(expected = IllegalArgumentException.class)
public void assertThatThingRegistryThrowsExceptionForConfigUpdateOfNonExistingThing() {
    ThingRegistry thingRegistry = getService(ThingRegistry.class);
    ThingUID thingUID = new ThingUID(THING_TYPE_UID, "binding:type:thing");
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("param", "value1");
    thingRegistry.updateConfiguration(thingUID, parameters);
}
Also used : HashMap(java.util.HashMap) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 53 with ThingUID

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

the class ThingActionService method getThingStatusInfo.

public static ThingStatusInfo getThingStatusInfo(String thingUid) {
    ThingUID uid = new ThingUID(thingUid);
    Thing thing = thingRegistry.get(uid);
    if (thing != null) {
        return thing.getStatusInfo();
    } else {
        return null;
    }
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Thing(org.eclipse.smarthome.core.thing.Thing)

Example 54 with ThingUID

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

the class MagicDiscoveryService method startScan.

@Override
protected void startScan() {
    String serialNumber = createRandomSerialNumber();
    DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(new ThingUID(MagicBindingConstants.THING_TYPE_CONFIG_THING, serialNumber)).withRepresentationProperty(Thing.PROPERTY_SERIAL_NUMBER).withProperty(Thing.PROPERTY_SERIAL_NUMBER, serialNumber).withLabel("Magic Thing").build();
    thingDiscovered(discoveryResult);
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) ThingUID(org.eclipse.smarthome.core.thing.ThingUID)

Example 55 with ThingUID

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

the class DigitalSTROMHandlerFactory method createHandler.

@Override
protected ThingHandler createHandler(Thing thing) {
    ThingTypeUID thingTypeUID = thing.getThingTypeUID();
    if (thingTypeUID == null) {
        return null;
    }
    if (BridgeHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
        BridgeHandler handler = new BridgeHandler((Bridge) thing);
        if (bridgeHandlers == null) {
            bridgeHandlers = new HashMap<ThingUID, BridgeHandler>();
        }
        bridgeHandlers.put(thing.getUID(), handler);
        DiscoveryServiceManager discoveryServiceManager = new DiscoveryServiceManager(handler);
        discoveryServiceManager.registerDiscoveryServices(bundleContext);
        discoveryServiceManagers.put(handler.getThing().getUID().getAsString(), discoveryServiceManager);
        return handler;
    }
    if (DeviceHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
        return new DeviceHandler(thing);
    }
    if (CircuitHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
        return new CircuitHandler(thing);
    }
    if (ZoneTemperatureControlHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
        return new ZoneTemperatureControlHandler(thing);
    }
    if (SceneHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
        return new SceneHandler(thing);
    }
    return null;
}
Also used : BridgeHandler(org.eclipse.smarthome.binding.digitalstrom.handler.BridgeHandler) CircuitHandler(org.eclipse.smarthome.binding.digitalstrom.handler.CircuitHandler) DiscoveryServiceManager(org.eclipse.smarthome.binding.digitalstrom.internal.discovery.DiscoveryServiceManager) ZoneTemperatureControlHandler(org.eclipse.smarthome.binding.digitalstrom.handler.ZoneTemperatureControlHandler) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) DeviceHandler(org.eclipse.smarthome.binding.digitalstrom.handler.DeviceHandler) SceneHandler(org.eclipse.smarthome.binding.digitalstrom.handler.SceneHandler)

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