use of org.eclipse.smarthome.core.library.types.HSBType in project smarthome by eclipse.
the class TradfriColorTest method testFromCieKnownGood2.
@Test
public void testFromCieKnownGood2() {
TradfriColor color = new TradfriColor(19983, 37417, 84);
assertEquals(19983, (int) color.xyX);
assertEquals(37417, (int) color.xyY);
assertEquals(84, (int) color.brightness);
HSBType hsbType = color.getHSB();
assertNotNull(hsbType);
assertEquals(115, hsbType.getHue().intValue());
assertEquals(77, hsbType.getSaturation().intValue());
assertEquals(34, hsbType.getBrightness().intValue());
}
use of org.eclipse.smarthome.core.library.types.HSBType in project smarthome by eclipse.
the class TradfriColorTest method testFromHSBTypeKnownGood1.
@Test
public void testFromHSBTypeKnownGood1() {
TradfriColor color = new TradfriColor(HSBType.RED);
assertEquals(41947, (int) color.xyX);
assertEquals(21625, (int) color.xyY);
assertEquals(254, (int) color.brightness);
HSBType hsbType = color.getHSB();
assertNotNull(hsbType);
assertEquals(0, hsbType.getHue().intValue());
assertEquals(100, hsbType.getSaturation().intValue());
assertEquals(100, hsbType.getBrightness().intValue());
}
use of org.eclipse.smarthome.core.library.types.HSBType in project smarthome by eclipse.
the class TradfriColorTest method testFromCieKnownGood3.
@Test
public void testFromCieKnownGood3() {
TradfriColor color = new TradfriColor(19983, 37417, 1);
assertEquals(19983, (int) color.xyX);
assertEquals(37417, (int) color.xyY);
assertEquals(1, (int) color.brightness);
HSBType hsbType = color.getHSB();
assertNotNull(hsbType);
assertEquals(115, hsbType.getHue().intValue());
assertEquals(77, hsbType.getSaturation().intValue());
assertEquals(1, hsbType.getBrightness().intValue());
}
use of org.eclipse.smarthome.core.library.types.HSBType in project smarthome by eclipse.
the class TradfriColorTest method testConversionReverse.
@Test
public void testConversionReverse() {
// convert from HSBType
TradfriColor color = new TradfriColor(HSBType.GREEN);
assertEquals(19660, (int) color.xyX);
assertEquals(39321, (int) color.xyY);
assertEquals(254, (int) color.brightness);
HSBType hsbType = color.getHSB();
assertNotNull(hsbType);
assertEquals(120, hsbType.getHue().intValue());
assertEquals(100, hsbType.getSaturation().intValue());
assertEquals(100, hsbType.getBrightness().intValue());
// convert the result again based on the XY values
TradfriColor reverse = new TradfriColor(color.xyX, color.xyY, color.brightness);
assertEquals(19660, (int) reverse.xyX);
assertEquals(39321, (int) reverse.xyY);
assertEquals(254, (int) reverse.brightness);
HSBType hsbTypeReverse = color.getHSB();
assertNotNull(hsbTypeReverse);
assertEquals(120, hsbTypeReverse.getHue().intValue());
assertEquals(100, hsbTypeReverse.getSaturation().intValue());
assertEquals(100, hsbTypeReverse.getBrightness().intValue());
}
use of org.eclipse.smarthome.core.library.types.HSBType 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