Search in sources :

Example 11 with PercentType

use of org.eclipse.smarthome.core.library.types.PercentType 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 12 with PercentType

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

the class DeviceHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    BridgeHandler dssBridgeHandler = getDssBridgeHandler();
    if (dssBridgeHandler == null) {
        logger.debug("BridgeHandler not found. Cannot handle command without bridge.");
        return;
    }
    if (device == null) {
        logger.debug("Device not known on StructureManager or DeviceStatusListener is not registerd. Cannot handle command.");
        return;
    }
    if (command instanceof RefreshType) {
        try {
            SensorEnum sensorType = SensorEnum.valueOf(channelUID.getId());
            dssBridgeHandler.sendComandsToDSS(device, new DeviceStateUpdateImpl(sensorType, 1));
        } catch (IllegalArgumentException e) {
            dssBridgeHandler.sendComandsToDSS(device, new DeviceStateUpdateImpl(DeviceStateUpdate.REFRESH_OUTPUT, 0));
        }
    } else if (!device.isShade()) {
        if (DsChannelTypeProvider.isOutputChannel(channelUID.getId())) {
            if (command instanceof PercentType) {
                device.setOutputValue((short) fromPercentToValue(((PercentType) command).intValue(), device.getMaxOutputValue()));
            } else if (command instanceof OnOffType) {
                if (OnOffType.ON.equals(command)) {
                    device.setIsOn(true);
                } else {
                    device.setIsOn(false);
                }
            } else if (command instanceof IncreaseDecreaseType) {
                if (IncreaseDecreaseType.INCREASE.equals(command)) {
                    device.increase();
                } else {
                    device.decrease();
                }
            } else if (command instanceof StringType) {
                device.setOutputValue(Short.parseShort(((StringType) command).toString()));
            }
        } else {
            logger.debug("Command sent to an unknown channel id: {}", channelUID);
        }
    } else {
        if (channelUID.getId().contains(DsChannelTypeProvider.ANGLE)) {
            if (command instanceof PercentType) {
                device.setAnglePosition((short) fromPercentToValue(((PercentType) command).intValue(), device.getMaxSlatAngle()));
            } else if (command instanceof OnOffType) {
                if (OnOffType.ON.equals(command)) {
                    device.setAnglePosition(device.getMaxSlatAngle());
                } else {
                    device.setAnglePosition(device.getMinSlatAngle());
                }
            } else if (command instanceof IncreaseDecreaseType) {
                if (IncreaseDecreaseType.INCREASE.equals(command)) {
                    device.increaseSlatAngle();
                } else {
                    device.decreaseSlatAngle();
                }
            }
        } else if (channelUID.getId().contains(DsChannelTypeProvider.SHADE)) {
            if (command instanceof PercentType) {
                int percent = ((PercentType) command).intValue();
                if (!device.getHWinfo().equals("GR-KL200")) {
                    percent = 100 - percent;
                }
                device.setSlatPosition(fromPercentToValue(percent, device.getMaxSlatPosition()));
                this.lastComand = command;
            } else if (command instanceof StopMoveType) {
                if (StopMoveType.MOVE.equals(command)) {
                    handleCommand(channelUID, this.lastComand);
                } else {
                    dssBridgeHandler.stopOutputValue(device);
                }
            } else if (command instanceof UpDownType) {
                if (UpDownType.UP.equals(command)) {
                    device.setIsOpen(true);
                    this.lastComand = command;
                } else {
                    device.setIsOpen(false);
                    this.lastComand = command;
                }
            }
        } else {
            logger.debug("Command sent to an unknown channel id: {}", channelUID);
        }
    }
}
Also used : SensorEnum(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum) OnOffType(org.eclipse.smarthome.core.library.types.OnOffType) StringType(org.eclipse.smarthome.core.library.types.StringType) DeviceStateUpdateImpl(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl) IncreaseDecreaseType(org.eclipse.smarthome.core.library.types.IncreaseDecreaseType) UpDownType(org.eclipse.smarthome.core.library.types.UpDownType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) RefreshType(org.eclipse.smarthome.core.types.RefreshType) StopMoveType(org.eclipse.smarthome.core.library.types.StopMoveType)

Example 13 with PercentType

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

the class DeviceHandler method onDeviceStateChanged.

@Override
public synchronized void onDeviceStateChanged(DeviceStateUpdate deviceStateUpdate) {
    if (device != null) {
        if (deviceStateUpdate != null) {
            if (sensorChannelsLoaded()) {
                if (deviceStateUpdate.isSensorUpdateType()) {
                    updateState(getSensorChannelID(deviceStateUpdate.getTypeAsSensorEnum()), new DecimalType(deviceStateUpdate.getValueAsFloat()));
                    logger.debug("Update ESH-State");
                    return;
                }
                if (deviceStateUpdate.isBinarayInputType()) {
                    if (deviceStateUpdate.getValueAsShort() == 1) {
                        updateState(getBinaryInputChannelID(deviceStateUpdate.getTypeAsDeviceBinarayInputEnum()), OnOffType.ON);
                    } else {
                        updateState(getBinaryInputChannelID(deviceStateUpdate.getTypeAsDeviceBinarayInputEnum()), OnOffType.OFF);
                    }
                }
            }
            if (!device.isShade()) {
                if (currentChannel != null) {
                    switch(deviceStateUpdate.getType()) {
                        case DeviceStateUpdate.OUTPUT_DECREASE:
                        case DeviceStateUpdate.OUTPUT_INCREASE:
                        case DeviceStateUpdate.OUTPUT:
                            if (currentChannel.contains(DsChannelTypeProvider.DIMMER)) {
                                if (deviceStateUpdate.getValueAsInteger() > 0) {
                                    updateState(currentChannel, new PercentType(fromValueToPercent(deviceStateUpdate.getValueAsInteger(), device.getMaxOutputValue())));
                                } else {
                                    updateState(currentChannel, OnOffType.OFF);
                                }
                            } else if (currentChannel.contains(DsChannelTypeProvider.STAGE)) {
                                if (currentChannel.contains(TWO_STAGE_SWITCH_IDENTICATOR)) {
                                    updateState(currentChannel, new StringType(convertStageValue((short) 2, device.getOutputValue())));
                                } else {
                                    updateState(currentChannel, new StringType(convertStageValue((short) 3, device.getOutputValue())));
                                }
                            }
                            break;
                        case DeviceStateUpdate.ON_OFF:
                            if (currentChannel.contains(DsChannelTypeProvider.STAGE)) {
                                onDeviceStateChanged(new DeviceStateUpdateImpl(DeviceStateUpdate.OUTPUT, device.getOutputValue()));
                            }
                            if (deviceStateUpdate.getValueAsInteger() > 0) {
                                updateState(currentChannel, OnOffType.ON);
                            } else {
                                updateState(currentChannel, OnOffType.OFF);
                            }
                            break;
                        default:
                            return;
                    }
                }
            } else {
                int percent = 0;
                switch(deviceStateUpdate.getType()) {
                    case DeviceStateUpdate.SLAT_DECREASE:
                    case DeviceStateUpdate.SLAT_INCREASE:
                    case DeviceStateUpdate.SLATPOSITION:
                        percent = fromValueToPercent(deviceStateUpdate.getValueAsInteger(), device.getMaxSlatPosition());
                        break;
                    case DeviceStateUpdate.OPEN_CLOSE:
                        if (deviceStateUpdate.getValueAsInteger() > 0) {
                            percent = 100;
                        }
                        break;
                    case DeviceStateUpdate.OPEN_CLOSE_ANGLE:
                        if (device.isBlind() && currentChannel != null) {
                            if (deviceStateUpdate.getValueAsInteger() > 0) {
                                updateState(currentChannel, PercentType.HUNDRED);
                            } else {
                                updateState(currentChannel, PercentType.ZERO);
                            }
                        }
                        return;
                    case DeviceStateUpdate.SLAT_ANGLE_DECREASE:
                    case DeviceStateUpdate.SLAT_ANGLE_INCREASE:
                    case DeviceStateUpdate.SLAT_ANGLE:
                        if (device.isBlind() && currentChannel != null) {
                            updateState(currentChannel, new PercentType(fromValueToPercent(deviceStateUpdate.getValueAsInteger(), device.getMaxSlatAngle())));
                        }
                        return;
                    default:
                        return;
                }
                if (!device.getHWinfo().equals("GR-KL210")) {
                    percent = 100 - percent;
                }
                updateState(DsChannelTypeProvider.SHADE, new PercentType(percent));
            }
            logger.debug("Update ESH-State");
        }
    }
}
Also used : StringType(org.eclipse.smarthome.core.library.types.StringType) DeviceStateUpdateImpl(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) PercentType(org.eclipse.smarthome.core.library.types.PercentType)

Example 14 with PercentType

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

the class LifxLightCurrentStateUpdater method handleInfraredStatus.

private void handleInfraredStatus(StateLightInfraredResponse packet) {
    PercentType infrared = infraredToPercentType(packet.getInfrared());
    currentLightState.setInfrared(infrared);
}
Also used : LifxMessageUtil.infraredToPercentType(org.eclipse.smarthome.binding.lifx.internal.util.LifxMessageUtil.infraredToPercentType) PercentType(org.eclipse.smarthome.core.library.types.PercentType)

Example 15 with PercentType

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

the class LifxLightHandler method handleIncreaseDecreaseInfraredCommand.

private void handleIncreaseDecreaseInfraredCommand(IncreaseDecreaseType increaseDecrease) {
    PercentType baseInfrared = getLightStateForCommand().getInfrared();
    if (baseInfrared != null) {
        PercentType newInfrared = increaseDecreasePercentType(increaseDecrease, baseInfrared);
        handleInfraredCommand(newInfrared);
    }
}
Also used : PercentType(org.eclipse.smarthome.core.library.types.PercentType) LifxMessageUtil.increaseDecreasePercentType(org.eclipse.smarthome.binding.lifx.internal.util.LifxMessageUtil.increaseDecreasePercentType)

Aggregations

PercentType (org.eclipse.smarthome.core.library.types.PercentType)63 Test (org.junit.Test)25 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)17 State (org.eclipse.smarthome.core.types.State)17 HSBType (org.eclipse.smarthome.core.library.types.HSBType)16 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)13 LifxMessageUtil.increaseDecreasePercentType (org.eclipse.smarthome.binding.lifx.internal.util.LifxMessageUtil.increaseDecreasePercentType)9 StringType (org.eclipse.smarthome.core.library.types.StringType)9 IncreaseDecreaseType (org.eclipse.smarthome.core.library.types.IncreaseDecreaseType)7 RefreshType (org.eclipse.smarthome.core.types.RefreshType)7 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)6 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)4 RollershutterItem (org.eclipse.smarthome.core.library.items.RollershutterItem)4 QuantityType (org.eclipse.smarthome.core.library.types.QuantityType)4 BigDecimal (java.math.BigDecimal)3 ValueSet (org.eclipse.smarthome.binding.dmx.internal.ValueSet)3 FadeAction (org.eclipse.smarthome.binding.dmx.internal.action.FadeAction)3 DimmerItem (org.eclipse.smarthome.core.library.items.DimmerItem)3 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)3 LinkedList (java.util.LinkedList)2