Search in sources :

Example 1 with PercentType

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

the class ItemStateConverterImplTest method testStateConversion.

@Test
public void testStateConversion() {
    Item item = new NumberItem("number");
    State originalState = new PercentType("42");
    State convertedState = itemStateConverter.convertToAcceptedState(originalState, item);
    assertThat(convertedState, is(new DecimalType("0.42")));
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) Item(org.eclipse.smarthome.core.items.Item) State(org.eclipse.smarthome.core.types.State) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) Test(org.junit.Test)

Example 2 with PercentType

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

the class AudioConsoleCommandExtension method play.

private void play(String[] args, Console console) {
    switch(args.length) {
        case 1:
            playOnSink(null, args[0], null, console);
            break;
        case 2:
            playOnSinks(args[0], args[1], null, console);
            break;
        case 3:
            PercentType volume = null;
            try {
                volume = PercentType.valueOf(args[2]);
            } catch (Exception e) {
                console.println(e.getMessage());
                break;
            }
            playOnSinks(args[0], args[1], volume, console);
            break;
        default:
            break;
    }
}
Also used : PercentType(org.eclipse.smarthome.core.library.types.PercentType) AudioException(org.eclipse.smarthome.core.audio.AudioException)

Example 3 with PercentType

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

the class TradfriColorTest method testFromColorTemperatureMinMiddleMax.

@Test
public void testFromColorTemperatureMinMiddleMax() {
    // coldest color temperature -> preset 1
    TradfriColor colorMin = new TradfriColor(PercentType.ZERO);
    assertNotNull(colorMin);
    assertEquals(24933, (int) colorMin.xyX);
    assertEquals(24691, (int) colorMin.xyY);
    // middle color temperature -> preset 2
    TradfriColor colorMiddle = new TradfriColor(new PercentType(50));
    assertNotNull(colorMiddle);
    assertEquals(30138, (int) colorMiddle.xyX);
    assertEquals(26909, (int) colorMiddle.xyY);
    // warmest color temperature -> preset 3
    TradfriColor colorMax = new TradfriColor(PercentType.HUNDRED);
    assertNotNull(colorMax);
    assertEquals(33137, (int) colorMax.xyX);
    assertEquals(27211, (int) colorMax.xyY);
}
Also used : PercentType(org.eclipse.smarthome.core.library.types.PercentType) Test(org.junit.Test)

Example 4 with PercentType

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

the class TradfriColorTest method testFromColorTemperatureInbetween.

@Test
public void testFromColorTemperatureInbetween() {
    // 30 percent must be between preset 1 and 2
    TradfriColor color2 = new TradfriColor(new PercentType(30));
    assertNotNull(color2);
    assertEquals(28056, (int) color2.xyX);
    assertEquals(26022, (int) color2.xyY);
    // 70 percent must be between preset 2 and 3
    TradfriColor color3 = new TradfriColor(new PercentType(70));
    assertNotNull(color3);
    assertEquals(31338, (int) color3.xyX);
    assertEquals(27030, (int) color3.xyY);
}
Also used : PercentType(org.eclipse.smarthome.core.library.types.PercentType) Test(org.junit.Test)

Example 5 with PercentType

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

the class TradfriLightHandler method onUpdate.

@Override
public void onUpdate(JsonElement data) {
    if (active && !(data.isJsonNull())) {
        state = new TradfriLightData(data);
        updateStatus(state.getReachabilityStatus() ? ThingStatus.ONLINE : ThingStatus.OFFLINE);
        if (!state.getOnOffState()) {
            logger.debug("Setting state to OFF");
            updateState(CHANNEL_BRIGHTNESS, PercentType.ZERO);
            if (lightHasColorSupport()) {
                updateState(CHANNEL_COLOR, HSBType.BLACK);
            }
            // if we are turned off, we do not set any brightness value
            return;
        }
        PercentType dimmer = state.getBrightness();
        if (dimmer != null && !lightHasColorSupport()) {
            // color lights do not have brightness channel
            updateState(CHANNEL_BRIGHTNESS, dimmer);
        }
        PercentType colorTemp = state.getColorTemperature();
        if (colorTemp != null) {
            updateState(CHANNEL_COLOR_TEMPERATURE, colorTemp);
        }
        HSBType color = null;
        if (lightHasColorSupport()) {
            color = state.getColor();
            if (color != null) {
                updateState(CHANNEL_COLOR, color);
            }
        }
        updateDeviceProperties(state);
        logger.debug("Updating thing for lightId {} to state {dimmer: {}, colorTemp: {}, color: {}, firmwareVersion: {}, modelId: {}, vendor: {}}", state.getDeviceId(), dimmer, colorTemp, color, state.getFirmwareVersion(), state.getModelId(), state.getVendor());
    }
}
Also used : TradfriLightData(org.eclipse.smarthome.binding.tradfri.internal.model.TradfriLightData) PercentType(org.eclipse.smarthome.core.library.types.PercentType) HSBType(org.eclipse.smarthome.core.library.types.HSBType)

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