forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[knx] Implement console commands (openhab#15064)
* [knx] Implement console commands Add commands knx:* to openHAB console. Initial implementation of knx:show_unknown_ga, which shows group addresses which are seen in the installation but not used by openHAB. Signed-off-by: Holger Friedrich <[email protected]> Signed-off-by: Thomas Burri <[email protected]>
- Loading branch information
1 parent
833dad3
commit c77a58a
Showing
9 changed files
with
162 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...nding.knx/src/main/java/org/openhab/binding/knx/internal/console/KNXCommandExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* Copyright (c) 2010-2023 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.knx.internal.console; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map.Entry; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.openhab.binding.knx.internal.KNXBindingConstants; | ||
import org.openhab.binding.knx.internal.factory.KNXHandlerFactory; | ||
import org.openhab.binding.knx.internal.handler.KNXBridgeBaseThingHandler; | ||
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.osgi.service.component.annotations.Activate; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Reference; | ||
|
||
/** | ||
* The {@link KNXCommandExtension} is responsible for handling console commands | ||
* | ||
* @author Holger Friedrich - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
@Component(service = ConsoleCommandExtension.class) | ||
public class KNXCommandExtension extends AbstractConsoleCommandExtension implements ConsoleCommandCompleter { | ||
|
||
private static final String CMD_LIST_UNKNOWN_GA = "list-unknown-ga"; | ||
private static final StringsCompleter CMD_COMPLETER = new StringsCompleter(List.of(CMD_LIST_UNKNOWN_GA), false); | ||
|
||
private final KNXHandlerFactory knxHandlerFactory; | ||
|
||
@Activate | ||
public KNXCommandExtension(final @Reference KNXHandlerFactory knxHandlerFactory) { | ||
super(KNXBindingConstants.BINDING_ID, "Interact with KNX devices."); | ||
this.knxHandlerFactory = knxHandlerFactory; | ||
} | ||
|
||
@Override | ||
public void execute(String[] args, Console console) { | ||
if (args.length == 1 && CMD_LIST_UNKNOWN_GA.equalsIgnoreCase(args[0])) { | ||
for (KNXBridgeBaseThingHandler bridgeHandler : knxHandlerFactory.getBridges()) { | ||
console.println("KNX bridge \"" + bridgeHandler.getThing().getLabel() | ||
+ "\": group address, type, number of bytes, and number of occurence since last reload of binding:"); | ||
// console.println(handler.getCommandExtensionData().unknownGA().toString()); | ||
for (Entry<String, Long> entry : bridgeHandler.getCommandExtensionData().unknownGA().entrySet()) { | ||
console.println(entry.getKey() + " " + entry.getValue()); | ||
} | ||
} | ||
return; | ||
} | ||
printUsage(console); | ||
} | ||
|
||
@Override | ||
public List<String> getUsages() { | ||
return Arrays.asList( | ||
buildCommandUsage(CMD_LIST_UNKNOWN_GA, "list group addresses which are not configured in openHAB")); | ||
} | ||
|
||
@Override | ||
public @Nullable ConsoleCommandCompleter getCompleter() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public boolean complete(String[] args, int cursorArgumentIndex, int cursorPosition, List<String> candidates) { | ||
if (cursorArgumentIndex <= 0) { | ||
return CMD_COMPLETER.complete(args, cursorArgumentIndex, cursorPosition, candidates); | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters