Search in sources :

Example 6 with PercentType

use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.

the class WemoLightHandler method onValueReceived.

@Override
public void onValueReceived(String variable, String value, String service) {
    logger.trace("Received pair '{}':'{}' (service '{}') for thing '{}'", new Object[] { variable, value, service, this.getThing().getUID() });
    String capabilityId = StringUtils.substringBetween(value, "<CapabilityId>", "</CapabilityId>");
    String newValue = StringUtils.substringBetween(value, "<Value>", "</Value>");
    switch(capabilityId) {
        case "10006":
            OnOffType binaryState = null;
            binaryState = newValue.equals("0") ? OnOffType.OFF : OnOffType.ON;
            if (binaryState != null) {
                updateState(CHANNEL_STATE, binaryState);
            }
            break;
        case "10008":
            String[] splitValue = newValue.split(":");
            if (splitValue[0] != null) {
                int newBrightnessValue = Integer.valueOf(splitValue[0]);
                int newBrightness = Math.round(newBrightnessValue * 100 / 255);
                State newBrightnessState = new PercentType(newBrightness);
                updateState(CHANNEL_BRIGHTNESS, newBrightnessState);
                currentBrightness = newBrightness;
            }
            break;
    }
}
Also used : OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) State(org.eclipse.smarthome.core.types.State) PercentType(org.eclipse.smarthome.core.library.types.PercentType)

Example 7 with PercentType

use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.

the class JavaSoundAudioSink method getVolume.

@Override
public PercentType getVolume() throws IOException {
    if (!isMac) {
        final Float[] volumes = new Float[1];
        runVolumeCommand(new Closure() {

            @Override
            public void execute(Object input) {
                FloatControl volumeControl = (FloatControl) input;
                volumes[0] = volumeControl.getValue();
            }
        });
        if (volumes[0] != null) {
            return new PercentType(new BigDecimal(volumes[0] * 100f));
        } else {
            throw new IOException("Cannot determine master volume level");
        }
    } else {
        // we use a cache of the value as the script execution is pretty slow
        if (macVolumeValue == null) {
            Process p = Runtime.getRuntime().exec(new String[] { "osascript", "-e", "output volume of (get volume settings)" });
            String value = IOUtils.toString(p.getInputStream()).trim();
            macVolumeValue = new PercentType(value);
        }
        return macVolumeValue;
    }
}
Also used : Closure(org.apache.commons.collections.Closure) PercentType(org.eclipse.smarthome.core.library.types.PercentType) IOException(java.io.IOException) FloatControl(javax.sound.sampled.FloatControl) BigDecimal(java.math.BigDecimal)

Example 8 with PercentType

use of org.eclipse.smarthome.core.library.types.PercentType 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 9 with PercentType

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

Example 10 with PercentType

use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.

the class ColorItemTest method testUpdateStateWithPercentType.

@Test
public void testUpdateStateWithPercentType() {
    ColorItem item = new ColorItem("test");
    item.setState(new HSBType(new DecimalType(75), new PercentType(75), new PercentType(75)));
    item.setState(new PercentType(50));
    assertEquals(new HSBType(new DecimalType(75), new PercentType(75), new PercentType(50)), item.getState());
}
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) 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