use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.
the class UtilTest method conversionToPercentType.
@Test
public void conversionToPercentType() {
// borders
PercentType value = Util.toPercentValue(255);
assertThat(value.intValue(), is(100));
value = Util.toPercentValue(0);
assertThat(value.intValue(), is(0));
// middle
value = Util.toPercentValue(127);
assertThat(value.intValue(), is(49));
}
use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.
the class UtilTest method conversionFromPercentType.
@Test
public void conversionFromPercentType() {
// borders
int value = Util.toDmxValue(new PercentType(100));
assertThat(value, is(255));
value = Util.toDmxValue(new PercentType(0));
assertThat(value, is(0));
// middle
value = Util.toDmxValue(new PercentType(50));
assertThat(value, is(127));
}
use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.
the class ColorItem method setState.
@Override
public void setState(State state) {
if (isAcceptedState(acceptedDataTypes, state)) {
State currentState = this.state;
if (currentState instanceof HSBType) {
DecimalType hue = ((HSBType) currentState).getHue();
PercentType saturation = ((HSBType) currentState).getSaturation();
// we map ON/OFF values to dark/bright, so that the hue and saturation values are not changed
if (state == OnOffType.OFF) {
applyState(new HSBType(hue, saturation, PercentType.ZERO));
} else if (state == OnOffType.ON) {
applyState(new HSBType(hue, saturation, PercentType.HUNDRED));
} else if (state instanceof PercentType && !(state instanceof HSBType)) {
applyState(new HSBType(hue, saturation, (PercentType) state));
} else if (state instanceof DecimalType && !(state instanceof HSBType)) {
applyState(new HSBType(hue, saturation, new PercentType(((DecimalType) state).toBigDecimal().multiply(BigDecimal.valueOf(100)))));
} else {
applyState(state);
}
} else {
// try conversion
State convertedState = state.as(HSBType.class);
if (convertedState != null) {
applyState(convertedState);
} else {
applyState(state);
}
}
} else {
logSetTypeError(state);
}
}
use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.
the class SitemapResourceTest method whenGetPageData_ShouldReturnPageBean.
@Test
public void whenGetPageData_ShouldReturnPageBean() throws ItemNotFoundException {
item.setState(new PercentType(50));
configureItemUIRegistry(item.getState(), OnOffType.ON);
// Disable long polling
when(headers.getRequestHeader(HTTP_HEADER_X_ATMOSPHERE_TRANSPORT)).thenReturn(null);
Response response = sitemapResource.getPageData(headers, null, SITEMAP_MODEL_NAME, SITEMAP_NAME, null);
PageDTO pageDTO = (PageDTO) response.getEntity();
assertThat(pageDTO.id, is(SITEMAP_NAME));
assertThat(pageDTO.title, is(SITEMAP_TITLE));
assertThat(pageDTO.leaf, is(true));
assertThat(pageDTO.timeout, is(false));
assertThat(pageDTO.widgets, notNullValue());
assertThat((Collection<?>) pageDTO.widgets, hasSize(2));
assertThat(pageDTO.widgets.get(0).widgetId, is(WIDGET1_ID));
assertThat(pageDTO.widgets.get(0).label, is(WIDGET1_LABEL));
assertThat(pageDTO.widgets.get(0).labelcolor, is("GREEN"));
assertThat(pageDTO.widgets.get(0).valuecolor, is("BLUE"));
assertThat(pageDTO.widgets.get(0).state, nullValue());
assertThat(pageDTO.widgets.get(0).item, notNullValue());
assertThat(pageDTO.widgets.get(0).item.name, is(ITEM_NAME));
assertThat(pageDTO.widgets.get(0).item.state, is("50"));
assertThat(pageDTO.widgets.get(1).widgetId, is(WIDGET2_ID));
assertThat(pageDTO.widgets.get(1).label, is(WIDGET2_LABEL));
assertThat(pageDTO.widgets.get(1).labelcolor, nullValue());
assertThat(pageDTO.widgets.get(1).valuecolor, nullValue());
assertThat(pageDTO.widgets.get(1).state, is("ON"));
assertThat(pageDTO.widgets.get(1).item, notNullValue());
assertThat(pageDTO.widgets.get(1).item.name, is(ITEM_NAME));
assertThat(pageDTO.widgets.get(1).item.state, is("50"));
}
use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.
the class LifxLightHandler method handleOnOffCommand.
private void handleOnOffCommand(OnOffType onOff) {
if (powerOnColor != null && onOff == OnOffType.ON) {
getLightStateForCommand().setColor(powerOnColor);
}
if (powerOnTemperature != null && onOff == OnOffType.ON) {
getLightStateForCommand().setTemperature(powerOnTemperature);
}
if (powerOnBrightness != null) {
PercentType newBrightness = onOff == OnOffType.ON ? powerOnBrightness : new PercentType(0);
getLightStateForCommand().setBrightness(newBrightness);
}
getLightStateForCommand().setPowerState(onOff);
}
Aggregations