Skip to content

Commit 51b5c89

Browse files
authored
[insteon] Add device refresh all command parameter (openhab#18051)
Signed-off-by: Jeremy Setton <[email protected]>
1 parent 19ca89c commit 51b5c89

File tree

1 file changed

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

1 file changed

+19
-10
lines changed

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

+19-10
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ public List<String> getUsages() {
103103
"set a button radio group for a configured Insteon KeypadLinc device"),
104104
buildCommandUsage(CLEAR_BUTTON_RADIO_GROUP + " <thingId> <button1> <button2> [<button3> ... <button7>]",
105105
"clear a button radio group for a configured Insteon KeypadLinc device"),
106-
buildCommandUsage(REFRESH + " <thingId>", "refresh data for a configured Insteon device"));
106+
buildCommandUsage(REFRESH + " " + ALL_OPTION + "|<thingId>",
107+
"refresh data for a specific or all configured Insteon devices"));
107108
}
108109

109110
@Override
@@ -222,7 +223,11 @@ public void execute(String[] args, Console console) {
222223
break;
223224
case REFRESH:
224225
if (args.length == 2) {
225-
refreshDevice(console, args[1]);
226+
if (ALL_OPTION.equals(args[1])) {
227+
refreshDevices(console);
228+
} else {
229+
refreshDevice(console, args[1], true);
230+
}
226231
} else {
227232
printUsage(console, args[0]);
228233
}
@@ -246,7 +251,6 @@ public boolean complete(String[] args, int cursorArgumentIndex, int cursorPositi
246251
strings = getAllDeviceHandlers().map(InsteonThingHandler::getThingId).toList();
247252
break;
248253
case LIST_DATABASE:
249-
case REFRESH:
250254
strings = getInsteonDeviceHandlers().map(InsteonDeviceHandler::getThingId).toList();
251255
break;
252256
case ADD_DATABASE_CONTROLLER:
@@ -272,6 +276,7 @@ public boolean complete(String[] args, int cursorArgumentIndex, int cursorPositi
272276
break;
273277
case LIST_MISSING_LINKS:
274278
case ADD_MISSING_LINKS:
279+
case REFRESH:
275280
strings = Stream.concat(Stream.of(ALL_OPTION),
276281
getInsteonDeviceHandlers().map(InsteonDeviceHandler::getThingId)).toList();
277282
break;
@@ -510,7 +515,7 @@ private void addMissingLinks(Console console, String thingId) {
510515
if (!device.isAwake() || !device.isResponding()) {
511516
console.println("Scheduling " + deviceLinkCount + " missing links for device "
512517
+ device.getAddress() + " to be added to its link database the next time it is "
513-
+ (device.isBatteryPowered() ? "awake" : "responding") + ".");
518+
+ (device.isBatteryPowered() ? "awake" : "online") + ".");
514519
} else {
515520
console.println("Adding " + deviceLinkCount + " missing links for device " + device.getAddress()
516521
+ " to its link database...");
@@ -605,7 +610,7 @@ private void applyDatabaseChanges(Console console, String thingId, boolean isCon
605610
if (!device.isAwake() || !device.isResponding() || !getModem().getDB().isComplete()) {
606611
console.println("Scheduling " + count + " pending changes for device " + device.getAddress()
607612
+ " to be applied to its link database the next time it is "
608-
+ (device.isBatteryPowered() ? "awake" : "responding") + ".");
613+
+ (device.isBatteryPowered() ? "awake" : "online") + ".");
609614
} else {
610615
console.println("Applying " + count + " pending changes to link database for device "
611616
+ device.getAddress() + "...");
@@ -694,7 +699,11 @@ private void clearButtonRadioGroup(Console console, String[] args) {
694699
}
695700
}
696701

697-
private void refreshDevice(Console console, String thingId) {
702+
private void refreshDevices(Console console) {
703+
getInsteonDeviceHandlers().forEach(handler -> refreshDevice(console, handler.getThingId(), false));
704+
}
705+
706+
private void refreshDevice(Console console, String thingId, boolean immediate) {
698707
InsteonDevice device = getInsteonDevice(thingId);
699708
if (device == null) {
700709
console.println("The device " + thingId + " is not configured or enabled!");
@@ -706,10 +715,10 @@ private void refreshDevice(Console console, String thingId) {
706715
device.getLinkDB().setReload(true);
707716
device.resetFeaturesQueryStatus();
708717

709-
if (!device.isAwake() || !device.isResponding() || !getModem().getDB().isComplete()) {
710-
console.println(
711-
"The device " + device.getAddress() + " is scheduled to be refreshed the next time it is "
712-
+ (device.isBatteryPowered() ? "awake" : "responding") + ".");
718+
if (!device.isAwake() || !device.isResponding() || !getModem().getDB().isComplete() || !immediate) {
719+
console.println("The device " + device.getAddress()
720+
+ " is scheduled to be refreshed the next time it is "
721+
+ (device.isBatteryPowered() ? "awake" : !device.isResponding() ? "online" : "polled") + ".");
713722
} else {
714723
console.println("Refreshing device " + device.getAddress() + "...");
715724
device.doPoll(0L);

0 commit comments

Comments
 (0)