Search in sources :

Example 11 with HSBType

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

the class ColorItemTest method testSetStateWithOnOffType.

@Test
public void testSetStateWithOnOffType() {
    ColorItem item = new ColorItem("test");
    item.setState(OnOffType.ON);
    assertEquals(new HSBType("0,0,100"), item.getState());
    item.setState(OnOffType.OFF);
    assertEquals(new HSBType("0,0,0"), item.getState());
}
Also used : HSBType(org.eclipse.smarthome.core.library.types.HSBType) Test(org.junit.Test)

Example 12 with HSBType

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

the class DimmerItemTest method getAsPercentFromHSB.

@Test
public void getAsPercentFromHSB() {
    // HSBType is supported because it is a sub-type of PercentType
    HSBType origin = new HSBType("23,42,75");
    final DimmerItem item = createDimmerItem(origin);
    final BigDecimal result = getState(item, PercentType.class);
    assertEquals(origin.getBrightness().toBigDecimal(), result);
}
Also used : HSBType(org.eclipse.smarthome.core.library.types.HSBType) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 13 with HSBType

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

the class StateUtil method getAllStates.

public static List<State> getAllStates() {
    LinkedList<State> states = new LinkedList<>();
    DateTimeType dateTime = new DateTimeType();
    states.add(dateTime);
    DecimalType decimal = new DecimalType(23);
    states.add(decimal);
    PercentType percent = new PercentType(50);
    states.add(percent);
    HSBType hsb = new HSBType("50,75,42");
    states.add(hsb);
    states.add(OnOffType.ON);
    states.add(OnOffType.OFF);
    states.add(OpenClosedType.OPEN);
    states.add(OpenClosedType.CLOSED);
    states.add(PlayPauseType.PLAY);
    states.add(PlayPauseType.PAUSE);
    PointType point = new PointType("42.23,23.5");
    states.add(point);
    RawType raw = new RawType(new byte[0], "application/octet-stream");
    states.add(raw);
    states.add(RewindFastforwardType.REWIND);
    states.add(RewindFastforwardType.FASTFORWARD);
    StringListType stringList = new StringListType(new String[] { "foo", "bar" });
    states.add(stringList);
    StringType string = new StringType("foo");
    states.add(string);
    states.add(UnDefType.NULL);
    states.add(UnDefType.UNDEF);
    states.add(UpDownType.UP);
    states.add(UpDownType.DOWN);
    QuantityType<Temperature> quantityType = new QuantityType<Temperature>("12 °C");
    states.add(quantityType);
    return states;
}
Also used : Temperature(javax.measure.quantity.Temperature) StringType(org.eclipse.smarthome.core.library.types.StringType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) LinkedList(java.util.LinkedList) DateTimeType(org.eclipse.smarthome.core.library.types.DateTimeType) QuantityType(org.eclipse.smarthome.core.library.types.QuantityType) State(org.eclipse.smarthome.core.types.State) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) PointType(org.eclipse.smarthome.core.library.types.PointType) RawType(org.eclipse.smarthome.core.library.types.RawType) HSBType(org.eclipse.smarthome.core.library.types.HSBType) StringListType(org.eclipse.smarthome.core.library.types.StringListType)

Example 14 with HSBType

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

the class LifxLightHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    if (command instanceof RefreshType) {
        switch(channelUID.getId()) {
            case CHANNEL_COLOR:
            case CHANNEL_BRIGHTNESS:
                sendPacket(new GetLightPowerRequest());
                sendPacket(new GetRequest());
                break;
            case CHANNEL_TEMPERATURE:
                sendPacket(new GetRequest());
                break;
            case CHANNEL_INFRARED:
                sendPacket(new GetLightInfraredRequest());
                break;
            case CHANNEL_SIGNAL_STRENGTH:
                sendPacket(new GetWifiInfoRequest());
                break;
            default:
                break;
        }
    } else {
        boolean supportedCommand = true;
        switch(channelUID.getId()) {
            case CHANNEL_COLOR:
                if (command instanceof HSBType) {
                    handleHSBCommand((HSBType) command);
                } else if (command instanceof PercentType) {
                    handlePercentCommand((PercentType) command);
                } else if (command instanceof OnOffType) {
                    handleOnOffCommand((OnOffType) command);
                } else if (command instanceof IncreaseDecreaseType) {
                    handleIncreaseDecreaseCommand((IncreaseDecreaseType) command);
                } else {
                    supportedCommand = false;
                }
                break;
            case CHANNEL_BRIGHTNESS:
                if (command instanceof PercentType) {
                    handlePercentCommand((PercentType) command);
                } else if (command instanceof OnOffType) {
                    handleOnOffCommand((OnOffType) command);
                } else if (command instanceof IncreaseDecreaseType) {
                    handleIncreaseDecreaseCommand((IncreaseDecreaseType) command);
                } else {
                    supportedCommand = false;
                }
                break;
            case CHANNEL_TEMPERATURE:
                if (command instanceof PercentType) {
                    handleTemperatureCommand((PercentType) command);
                } else if (command instanceof IncreaseDecreaseType) {
                    handleIncreaseDecreaseTemperatureCommand((IncreaseDecreaseType) command);
                } else {
                    supportedCommand = false;
                }
                break;
            case CHANNEL_INFRARED:
                if (command instanceof PercentType) {
                    handleInfraredCommand((PercentType) command);
                } else if (command instanceof IncreaseDecreaseType) {
                    handleIncreaseDecreaseInfraredCommand((IncreaseDecreaseType) command);
                } else {
                    supportedCommand = false;
                }
                break;
            default:
                try {
                    if (channelUID.getId().startsWith(CHANNEL_COLOR_ZONE)) {
                        int zoneIndex = Integer.parseInt(channelUID.getId().replace(CHANNEL_COLOR_ZONE, ""));
                        if (command instanceof HSBType) {
                            handleHSBCommand((HSBType) command, zoneIndex);
                        } else if (command instanceof PercentType) {
                            handlePercentCommand((PercentType) command, zoneIndex);
                        } else if (command instanceof IncreaseDecreaseType) {
                            handleIncreaseDecreaseCommand((IncreaseDecreaseType) command, zoneIndex);
                        } else {
                            supportedCommand = false;
                        }
                    } else if (channelUID.getId().startsWith(CHANNEL_TEMPERATURE_ZONE)) {
                        int zoneIndex = Integer.parseInt(channelUID.getId().replace(CHANNEL_TEMPERATURE_ZONE, ""));
                        if (command instanceof PercentType) {
                            handleTemperatureCommand((PercentType) command, zoneIndex);
                        } else if (command instanceof IncreaseDecreaseType) {
                            handleIncreaseDecreaseTemperatureCommand((IncreaseDecreaseType) command, zoneIndex);
                        } else {
                            supportedCommand = false;
                        }
                    } else {
                        supportedCommand = false;
                    }
                } catch (NumberFormatException e) {
                    logger.error("Failed to parse zone index for a command of a light ({}) : {}", logId, e.getMessage());
                    supportedCommand = false;
                }
                break;
        }
        if (supportedCommand && !(command instanceof OnOffType) && !CHANNEL_INFRARED.equals(channelUID.getId())) {
            getLightStateForCommand().setPowerState(PowerState.ON);
        }
    }
}
Also used : OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) GetWifiInfoRequest(org.eclipse.smarthome.binding.lifx.internal.protocol.GetWifiInfoRequest) GetRequest(org.eclipse.smarthome.binding.lifx.internal.protocol.GetRequest) GetLightInfraredRequest(org.eclipse.smarthome.binding.lifx.internal.protocol.GetLightInfraredRequest) IncreaseDecreaseType(org.eclipse.smarthome.core.library.types.IncreaseDecreaseType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) LifxMessageUtil.increaseDecreasePercentType(org.eclipse.smarthome.binding.lifx.internal.util.LifxMessageUtil.increaseDecreasePercentType) RefreshType(org.eclipse.smarthome.core.types.RefreshType) GetLightPowerRequest(org.eclipse.smarthome.binding.lifx.internal.protocol.GetLightPowerRequest) HSBType(org.eclipse.smarthome.core.library.types.HSBType)

Example 15 with HSBType

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

the class LifxLightHandler method getPowerOnColor.

private HSBType getPowerOnColor() {
    Channel channel = null;
    if (product.isColor()) {
        ChannelUID channelUID = new ChannelUID(getThing().getUID(), LifxBindingConstants.CHANNEL_COLOR);
        channel = getThing().getChannel(channelUID.getId());
    }
    if (channel == null) {
        return null;
    }
    Configuration configuration = channel.getConfiguration();
    Object powerOnColor = configuration.get(LifxBindingConstants.CONFIG_PROPERTY_POWER_ON_COLOR);
    return powerOnColor == null ? null : new HSBType(powerOnColor.toString());
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Channel(org.eclipse.smarthome.core.thing.Channel) 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