diff --git a/bundles/org.openhab.io.homekit/README.md b/bundles/org.openhab.io.homekit/README.md index 12a7069ae19a..833f3f3b397d 100644 --- a/bundles/org.openhab.io.homekit/README.md +++ b/bundles/org.openhab.io.homekit/README.md @@ -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 | diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitAuthInfoImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitAuthInfoImpl.java index ae164900b5b0..f6da8fe2df30 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitAuthInfoImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitAuthInfoImpl.java @@ -46,22 +46,24 @@ public class HomekitAuthInfoImpl implements HomekitAuthInfo { private byte[] privateKey; private String pin; private String setupId; + private boolean blockUserDeletion; - public HomekitAuthInfoImpl(Storage storage, String pin, String setupId) + public HomekitAuthInfoImpl(Storage 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 byte[] getUserPublicKey(String username) { @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 boolean hasUser() { } 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 @@ private void initializeStorage() throws InvalidAlgorithmParameterException { 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); diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitImpl.java index f6a38905225f..9e04d135280c 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitImpl.java @@ -94,7 +94,7 @@ public HomekitImpl(@Reference StorageService storageService, @Reference ItemRegi 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()); diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitSettings.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitSettings.java index 5f040fa003f3..fdeb303fd316 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitSettings.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitSettings.java @@ -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 boolean equals(Object obj) { } } 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)) { diff --git a/bundles/org.openhab.io.homekit/src/main/resources/OH-INF/config/config.xml b/bundles/org.openhab.io.homekit/src/main/resources/OH-INF/config/config.xml index b13659889eb7..16d0a6905e64 100644 --- a/bundles/org.openhab.io.homekit/src/main/resources/OH-INF/config/config.xml +++ b/bundles/org.openhab.io.homekit/src/main/resources/OH-INF/config/config.xml @@ -116,5 +116,10 @@ Defines whether mDNS service of openHAB or a separate instance of mDNS should be used. false + + + Block deletion of the HomeKit user information from openHAB and the unpairing of devices + false +