From 4083b5f28d4c9f2289c3a56c47cf7208fde10667 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Wed, 26 Oct 2022 10:30:30 -0600 Subject: [PATCH] Use toUnitRelative for SystemOffsetProfile Now that we have it, instead of resorting to special casing Signed-off-by: Cody Cutrer --- .../profiles/SystemOffsetProfile.java | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/SystemOffsetProfile.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/SystemOffsetProfile.java index 10212285548..93868a962fc 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/SystemOffsetProfile.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/profiles/SystemOffsetProfile.java @@ -21,8 +21,6 @@ import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.QuantityType; -import org.openhab.core.library.unit.ImperialUnits; -import org.openhab.core.library.unit.SIUnits; import org.openhab.core.library.unit.Units; import org.openhab.core.thing.profiles.ProfileCallback; import org.openhab.core.thing.profiles.ProfileContext; @@ -44,10 +42,6 @@ @NonNullByDefault public class SystemOffsetProfile implements StateProfile { - private static final @Nullable QuantityType ZERO_CELSIUS_IN_KELVIN = new QuantityType<>(0, - SIUnits.CELSIUS).toUnit(Units.KELVIN); - private static final @Nullable QuantityType ZERO_FAHRENHEIT_IN_KELVIN = new QuantityType<>(0, - ImperialUnits.FAHRENHEIT).toUnit(Units.KELVIN); static final String OFFSET_PARAM = "offset"; private final Logger logger = LoggerFactory.getLogger(SystemOffsetProfile.class); @@ -152,20 +146,11 @@ private Type applyOffset(Type state, boolean towardsItem) { QuantityType offset) { // do the math in Kelvin and afterwards convert it back to the unit of the state final QuantityType kelvinState = qtState.toUnit(Units.KELVIN); - final QuantityType kelvinOffset = offset.toUnit(Units.KELVIN); + final QuantityType kelvinOffset = offset.toUnitRelative(Units.KELVIN); if (kelvinState == null || kelvinOffset == null) { return null; } - final QuantityType finalOffset; - if (SIUnits.CELSIUS.equals(offset.getUnit())) { - finalOffset = kelvinOffset.add(ZERO_CELSIUS_IN_KELVIN.negate()); - } else if (ImperialUnits.FAHRENHEIT.equals(offset.getUnit())) { - finalOffset = kelvinOffset.add(ZERO_FAHRENHEIT_IN_KELVIN.negate()); - } else { - // offset is already in Kelvin - finalOffset = offset; - } - return kelvinState.add(finalOffset).toUnit(qtState.getUnit()); + return kelvinState.add(kelvinOffset).toUnit(qtState.getUnit()); } }