Search in sources :

Example 16 with DecimalType

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

the class NumberItemTest method setDecimalType.

@Test
public void setDecimalType() {
    NumberItem item = new NumberItem("test");
    State decimal = new DecimalType("23");
    item.setState(decimal);
    assertEquals(decimal, item.getState());
}
Also used : State(org.eclipse.smarthome.core.types.State) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) Test(org.junit.Test)

Example 17 with DecimalType

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

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

the class SwitchItemTest method getAsDecimalFromSwitch.

@Test
public void getAsDecimalFromSwitch() {
    SwitchItem item = new SwitchItem("Test");
    item.setState(OnOffType.ON);
    assertEquals(new DecimalType(1), item.getStateAs(DecimalType.class));
    item.setState(OnOffType.OFF);
    assertEquals(new DecimalType(0), item.getStateAs(DecimalType.class));
}
Also used : DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) Test(org.junit.Test)

Example 19 with DecimalType

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

the class CircuitHandler method channelLinked.

@Override
public void channelLinked(ChannelUID channelUID) {
    if (circuit != null) {
        MeteringTypeEnum meteringType = DsChannelTypeProvider.getMeteringType(channelUID.getId());
        double val = circuit.getMeteringValue(meteringType, MeteringUnitsEnum.WH);
        if (val > -1) {
            if (meteringType.equals(MeteringTypeEnum.ENERGY)) {
                updateState(channelUID, new DecimalType(val * 0.001));
            } else {
                updateState(channelUID, new DecimalType(val));
            }
        }
    }
}
Also used : MeteringTypeEnum(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.MeteringTypeEnum) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType)

Example 20 with DecimalType

use of org.eclipse.smarthome.core.library.types.DecimalType 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)

Aggregations

DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)68 Test (org.junit.Test)33 State (org.eclipse.smarthome.core.types.State)17 PercentType (org.eclipse.smarthome.core.library.types.PercentType)16 HistoricItem (org.eclipse.smarthome.core.persistence.HistoricItem)11 StringType (org.eclipse.smarthome.core.library.types.StringType)9 HSBType (org.eclipse.smarthome.core.library.types.HSBType)8 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)7 Type (org.eclipse.smarthome.core.types.Type)7 Item (org.eclipse.smarthome.core.items.Item)6 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 BigDecimal (java.math.BigDecimal)5 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)4 QuantityType (org.eclipse.smarthome.core.library.types.QuantityType)4 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)4 Response (javax.ws.rs.core.Response)3 ValueSet (org.eclipse.smarthome.binding.dmx.internal.ValueSet)3 FadeAction (org.eclipse.smarthome.binding.dmx.internal.action.FadeAction)3 DateTimeType (org.eclipse.smarthome.core.library.types.DateTimeType)3