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;
}
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);
}
}
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);
}
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<Temperature>(quantityCommand.floatValue(), SIUnits.CELSIUS);
+ }
+ return harmonizedUnit;
+ }
+
private static Map<Integer, String> createRegulationMap() {
HashMap<Integer, String> map = new HashMap<>();
map.put(1, "auto");