NumberItem extends GenericItem { @Override public void setState(State state) { if (state instanceof DecimalType && dimension != null) { Unit<?> unit = getUnit(); if (unit != null) { super.setState(new QuantityType<>(((DecimalType) state).doubleValue(), unit)); return; } } if (state instanceof QuantityType) { Unit<?> itemUnit = getUnit(); Unit<?> stateUnit = ((QuantityType<?>) state).getUnit(); if (itemUnit != null && (!stateUnit.getSystemUnit().equals(itemUnit.getSystemUnit()) || UnitUtils.isDifferentMeasurementSystem(itemUnit, stateUnit))) { QuantityType<?> convertedState = ((QuantityType<?>) state).toUnit(itemUnit); if (convertedState != null) { super.setState(convertedState); return; } return; } } if (isAcceptedState(acceptedDataTypes, state)) { super.setState(state); } else { logSetTypeError(state); } } NumberItem(String name);  NumberItem(String type, String name); @Override List<Class<? extends State>> getAcceptedDataTypes(); @Override List<Class<? extends Command>> getAcceptedCommandTypes(); void send(DecimalType command); @Override @Nullable StateDescription getStateDescription(@Nullable Locale locale); @Nullable Class<? extends Quantity<?>> getDimension(); @Override void setState(State state); @Nullable String getUnitSymbol(); @Nullable Unit<? extends Quantity<?>> getUnit(); @Nullable QuantityType<?> toQuantityType(DecimalType originalType,
            @Nullable Class<? extends Quantity<?>> dimension);  }
@Test public void setDecimalType() { NumberItem item = new NumberItem(ITEM_NAME); State decimal = new DecimalType("23"); item.setState(decimal); assertEquals(decimal, item.getState()); }
@Test public void setPercentType() { NumberItem item = new NumberItem(ITEM_NAME); State percent = new PercentType(50); item.setState(percent); assertEquals(percent, item.getState()); }
@Test public void setHSBType() { NumberItem item = new NumberItem(ITEM_NAME); State hsb = new HSBType("5,23,42"); item.setState(hsb); assertEquals(hsb, item.getState()); }
@Test public void testSetQuantityTypeAccepted() { NumberItem item = new NumberItem("Number:Temperature", ITEM_NAME); item.setState(new QuantityType<>("20 °C")); assertThat(item.getState(), is(new QuantityType<>("20 °C"))); }
@Test public void testSetQuantityTypeConverted() { NumberItem item = new NumberItem("Number:Temperature", ITEM_NAME); item.setState(new QuantityType<>(68, ImperialUnits.FAHRENHEIT)); assertThat(item.getState(), is(new QuantityType<>("20 °C"))); }