]> git.basschouten.com Git - openhab-addons.git/commitdiff
[homekit] Adjust default ranges for some characteristics (#17157)
authorCody Cutrer <cody@cutrer.us>
Mon, 9 Sep 2024 21:53:27 +0000 (15:53 -0600)
committerGitHub <noreply@github.com>
Mon, 9 Sep 2024 21:53:27 +0000 (23:53 +0200)
* [homekit] adjust default ranges for some characteristics

Signed-off-by: Cody Cutrer <cody@cutrer.us>
bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitCharacteristicFactory.java
bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitLightSensorImpl.java

index 9828ec7c267f9b742b3b1a12b8d4803c984d17e1..a0a12bd13d736549a73a14d0115dd94b2a81e8bb 100644 (file)
@@ -188,6 +188,26 @@ import io.github.hapjava.characteristics.impl.windowcovering.TargetVerticalTiltA
  */
 @NonNullByDefault
 public class HomekitCharacteristicFactory {
+    // These values represent ranges that do not match the defaults that are part of
+    // the HAP specification/the defaults in HAP-Java, but nonetheless are commonly
+    // encountered in consumer-grade devices. So we define our own default min/max so
+    // that users don't have to override the default unnecessarily.
+
+    // HAP default is 50-400 mired/2500-20,000 K. These numbers represent
+    // the warmest and coolest bulbs I could reasonably find at general
+    // purpose retailers.
+    public static final int COLOR_TEMPERATURE_MIN_MIREDS = 107; // 9300 K
+    public static final int COLOR_TEMPERATURE_MAX_MIREDS = 556; // 1800 K
+    // HAP default is 0 °C, but it's very common for outdoor temperatures and/or
+    // refrigation devices to go below freezing.
+    // Lowest recorded temperature on Earth is -89.2 °C. This is just a nice round number.
+    public static final int CURRENT_TEMPERATURE_MIN_CELSIUS = -100;
+    // HAP default is 0.0001 lx, but this is commonly rounded to 0 by many devices
+    public static final int CURRENT_AMBIENT_LIGHT_LEVEL_MIN_LUX = 0;
+    // HAP default is 100k
+    // https://en.wikipedia.org/wiki/Daylight#Intensity_in_different_conditions
+    public static final int CURRENT_AMBIENT_LIGHT_LEVEL_MAX_LUX = 120000;
+
     private static final Logger LOGGER = LoggerFactory.getLogger(HomekitCharacteristicFactory.class);
 
     // List of optional characteristics and corresponding method to create them.
@@ -796,14 +816,10 @@ public class HomekitCharacteristicFactory {
             HomekitAccessoryUpdater updater) {
         final boolean inverted = taggedItem.isInverted();
 
-        int minValue = taggedItem
-                .getConfigurationAsQuantity(HomekitTaggedItem.MIN_VALUE,
-                        new QuantityType(ColorTemperatureCharacteristic.DEFAULT_MIN_VALUE, Units.MIRED), false)
-                .intValue();
-        int maxValue = taggedItem
-                .getConfigurationAsQuantity(HomekitTaggedItem.MAX_VALUE,
-                        new QuantityType(ColorTemperatureCharacteristic.DEFAULT_MAX_VALUE, Units.MIRED), false)
-                .intValue();
+        int minValue = taggedItem.getConfigurationAsQuantity(HomekitTaggedItem.MIN_VALUE,
+                new QuantityType(COLOR_TEMPERATURE_MIN_MIREDS, Units.MIRED), false).intValue();
+        int maxValue = taggedItem.getConfigurationAsQuantity(HomekitTaggedItem.MAX_VALUE,
+                new QuantityType(COLOR_TEMPERATURE_MAX_MIREDS, Units.MIRED), false).intValue();
 
         // It's common to swap these if you're providing in Kelvin instead of mired
         if (minValue > maxValue) {
@@ -947,13 +963,9 @@ public class HomekitCharacteristicFactory {
 
     private static CurrentTemperatureCharacteristic createCurrentTemperatureCharacteristic(HomekitTaggedItem taggedItem,
             HomekitAccessoryUpdater updater) {
-        double minValue = taggedItem
-                .getConfigurationAsQuantity(HomekitTaggedItem.MIN_VALUE,
-                        Objects.requireNonNull(
-                                new QuantityType(CurrentTemperatureCharacteristic.DEFAULT_MIN_VALUE, SIUnits.CELSIUS)
-                                        .toUnit(getSystemTemperatureUnit())),
-                        false)
-                .toUnit(SIUnits.CELSIUS).doubleValue();
+        double minValue = taggedItem.getConfigurationAsQuantity(HomekitTaggedItem.MIN_VALUE, Objects.requireNonNull(
+                new QuantityType(CURRENT_TEMPERATURE_MIN_CELSIUS, SIUnits.CELSIUS).toUnit(getSystemTemperatureUnit())),
+                false).toUnit(SIUnits.CELSIUS).doubleValue();
         double maxValue = taggedItem
                 .getConfigurationAsQuantity(HomekitTaggedItem.MAX_VALUE,
                         Objects.requireNonNull(
index cea33839e3151b934da425a4d29a5ddc8bb7d8e3..7247d38c7cfe8e22c197b2d9308f9f4ccd04c5fc 100644 (file)
@@ -29,7 +29,6 @@ import org.openhab.io.homekit.internal.HomekitTaggedItem;
 import io.github.hapjava.accessories.LightSensorAccessory;
 import io.github.hapjava.characteristics.Characteristic;
 import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
-import io.github.hapjava.characteristics.impl.lightsensor.CurrentAmbientLightLevelCharacteristic;
 import io.github.hapjava.services.impl.LightSensorService;
 
 /**
@@ -61,13 +60,13 @@ public class HomekitLightSensorImpl extends AbstractHomekitAccessoryImpl impleme
     @Override
     public double getMinCurrentAmbientLightLevel() {
         return getAccessoryConfiguration(HomekitCharacteristicType.LIGHT_LEVEL, HomekitTaggedItem.MIN_VALUE,
-                BigDecimal.valueOf(CurrentAmbientLightLevelCharacteristic.DEFAULT_MIN_VALUE)).doubleValue();
+                BigDecimal.valueOf(HomekitCharacteristicFactory.CURRENT_AMBIENT_LIGHT_LEVEL_MIN_LUX)).doubleValue();
     }
 
     @Override
     public double getMaxCurrentAmbientLightLevel() {
         return getAccessoryConfiguration(HomekitCharacteristicType.LIGHT_LEVEL, HomekitTaggedItem.MAX_VALUE,
-                BigDecimal.valueOf(CurrentAmbientLightLevelCharacteristic.DEFAULT_MAX_VALUE)).doubleValue();
+                BigDecimal.valueOf(HomekitCharacteristicFactory.CURRENT_AMBIENT_LIGHT_LEVEL_MAX_LUX)).doubleValue();
     }
 
     @Override