[homekit] implement basic command completion (#13878)

just the sub-commands.

since the show command is already a "search", I didn't feel it's super
important to implement on that

Signed-off-by: Cody Cutrer <cody@cutrer.us>
This commit is contained in:
Cody Cutrer 2022-12-09 00:56:27 -07:00 committed by GitHub
parent 3e66cd1b33
commit b56ab10e00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 0 deletions

View File

@ -17,7 +17,10 @@ import java.util.List;
import java.util.concurrent.ExecutionException;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.io.console.Console;
import org.openhab.core.io.console.ConsoleCommandCompleter;
import org.openhab.core.io.console.StringsCompleter;
import org.openhab.core.io.console.extensions.AbstractConsoleCommandExtension;
import org.openhab.core.io.console.extensions.ConsoleCommandExtension;
import org.openhab.io.homekit.Homekit;
@ -43,6 +46,20 @@ public class HomekitCommandExtension extends AbstractConsoleCommandExtension {
private static final String SUBCMD_ALLOW_UNAUTHENTICATED = "allowUnauthenticated";
private static final String SUBCMD_PRUNE_DUMMY_ACCESSORIES = "pruneDummyAccessories";
private static final String SUBCMD_LIST_DUMMY_ACCESSORIES = "listDummyAccessories";
private static final StringsCompleter SUBCMD_COMPLETER = new StringsCompleter(
List.of(SUBCMD_CLEAR_PAIRINGS, SUBCMD_LIST_ACCESSORIES, SUBCMD_PRINT_ACCESSORY,
SUBCMD_ALLOW_UNAUTHENTICATED, SUBCMD_PRUNE_DUMMY_ACCESSORIES, SUBCMD_LIST_DUMMY_ACCESSORIES),
false);
private class CommandCompleter implements ConsoleCommandCompleter {
public boolean complete(String[] args, int cursorArgumentIndex, int cursorPosition, List<String> candidates) {
if (cursorArgumentIndex == 0) {
boolean result = SUBCMD_COMPLETER.complete(args, cursorArgumentIndex, cursorPosition, candidates);
return result;
}
return false;
}
}
private final Logger logger = LoggerFactory.getLogger(HomekitCommandExtension.class);
@ -114,6 +131,11 @@ public class HomekitCommandExtension extends AbstractConsoleCommandExtension {
this.homekit = homekit;
}
@Override
public @Nullable ConsoleCommandCompleter getCompleter() {
return new CommandCompleter();
}
private void clearHomekitPairings(Console console) {
homekit.clearHomekitPairings();
console.println("Cleared HomeKit pairings");