Adjust command handling (#16159)

Signed-off-by: Christian Kittel <ckittel@gmx.de>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
Christian Kittel 2024-01-15 18:47:17 +01:00 committed by Ciprian Pascu
parent e9a149cb15
commit d5eb92aaf0

View File

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