Search in sources :

Example 26 with HSBType

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

the class TradfriColorTest method testFromHSBTypeKnownGood2.

@Test
public void testFromHSBTypeKnownGood2() {
    TradfriColor color = new TradfriColor(new HSBType("0,100,1"));
    assertEquals(41947, (int) color.xyX);
    assertEquals(21625, (int) color.xyY);
    assertEquals(2, (int) color.brightness);
    HSBType hsbType = color.getHSB();
    assertNotNull(hsbType);
    assertEquals(0, hsbType.getHue().intValue());
    assertEquals(100, hsbType.getSaturation().intValue());
    assertEquals(1, hsbType.getBrightness().intValue());
}
Also used : HSBType(org.eclipse.smarthome.core.library.types.HSBType) Test(org.junit.Test)

Example 27 with HSBType

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

the class TradfriColorTest method testFromCieKnownGood1.

@Test
public void testFromCieKnownGood1() {
    TradfriColor color = new TradfriColor(29577, 12294, 354);
    assertEquals(29577, (int) color.xyX);
    assertEquals(12294, (int) color.xyY);
    assertEquals(254, (int) color.brightness);
    HSBType hsbType = color.getHSB();
    assertNotNull(hsbType);
    assertEquals(321, 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 28 with HSBType

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

the class TradfriColor method getHSB.

/**
 * Obtain the TradfriColor (x/y) as HSBType
 *
 * @return HSBType representing the x/y Tradfri color
 */
public HSBType getHSB() {
    float x = unnormalize(xyX);
    float y = unnormalize(xyY);
    HSBType converted = HSBType.fromXY(x, y);
    return new HSBType(converted.getHue(), converted.getSaturation(), xyBrightnessToPercentType(brightness));
}
Also used : HSBType(org.eclipse.smarthome.core.library.types.HSBType)

Example 29 with HSBType

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

the class ColorThingHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    logger.trace("received command {} in channel {}", command, channelUID);
    ValueSet targetValueSet = new ValueSet(fadeTime, -1);
    switch(channelUID.getId()) {
        case CHANNEL_BRIGHTNESS_R:
            if (command instanceof RefreshType) {
                logger.trace("sending update on refresh to channel {}:brightness_r", this.thing.getUID());
                currentValues.set(0, channels.get(0).getValue());
                updateCurrentColor();
                updateState(channelUID, Util.toPercentValue(currentValues.get(0)));
                return;
            } else {
                logger.debug("command {} not supported in channel {}:brightness_r", command.getClass(), this.thing.getUID());
                return;
            }
        case CHANNEL_BRIGHTNESS_G:
            if (command instanceof RefreshType) {
                logger.trace("sending update on refresh to channel {}:brightness_g", this.thing.getUID());
                currentValues.set(1, channels.get(1).getValue());
                updateCurrentColor();
                updateState(channelUID, Util.toPercentValue(currentValues.get(1)));
                return;
            } else {
                logger.debug("command {} not supported in channel {}:brightness_g", command.getClass(), this.thing.getUID());
                return;
            }
        case CHANNEL_BRIGHTNESS_B:
            if (command instanceof RefreshType) {
                logger.trace("sending update on refresh to channel {}:brightness_b", this.thing.getUID());
                currentValues.set(2, channels.get(2).getValue());
                updateCurrentColor();
                updateState(channelUID, Util.toPercentValue(currentValues.get(2)));
                return;
            } else {
                logger.debug("command {} not supported in channel {}:brightness_b", command.getClass(), this.thing.getUID());
                return;
            }
        case CHANNEL_COLOR:
            {
                if (command instanceof OnOffType) {
                    logger.trace("adding {} fade to channels in thing {}", command, this.thing.getUID());
                    targetValueSet = ((OnOffType) command).equals(OnOffType.ON) ? turnOnValue : turnOffValue;
                } else if (command instanceof HSBType) {
                    logger.trace("adding color fade to channels in thing {}", this.thing.getUID());
                    targetValueSet.addValue(((HSBType) command).getRed());
                    targetValueSet.addValue(((HSBType) command).getGreen());
                    targetValueSet.addValue(((HSBType) command).getBlue());
                } else if ((command instanceof PercentType) || (command instanceof DecimalType)) {
                    logger.trace("adding brightness fade to channels in thing {}", this.thing.getUID());
                    PercentType brightness = (command instanceof PercentType) ? (PercentType) command : Util.toPercentValue(((DecimalType) command).intValue());
                    HSBType targetColor = new HSBType(currentColor.getHue(), currentColor.getSaturation(), brightness);
                    targetValueSet.addValue(targetColor.getRed());
                    targetValueSet.addValue(targetColor.getGreen());
                    targetValueSet.addValue(targetColor.getBlue());
                } else if (command instanceof IncreaseDecreaseType) {
                    if (isDimming && ((IncreaseDecreaseType) command).equals(IncreaseDecreaseType.INCREASE)) {
                        logger.trace("stopping fade in thing {}", this.thing.getUID());
                        channels.forEach(DmxChannel::clearAction);
                        isDimming = false;
                        return;
                    } else {
                        logger.trace("starting {} fade in thing {}", command, this.thing.getUID());
                        HSBType targetColor;
                        if (((IncreaseDecreaseType) command).equals(IncreaseDecreaseType.INCREASE)) {
                            targetColor = new HSBType(currentColor.getHue(), currentColor.getSaturation(), PercentType.HUNDRED);
                        } else {
                            targetColor = new HSBType(currentColor.getHue(), currentColor.getSaturation(), PercentType.ZERO);
                        }
                        targetValueSet.addValue(targetColor.getRed());
                        targetValueSet.addValue(targetColor.getGreen());
                        targetValueSet.addValue(targetColor.getBlue());
                        targetValueSet.setFadeTime(dimTime);
                        isDimming = true;
                    }
                } else if (command instanceof RefreshType) {
                    logger.trace("sending update on refresh to channel {}:color", this.thing.getUID());
                    currentValues.set(0, channels.get(0).getValue());
                    currentValues.set(1, channels.get(1).getValue());
                    currentValues.set(2, channels.get(2).getValue());
                    updateCurrentColor();
                    updateState(channelUID, currentColor);
                    return;
                } else {
                    logger.debug("command {} not supported in channel {}:color", command.getClass(), this.thing.getUID());
                    return;
                }
                break;
            }
        default:
            logger.debug("channel {} not supported in thing {}", channelUID.getId(), this.thing.getUID());
            return;
    }
    final ValueSet valueSet = targetValueSet;
    IntStream.range(0, channels.size()).forEach(i -> {
        channels.get(i).setChannelAction(new FadeAction(valueSet.getFadeTime(), channels.get(i).getValue(), valueSet.getValue(i), valueSet.getHoldTime()));
    });
}
Also used : FadeAction(org.eclipse.smarthome.binding.dmx.internal.action.FadeAction) BaseDmxChannel(org.eclipse.smarthome.binding.dmx.internal.multiverse.BaseDmxChannel) DmxChannel(org.eclipse.smarthome.binding.dmx.internal.multiverse.DmxChannel) OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) IncreaseDecreaseType(org.eclipse.smarthome.core.library.types.IncreaseDecreaseType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) RefreshType(org.eclipse.smarthome.core.types.RefreshType) ValueSet(org.eclipse.smarthome.binding.dmx.internal.ValueSet) HSBType(org.eclipse.smarthome.core.library.types.HSBType)

Example 30 with HSBType

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

the class ColorThingHandler method dispose.

@Override
public void dispose() {
    if (channels.size() != 0) {
        channels.get(0).removeListener(new ChannelUID(this.thing.getUID(), CHANNEL_BRIGHTNESS_R));
        channels.get(1).removeListener(new ChannelUID(this.thing.getUID(), CHANNEL_BRIGHTNESS_G));
        channels.get(2).removeListener(new ChannelUID(this.thing.getUID(), CHANNEL_BRIGHTNESS_B));
    }
    channels.clear();
    currentValues.clear();
    currentColor = new HSBType();
}
Also used : ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) 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