Skip to content

Commit

Permalink
[homekit] implement List-Pairings method (openhab#13982)
Browse files Browse the repository at this point in the history
* [homekit] implement List-Pairings method
* [homekit] fix listUsers() method
* [homekit] bump HAP-java to 2.0.5

refs openhab#13949

Signed-off-by: Cody Cutrer <cody@cutrer.us>
  • Loading branch information
ccutrer committed Dec 22, 2022
1 parent fbf302e commit 7c2d5dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bundles/org.openhab.io.homekit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<dependency>
<groupId>io.github.hap-java</groupId>
<artifactId>hap</artifactId>
<version>2.0.4</version>
<version>2.0.5</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Base64;
import java.util.Collection;
import java.util.HashSet;
import java.util.stream.Collectors;

import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.storage.Storage;
Expand Down Expand Up @@ -62,7 +63,7 @@ public void setBlockUserDeletion(boolean blockUserDeletion) {
}

@Override
public void createUser(String username, byte[] publicKey) {
public void createUser(String username, byte[] publicKey, boolean isAdmin) {
logger.trace("create user {}", username);
final String userKey = createUserKey(username);
final String encodedPublicKey = Base64.getEncoder().encodeToString(publicKey);
Expand Down Expand Up @@ -133,6 +134,18 @@ public boolean hasUser() {
return keys.stream().anyMatch(this::isUserKey);
}

@Override
public Collection<String> listUsers() {
Collection<String> keys = storage.getKeys();
// don't forget to strip user_ prefix
return keys.stream().filter(this::isUserKey).map(u -> u.substring(5)).collect(Collectors.toList());
}

@Override
public boolean userIsAdmin(String username) {
return true;
}

public void clear() {
logger.trace("clear all users");
if (!this.blockUserDeletion) {
Expand Down

0 comments on commit 7c2d5dc

Please sign in to comment.