]> git.basschouten.com Git - openhab-addons.git/commitdiff
[homekit] add setting to block homekit user/pairing deletion (#11731)
authoreugen <freiter@gmail.com>
Wed, 8 Dec 2021 11:14:44 +0000 (12:14 +0100)
committerGitHub <noreply@github.com>
Wed, 8 Dec 2021 11:14:44 +0000 (12:14 +0100)
* add setting to block homekit user deletion and unpairing
* add logging
* remove . from settings label

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/HomekitAuthInfoImpl.java
bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitImpl.java
bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitSettings.java
bundles/org.openhab.io.homekit/src/main/resources/OH-INF/config/config.xml

index 12a7069ae19adc4ac6651f1da68e0fe0b1b8459c..833f3f3b397d637f751bec5cfb520872748b149f 100644 (file)
@@ -88,6 +88,7 @@ org.openhab.homekit:thermostatTargetModeAuto=Auto
 org.openhab.homekit:thermostatTargetModeOff=Off
 org.openhab.homekit:networkInterface=192.168.0.6
 org.openhab.homekit:useOHmDNS=false
+org.openhab.homekit:blockUserDeletion=false
 org.openhab.homekit:name=openHAB
 ```
 
@@ -98,6 +99,7 @@ org.openhab.homekit:name=openHAB
 | networkInterface         | IP address or domain name under which the HomeKit bridge can be reached. If no value is configured, the add-on uses the first network adapter address configured for openHAB.                                                                                  | (none)        |
 | port                     | Port under which the HomeKit bridge can be reached.                                                                                                                                                                                     | 9123          |
 | useOHmDNS                | mDNS service is used to advertise openHAB as HomeKit bridge in the network so that HomeKit clients can find it. openHAB has already mDNS service running. This option defines whether the mDNS service of openHAB or a separate service should be used.   | false  |
+| blockUserDeletion        | Blocks HomeKit user deletion in openHAB and as result unpairing of devices. If you experience an issue with accessories becoming non-responsive after some time, try to enable this setting. You can also enable this setting if your HomeKit setup is done and you will not re-pair ios devices.                                              | false         |
 | pin                      | Pin code used for pairing with iOS devices. Apparently, pin codes are provided by Apple and represent specific device types, so they cannot be chosen freely. The pin code 031-45-154 is used in sample applications and known to work. | 031-45-154    |
 | startDelay               | HomeKit start delay in seconds in case the number of accessories is lower than last time. This helps to avoid resetting home app in case not all items have been initialised properly before HomeKit integration start.                 | 30            |
 | useFahrenheitTemperature | Set to true to use Fahrenheit degrees, or false to use Celsius degrees.                                                                                                                                                                 | false         |
index ae164900b5b0364f36b8cd5222289d37cbb09272..f6da8fe2df309b95285647276f499c0ec43c4956 100644 (file)
@@ -46,22 +46,24 @@ public class HomekitAuthInfoImpl implements HomekitAuthInfo {
     private byte[] privateKey;
     private String pin;
     private String setupId;
+    private boolean blockUserDeletion;
 
-    public HomekitAuthInfoImpl(Storage<String> storage, String pin, String setupId)
+    public HomekitAuthInfoImpl(Storage<String> storage, String pin, String setupId, boolean blockUserDeletion)
             throws InvalidAlgorithmParameterException {
         this.storage = storage;
         this.pin = pin;
         this.setupId = setupId;
+        this.blockUserDeletion = blockUserDeletion;
         initializeStorage();
     }
 
     @Override
     public void createUser(String username, byte[] publicKey) {
-        logger.trace("Create user {}", username);
+        logger.trace("create user {}", username);
         final String userKey = createUserKey(username);
         final String encodedPublicKey = Base64.getEncoder().encodeToString(publicKey);
         storage.put(userKey, encodedPublicKey);
-        logger.trace("Stored user key {} with value {}", userKey, encodedPublicKey);
+        logger.trace("stored user key {} with value {}", userKey, encodedPublicKey);
     }
 
     @Override
@@ -113,8 +115,12 @@ public class HomekitAuthInfoImpl implements HomekitAuthInfo {
 
     @Override
     public void removeUser(String username) {
-        logger.trace("Remove user {}", username);
-        storage.remove(createUserKey(username));
+        logger.trace("remove user {}", username);
+        if (!this.blockUserDeletion) {
+            storage.remove(createUserKey(username));
+        } else {
+            logger.debug("deletion of the user was blocked by binding settings");
+        }
     }
 
     @Override
@@ -124,11 +130,15 @@ public class HomekitAuthInfoImpl implements HomekitAuthInfo {
     }
 
     public void clear() {
-        logger.trace("Clear all users");
-        for (String key : new HashSet<>(storage.getKeys())) {
-            if (isUserKey(key)) {
-                storage.remove(key);
+        logger.trace("clear all users");
+        if (!this.blockUserDeletion) {
+            for (String key : new HashSet<>(storage.getKeys())) {
+                if (isUserKey(key)) {
+                    storage.remove(key);
+                }
             }
+        } else {
+            logger.debug("deletion of users information was blocked by binding settings");
         }
     }
 
@@ -146,7 +156,7 @@ public class HomekitAuthInfoImpl implements HomekitAuthInfo {
         final @Nullable Object privateKeyConfig = storage.get(STORAGE_PRIVATE_KEY);
         if (mac == null) {
             logger.warn(
-                    "Could not find existing MAC in {}. Generating new MAC. This will require re-pairing of iOS devices.",
+                    "could not find existing MAC in {}. Generating new MAC. This will require re-pairing of iOS devices.",
                     storage.getClass().getName());
             mac = HomekitServer.generateMac();
             storage.put(STORAGE_MAC, mac);
index f6a38905225f0c4a456fd26b255c39d286fb9373..9e04d135280c4274fb254b8683f0587ac9a7cc6b 100644 (file)
@@ -94,7 +94,7 @@ public class HomekitImpl implements Homekit, NetworkAddressChangeListener {
         this.changeListener = new HomekitChangeListener(itemRegistry, settings, metadataRegistry, storageService);
         try {
             authInfo = new HomekitAuthInfoImpl(storageService.getStorage(HomekitAuthInfoImpl.STORAGE_KEY), settings.pin,
-                    settings.setupId);
+                    settings.setupId, settings.blockUserDeletion);
             startHomekitServer();
         } catch (IOException | InvalidAlgorithmParameterException e) {
             logger.warn("cannot activate HomeKit binding. {}", e.getMessage());
index 5f040fa003f3b0c7d2e1148f0688bf4cf3993e52..fdeb303fd316e137a990257c9ca8a9d84940c414 100644 (file)
@@ -32,6 +32,7 @@ public class HomekitSettings {
     public int startDelay = 30;
     public boolean useFahrenheitTemperature = false;
     public boolean useOHmDNS = false;
+    public boolean blockUserDeletion = false;
     public String thermostatTargetModeHeat = "HeatOn";
     public String thermostatTargetModeCool = "CoolOn";
     public String thermostatTargetModeAuto = "Auto";
@@ -81,6 +82,8 @@ public class HomekitSettings {
             }
         } else if (!useOHmDNS != other.useOHmDNS) {
             return false;
+        } else if (!blockUserDeletion != other.blockUserDeletion) {
+            return false;
         } else if (!pin.equals(other.pin)) {
             return false;
         } else if (!setupId.equals(other.setupId)) {
index b13659889eb7a902e87becbbd2acbba3276787bd..16d0a6905e64ce25a63d3384a7c1edc1cab237eb 100644 (file)
                        <description>Defines whether mDNS service of openHAB or a separate instance of mDNS should be used.</description>
                        <default>false</default>
                </parameter>
+               <parameter name="blockUserDeletion" type="boolean" required="false" groupName="network">
+                       <label>Block deletion of the HomeKit user</label>
+                       <description>Block deletion of the HomeKit user information from openHAB and the unpairing of devices</description>
+                       <default>false</default>
+               </parameter>
        </config-description>
 </config-description:config-descriptions>