Temperature Values in ThingHandler.updateState

This may be a noob question, but I am migrating an old binding to v2. The old code reads Temperature values in the form of Bigdecimals. I would like to call my ThingHandler.updateState(ChannelID, Temperature) but it seems that method won’t accept BigDecimal arguments. I think I need to cast the values to another number type, but how?

The method expects a subclass of type State. Depending on what you channel definition is in the xml of the thing definition it’s very likely either:
new DecimalType(temperature) (If channel is <item-type>Number</item-type>) or
new QuantityType(temperature, SIUnits.CELSIUS) (assuming it’s Celsius) if <item-type>Number:Temperature</item-type>

1 Like

Many thanks Hillbrand. I implemented the update code as follows…

import javax.measure.quantity.Temperature;

import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.library.types.QuantityType;
import org.eclipse.smarthome.core.library.unit.SIUnits;

protected void setChannelValues(NeoHubInfoResponse.DeviceInfo device) {
        updateState(CHANNEL_SET_TEMP,     new QuantityType<Temperature>(device.getCurrentSetTemperature(), SIUnits.CELSIUS));
        updateState(CHANNEL_ROOM_TEMP,    new QuantityType<Temperature>(device.getCurrentTemperature(), SIUnits.CELSIUS));
        updateState(CHANNEL_FLOOR_TEMP,   new QuantityType<Temperature>(device.getCurrentFloorTemperature(), SIUnits.CELSIUS));
        updateState(CHANNEL_AWAY_MODE,    OnOffType.from(device.isAway()));
        updateState(CHANNEL_STANDBY_MODE, OnOffType.from(device.isStandby()));
        updateState(CHANNEL_HEATING_MODE, OnOffType.from(device.isHeating() || device.isPreHeat()));