Add numericState and unit to StateDTO (#4123)
* Add numericState to StateDTO Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>pull/4125/head
parent
06ee46dff6
commit
97d64a156b
|
@ -31,6 +31,7 @@ import org.openhab.core.items.Item;
|
|||
import org.openhab.core.items.ItemNotFoundException;
|
||||
import org.openhab.core.items.ItemRegistry;
|
||||
import org.openhab.core.library.types.DateTimeType;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
import org.openhab.core.library.types.QuantityType;
|
||||
import org.openhab.core.service.StartLevelService;
|
||||
import org.openhab.core.transform.TransformationException;
|
||||
|
@ -87,6 +88,13 @@ public class SseItemStatesEventBuilder {
|
|||
if (stateDto.state != null && !stateDto.state.equals(displayState)) {
|
||||
stateDto.displayState = displayState;
|
||||
}
|
||||
if (item.getState() instanceof DecimalType decimalState) {
|
||||
stateDto.numericState = decimalState.floatValue();
|
||||
}
|
||||
if (item.getState() instanceof QuantityType quantityState) {
|
||||
stateDto.numericState = quantityState.floatValue();
|
||||
stateDto.unit = quantityState.getUnit().toString();
|
||||
}
|
||||
payload.put(itemName, stateDto);
|
||||
} catch (ItemNotFoundException e) {
|
||||
if (startLevelService.getStartLevel() >= StartLevelService.STARTLEVEL_MODEL) {
|
||||
|
|
|
@ -20,6 +20,8 @@ package org.openhab.core.io.rest.sse.internal.dto;
|
|||
public class StateDTO {
|
||||
public String state;
|
||||
public String displayState;
|
||||
public Number numericState;
|
||||
public String unit;
|
||||
|
||||
public String type;
|
||||
|
||||
|
|
Loading…
Reference in New Issue