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