Search in sources :

Example 31 with ThingUID

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

the class ThingEventFactory method createStatusInfoChangedEvent.

private Event createStatusInfoChangedEvent(String topic, String payload) throws Exception {
    String[] topicElements = getTopicElements(topic);
    if (topicElements.length != 4) {
        throw new IllegalArgumentException("ThingStatusInfoChangedEvent creation failed, invalid topic: " + topic);
    }
    ThingUID thingUID = new ThingUID(topicElements[2]);
    ThingStatusInfo[] thingStatusInfo = deserializePayload(payload, ThingStatusInfo[].class);
    return new ThingStatusInfoChangedEvent(topic, payload, thingUID, thingStatusInfo[0], thingStatusInfo[1]);
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingStatusInfo(org.eclipse.smarthome.core.thing.ThingStatusInfo)

Example 32 with ThingUID

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

the class BlukiiDiscoveryParticipant method createResult.

@Override
public DiscoveryResult createResult(@NonNull BluetoothDevice device) {
    ThingUID thingUID = getThingUID(device);
    if (thingUID != null) {
        String label = "Blukii SmartBeacon";
        Map<String, Object> properties = new HashMap<>();
        properties.put(BluetoothBindingConstants.CONFIGURATION_ADDRESS, device.getAddress().toString());
        properties.put(Thing.PROPERTY_VENDOR, "Schneider Schreibgeräte GmbH");
        Integer txPower = device.getTxPower();
        if (txPower != null) {
            properties.put(BluetoothBindingConstants.PROPERTY_TXPOWER, Integer.toString(txPower));
        }
        // Create the discovery result and add to the inbox
        return DiscoveryResultBuilder.create(thingUID).withProperties(properties).withRepresentationProperty(BluetoothBindingConstants.CONFIGURATION_ADDRESS).withBridge(device.getAdapter().getUID()).withLabel(label).build();
    } else {
        return null;
    }
}
Also used : HashMap(java.util.HashMap) ThingUID(org.eclipse.smarthome.core.thing.ThingUID)

Example 33 with ThingUID

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

the class ModelRestrictedFirmwareUpdateServiceOSGiTest method testUpdateModelRestrictedFirmware.

@Test
public void testUpdateModelRestrictedFirmware() {
    // given two things of the same thing type but with different models, both with firmware 1.0.0 installed
    ThingUID thingUID1 = createAndRegisterThing(THING_ID_1, MODEL_ID_1, VERSION_1_0_0).getUID();
    ThingUID thingUID2 = createAndRegisterThing(THING_ID_2, MODEL_ID_2, VERSION_1_0_0).getUID();
    // given a firmware provider that provides different firmwares for the different models
    Firmware firmwareModelA = createModelRestrictedFirmware(MODEL_ID_1, VERSION_1_0_1);
    Firmware firmwareModelB = createModelRestrictedFirmware(MODEL_ID_2, VERSION_1_0_2);
    registerService(createFirmwareProvider(firmwareModelA, firmwareModelB));
    // when the firmware on thing1 is updated to the firmware for model1
    firmwareUpdateService.updateFirmware(thingUID1, firmwareModelA.getUID(), null);
    // then the new firmware is installed on thing 1 and no more update is available
    waitForAssert(() -> {
        assertThatThingHasFirmware(thingUID1, VERSION_1_0_1);
        assertThatThingHasFirmwareStatus(thingUID1, UP_TO_DATE);
    });
    // and when the firmware on thing2 is updated to the firmware for model2
    firmwareUpdateService.updateFirmware(thingUID2, firmwareModelB.getUID(), null);
    // then the new firmware is installed on thing2 and no more update is available
    waitForAssert(() -> {
        assertThatThingHasFirmware(thingUID2, VERSION_1_0_2);
        assertThatThingHasFirmwareStatus(thingUID2, UP_TO_DATE);
    });
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Firmware(org.eclipse.smarthome.core.thing.binding.firmware.Firmware) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 34 with ThingUID

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

the class ModelRestrictedFirmwareUpdateServiceOSGiTest method testUpdateModelRestrictedFirmwareMultipleFirmwareProviders.

@Test
public void testUpdateModelRestrictedFirmwareMultipleFirmwareProviders() {
    // given two things of the same thing type but with different models and with different firmwares installed
    ThingUID thingUID1 = createAndRegisterThing(THING_ID_1, MODEL_ID_1, VERSION_1_0_1).getUID();
    ThingUID thingUID2 = createAndRegisterThing(THING_ID_2, MODEL_ID_2, VERSION_1_0_2).getUID();
    // given a firmware provider that provides the current firmware for both things,
    // and another firmware provider that provides a more recent firmware for the first model
    Firmware firmwareModelA = createModelRestrictedFirmware(MODEL_ID_1, VERSION_1_0_1);
    Firmware firmwareModelB = createModelRestrictedFirmware(MODEL_ID_2, VERSION_1_0_2);
    Firmware firmwareModelC = createModelRestrictedFirmware(MODEL_ID_1, VERSION_1_0_3);
    registerService(createFirmwareProvider(firmwareModelA, firmwareModelB));
    registerService(createFirmwareProvider(firmwareModelC));
    // then there is an update to 1.0.3 available for thing1
    FirmwareStatusInfo firmwareStatusInfoA = firmwareUpdateService.getFirmwareStatusInfo(thingUID1);
    assertThat(firmwareStatusInfoA.getFirmwareStatus(), is(UPDATE_EXECUTABLE));
    assertThat(firmwareStatusInfoA.getUpdatableFirmwareUID().getFirmwareVersion(), is(VERSION_1_0_3));
    // but there is no update available for thing2
    assertThatThingHasFirmwareStatus(thingUID2, UP_TO_DATE);
    // and when the firmware on thing1 is updated
    firmwareUpdateService.updateFirmware(thingUID1, firmwareModelC.getUID(), null);
    // then the new firmware is installed on thing 1 and no more update is available
    waitForAssert(() -> {
        assertThatThingHasFirmware(thingUID1, VERSION_1_0_3);
        assertThatThingHasFirmwareStatus(thingUID1, UP_TO_DATE);
    });
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Firmware(org.eclipse.smarthome.core.thing.binding.firmware.Firmware) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 35 with ThingUID

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

the class ThingRegistryOSGiTest method assertThatThingRegistryDelegatesConfigUpdateToThingHandler.

@Test
public void assertThatThingRegistryDelegatesConfigUpdateToThingHandler() {
    ThingUID thingUID = new ThingUID("binding:type:thing");
    Thing thing = ThingBuilder.create(THING_TYPE_UID, thingUID).build();
    ThingHandler thingHandler = new BaseThingHandler(thing) {

        @Override
        public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) {
        }

        @Override
        public void handleConfigurationUpdate(@NonNull Map<@NonNull String, @NonNull Object> configurationParameters) {
            changedParameters = configurationParameters;
        }
    };
    thing.setHandler(thingHandler);
    ThingProvider thingProvider = new ThingProvider() {

        @Override
        public void addProviderChangeListener(ProviderChangeListener<@NonNull Thing> listener) {
        }

        @Override
        public Collection<@NonNull Thing> getAll() {
            return Collections.singleton(thing);
        }

        @Override
        public void removeProviderChangeListener(ProviderChangeListener<@NonNull Thing> listener) {
        }
    };
    registerService(thingProvider);
    ThingRegistry thingRegistry = getService(ThingRegistry.class);
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("param1", "value1");
    parameters.put("param2", 1);
    thingRegistry.updateConfiguration(thingUID, parameters);
    assertThat(changedParameters.entrySet(), is(equalTo(parameters.entrySet())));
}
Also used : BaseThingHandler(org.eclipse.smarthome.core.thing.binding.BaseThingHandler) HashMap(java.util.HashMap) BaseThingHandler(org.eclipse.smarthome.core.thing.binding.BaseThingHandler) ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) ThingProvider(org.eclipse.smarthome.core.thing.ThingProvider) ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) Command(org.eclipse.smarthome.core.types.Command) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) NonNull(org.eclipse.jdt.annotation.NonNull) ProviderChangeListener(org.eclipse.smarthome.core.common.registry.ProviderChangeListener) HashMap(java.util.HashMap) Map(java.util.Map) Thing(org.eclipse.smarthome.core.thing.Thing) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) 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