]> git.basschouten.com Git - openhab-addons.git/commitdiff
[homekit] add support for flag "inverted" to lock accessory (#10169)
authoreugen <freiter@gmail.com>
Tue, 16 Feb 2021 18:19:37 +0000 (19:19 +0100)
committerGitHub <noreply@github.com>
Tue, 16 Feb 2021 18:19:37 +0000 (10:19 -0800)
* add support for inverted to lock
* run spotless

Signed-off-by: Eugen Freiter <freiter@gmx.de>
bundles/org.openhab.io.homekit/README.md
bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitLockImpl.java

index 0c60c54cf864b726d0d8482046367eb85f132e0d..763688c0129aeffb13856df2f2de94ca6c1e6d8c 100644 (file)
@@ -581,7 +581,7 @@ Switch          motionsensor_tampered      "Motion Sensor Tampered"
 |                      |                             | Hue                          | Dimmer, Color            | Hue                                                                                                                                                                                                                                                                                                       |
 |                      |                             | Saturation                   | Dimmer, Color            | Saturation in % (1-100)                                                                                                                                                                                                                                                                                   |
 |                      |                             | Brightness                   | Dimmer, Color            | Brightness in % (1-100). See "Usage of dimmer modes" for configuration details.                                                                                                                                                                                                                                                                                  |
-|                      |                             | ColorTemperature             | Number                   | Color temperature which is represented in reciprocal megaKelvin, values - 50 to 400. should not be used in combination with hue, saturation and brightness                                                                                                                                                |
+|                      |                             | ColorTemperature             | Number                   | NOT WORKING on iOS 14.x. Color temperature which is represented in reciprocal megaKelvin, values - 50 to 400. should not be used in combination with hue, saturation and brightness                                                                                                                                                |
 | 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                                                                                                                                                                                                                                             |
@@ -609,7 +609,7 @@ Switch          motionsensor_tampered      "Motion Sensor Tampered"
 |                      |                             | 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                                                                                                                                                                                                                                                                                          |
+| 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                                                                                                                                                                                                                                                                                          |
index 33c13c00be550af6d7c6403b2367fd0b0e8a237c..add1698d5a6f457353c434f20d6a82e537d113d0 100644 (file)
@@ -40,10 +40,16 @@ import io.github.hapjava.services.impl.LockMechanismService;
  *
  */
 public class HomekitLockImpl extends AbstractHomekitAccessoryImpl implements LockMechanismAccessory {
+    final OnOffType securedState;
+    final OnOffType unsecuredState;
 
     public HomekitLockImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
             HomekitAccessoryUpdater updater, HomekitSettings settings) {
         super(taggedItem, mandatoryCharacteristics, updater, settings);
+        final String invertedConfig = getAccessoryConfiguration(HomekitTaggedItem.INVERTED, "false");
+        final boolean inverted = invertedConfig.equalsIgnoreCase("yes") || invertedConfig.equalsIgnoreCase("true");
+        securedState = inverted ? OnOffType.OFF : OnOffType.ON;
+        unsecuredState = inverted ? OnOffType.ON : OnOffType.OFF;
         getServices().add(new LockMechanismService(this));
     }
 
@@ -56,7 +62,7 @@ public class HomekitLockImpl extends AbstractHomekitAccessoryImpl implements Loc
             if (state instanceof DecimalType) {
                 lockState = LockCurrentStateEnum.fromCode(((DecimalType) state).intValue());
             } else if (state instanceof OnOffType) {
-                lockState = state == OnOffType.ON ? LockCurrentStateEnum.SECURED : LockCurrentStateEnum.UNSECURED;
+                lockState = state == securedState ? LockCurrentStateEnum.SECURED : LockCurrentStateEnum.UNSECURED;
             }
         }
         return CompletableFuture.completedFuture(lockState);
@@ -67,7 +73,7 @@ public class HomekitLockImpl extends AbstractHomekitAccessoryImpl implements Loc
         final @Nullable OnOffType state = getStateAs(HomekitCharacteristicType.LOCK_TARGET_STATE, OnOffType.class);
         if (state != null) {
             return CompletableFuture.completedFuture(
-                    state == OnOffType.ON ? LockTargetStateEnum.SECURED : LockTargetStateEnum.UNSECURED);
+                    state == securedState ? LockTargetStateEnum.SECURED : LockTargetStateEnum.UNSECURED);
         }
         return CompletableFuture.completedFuture(LockTargetStateEnum.UNSECURED);
         // Apple HAP specification has only SECURED and UNSECURED values for lock target state.
@@ -79,15 +85,13 @@ public class HomekitLockImpl extends AbstractHomekitAccessoryImpl implements Loc
         getItem(HomekitCharacteristicType.LOCK_TARGET_STATE, SwitchItem.class).ifPresent(item -> {
             switch (state) {
                 case SECURED:
-                    // Close the door
                     if (item instanceof SwitchItem) {
-                        item.send(OnOffType.ON);
+                        item.send(securedState);
                     }
                     break;
                 case UNSECURED:
-                    // Open the door
                     if (item instanceof SwitchItem) {
-                        item.send(OnOffType.OFF);
+                        item.send(unsecuredState);
                     }
                     break;
                 default: