use of org.eclipse.smarthome.core.thing.ManagedThingProvider in project smarthome by eclipse.
the class NtpOSGiTest method setUp.
@Before
public void setUp() {
VolatileStorageService volatileStorageService = new VolatileStorageService();
registerService(volatileStorageService);
managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
assertNotNull(managedThingProvider);
thingRegistry = getService(ThingRegistry.class);
assertNotNull(thingRegistry);
itemRegistry = getService(ItemRegistry.class);
assertNotNull(itemRegistry);
channelTypeUID = new ChannelTypeUID(NtpBindingConstants.BINDING_ID + ":channelType");
channelTypeProvider = mock(ChannelTypeProvider.class);
when(channelTypeProvider.getChannelType(any(ChannelTypeUID.class), any(Locale.class))).thenReturn(new ChannelType(channelTypeUID, false, "Switch", ChannelKind.STATE, "label", null, null, null, null, null, null));
registerService(channelTypeProvider);
}
use of org.eclipse.smarthome.core.thing.ManagedThingProvider in project smarthome by eclipse.
the class SayCommandTest method testSayCommand.
@Test
public void testSayCommand() throws IOException {
String[] methodParameters = new String[2];
methodParameters[0] = SUBCMD_SAY;
if (defaultTTSService != null) {
Dictionary<String, Object> config = new Hashtable<String, Object>();
config.put(CONFIG_DEFAULT_TTS, defaultTTSService);
ConfigurationAdmin configAdmin = super.getService(ConfigurationAdmin.class);
String pid = "org.eclipse.smarthome.voice";
Configuration configuration = configAdmin.getConfiguration(pid);
configuration.update(config);
}
if (TTSServiceMockShouldBeRegistered) {
registerService(ttsService);
}
if (shouldItemsBePassed) {
VolatileStorageService volatileStorageService = new VolatileStorageService();
registerService(volatileStorageService);
ManagedThingProvider managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
assertNotNull(managedThingProvider);
ItemRegistry itemRegistry = getService(ItemRegistry.class);
assertNotNull(itemRegistry);
Item item = new StringItem("itemName");
if (shouldItemsBeRegistered) {
itemRegistry.add(item);
}
methodParameters[1] = "%" + item.getName() + "%";
if (shouldMultipleItemsBeRegistered) {
Item item1 = new StringItem("itemName1");
itemRegistry.add(item1);
Item item2 = new StringItem("itemName2");
itemRegistry.add(item2);
Item item3 = new StringItem("itemName3");
itemRegistry.add(item3);
methodParameters[1] = "%itemName.%";
}
} else {
methodParameters[1] = "hello";
}
extensionService.execute(methodParameters, console);
assertThat(sink.isStreamProcessed(), is(shouldStreamBeExpected));
}
use of org.eclipse.smarthome.core.thing.ManagedThingProvider 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.ManagedThingProvider in project smarthome by eclipse.
the class ChannelStateDescriptionProviderOSGiTest method teardown.
@After
public void teardown() {
ManagedThingProvider managedThingProvider = getService(ManagedThingProvider.class);
managedThingProvider.getAll().forEach(thing -> {
managedThingProvider.remove(thing.getUID());
});
linkRegistry.getAll().forEach(link -> {
linkRegistry.remove(link.getUID());
});
}
use of org.eclipse.smarthome.core.thing.ManagedThingProvider in project smarthome by eclipse.
the class ThingManagerOSGiJavaTest method setUp.
@Before
public void setUp() throws Exception {
CONFIG_DESCRIPTION_THING = new URI("test:test");
CONFIG_DESCRIPTION_CHANNEL = new URI("test:channel");
THING = ThingBuilder.create(THING_TYPE_UID, THING_UID).withChannels(//
Collections.singletonList(//
ChannelBuilder.create(CHANNEL_UID, "Switch").withType(CHANNEL_TYPE_UID).build())).build();
registerVolatileStorageService();
configureAutoLinking(false);
managedThingProvider = getService(ManagedThingProvider.class);
itemRegistry = getService(ItemRegistry.class);
assertNotNull(itemRegistry);
itemChannelLinkRegistry = getService(ItemChannelLinkRegistry.class);
assertNotNull(itemChannelLinkRegistry);
readyService = getService(ReadyService.class);
assertNotNull(readyService);
waitForAssert(() -> {
try {
assertThat(bundleContext.getServiceReferences(ReadyMarker.class, "(esh.xmlThingTypes=" + bundleContext.getBundle().getSymbolicName() + ")"), is(notNullValue()));
} catch (InvalidSyntaxException e) {
throw new RuntimeException(e);
}
});
waitForAssert(() -> {
try {
assertThat(bundleContext.getServiceReferences(ChannelItemProvider.class, null), is(notNullValue()));
} catch (InvalidSyntaxException e) {
throw new RuntimeException(e);
}
});
}
Aggregations