diff --git a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/adapter/TadoZoneStateAdapter.java b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/adapter/TadoZoneStateAdapter.java index ed33bac2007..579d7ca4aa3 100644 --- a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/adapter/TadoZoneStateAdapter.java +++ b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/adapter/TadoZoneStateAdapter.java @@ -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); diff --git a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/builder/AirConditioningZoneSettingsBuilder.java b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/builder/AirConditioningZoneSettingsBuilder.java index e914c9f56d2..f8fe6a81872 100644 --- a/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/builder/AirConditioningZoneSettingsBuilder.java +++ b/bundles/org.openhab.binding.tado/src/main/java/org/openhab/binding/tado/internal/builder/AirConditioningZoneSettingsBuilder.java @@ -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);