Skip to content

Commit a829cef

Browse files
jsettonchilobo
authored andcommitted
[insteon] Add modem list features and product data console commands (openhab#18095)
Signed-off-by: Jeremy Setton <[email protected]> Signed-off-by: Christian Koch <[email protected]>
1 parent c515aad commit a829cef

File tree

1 file changed

+48
-3
lines changed
  • bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/command

1 file changed

+48
-3
lines changed

bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/command/ModemCommand.java

+48-3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public class ModemCommand extends InsteonCommand {
4747

4848
private static final String LIST_ALL = "listAll";
4949
private static final String LIST_DATABASE = "listDatabase";
50+
private static final String LIST_FEATURES = "listFeatures";
51+
private static final String LIST_PRODUCT_DATA = "listProductData";
5052
private static final String RELOAD_DATABASE = "reloadDatabase";
5153
private static final String BACKUP_DATABASE = "backupDatabase";
5254
private static final String RESTORE_DATABASE = "restoreDatabase";
@@ -60,9 +62,10 @@ public class ModemCommand extends InsteonCommand {
6062
private static final String RESET = "reset";
6163
private static final String SWITCH = "switch";
6264

63-
private static final List<String> SUBCMDS = List.of(LIST_ALL, LIST_DATABASE, RELOAD_DATABASE, BACKUP_DATABASE,
64-
RESTORE_DATABASE, ADD_DATABASE_CONTROLLER, ADD_DATABASE_RESPONDER, DELETE_DATABASE_RECORD,
65-
APPLY_DATABASE_CHANGES, CLEAR_DATABASE_CHANGES, ADD_DEVICE, REMOVE_DEVICE, RESET, SWITCH);
65+
private static final List<String> SUBCMDS = List.of(LIST_ALL, LIST_DATABASE, LIST_FEATURES, LIST_PRODUCT_DATA,
66+
RELOAD_DATABASE, BACKUP_DATABASE, RESTORE_DATABASE, ADD_DATABASE_CONTROLLER, ADD_DATABASE_RESPONDER,
67+
DELETE_DATABASE_RECORD, APPLY_DATABASE_CHANGES, CLEAR_DATABASE_CHANGES, ADD_DEVICE, REMOVE_DEVICE, RESET,
68+
SWITCH);
6669

6770
private static final String CONFIRM_OPTION = "--confirm";
6871
private static final String FORCE_OPTION = "--force";
@@ -80,6 +83,8 @@ public List<String> getUsages() {
8083
buildCommandUsage(LIST_ALL, "list configured Insteon modem bridges with related channels and status"),
8184
buildCommandUsage(LIST_DATABASE + " [" + RECORDS_OPTION + "]",
8285
"list all-link database summary or records and pending changes for the Insteon modem"),
86+
buildCommandUsage(LIST_FEATURES, "list features for the Insteon modem"),
87+
buildCommandUsage(LIST_PRODUCT_DATA, "list product data for the Insteon modem"),
8388
buildCommandUsage(RELOAD_DATABASE, "reload all-link database from the Insteon modem"),
8489
buildCommandUsage(BACKUP_DATABASE, "backup all-link database from the Insteon modem to a file"),
8590
buildCommandUsage(RESTORE_DATABASE + " <filename> " + CONFIRM_OPTION,
@@ -127,6 +132,20 @@ public void execute(String[] args, Console console) {
127132
printUsage(console, args[0]);
128133
}
129134
break;
135+
case LIST_FEATURES:
136+
if (args.length == 1) {
137+
listFeatures(console);
138+
} else {
139+
printUsage(console, args[0]);
140+
}
141+
break;
142+
case LIST_PRODUCT_DATA:
143+
if (args.length == 1) {
144+
listProductData(console);
145+
} else {
146+
printUsage(console, args[0]);
147+
}
148+
break;
130149
case RELOAD_DATABASE:
131150
if (args.length == 1) {
132151
reloadDatabase(console);
@@ -323,6 +342,32 @@ private void listDatabaseChanges(Console console) {
323342
}
324343
}
325344

345+
private void listFeatures(Console console) {
346+
InsteonAddress address = getModem().getAddress();
347+
List<String> features = getModem().getFeatures().stream()
348+
.filter(feature -> !feature.isEventFeature() && !feature.isGroupFeature())
349+
.map(feature -> String.format("%s: type=%s state=%s isHidden=%s", feature.getName(), feature.getType(),
350+
feature.getState().toFullString(), feature.isHiddenFeature()))
351+
.sorted().toList();
352+
if (features.isEmpty()) {
353+
console.println("The features for modem " + address + " are not defined");
354+
} else {
355+
console.println("The features for modem " + address + " are:");
356+
print(console, features);
357+
}
358+
}
359+
360+
private void listProductData(Console console) {
361+
InsteonAddress address = getModem().getAddress();
362+
ProductData productData = getModem().getProductData();
363+
if (productData == null) {
364+
console.println("The product data for modem " + address + " is not defined");
365+
} else {
366+
console.println("The product data for modem " + address + " is:");
367+
console.println(productData.toString().replace("|", "\n"));
368+
}
369+
}
370+
326371
private void reloadDatabase(Console console) {
327372
InsteonAddress address = getModem().getAddress();
328373
InsteonBridgeHandler handler = getBridgeHandler();

0 commit comments

Comments
 (0)