Search in sources :

Example 51 with PercentType

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

Example 52 with PercentType

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

Example 53 with PercentType

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

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"));
}
Also used : Response(javax.ws.rs.core.Response) PercentType(org.eclipse.smarthome.core.library.types.PercentType) Test(org.junit.Test)

Example 55 with PercentType

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);
}
Also used : PercentType(org.eclipse.smarthome.core.library.types.PercentType) LifxMessageUtil.increaseDecreasePercentType(org.eclipse.smarthome.binding.lifx.internal.util.LifxMessageUtil.increaseDecreasePercentType)

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