[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 java.time.OffsetDateTime;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
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.HvacMode;
|
||||||
import org.openhab.binding.tado.internal.TadoBindingConstants.OperationMode;
|
import org.openhab.binding.tado.internal.TadoBindingConstants.OperationMode;
|
||||||
import org.openhab.binding.tado.internal.TadoBindingConstants.TemperatureUnit;
|
import org.openhab.binding.tado.internal.TadoBindingConstants.TemperatureUnit;
|
||||||
|
@ -232,13 +233,20 @@ public class TadoZoneStateAdapter {
|
||||||
return new DateTimeType(offsetDateTime.toZonedDateTime());
|
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
|
return temperatureUnit == TemperatureUnit.FAHRENHEIT
|
||||||
? new QuantityType<>(temperature.getFahrenheit(), ImperialUnits.FAHRENHEIT)
|
? new QuantityType<>(temperature.getFahrenheit(), ImperialUnits.FAHRENHEIT)
|
||||||
: new QuantityType<>(temperature.getCelsius(), SIUnits.CELSIUS);
|
: 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
|
return temperatureUnit == TemperatureUnit.FAHRENHEIT
|
||||||
? new QuantityType<>(temperature.getFahrenheit(), ImperialUnits.FAHRENHEIT)
|
? new QuantityType<>(temperature.getFahrenheit(), ImperialUnits.FAHRENHEIT)
|
||||||
: new QuantityType<>(temperature.getCelsius(), SIUnits.CELSIUS);
|
: new QuantityType<>(temperature.getCelsius(), SIUnits.CELSIUS);
|
||||||
|
|
|
@ -76,11 +76,6 @@ public class AirConditioningZoneSettingsBuilder extends ZoneSettingsBuilder {
|
||||||
targetMode = getCurrentOrDefaultAcMode(zoneStateProvider);
|
targetMode = getCurrentOrDefaultAcMode(zoneStateProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
Float temperature = this.temperature;
|
|
||||||
if (temperature != null) {
|
|
||||||
newSetting.setTemperature(temperature(temperature, temperatureUnit));
|
|
||||||
}
|
|
||||||
|
|
||||||
Boolean swing = this.swing;
|
Boolean swing = this.swing;
|
||||||
if (swing != null) {
|
if (swing != null) {
|
||||||
newSetting.setSwing(swing.booleanValue() ? Power.ON : Power.OFF);
|
newSetting.setSwing(swing.booleanValue() ? Power.ON : Power.OFF);
|
||||||
|
@ -105,6 +100,24 @@ public class AirConditioningZoneSettingsBuilder extends ZoneSettingsBuilder {
|
||||||
AcModeCapabilities targetModeCapabilities = TadoApiTypeUtils.getModeCapabilities(targetMode,
|
AcModeCapabilities targetModeCapabilities = TadoApiTypeUtils.getModeCapabilities(targetMode,
|
||||||
genericCapabilities);
|
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;
|
FanLevel fanLevel = this.fanLevel;
|
||||||
if (fanLevel != null) {
|
if (fanLevel != null) {
|
||||||
ACFanLevel targetFanLevel = getFanLevel(fanLevel);
|
ACFanLevel targetFanLevel = getFanLevel(fanLevel);
|
||||||
|
|
Loading…
Reference in New Issue