From 0409484c2ec542cc1e9a9f0e98772baa06e7c2d0 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Sun, 9 Oct 2022 03:01:25 -0600 Subject: [PATCH] [homekit] allow RelativeHumidity as an optional characteristic on Thermostat (#13504) also support QuantityType as a valid state type for double characteristics (such as RelativeHumidity). Signed-off-by: Cody Cutrer --- bundles/org.openhab.io.homekit/README.md | 15 ++++++++------- .../accessories/HomekitCharacteristicFactory.java | 11 +++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/bundles/org.openhab.io.homekit/README.md b/bundles/org.openhab.io.homekit/README.md index 48b3b1c7a98..e0b11932c1a 100644 --- a/bundles/org.openhab.io.homekit/README.md +++ b/bundles/org.openhab.io.homekit/README.md @@ -656,7 +656,7 @@ Support for this is planned for the future release of openHAB HomeKit binding. | | | CurrentVerticalTiltAngle | Number, Dimmer | Number Item = current angle of vertical slats (-90 to +90) . Dimmer Item = the percentage of openness (0%-100%) | | | | TargetVerticalTiltAngle | Number, Dimmer | Number Item = target angle of vertical slats. Dimmer Item = the percentage of openness (0%-100%) | | Slat | | | | Slat which tilts on a vertical or a horizontal axis. Configuration "type:horizontal" or "type:vertical" | -| | CurrentSlatState | | String | Current slat state. possible values (FIXED,SWINGING,JAMMED). Custom mapping can be defined at item level, e.g. [JAMMED="JAM", FIXED="FIX"] | +| | CurrentSlatState | | String | Current slat state. possible values (FIXED,SWINGING,JAMMED). Custom mapping can be defined at item level, e.g. [JAMMED="JAM", FIXED="FIX"] | | | | Name | String | Name of the slat | | | | SwingMode | Number, Switch | Swing mode. values: 0/OFF=SWING DISABLED, 1/ON=SWING ENABLED | | | | CurrentTiltAngle | Number, Dimmer | Number Item = current angle of slats. values -90 to 90. A value of 0 indicates that the slats are rotated to a fully open position. Dimmer Item = the percentage of openness (0%-100%) | @@ -678,11 +678,11 @@ Support for this is planned for the future release of openHAB HomeKit binding. | Fan | | | | Fan | | | ActiveStatus | | Switch | Accessory current working status. A value of "ON"/"OPEN" indicates that the accessory is active and is functioning without any errors. | | | | CurrentFanState | Number | Current fan state. values: 0=INACTIVE, 1=IDLE, 2=BLOWING AIR | -| | | TargetFanState | Number, Switch | Target fan state. values: 0/OFF=MANUAL, 1/ON=AUTO. Flag [inverted=true] swaps the default mapping | -| | | RotationDirection | Number, Switch | Rotation direction. values: 0/OFF=CLOCKWISE, 1/ON=COUNTER CLOCKWISE. Flag [inverted=true] swaps the default mapping | +| | | TargetFanState | Number, Switch | Target fan state. values: 0/OFF=MANUAL, 1/ON=AUTO. Flag [inverted=true] swaps the default mapping | +| | | RotationDirection | Number, Switch | Rotation direction. values: 0/OFF=CLOCKWISE, 1/ON=COUNTER CLOCKWISE. Flag [inverted=true] swaps the default mapping | | | | RotationSpeed | Number, Dimmer | Fan rotation speed in % (1-100) | -| | | SwingMode | Number, Switch | Swing mode. values: 0/OFF=SWING DISABLED, 1/ON=SWING ENABLED. Flag [inverted=true] swaps the default mapping | -| | | LockControl | Number, Switch | Status of physical control lock. values: 0/OFF=CONTROL LOCK DISABLED, 1/ON=CONTROL LOCK ENABLED.Flag [inverted=true] swaps the default mapping | +| | | SwingMode | Number, Switch | Swing mode. values: 0/OFF=SWING DISABLED, 1/ON=SWING ENABLED. Flag [inverted=true] swaps the default mapping | +| | | LockControl | Number, Switch | Status of physical control lock. values: 0/OFF=CONTROL LOCK DISABLED, 1/ON=CONTROL LOCK ENABLED.Flag [inverted=true] swaps the default mapping | | Thermostat | | | | A thermostat requires all mandatory characteristics defined below | | | CurrentTemperature | | Number | Current temperature. supported configuration: minValue, maxValue, step | | | TargetTemperature | | Number | Target temperature. supported configuration: minValue, maxValue, step | @@ -691,6 +691,7 @@ Support for this is planned for the future release of openHAB HomeKit binding. | | | Name | String | Name of the thermostat | | | | CoolingThresholdTemperature | Number | Maximum temperature that must be reached before cooling is turned on. min/max/step can configured at item level, e.g. minValue=10.5, maxValue=50, step=2] | | | | HeatingThresholdTemperature | Number | Minimum temperature that must be reached before heating is turned on. min/max/step can configured at item level, e.g. minValue=10.5, maxValue=50, step=2] | +| | | RelativeHumidity | Number | Relative humidity in % between 0 and 100. | | HeaterCooler | | | | Heater or/and cooler device | | | ActiveStatus | | Switch | Accessory current working status. A value of "ON"/"OPEN" indicates that the accessory is active and is functioning without any errors. | | | CurrentTemperature | | Number | Current temperature. supported configuration: minValue, maxValue, step | @@ -702,7 +703,7 @@ Support for this is planned for the future release of openHAB HomeKit binding. | | | LockControl | Number, Switch | Status of physical control lock. values: 0/OFF=CONTROL LOCK DISABLED, 1/ON=CONTROL LOCK ENABLED | | | | CoolingThresholdTemperature | Number | Maximum temperature that must be reached before cooling is turned on. min/max/step can configured at item level, e.g. minValue=10.5, maxValue=50, step=2] | | | | HeatingThresholdTemperature | Number | Minimum temperature that must be reached before heating is turned on. min/max/step can configured at item level, e.g. minValue=10.5, maxValue=50, step=2] | -| Lock | | | | A Lock Mechanism. with flag [inverted=true] the default mapping to switch ON/OFF can be inverted. | +| Lock | | | | A Lock Mechanism. with flag [inverted=true] the default mapping to switch ON/OFF can be inverted. | | | LockCurrentState | | Switch, Number | Current state of lock mechanism (1/ON=SECURED, 0/OFF=UNSECURED, 2=JAMMED, 3=UNKNOWN) | | | LockTargetState | | Switch | Target state of lock mechanism (ON=SECURED, OFF=UNSECURED) | | | | Name | String | Name of the lock | @@ -732,7 +733,7 @@ Support for this is planned for the future release of openHAB HomeKit binding. | | | LockTargetState | Switch | target states of lock mechanism (OFF=SECURED, ON=UNSECURED) | | Battery | | | | Accessory with battery. Battery can be chargeable (configuration chargeable:true) and non-chargeable (configuration chargeable:false) | | | BatteryLevel | | Number | Battery level 0% to 100% | -| | BatteryLowStatus | | Switch, Contact, Number | Battery low indicator. ON/OPEN = battery level is low; for number if the value is below the lowThreshold, then it is low. Default is 20. | +| | BatteryLowStatus | | Switch, Contact, Number | Battery low indicator. ON/OPEN = battery level is low; for number if the value is below the lowThreshold, then it is low. Default is 20. | | | BatteryChargingState | | Switch, Contact | Mandatory only for chargeable battery. ON/OPEN = battery is charging | | | | Name | String | Name of the battery accessory | | Filter | | | | Accessory with filter maintenance indicator | 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 662addf6d54..611b7f33e8d 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 @@ -96,6 +96,7 @@ import io.github.hapjava.characteristics.impl.fan.TargetFanStateCharacteristic; import io.github.hapjava.characteristics.impl.fan.TargetFanStateEnum; import io.github.hapjava.characteristics.impl.filtermaintenance.FilterLifeLevelCharacteristic; import io.github.hapjava.characteristics.impl.filtermaintenance.ResetFilterIndicationCharacteristic; +import io.github.hapjava.characteristics.impl.humiditysensor.CurrentRelativeHumidityCharacteristic; import io.github.hapjava.characteristics.impl.lightbulb.BrightnessCharacteristic; import io.github.hapjava.characteristics.impl.lightbulb.ColorTemperatureCharacteristic; import io.github.hapjava.characteristics.impl.lightbulb.HueCharacteristic; @@ -159,6 +160,7 @@ public class HomekitCharacteristicFactory { put(VOLUME, HomekitCharacteristicFactory::createVolumeCharacteristic); put(COOLING_THRESHOLD_TEMPERATURE, HomekitCharacteristicFactory::createCoolingThresholdCharacteristic); put(HEATING_THRESHOLD_TEMPERATURE, HomekitCharacteristicFactory::createHeatingThresholdCharacteristic); + put(RELATIVE_HUMIDITY, HomekitCharacteristicFactory::createRelativeHumidityCharacteristic); put(REMAINING_DURATION, HomekitCharacteristicFactory::createRemainingDurationCharacteristic); put(OZONE_DENSITY, HomekitCharacteristicFactory::createOzoneDensityCharacteristic); put(NITROGEN_DIOXIDE_DENSITY, HomekitCharacteristicFactory::createNitrogenDioxideDensityCharacteristic); @@ -355,6 +357,8 @@ public class HomekitCharacteristicFactory { value = ((PercentType) state).doubleValue(); } else if (state instanceof DecimalType) { value = ((DecimalType) state).doubleValue(); + } else if (state instanceof QuantityType) { + value = ((QuantityType) state).doubleValue(); } return CompletableFuture.completedFuture(value); }; @@ -750,6 +754,13 @@ public class HomekitCharacteristicFactory { getUnsubscriber(taggedItem, HEATING_THRESHOLD_TEMPERATURE, updater)); } + private static CurrentRelativeHumidityCharacteristic createRelativeHumidityCharacteristic( + HomekitTaggedItem taggedItem, HomekitAccessoryUpdater updater) { + return new CurrentRelativeHumidityCharacteristic(getDoubleSupplier(taggedItem, 0.0), + getSubscriber(taggedItem, RELATIVE_HUMIDITY, updater), + getUnsubscriber(taggedItem, RELATIVE_HUMIDITY, updater)); + } + private static OzoneDensityCharacteristic createOzoneDensityCharacteristic(final HomekitTaggedItem taggedItem, HomekitAccessoryUpdater updater) { return new OzoneDensityCharacteristic(