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