Search in sources :

Example 21 with PercentType

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))));
    });
}
Also used : PercentType(org.eclipse.smarthome.core.library.types.PercentType)

Example 22 with PercentType

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));
}
Also used : PercentType(org.eclipse.smarthome.core.library.types.PercentType) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 23 with PercentType

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));
}
Also used : DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) HSBType(org.eclipse.smarthome.core.library.types.HSBType)

Example 24 with PercentType

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));
}
Also used : State(org.eclipse.smarthome.core.types.State) PercentType(org.eclipse.smarthome.core.library.types.PercentType) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 25 with PercentType

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));
}
Also used : SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) CoreMatchers(org.hamcrest.CoreMatchers) MockitoAnnotations.initMocks(org.mockito.MockitoAnnotations.initMocks) RollershutterItem(org.eclipse.smarthome.core.library.items.RollershutterItem) NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) Mock(org.mockito.Mock) OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) UnDefType(org.eclipse.smarthome.core.types.UnDefType) EventFilter(org.eclipse.smarthome.core.events.EventFilter) EventSubscriber(org.eclipse.smarthome.core.events.EventSubscriber) GroupFunctionDTO(org.eclipse.smarthome.core.items.dto.GroupFunctionDTO) GroupFunctionHelper(org.eclipse.smarthome.core.internal.items.GroupFunctionHelper) HashSet(java.util.HashSet) ColorItem(org.eclipse.smarthome.core.library.items.ColorItem) GroupItemStateChangedEvent(org.eclipse.smarthome.core.items.events.GroupItemStateChangedEvent) Temperature(javax.measure.quantity.Temperature) Quantity(javax.measure.Quantity) Pressure(javax.measure.quantity.Pressure) ItemStateConverterImpl(org.eclipse.smarthome.core.internal.items.ItemStateConverterImpl) QuantityType(org.eclipse.smarthome.core.library.types.QuantityType) CoreItemFactory(org.eclipse.smarthome.core.library.CoreItemFactory) StringType(org.eclipse.smarthome.core.library.types.StringType) LinkedList(java.util.LinkedList) State(org.eclipse.smarthome.core.types.State) Dimensionless(javax.measure.quantity.Dimensionless) Before(org.junit.Before) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) RefreshType(org.eclipse.smarthome.core.types.RefreshType) Set(java.util.Set) EventPublisher(org.eclipse.smarthome.core.events.EventPublisher) ItemUpdatedEvent(org.eclipse.smarthome.core.items.events.ItemUpdatedEvent) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) Collectors(java.util.stream.Collectors) RawType(org.eclipse.smarthome.core.library.types.RawType) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) List(java.util.List) HSBType(org.eclipse.smarthome.core.library.types.HSBType) Ignore(org.junit.Ignore) PercentType(org.eclipse.smarthome.core.library.types.PercentType) Units(tec.uom.se.unit.Units) ArithmeticGroupFunction(org.eclipse.smarthome.core.library.types.ArithmeticGroupFunction) UnitProvider(org.eclipse.smarthome.core.i18n.UnitProvider) DimmerItem(org.eclipse.smarthome.core.library.items.DimmerItem) Assert(org.junit.Assert) Event(org.eclipse.smarthome.core.events.Event) Collections(java.util.Collections) GroupItemStateChangedEvent(org.eclipse.smarthome.core.items.events.GroupItemStateChangedEvent) State(org.eclipse.smarthome.core.types.State) DimmerItem(org.eclipse.smarthome.core.library.items.DimmerItem) GroupItemStateChangedEvent(org.eclipse.smarthome.core.items.events.GroupItemStateChangedEvent) ItemUpdatedEvent(org.eclipse.smarthome.core.items.events.ItemUpdatedEvent) Event(org.eclipse.smarthome.core.events.Event) PercentType(org.eclipse.smarthome.core.library.types.PercentType) ArithmeticGroupFunction(org.eclipse.smarthome.core.library.types.ArithmeticGroupFunction) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Aggregations

PercentType (org.eclipse.smarthome.core.library.types.PercentType)63 Test (org.junit.Test)25 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)17 State (org.eclipse.smarthome.core.types.State)17 HSBType (org.eclipse.smarthome.core.library.types.HSBType)16 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)13 LifxMessageUtil.increaseDecreasePercentType (org.eclipse.smarthome.binding.lifx.internal.util.LifxMessageUtil.increaseDecreasePercentType)9 StringType (org.eclipse.smarthome.core.library.types.StringType)9 IncreaseDecreaseType (org.eclipse.smarthome.core.library.types.IncreaseDecreaseType)7 RefreshType (org.eclipse.smarthome.core.types.RefreshType)7 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)6 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)4 RollershutterItem (org.eclipse.smarthome.core.library.items.RollershutterItem)4 QuantityType (org.eclipse.smarthome.core.library.types.QuantityType)4 BigDecimal (java.math.BigDecimal)3 ValueSet (org.eclipse.smarthome.binding.dmx.internal.ValueSet)3 FadeAction (org.eclipse.smarthome.binding.dmx.internal.action.FadeAction)3 DimmerItem (org.eclipse.smarthome.core.library.items.DimmerItem)3 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)3 LinkedList (java.util.LinkedList)2