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]);
}
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;
}
}
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);
});
}
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);
});
}
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())));
}
Aggregations