use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.
the class AbstractDmxThingTest method assertPercentTypeCommands.
public void assertPercentTypeCommands(ThingHandler handler, ChannelUID channelUID, int fadeTime) {
long currentTime = System.currentTimeMillis();
// set 30%
handler.handleCommand(channelUID, new PercentType(30));
currentTime = dmxBridgeHandler.calcBuffer(currentTime, fadeTime);
waitForAssert(() -> {
assertChannelStateUpdate(channelUID, state -> assertThat(((PercentType) state).doubleValue(), is(closeTo(30.0, 1.0))));
});
// set 0%
handler.handleCommand(channelUID, PercentType.ZERO);
currentTime = dmxBridgeHandler.calcBuffer(currentTime, fadeTime);
waitForAssert(() -> {
assertChannelStateUpdate(channelUID, state -> assertEquals(PercentType.ZERO, state));
});
// set 100%
handler.handleCommand(channelUID, PercentType.HUNDRED);
currentTime = dmxBridgeHandler.calcBuffer(currentTime, fadeTime);
waitForAssert(() -> {
assertChannelStateUpdate(channelUID, state -> assertThat(((PercentType) state).doubleValue(), is(closeTo(100.0, 0.5))));
});
}
use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.
the class LightStateConverterOSGiTest method lightStateConverterConversionIsBijective.
@Test
public void lightStateConverterConversionIsBijective() {
int PERCENT_VALUE_67 = 67;
StateUpdate stateUpdate = LightStateConverter.toBrightnessLightState(new PercentType(PERCENT_VALUE_67));
assertThat(stateUpdate.commands.size(), is(2));
assertThat(stateUpdate.commands.get(1).key, is("bri"));
State lightState = new State();
lightState.bri = Integer.parseInt(stateUpdate.commands.get(1).value.toString());
assertThat(LightStateConverter.toBrightnessPercentType(lightState).intValue(), is(PERCENT_VALUE_67));
}
use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.
the class LightStateConverter method toHSBType.
/**
* Transforms Hue Light {@link State} into {@link HSBType} representing the
* color.
*
* @param lightState light state
* @return HSB type representing the color
*/
public static HSBType toHSBType(State lightState) {
int hue = lightState.getHue();
int saturationInPercent = (int) (lightState.getSaturation() / SATURATION_FACTOR);
int brightnessInPercent = (int) (lightState.getBrightness() / BRIGHTNESS_FACTOR);
saturationInPercent = restrictToBounds(saturationInPercent);
brightnessInPercent = restrictToBounds(brightnessInPercent);
return new HSBType(new DecimalType(hue / HUE_FACTOR), new PercentType(saturationInPercent), new PercentType(brightnessInPercent));
}
use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.
the class GroupItemTest method assertThatGroupItemWithoutFunctionCanHaveAconvertibleState.
@Test
public void assertThatGroupItemWithoutFunctionCanHaveAconvertibleState() {
GroupItem groupItem = new GroupItem("root");
PercentType pt = new PercentType(50);
groupItem.setState(pt);
State groupStateAsOnOff = groupItem.getStateAs(OnOffType.class);
// any value >0 means on, so 50% means the group state should be ON
assertTrue(OnOffType.ON.equals(groupStateAsOnOff));
}
use of org.eclipse.smarthome.core.library.types.PercentType 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));
}
Aggregations