From d5eb92aaf07e2081a1ab190fe78c497a5b3c1c8f Mon Sep 17 00:00:00 2001 From: Christian Kittel Date: Mon, 15 Jan 2024 18:47:17 +0100 Subject: [PATCH] Adjust command handling (#16159) Signed-off-by: Christian Kittel Signed-off-by: Ciprian Pascu --- .../internal/ThermostatHandler.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.ojelectronics/src/main/java/org/openhab/binding/ojelectronics/internal/ThermostatHandler.java b/bundles/org.openhab.binding.ojelectronics/src/main/java/org/openhab/binding/ojelectronics/internal/ThermostatHandler.java index 2ca01de22d4..10098113e44 100644 --- a/bundles/org.openhab.binding.ojelectronics/src/main/java/org/openhab/binding/ojelectronics/internal/ThermostatHandler.java +++ b/bundles/org.openhab.binding.ojelectronics/src/main/java/org/openhab/binding/ojelectronics/internal/ThermostatHandler.java @@ -23,6 +23,8 @@ import java.util.Map; import java.util.Objects; import java.util.function.Consumer; +import javax.measure.quantity.Temperature; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.ojelectronics.internal.config.OJElectronicsThermostatConfiguration; @@ -195,8 +197,9 @@ public class ThermostatHandler extends BaseThingHandler { } private void updateManualSetpoint(Command command) { - if (command instanceof QuantityType quantityCommand) { - getCurrentThermostat().manualModeSetpoint = (int) (quantityCommand.floatValue() * 100); + QuantityType harmonizedUnit = getHarmonizedQuantityType(command); + if (harmonizedUnit != null) { + getCurrentThermostat().manualModeSetpoint = (int) (harmonizedUnit.floatValue() * 100); } else { logger.warn("Unable to set value {}", command); } @@ -235,8 +238,9 @@ public class ThermostatHandler extends BaseThingHandler { } private void updateComfortSetpoint(Command command) { - if (command instanceof QuantityType quantityCommand) { - getCurrentThermostat().comfortSetpoint = (int) (quantityCommand.floatValue() * 100); + QuantityType harmonizedUnit = getHarmonizedQuantityType(command); + if (harmonizedUnit != null) { + getCurrentThermostat().comfortSetpoint = (int) (harmonizedUnit.floatValue() * 100); } else { logger.warn("Unable to set value {}", command); } @@ -351,6 +355,17 @@ public class ThermostatHandler extends BaseThingHandler { return REGULATION_MODES.get(regulationMode); } + private @Nullable QuantityType getHarmonizedQuantityType(Command command) { + QuantityType harmonizedUnit = null; + + if (command instanceof QuantityType quantityCommand) { + harmonizedUnit = quantityCommand.toUnit(SIUnits.CELSIUS); + } else if (command instanceof Number quantityCommand) { + harmonizedUnit = new QuantityType(quantityCommand.floatValue(), SIUnits.CELSIUS); + } + return harmonizedUnit; + } + private static Map createRegulationMap() { HashMap map = new HashMap<>(); map.put(1, "auto");