use of org.eclipse.smarthome.core.library.items.DimmerItem in project smarthome by eclipse.
the class GroupItemTest method assertThatGroupItemWithDimmeritemBaseItemConversionWorks.
@Test
public void assertThatGroupItemWithDimmeritemBaseItemConversionWorks() {
// initially this group has State UndefType.NULL
GroupItem groupItem = new GroupItem("root", new DimmerItem("myDimmer"));
State groupStateAsPercent = groupItem.getStateAs(PercentType.class);
// a state conversion from NULL to PercentType should not be possible
assertNull(groupStateAsPercent);
// init group
groupItem.setState(new PercentType(80));
groupStateAsPercent = groupItem.getStateAs(PercentType.class);
assertTrue(groupStateAsPercent instanceof PercentType);
assertThat(((PercentType) groupStateAsPercent).intValue(), is(80));
}
use of org.eclipse.smarthome.core.library.items.DimmerItem 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);
}
use of org.eclipse.smarthome.core.library.items.DimmerItem in project smarthome by eclipse.
the class GroupItemTest method assertThatGroupItemwithDimmeritemAcceptsGetsPercentTypeStateIfMembersHavePercentTypeStates.
@Test
public void assertThatGroupItemwithDimmeritemAcceptsGetsPercentTypeStateIfMembersHavePercentTypeStates() {
events.clear();
GroupItem groupItem = new GroupItem("root", new DimmerItem("myDimmer"), new ArithmeticGroupFunction.Avg());
groupItem.setItemStateConverter(itemStateConverter);
DimmerItem member1 = new DimmerItem("dimmer1");
groupItem.addMember(member1);
DimmerItem member2 = new DimmerItem("dimmer2");
groupItem.addMember(member2);
groupItem.setEventPublisher(publisher);
member1.setState(new PercentType(50));
waitForAssert(() -> assertThat(events.size(), is(1)));
List<Event> changes = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent).collect(Collectors.toList());
GroupItemStateChangedEvent change = (GroupItemStateChangedEvent) changes.get(0);
assertTrue(change.getItemName().equals(groupItem.getName()));
State newEventState = change.getItemState();
assertTrue(newEventState instanceof PercentType);
assertThat(((PercentType) newEventState).intValue(), is(50));
State newGroupState = groupItem.getState();
assertTrue(newGroupState instanceof PercentType);
assertThat(((PercentType) newGroupState).intValue(), is(50));
events.clear();
member2.setState(new PercentType(10));
waitForAssert(() -> assertThat(events.size(), is(1)));
changes = events.stream().filter(it -> it instanceof GroupItemStateChangedEvent).collect(Collectors.toList());
assertThat(changes.size(), is(1));
change = (GroupItemStateChangedEvent) changes.get(0);
assertTrue(change.getItemName().equals(groupItem.getName()));
newEventState = change.getItemState();
assertTrue(newEventState instanceof PercentType);
assertThat(((PercentType) newEventState).intValue(), is(30));
newGroupState = groupItem.getState();
assertTrue(newGroupState instanceof PercentType);
assertThat(((PercentType) newGroupState).intValue(), is(30));
}
use of org.eclipse.smarthome.core.library.items.DimmerItem in project smarthome by eclipse.
the class ArithmeticGroupFunctionTest method testOrFunction_differntTypes.
@Test
public void testOrFunction_differntTypes() {
DimmerItem dimmer1 = new DimmerItem("TestDimmer1");
dimmer1.setState(new PercentType("42"));
DimmerItem dimmer2 = new DimmerItem("TestDimmer2");
dimmer2.setState(new DecimalType("0"));
SwitchItem switch1 = new SwitchItem("TestSwitch1");
switch1.setState(OnOffType.ON);
SwitchItem switch2 = new SwitchItem("TestSwitch2");
switch2.setState(OnOffType.OFF);
items.add(dimmer1);
items.add(dimmer2);
items.add(switch1);
items.add(switch2);
function = new ArithmeticGroupFunction.Or(OnOffType.ON, OnOffType.OFF);
State state = function.calculate(items);
State decimalState = function.getStateAs(items, DecimalType.class);
assertEquals(OnOffType.ON, state);
assertEquals(new DecimalType("2"), decimalState);
}
use of org.eclipse.smarthome.core.library.items.DimmerItem in project smarthome by eclipse.
the class ItemResourceOSGiTest method setup.
@Before
public void setup() {
initMocks(this);
itemResource = getService(ItemResource.class);
itemResource.uriInfo = mock(UriInfo.class);
registerVolatileStorageService();
managedItemProvider = getService(ManagedItemProvider.class);
item1 = new SwitchItem(ITEM_NAME1);
item2 = new SwitchItem(ITEM_NAME2);
item3 = new DimmerItem(ITEM_NAME3);
when(itemProvider.getAll()).thenReturn(Arrays.asList(item1, item2, item3));
registerService(itemProvider);
}
Aggregations