From d06cc6a60a9b33c0f3aee65989d292ef1e8e6f6c Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Wed, 9 Mar 2022 00:53:01 -0700 Subject: [PATCH] [homekit] do unit conversion for min/max heating/cooling temps (#12450) this is especially important if you use the same item for both TargetTemperature and HeatingThresholdTemperature characteristics, since the former was already doing unit conversion for min/max. Signed-off-by: Cody Cutrer --- .../HomekitCharacteristicFactory.java | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitCharacteristicFactory.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitCharacteristicFactory.java index 1860bc53b12..fe93c964d07 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitCharacteristicFactory.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitCharacteristicFactory.java @@ -694,33 +694,29 @@ public class HomekitCharacteristicFactory { private static CoolingThresholdTemperatureCharacteristic createCoolingThresholdCharacteristic( HomekitTaggedItem taggedItem, HomekitAccessoryUpdater updater) { - return new CoolingThresholdTemperatureCharacteristic( - taggedItem.getConfigurationAsDouble(HomekitTaggedItem.MIN_VALUE, - CoolingThresholdTemperatureCharacteristic.DEFAULT_MIN_VALUE), - taggedItem.getConfigurationAsDouble(HomekitTaggedItem.MAX_VALUE, - CoolingThresholdTemperatureCharacteristic.DEFAULT_MAX_VALUE), + double minValue = HomekitCharacteristicFactory.convertToCelsius(taggedItem.getConfigurationAsDouble( + HomekitTaggedItem.MIN_VALUE, CoolingThresholdTemperatureCharacteristic.DEFAULT_MIN_VALUE)); + double maxValue = HomekitCharacteristicFactory.convertToCelsius(taggedItem.getConfigurationAsDouble( + HomekitTaggedItem.MAX_VALUE, CoolingThresholdTemperatureCharacteristic.DEFAULT_MAX_VALUE)); + return new CoolingThresholdTemperatureCharacteristic(minValue, maxValue, taggedItem.getConfigurationAsDouble(HomekitTaggedItem.STEP, CoolingThresholdTemperatureCharacteristic.DEFAULT_STEP), - getTemperatureSupplier(taggedItem, - taggedItem.getConfigurationAsDouble(HomekitTaggedItem.MIN_VALUE, - CoolingThresholdTemperatureCharacteristic.DEFAULT_MIN_VALUE)), - setTemperatureConsumer(taggedItem), getSubscriber(taggedItem, COOLING_THRESHOLD_TEMPERATURE, updater), + getTemperatureSupplier(taggedItem, minValue), setTemperatureConsumer(taggedItem), + getSubscriber(taggedItem, COOLING_THRESHOLD_TEMPERATURE, updater), getUnsubscriber(taggedItem, COOLING_THRESHOLD_TEMPERATURE, updater)); } private static HeatingThresholdTemperatureCharacteristic createHeatingThresholdCharacteristic( HomekitTaggedItem taggedItem, HomekitAccessoryUpdater updater) { - return new HeatingThresholdTemperatureCharacteristic( - taggedItem.getConfigurationAsDouble(HomekitTaggedItem.MIN_VALUE, - HeatingThresholdTemperatureCharacteristic.DEFAULT_MIN_VALUE), - taggedItem.getConfigurationAsDouble(HomekitTaggedItem.MAX_VALUE, - HeatingThresholdTemperatureCharacteristic.DEFAULT_MAX_VALUE), + double minValue = HomekitCharacteristicFactory.convertToCelsius(taggedItem.getConfigurationAsDouble( + HomekitTaggedItem.MIN_VALUE, HeatingThresholdTemperatureCharacteristic.DEFAULT_MIN_VALUE)); + double maxValue = HomekitCharacteristicFactory.convertToCelsius(taggedItem.getConfigurationAsDouble( + HomekitTaggedItem.MAX_VALUE, HeatingThresholdTemperatureCharacteristic.DEFAULT_MAX_VALUE)); + return new HeatingThresholdTemperatureCharacteristic(minValue, maxValue, taggedItem.getConfigurationAsDouble(HomekitTaggedItem.STEP, HeatingThresholdTemperatureCharacteristic.DEFAULT_STEP), - getTemperatureSupplier(taggedItem, - taggedItem.getConfigurationAsDouble(HomekitTaggedItem.MIN_VALUE, - HeatingThresholdTemperatureCharacteristic.DEFAULT_MIN_VALUE)), - setTemperatureConsumer(taggedItem), getSubscriber(taggedItem, HEATING_THRESHOLD_TEMPERATURE, updater), + getTemperatureSupplier(taggedItem, minValue), setTemperatureConsumer(taggedItem), + getSubscriber(taggedItem, HEATING_THRESHOLD_TEMPERATURE, updater), getUnsubscriber(taggedItem, HEATING_THRESHOLD_TEMPERATURE, updater)); }