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;
}
}
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;
}
}
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());
}
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));
}
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());
}
Aggregations