]> git.basschouten.com Git - openhab-addons.git/commitdiff
[homekit] Support lock optional characteristics on GarageDoorOpener (#17141)
authorCody Cutrer <cody@cutrer.us>
Thu, 25 Jul 2024 14:26:32 +0000 (08:26 -0600)
committerGitHub <noreply@github.com>
Thu, 25 Jul 2024 14:26:32 +0000 (16:26 +0200)
Signed-off-by: Cody Cutrer <cody@cutrer.us>
bundles/org.openhab.io.homekit/README.md
bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitCharacteristicFactory.java

index 91fe8a3e1f121220c1945d6e59e0358a29386263..88156aa0f601de231babbb4d9b2559ff70501f8c 100644 (file)
@@ -805,6 +805,8 @@ All accessories also support the following optional characteristic that can be l
 | GarageDoorOpener            |                             |                             |                                         | A garage door opener.                                                                                                                                                                                                                                                                                                                                         |                                                                       |                                                                                                             |
 |                             | CurrentDoorState            |                             | Contact, Switch, Number, String         | Current door state.                                                                                                                                                                                                                                                                                                                                           | inverted (false)                                                      | OPEN (0, ON, OPEN), CLOSED (1, OFF, CLOSED), OPENING (2), CLOSING (3), STOPPED (4)                          |
 |                             | TargetDoorState             |                             | Contact, Switch, Number, String         | Target door state.                                                                                                                                                                                                                                                                                                                                            | inverted (false)                                                      | OPEN (0, ON, OPEN), CLOSED (1, OFF, CLOSED)                                                                 |
+|                             |                             | LockCurrentState            | Contact, Number, String, Switch         | Current state of lock mechanism                                                                                                                                                                                                                                                                                                                               | inverted (false)                                                      | UNSECURED (0, OFF, CLOSED), SECURED (1, ON, OPEN), JAMMED (2), UNKNOWN (3)                                  |
+|                             |                             | LockTargetState             | Number, String, Switch                  | Target state of lock mechanism                                                                                                                                                                                                                                                                                                                                | inverted (false)                                                      | UNSECURED (0, OFF), SECURED (1, ON)                                                                         |
 |                             |                             | ObstructionStatus           | Contact, Switch                         | Current status of obstruction sensor. ON-obstruction detected, OFF - no obstruction                                                                                                                                                                                                                                                                           | inverted (false)                                                      |                                                                                                             |
 | HeaterCooler                |                             |                             |                                         | Heater or/and cooler device                                                                                                                                                                                                                                                                                                                                   |                                                                       |                                                                                                             |
 |                             | ActiveStatus                |                             | Dimmer, Switch                          | Accessory current working status. A value of "ON"/"OPEN" indicates that the accessory is active and is functioning without any errors.                                                                                                                                                                                                                        |                                                                       |                                                                                                             |
index 37fcede6c8ee1758b86bffb795bd86af5ca42d3f..5797e6238dce2a6923e73e3b6030e8c6774826bb 100644 (file)
@@ -137,6 +137,10 @@ import io.github.hapjava.characteristics.impl.lightbulb.BrightnessCharacteristic
 import io.github.hapjava.characteristics.impl.lightbulb.ColorTemperatureCharacteristic;
 import io.github.hapjava.characteristics.impl.lightbulb.HueCharacteristic;
 import io.github.hapjava.characteristics.impl.lightbulb.SaturationCharacteristic;
+import io.github.hapjava.characteristics.impl.lock.LockCurrentStateCharacteristic;
+import io.github.hapjava.characteristics.impl.lock.LockCurrentStateEnum;
+import io.github.hapjava.characteristics.impl.lock.LockTargetStateCharacteristic;
+import io.github.hapjava.characteristics.impl.lock.LockTargetStateEnum;
 import io.github.hapjava.characteristics.impl.slat.CurrentTiltAngleCharacteristic;
 import io.github.hapjava.characteristics.impl.slat.TargetTiltAngleCharacteristic;
 import io.github.hapjava.characteristics.impl.television.ClosedCaptionsCharacteristic;
@@ -227,6 +231,8 @@ public class HomekitCharacteristicFactory {
             put(INPUT_DEVICE_TYPE, HomekitCharacteristicFactory::createInputDeviceTypeCharacteristic);
             put(INPUT_SOURCE_TYPE, HomekitCharacteristicFactory::createInputSourceTypeCharacteristic);
             put(LOCK_CONTROL, HomekitCharacteristicFactory::createLockPhysicalControlsCharacteristic);
+            put(LOCK_CURRENT_STATE, HomekitCharacteristicFactory::createLockCurrentStateCharacteristic);
+            put(LOCK_TARGET_STATE, HomekitCharacteristicFactory::createLockTargetStateCharacteristic);
             put(MANUFACTURER, HomekitCharacteristicFactory::createManufacturerCharacteristic);
             put(MODEL, HomekitCharacteristicFactory::createModelCharacteristic);
             put(MUTE, HomekitCharacteristicFactory::createMuteCharacteristic);
@@ -1097,6 +1103,23 @@ public class HomekitCharacteristicFactory {
                 getUnsubscriber(taggedItem, LOCK_CONTROL, updater));
     }
 
+    private static LockCurrentStateCharacteristic createLockCurrentStateCharacteristic(HomekitTaggedItem taggedItem,
+            HomekitAccessoryUpdater updater) {
+        var map = createMapping(taggedItem, LockCurrentStateEnum.class);
+        return new LockCurrentStateCharacteristic(() -> getEnumFromItem(taggedItem, map, LockCurrentStateEnum.UNKNOWN),
+                getSubscriber(taggedItem, LOCK_CURRENT_STATE, updater),
+                getUnsubscriber(taggedItem, LOCK_CURRENT_STATE, updater));
+    }
+
+    private static LockTargetStateCharacteristic createLockTargetStateCharacteristic(HomekitTaggedItem taggedItem,
+            HomekitAccessoryUpdater updater) {
+        var map = createMapping(taggedItem, LockTargetStateEnum.class);
+        return new LockTargetStateCharacteristic(() -> getEnumFromItem(taggedItem, map, LockTargetStateEnum.UNSECURED),
+                (value) -> setValueFromEnum(taggedItem, value, map),
+                getSubscriber(taggedItem, LOCK_TARGET_STATE, updater),
+                getUnsubscriber(taggedItem, LOCK_TARGET_STATE, updater));
+    }
+
     private static ManufacturerCharacteristic createManufacturerCharacteristic(HomekitTaggedItem taggedItem,
             HomekitAccessoryUpdater updater) {
         return new ManufacturerCharacteristic(() -> {