Add numericState and unit to StateDTO (#4123)

* Add numericState to StateDTO

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
pull/4125/head
jimtng 2024-03-02 03:43:02 +10:00 committed by GitHub
parent 06ee46dff6
commit 97d64a156b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 0 deletions

View File

@ -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) {

View File

@ -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;