Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ojelectronics] Adjust setpoint command handling #16159

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
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;
Expand Down Expand Up @@ -195,8 +197,9 @@ private void updateManualSetpoint(ThermostatModel thermostat) {
}

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);
}
Expand Down Expand Up @@ -235,8 +238,9 @@ private void updateComfortSetpoint(ThermostatModel thermostat) {
}

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);
}
Expand Down Expand Up @@ -351,6 +355,17 @@ private void updateVacationEndDay(Command 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");
Expand Down