Search in sources :

Example 1 with ManagedThingProvider

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);
}
Also used : Locale(java.util.Locale) ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) ThingProvider(org.eclipse.smarthome.core.thing.ThingProvider) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) ChannelTypeProvider(org.eclipse.smarthome.core.thing.type.ChannelTypeProvider) VolatileStorageService(org.eclipse.smarthome.test.storage.VolatileStorageService) ItemRegistry(org.eclipse.smarthome.core.items.ItemRegistry) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) Before(org.junit.Before)

Example 2 with ManagedThingProvider

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));
}
Also used : Item(org.eclipse.smarthome.core.items.Item) StringItem(org.eclipse.smarthome.core.library.items.StringItem) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) VolatileStorageService(org.eclipse.smarthome.test.storage.VolatileStorageService) ItemRegistry(org.eclipse.smarthome.core.items.ItemRegistry) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) StringItem(org.eclipse.smarthome.core.library.items.StringItem) Test(org.junit.Test)

Example 3 with ManagedThingProvider

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());
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) ColorItem(org.eclipse.smarthome.core.library.items.ColorItem) Item(org.eclipse.smarthome.core.items.Item) StringItem(org.eclipse.smarthome.core.library.items.StringItem) DimmerItem(org.eclipse.smarthome.core.library.items.DimmerItem) Configuration(org.eclipse.smarthome.config.core.Configuration) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) Thing(org.eclipse.smarthome.core.thing.Thing) StateOption(org.eclipse.smarthome.core.types.StateOption) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) StateDescription(org.eclipse.smarthome.core.types.StateDescription) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 4 with ManagedThingProvider

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());
    });
}
Also used : ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) After(org.junit.After)

Example 5 with ManagedThingProvider

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);
        }
    });
}
Also used : ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) ReadyService(org.eclipse.smarthome.core.service.ReadyService) ItemChannelLinkRegistry(org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ItemRegistry(org.eclipse.smarthome.core.items.ItemRegistry) ReadyMarker(org.eclipse.smarthome.core.service.ReadyMarker) URI(java.net.URI) Before(org.junit.Before)

Aggregations

ManagedThingProvider (org.eclipse.smarthome.core.thing.ManagedThingProvider)6 ItemRegistry (org.eclipse.smarthome.core.items.ItemRegistry)3 Before (org.junit.Before)3 Configuration (org.eclipse.smarthome.config.core.Configuration)2 Item (org.eclipse.smarthome.core.items.Item)2 StringItem (org.eclipse.smarthome.core.library.items.StringItem)2 ThingProvider (org.eclipse.smarthome.core.thing.ThingProvider)2 ThingRegistry (org.eclipse.smarthome.core.thing.ThingRegistry)2 VolatileStorageService (org.eclipse.smarthome.test.storage.VolatileStorageService)2 Test (org.junit.Test)2 URI (java.net.URI)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Locale (java.util.Locale)1 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)1 DimmerItem (org.eclipse.smarthome.core.library.items.DimmerItem)1 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)1 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)1 ReadyMarker (org.eclipse.smarthome.core.service.ReadyMarker)1 ReadyService (org.eclipse.smarthome.core.service.ReadyService)1