Search in sources :

Example 1 with HSBType

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

Example 2 with HSBType

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

Example 3 with HSBType

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

Example 4 with HSBType

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

Example 5 with HSBType

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

HSBType (org.eclipse.smarthome.core.library.types.HSBType)34 Test (org.junit.Test)19 PercentType (org.eclipse.smarthome.core.library.types.PercentType)16 State (org.eclipse.smarthome.core.types.State)10 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)9 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)4 IncreaseDecreaseType (org.eclipse.smarthome.core.library.types.IncreaseDecreaseType)3 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)3 StringType (org.eclipse.smarthome.core.library.types.StringType)3 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)2 RefreshType (org.eclipse.smarthome.core.types.RefreshType)2 Colorpicker (org.eclipse.smarthome.model.sitemap.Colorpicker)2 Mapping (org.eclipse.smarthome.model.sitemap.Mapping)2 Switch (org.eclipse.smarthome.model.sitemap.Switch)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 BigDecimal (java.math.BigDecimal)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Locale (java.util.Locale)1 MissingResourceException (java.util.MissingResourceException)1