Search in sources :

Example 1 with ColorItem

use of org.eclipse.smarthome.core.library.items.ColorItem in project smarthome by eclipse.

the class ItemUIRegistryImplTest method testStateConversionForSwitchWidgetThroughGetState.

@Test
public void testStateConversionForSwitchWidgetThroughGetState() throws ItemNotFoundException {
    State colorState = new HSBType("23,42,50");
    ColorItem colorItem = new ColorItem("myItem");
    colorItem.setLabel("myItem");
    colorItem.setState(colorState);
    when(registry.getItem("myItem")).thenReturn(colorItem);
    Switch switchWidget = mock(Switch.class);
    when(switchWidget.getItem()).thenReturn("myItem");
    when(switchWidget.getMappings()).thenReturn(new BasicEList<Mapping>());
    State stateForSwitch = uiRegistry.getState(switchWidget);
    assertEquals(OnOffType.ON, stateForSwitch);
}
Also used : Switch(org.eclipse.smarthome.model.sitemap.Switch) State(org.eclipse.smarthome.core.types.State) ColorItem(org.eclipse.smarthome.core.library.items.ColorItem) Mapping(org.eclipse.smarthome.model.sitemap.Mapping) HSBType(org.eclipse.smarthome.core.library.types.HSBType) Test(org.junit.Test)

Example 2 with ColorItem

use of org.eclipse.smarthome.core.library.items.ColorItem in project smarthome by eclipse.

the class ItemUIRegistryImplTest method testStateConversionForSliderWidgetThroughGetState.

@Test
public void testStateConversionForSliderWidgetThroughGetState() throws ItemNotFoundException {
    State colorState = new HSBType("23,42,75");
    ColorItem colorItem = new ColorItem("myItem");
    colorItem.setLabel("myItem");
    colorItem.setState(colorState);
    when(registry.getItem("myItem")).thenReturn(colorItem);
    Slider sliderWidget = mock(Slider.class);
    when(sliderWidget.getItem()).thenReturn("myItem");
    State stateForSlider = uiRegistry.getState(sliderWidget);
    assertTrue(stateForSlider instanceof PercentType);
    PercentType pt = (PercentType) stateForSlider;
    assertEquals(75, pt.longValue());
}
Also used : Slider(org.eclipse.smarthome.model.sitemap.Slider) State(org.eclipse.smarthome.core.types.State) ColorItem(org.eclipse.smarthome.core.library.items.ColorItem) PercentType(org.eclipse.smarthome.core.library.types.PercentType) HSBType(org.eclipse.smarthome.core.library.types.HSBType) Test(org.junit.Test)

Example 3 with ColorItem

use of org.eclipse.smarthome.core.library.items.ColorItem in project smarthome by eclipse.

the class ItemUIRegistryImplTest method testStateConversionForSwitchWidgetWithMappingThroughGetState.

@Test
public void testStateConversionForSwitchWidgetWithMappingThroughGetState() throws ItemNotFoundException {
    State colorState = new HSBType("23,42,50");
    ColorItem colorItem = new ColorItem("myItem");
    colorItem.setLabel("myItem");
    colorItem.setState(colorState);
    when(registry.getItem("myItem")).thenReturn(colorItem);
    Switch switchWidget = mock(Switch.class);
    when(switchWidget.getItem()).thenReturn("myItem");
    Mapping mapping = mock(Mapping.class);
    BasicEList<Mapping> mappings = new BasicEList<Mapping>();
    mappings.add(mapping);
    when(switchWidget.getMappings()).thenReturn(mappings);
    State stateForSwitch = uiRegistry.getState(switchWidget);
    assertEquals(colorState, stateForSwitch);
}
Also used : Switch(org.eclipse.smarthome.model.sitemap.Switch) State(org.eclipse.smarthome.core.types.State) BasicEList(org.eclipse.emf.common.util.BasicEList) ColorItem(org.eclipse.smarthome.core.library.items.ColorItem) Mapping(org.eclipse.smarthome.model.sitemap.Mapping) HSBType(org.eclipse.smarthome.core.library.types.HSBType) Test(org.junit.Test)

Example 4 with ColorItem

use of org.eclipse.smarthome.core.library.items.ColorItem in project smarthome by eclipse.

the class ChannelStateDescriptionProviderOSGiTest method setup.

@Before
public void setup() {
    initMocks(this);
    Mockito.when(componentContext.getBundleContext()).thenReturn(bundleContext);
    registerVolatileStorageService();
    itemRegistry = getService(ItemRegistry.class);
    assertNotNull(itemRegistry);
    final TestThingHandlerFactory thingHandlerFactory = new TestThingHandlerFactory();
    thingHandlerFactory.activate(componentContext);
    registerService(thingHandlerFactory, ThingHandlerFactory.class.getName());
    final StateDescription state = new StateDescription(BigDecimal.ZERO, BigDecimal.valueOf(100), BigDecimal.TEN, "%d Peek", true, Collections.singletonList(new StateOption("SOUND", "My great sound.")));
    final StateDescription state2 = new StateDescription(BigDecimal.ZERO, BigDecimal.valueOf(256), BigDecimal.valueOf(8), null, false, null);
    final ChannelType channelType = new ChannelType(new ChannelTypeUID("hue:alarm"), false, "Number", " ", "", null, null, state, null);
    final ChannelType channelType2 = new ChannelType(new ChannelTypeUID("hue:num"), false, "Number", " ", "", null, null, state2, null);
    final ChannelType channelType3 = new ChannelType(new ChannelTypeUID("hue:info"), true, "String", " ", "", null, null, null, null);
    final ChannelType channelType4 = new ChannelType(new ChannelTypeUID("hue:color"), false, "Color", "Color", "", "ColorLight", null, null, null);
    final ChannelType channelType5 = new ChannelType(new ChannelTypeUID("hue:brightness"), false, "Dimmer", "Brightness", "", "DimmableLight", null, null, null);
    final ChannelType channelType6 = new ChannelType(new ChannelTypeUID("hue:switch"), false, "Switch", "Switch", "", "Light", null, null, null);
    final ChannelType channelType7 = new ChannelType(new ChannelTypeUID("hue:num-dynamic"), false, "Number", " ", "", "Light", null, state, null);
    List<ChannelType> channelTypes = new ArrayList<>();
    channelTypes.add(channelType);
    channelTypes.add(channelType2);
    channelTypes.add(channelType3);
    channelTypes.add(channelType4);
    channelTypes.add(channelType5);
    channelTypes.add(channelType6);
    channelTypes.add(channelType7);
    registerService(new ChannelTypeProvider() {

        @Override
        public Collection<ChannelType> getChannelTypes(Locale locale) {
            return channelTypes;
        }

        @Override
        public ChannelType getChannelType(ChannelTypeUID channelTypeUID, Locale locale) {
            for (final ChannelType channelType : channelTypes) {
                if (channelType.getUID().equals(channelTypeUID)) {
                    return channelType;
                }
            }
            return null;
        }

        @Override
        public ChannelGroupType getChannelGroupType(ChannelGroupTypeUID channelGroupTypeUID, Locale locale) {
            return null;
        }

        @Override
        public Collection<ChannelGroupType> getChannelGroupTypes(Locale locale) {
            return Collections.emptySet();
        }
    });
    registerService(new DynamicStateDescriptionProvider() {

        final StateDescription newState = new StateDescription(BigDecimal.valueOf(10), BigDecimal.valueOf(100), BigDecimal.valueOf(5), "VALUE %d", false, Arrays.asList(new StateOption("value0", "label0"), new StateOption("value1", "label1")));

        @Override
        @Nullable
        public StateDescription getStateDescription(@NonNull Channel channel, @Nullable StateDescription original, @Nullable Locale locale) {
            String id = channel.getUID().getIdWithoutGroup();
            if ("7_1".equals(id)) {
                assertEquals(channel.getChannelTypeUID(), channelType7.getUID());
                return newState;
            } else if ("7_2".equals(id)) {
                assertEquals(channel.getChannelTypeUID(), channelType7.getUID());
                StateDescription newState2 = new StateDescription(original.getMinimum().add(BigDecimal.ONE), original.getMaximum().add(BigDecimal.ONE), original.getStep().add(BigDecimal.TEN), "NEW " + original.getPattern(), true, original.getOptions());
                return newState2;
            }
            return null;
        }
    });
    List<ChannelDefinition> channelDefinitions = new ArrayList<>();
    channelDefinitions.add(new ChannelDefinition("1", channelType.getUID()));
    channelDefinitions.add(new ChannelDefinition("2", channelType2.getUID()));
    channelDefinitions.add(new ChannelDefinition("3", channelType3.getUID()));
    channelDefinitions.add(new ChannelDefinition("4", channelType4.getUID()));
    channelDefinitions.add(new ChannelDefinition("5", channelType5.getUID()));
    channelDefinitions.add(new ChannelDefinition("6", channelType6.getUID()));
    channelDefinitions.add(new ChannelDefinition("7_1", channelType7.getUID()));
    channelDefinitions.add(new ChannelDefinition("7_2", channelType7.getUID()));
    registerService(new SimpleThingTypeProvider(Collections.singleton(ThingTypeBuilder.instance(new ThingTypeUID("hue:lamp"), "label").withChannelDefinitions(channelDefinitions).build())));
    List<Item> items = new ArrayList<>();
    items.add(new NumberItem("TestItem"));
    items.add(new NumberItem("TestItem2"));
    items.add(new StringItem("TestItem3"));
    items.add(new ColorItem("TestItem4"));
    items.add(new DimmerItem("TestItem5"));
    items.add(new SwitchItem("TestItem6"));
    items.add(new NumberItem("TestItem7_1"));
    items.add(new NumberItem("TestItem7_2"));
    registerService(new TestItemProvider(items));
    linkRegistry = getService(ItemChannelLinkRegistry.class);
    stateDescriptionProvider = getService(StateDescriptionProvider.class);
    assertNotNull(stateDescriptionProvider);
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType) ColorItem(org.eclipse.smarthome.core.library.items.ColorItem) DynamicStateDescriptionProvider(org.eclipse.smarthome.core.thing.type.DynamicStateDescriptionProvider) ItemRegistry(org.eclipse.smarthome.core.items.ItemRegistry) 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) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) DimmerItem(org.eclipse.smarthome.core.library.items.DimmerItem) ItemChannelLinkRegistry(org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) StateDescription(org.eclipse.smarthome.core.types.StateDescription) Channel(org.eclipse.smarthome.core.thing.Channel) ChannelGroupTypeUID(org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID) BaseThingHandlerFactory(org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory) ThingHandlerFactory(org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory) StringItem(org.eclipse.smarthome.core.library.items.StringItem) StateOption(org.eclipse.smarthome.core.types.StateOption) NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ChannelTypeProvider(org.eclipse.smarthome.core.thing.type.ChannelTypeProvider) Collection(java.util.Collection) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) StateDescriptionProvider(org.eclipse.smarthome.core.types.StateDescriptionProvider) DynamicStateDescriptionProvider(org.eclipse.smarthome.core.thing.type.DynamicStateDescriptionProvider) Nullable(org.eclipse.jdt.annotation.Nullable) Before(org.junit.Before)

Example 5 with ColorItem

use of org.eclipse.smarthome.core.library.items.ColorItem in project smarthome by eclipse.

the class GroupItemTest method assertThatGroupItemWithColoritemBaseItemConversionWorks.

@Test
public void assertThatGroupItemWithColoritemBaseItemConversionWorks() {
    // initially this group has State UndefType.NULL
    GroupItem groupItem = new GroupItem("root", new ColorItem("myColor"));
    State groupStateAsPercent = groupItem.getStateAs(PercentType.class);
    // a state conversion from NULL to PercentType should not be possible
    assertNull(groupStateAsPercent);
    // init group
    groupItem.setState(new HSBType("200,80,80"));
    groupStateAsPercent = groupItem.getStateAs(PercentType.class);
    assertTrue(groupStateAsPercent instanceof PercentType);
    assertThat(((PercentType) groupStateAsPercent).intValue(), is(80));
}
Also used : State(org.eclipse.smarthome.core.types.State) ColorItem(org.eclipse.smarthome.core.library.items.ColorItem) PercentType(org.eclipse.smarthome.core.library.types.PercentType) HSBType(org.eclipse.smarthome.core.library.types.HSBType) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Aggregations

ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)5 HSBType (org.eclipse.smarthome.core.library.types.HSBType)4 State (org.eclipse.smarthome.core.types.State)4 Test (org.junit.Test)4 PercentType (org.eclipse.smarthome.core.library.types.PercentType)2 Mapping (org.eclipse.smarthome.model.sitemap.Mapping)2 Switch (org.eclipse.smarthome.model.sitemap.Switch)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Locale (java.util.Locale)1 BasicEList (org.eclipse.emf.common.util.BasicEList)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 Item (org.eclipse.smarthome.core.items.Item)1 ItemRegistry (org.eclipse.smarthome.core.items.ItemRegistry)1 DimmerItem (org.eclipse.smarthome.core.library.items.DimmerItem)1 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)1 StringItem (org.eclipse.smarthome.core.library.items.StringItem)1 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)1 Channel (org.eclipse.smarthome.core.thing.Channel)1 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)1