[netatmo] Console command completion (#13587)

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo 2022-10-24 23:34:32 +02:00 committed by GitHub
parent af8a941f1f
commit 50d946e467
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

View File

@ -23,6 +23,8 @@ import org.openhab.binding.netatmo.internal.api.data.ModuleType;
import org.openhab.binding.netatmo.internal.api.dto.NAModule;
import org.openhab.binding.netatmo.internal.handler.ApiBridgeHandler;
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.core.thing.Thing;
@ -41,9 +43,10 @@ import org.osgi.service.component.annotations.Reference;
@NonNullByDefault
@Component(service = ConsoleCommandExtension.class)
public class NetatmoCommandExtension extends AbstractConsoleCommandExtension {
public class NetatmoCommandExtension extends AbstractConsoleCommandExtension implements ConsoleCommandCompleter {
private static final String SHOW_IDS = "showIds";
private static final StringsCompleter SUBCMD_COMPLETER = new StringsCompleter(List.of(SHOW_IDS), false);
private final ThingRegistry thingRegistry;
private @Nullable Console console;
@ -94,4 +97,17 @@ public class NetatmoCommandExtension extends AbstractConsoleCommandExtension {
public List<String> getUsages() {
return Arrays.asList(buildCommandUsage(SHOW_IDS, "list all devices and modules ids"));
}
@Override
public @Nullable ConsoleCommandCompleter getCompleter() {
return this;
}
@Override
public boolean complete(String[] args, int cursorArgumentIndex, int cursorPosition, List<String> candidates) {
if (cursorArgumentIndex <= 0) {
return SUBCMD_COMPLETER.complete(args, cursorArgumentIndex, cursorPosition, candidates);
}
return false;
}
}