mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[tado] Fix AC target temperature reading and writing bugs (#13272)
* [tado] fix npe when target temperature json element is missing * [tado] apply temperature command/value restrictions Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
This commit is contained in:
parent
801895e2d2
commit
8baa500998
@ -17,6 +17,7 @@ import java.math.RoundingMode;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.tado.internal.TadoBindingConstants.HvacMode;
|
||||
import org.openhab.binding.tado.internal.TadoBindingConstants.OperationMode;
|
||||
import org.openhab.binding.tado.internal.TadoBindingConstants.TemperatureUnit;
|
||||
@ -232,13 +233,20 @@ public class TadoZoneStateAdapter {
|
||||
return new DateTimeType(offsetDateTime.toZonedDateTime());
|
||||
}
|
||||
|
||||
private static State toTemperatureState(TemperatureObject temperature, TemperatureUnit temperatureUnit) {
|
||||
private static State toTemperatureState(@Nullable TemperatureObject temperature, TemperatureUnit temperatureUnit) {
|
||||
if (temperature == null || (temperature.getCelsius() == null && temperature.getFahrenheit() == null)) {
|
||||
return UnDefType.UNDEF;
|
||||
}
|
||||
return temperatureUnit == TemperatureUnit.FAHRENHEIT
|
||||
? new QuantityType<>(temperature.getFahrenheit(), ImperialUnits.FAHRENHEIT)
|
||||
: new QuantityType<>(temperature.getCelsius(), SIUnits.CELSIUS);
|
||||
}
|
||||
|
||||
private static State toTemperatureState(TemperatureDataPoint temperature, TemperatureUnit temperatureUnit) {
|
||||
private static State toTemperatureState(@Nullable TemperatureDataPoint temperature,
|
||||
TemperatureUnit temperatureUnit) {
|
||||
if (temperature == null || (temperature.getCelsius() == null && temperature.getFahrenheit() == null)) {
|
||||
return UnDefType.UNDEF;
|
||||
}
|
||||
return temperatureUnit == TemperatureUnit.FAHRENHEIT
|
||||
? new QuantityType<>(temperature.getFahrenheit(), ImperialUnits.FAHRENHEIT)
|
||||
: new QuantityType<>(temperature.getCelsius(), SIUnits.CELSIUS);
|
||||
|
@ -76,11 +76,6 @@ public class AirConditioningZoneSettingsBuilder extends ZoneSettingsBuilder {
|
||||
targetMode = getCurrentOrDefaultAcMode(zoneStateProvider);
|
||||
}
|
||||
|
||||
Float temperature = this.temperature;
|
||||
if (temperature != null) {
|
||||
newSetting.setTemperature(temperature(temperature, temperatureUnit));
|
||||
}
|
||||
|
||||
Boolean swing = this.swing;
|
||||
if (swing != null) {
|
||||
newSetting.setSwing(swing.booleanValue() ? Power.ON : Power.OFF);
|
||||
@ -105,6 +100,24 @@ public class AirConditioningZoneSettingsBuilder extends ZoneSettingsBuilder {
|
||||
AcModeCapabilities targetModeCapabilities = TadoApiTypeUtils.getModeCapabilities(targetMode,
|
||||
genericCapabilities);
|
||||
|
||||
Float temperature = this.temperature;
|
||||
if (temperature != null) {
|
||||
IntRange range = null;
|
||||
boolean valid = false;
|
||||
TemperatureRange caps = targetModeCapabilities.getTemperatures();
|
||||
if (caps != null) {
|
||||
range = temperatureUnit == TemperatureUnit.CELSIUS ? caps.getCelsius() : caps.getFahrenheit();
|
||||
valid = (range != null) && (range.getMin() <= temperature) && (temperature <= range.getMax());
|
||||
}
|
||||
if (valid) {
|
||||
newSetting.setTemperature(temperature(temperature, temperatureUnit));
|
||||
} else {
|
||||
logger.warn(STATE_VALUE_NOT_SUPPORTED, "Target Temperature", temperature,
|
||||
targetMode.getClass().getSimpleName(), targetMode,
|
||||
range == null ? "none" : String.format("%d..%d", range.getMin(), range.getMax()));
|
||||
}
|
||||
}
|
||||
|
||||
FanLevel fanLevel = this.fanLevel;
|
||||
if (fanLevel != null) {
|
||||
ACFanLevel targetFanLevel = getFanLevel(fanLevel);
|
||||
|
Loading…
Reference in New Issue
Block a user