use of org.eclipse.smarthome.core.thing.Thing in project smarthome by eclipse.
the class ModelRestrictedFirmwareUpdateServiceOSGiTest method createAndRegisterThing.
/**
* Creates a thing, adds it to the thing registry, and registers a {@link FirmwareUpdateHandler} for the thing.
*/
private Thing createAndRegisterThing(String thingUID, String modelId, String firmwareVersion) {
Thing thing = ThingBuilder.create(thingType.getUID(), thingUID).build();
thing.setProperty(PROPERTY_MODEL_ID, modelId);
thing.setProperty(PROPERTY_FIRMWARE_VERSION, firmwareVersion);
managedThingProvider.add(thing);
registerService(createFirmwareUpdateHandler(thing));
return thing;
}
use of org.eclipse.smarthome.core.thing.Thing in project smarthome by eclipse.
the class ChannelStateDescriptionProviderOSGiTest method presentItemStateDescription.
/**
* Assert that item's state description is present.
*/
@Test
public void presentItemStateDescription() throws ItemNotFoundException {
ThingRegistry thingRegistry = getService(ThingRegistry.class);
ManagedThingProvider managedThingProvider = getService(ManagedThingProvider.class);
Thing thing = thingRegistry.createThingOfType(new ThingTypeUID("hue:lamp"), new ThingUID("hue:lamp:lamp1"), null, "test thing", new Configuration());
assertNotNull(thing);
managedThingProvider.add(thing);
ItemChannelLink link = new ItemChannelLink("TestItem", getChannel(thing, "1").getUID());
linkRegistry.add(link);
link = new ItemChannelLink("TestItem2", getChannel(thing, "2").getUID());
linkRegistry.add(link);
link = new ItemChannelLink("TestItem3", getChannel(thing, "3").getUID());
linkRegistry.add(link);
link = new ItemChannelLink("TestItem4", getChannel(thing, "4").getUID());
linkRegistry.add(link);
link = new ItemChannelLink("TestItem5", getChannel(thing, "5").getUID());
linkRegistry.add(link);
link = new ItemChannelLink("TestItem6", getChannel(thing, "6").getUID());
linkRegistry.add(link);
link = new ItemChannelLink("TestItem7_1", getChannel(thing, "7_1").getUID());
linkRegistry.add(link);
link = new ItemChannelLink("TestItem7_2", getChannel(thing, "7_2").getUID());
linkRegistry.add(link);
//
final Collection<Item> items = itemRegistry.getItems();
assertEquals(false, items.isEmpty());
Item item = itemRegistry.getItem("TestItem");
assertEquals("Number", item.getType());
StateDescription state = item.getStateDescription();
assertNotNull(state);
assertEquals(BigDecimal.ZERO, state.getMinimum());
assertEquals(BigDecimal.valueOf(100), state.getMaximum());
assertEquals(BigDecimal.TEN, state.getStep());
assertEquals("%d Peek", state.getPattern());
assertEquals(true, state.isReadOnly());
List<StateOption> opts = state.getOptions();
assertEquals(1, opts.size());
final StateOption opt = opts.get(0);
assertEquals("SOUND", opt.getValue());
assertEquals("My great sound.", opt.getLabel());
item = itemRegistry.getItem("TestItem2");
assertEquals("Number", item.getType());
state = item.getStateDescription();
assertNotNull(state);
assertEquals(BigDecimal.ZERO, state.getMinimum());
assertEquals(BigDecimal.valueOf(256), state.getMaximum());
assertEquals(BigDecimal.valueOf(8), state.getStep());
assertEquals("%.0f", state.getPattern());
assertEquals(false, state.isReadOnly());
opts = state.getOptions();
assertEquals(0, opts.size());
item = itemRegistry.getItem("TestItem3");
assertEquals("String", item.getType());
state = item.getStateDescription();
assertNotNull(state);
assertNull(state.getMinimum());
assertNull(state.getMaximum());
assertNull(state.getStep());
assertEquals("%s", state.getPattern());
assertEquals(false, state.isReadOnly());
opts = state.getOptions();
assertEquals(0, opts.size());
item = itemRegistry.getItem("TestItem4");
assertEquals("Color", item.getType());
state = item.getStateDescription();
assertNull(state);
item = itemRegistry.getItem("TestItem5");
assertEquals("Dimmer", item.getType());
state = item.getStateDescription();
assertNull(state);
item = itemRegistry.getItem("TestItem6");
assertEquals("Switch", item.getType());
state = item.getStateDescription();
assertNull(state);
item = itemRegistry.getItem("TestItem7_1");
assertEquals("Number", item.getType());
state = item.getStateDescription();
assertNotNull(state);
assertEquals(BigDecimal.valueOf(10), state.getMinimum());
assertEquals(BigDecimal.valueOf(100), state.getMaximum());
assertEquals(BigDecimal.valueOf(5), state.getStep());
assertEquals("VALUE %d", state.getPattern());
assertEquals(false, state.isReadOnly());
opts = state.getOptions();
assertNotNull(opts);
assertEquals(2, opts.size());
final StateOption opt0 = opts.get(0);
assertNotNull(opt0);
assertEquals(opt0.getValue(), "value0");
assertEquals(opt0.getLabel(), "label0");
final StateOption opt1 = opts.get(1);
assertNotNull(opt1);
assertEquals(opt1.getValue(), "value1");
assertEquals(opt1.getLabel(), "label1");
item = itemRegistry.getItem("TestItem7_2");
assertEquals("Number", item.getType());
state = item.getStateDescription();
assertNotNull(state);
assertEquals(BigDecimal.valueOf(1), state.getMinimum());
assertEquals(BigDecimal.valueOf(101), state.getMaximum());
assertEquals(BigDecimal.valueOf(20), state.getStep());
assertEquals("NEW %d Peek", state.getPattern());
assertEquals(true, state.isReadOnly());
opts = state.getOptions();
assertNotNull(opts);
assertEquals(1, opts.size());
final StateOption opt2 = opts.get(0);
assertEquals("SOUND", opt2.getValue());
assertEquals("My great sound.", opt2.getLabel());
}
use of org.eclipse.smarthome.core.thing.Thing in project smarthome by eclipse.
the class CommunicationManagerTest method testItemStateEvent_typeDowncast.
@Test
public void testItemStateEvent_typeDowncast() {
Thing thing = ThingBuilder.create(THING_TYPE_UID, THING_UID).withChannels(ChannelBuilder.create(STATE_CHANNEL_UID_2, "Dimmer").withKind(ChannelKind.STATE).build()).build();
thing.setHandler(mockHandler);
when(thingRegistry.get(eq(THING_UID))).thenReturn(thing);
manager.receive(ItemEventFactory.createStateEvent(ITEM_NAME_2, HSBType.fromRGB(128, 128, 128)));
waitForAssert(() -> {
ArgumentCaptor<State> stateCaptor = ArgumentCaptor.forClass(State.class);
verify(stateProfile).onStateUpdateFromItem(stateCaptor.capture());
State state = stateCaptor.getValue();
assertNotNull(state);
assertEquals(PercentType.class, state.getClass());
});
verifyNoMoreInteractions(stateProfile);
verifyNoMoreInteractions(triggerProfile);
}
use of org.eclipse.smarthome.core.thing.Thing in project smarthome by eclipse.
the class ThingManagerOSGiJavaTest method assertThingStatus.
private void assertThingStatus(Map<String, Object> propsThing, Map<String, Object> propsChannel, ThingStatus status, ThingStatusDetail statusDetail) {
Configuration configThing = new Configuration(propsThing);
Configuration configChannel = new Configuration(propsChannel);
Thing thing = ThingBuilder.create(THING_TYPE_UID, THING_UID).withChannels(//
Collections.singletonList(ChannelBuilder.create(CHANNEL_UID, "Switch").withType(CHANNEL_TYPE_UID).withConfiguration(configChannel).build())).withConfiguration(configThing).build();
managedThingProvider.add(thing);
waitForAssert(() -> {
assertEquals(status, thing.getStatus());
assertEquals(statusDetail, thing.getStatusInfo().getStatusDetail());
});
managedThingProvider.remove(thing.getUID());
}
use of org.eclipse.smarthome.core.thing.Thing in project smarthome by eclipse.
the class ThingManagerOSGiJavaTest method testChildHandlerInitialized_modifiedUninitializedThing.
@Test
public void testChildHandlerInitialized_modifiedUninitializedThing() {
Semaphore childHandlerInitializedSemaphore = new Semaphore(1);
Semaphore thingUpdatedSemapthore = new Semaphore(1);
registerThingHandlerFactory(BRIDGE_TYPE_UID, bridge -> new BaseBridgeHandler((Bridge) bridge) {
@Override
public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) {
}
@Override
public void initialize() {
updateStatus(ThingStatus.ONLINE);
}
@Override
public void childHandlerInitialized(ThingHandler childHandler, Thing childThing) {
try {
childHandlerInitializedSemaphore.acquire();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
registerThingHandlerFactory(THING_TYPE_UID, thing -> new BaseThingHandler(thing) {
@Override
public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) {
}
@Override
public void initialize() {
if (getBridge() == null) {
throw new RuntimeException("Fail because of missing bridge");
}
updateStatus(ThingStatus.ONLINE);
}
@Override
public void thingUpdated(Thing thing) {
this.thing = thing;
try {
thingUpdatedSemapthore.acquire();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
Bridge bridge = BridgeBuilder.create(BRIDGE_TYPE_UID, BRIDGE_UID).build();
managedThingProvider.add(bridge);
waitForAssert(() -> {
assertEquals(ThingStatus.ONLINE, bridge.getStatus());
});
Thing thing = ThingBuilder.create(THING_TYPE_UID, THING_UID).build();
managedThingProvider.add(thing);
waitForAssert(() -> {
assertEquals(ThingStatus.UNINITIALIZED, thing.getStatus());
assertEquals(ThingStatusDetail.HANDLER_INITIALIZING_ERROR, thing.getStatusInfo().getStatusDetail());
});
assertEquals(1, childHandlerInitializedSemaphore.availablePermits());
thing.setBridgeUID(bridge.getUID());
managedThingProvider.update(thing);
waitForAssert(() -> {
assertEquals(ThingStatus.ONLINE, thing.getStatus());
});
// childHandlerInitialized(...) must be called
waitForAssert(() -> assertEquals(0, childHandlerInitializedSemaphore.availablePermits()));
// thingUpdated(...) is not called
assertEquals(1, thingUpdatedSemapthore.availablePermits());
}
Aggregations