Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[insteon] Add modem list features and product data console commands #18095

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class ModemCommand extends InsteonCommand {

private static final String LIST_ALL = "listAll";
private static final String LIST_DATABASE = "listDatabase";
private static final String LIST_FEATURES = "listFeatures";
private static final String LIST_PRODUCT_DATA = "listProductData";
private static final String RELOAD_DATABASE = "reloadDatabase";
private static final String BACKUP_DATABASE = "backupDatabase";
private static final String RESTORE_DATABASE = "restoreDatabase";
Expand All @@ -60,9 +62,10 @@ public class ModemCommand extends InsteonCommand {
private static final String RESET = "reset";
private static final String SWITCH = "switch";

private static final List<String> SUBCMDS = List.of(LIST_ALL, LIST_DATABASE, RELOAD_DATABASE, BACKUP_DATABASE,
RESTORE_DATABASE, ADD_DATABASE_CONTROLLER, ADD_DATABASE_RESPONDER, DELETE_DATABASE_RECORD,
APPLY_DATABASE_CHANGES, CLEAR_DATABASE_CHANGES, ADD_DEVICE, REMOVE_DEVICE, RESET, SWITCH);
private static final List<String> SUBCMDS = List.of(LIST_ALL, LIST_DATABASE, LIST_FEATURES, LIST_PRODUCT_DATA,
RELOAD_DATABASE, BACKUP_DATABASE, RESTORE_DATABASE, ADD_DATABASE_CONTROLLER, ADD_DATABASE_RESPONDER,
DELETE_DATABASE_RECORD, APPLY_DATABASE_CHANGES, CLEAR_DATABASE_CHANGES, ADD_DEVICE, REMOVE_DEVICE, RESET,
SWITCH);

private static final String CONFIRM_OPTION = "--confirm";
private static final String FORCE_OPTION = "--force";
Expand All @@ -80,6 +83,8 @@ public List<String> getUsages() {
buildCommandUsage(LIST_ALL, "list configured Insteon modem bridges with related channels and status"),
buildCommandUsage(LIST_DATABASE + " [" + RECORDS_OPTION + "]",
"list all-link database summary or records and pending changes for the Insteon modem"),
buildCommandUsage(LIST_FEATURES, "list features for the Insteon modem"),
buildCommandUsage(LIST_PRODUCT_DATA, "list product data for the Insteon modem"),
buildCommandUsage(RELOAD_DATABASE, "reload all-link database from the Insteon modem"),
buildCommandUsage(BACKUP_DATABASE, "backup all-link database from the Insteon modem to a file"),
buildCommandUsage(RESTORE_DATABASE + " <filename> " + CONFIRM_OPTION,
Expand Down Expand Up @@ -127,6 +132,20 @@ public void execute(String[] args, Console console) {
printUsage(console, args[0]);
}
break;
case LIST_FEATURES:
if (args.length == 1) {
listFeatures(console);
} else {
printUsage(console, args[0]);
}
break;
case LIST_PRODUCT_DATA:
if (args.length == 1) {
listProductData(console);
} else {
printUsage(console, args[0]);
}
break;
case RELOAD_DATABASE:
if (args.length == 1) {
reloadDatabase(console);
Expand Down Expand Up @@ -323,6 +342,32 @@ private void listDatabaseChanges(Console console) {
}
}

private void listFeatures(Console console) {
InsteonAddress address = getModem().getAddress();
List<String> features = getModem().getFeatures().stream()
.filter(feature -> !feature.isEventFeature() && !feature.isGroupFeature())
.map(feature -> String.format("%s: type=%s state=%s isHidden=%s", feature.getName(), feature.getType(),
feature.getState().toFullString(), feature.isHiddenFeature()))
.sorted().toList();
if (features.isEmpty()) {
console.println("The features for modem " + address + " are not defined");
} else {
console.println("The features for modem " + address + " are:");
print(console, features);
}
}

private void listProductData(Console console) {
InsteonAddress address = getModem().getAddress();
ProductData productData = getModem().getProductData();
if (productData == null) {
console.println("The product data for modem " + address + " is not defined");
} else {
console.println("The product data for modem " + address + " is:");
console.println(productData.toString().replace("|", "\n"));
}
}

private void reloadDatabase(Console console) {
InsteonAddress address = getModem().getAddress();
InsteonBridgeHandler handler = getBridgeHandler();
Expand Down