From 51b5c89b6b354707a5efc85d6a35dae152b78d88 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Mon, 6 Jan 2025 07:09:20 -0500 Subject: [PATCH] [insteon] Add device refresh all command parameter (#18051) Signed-off-by: Jeremy Setton --- .../internal/command/DeviceCommand.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/command/DeviceCommand.java b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/command/DeviceCommand.java index 1a4f7fbaa88..b070d56aae1 100644 --- a/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/command/DeviceCommand.java +++ b/bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/command/DeviceCommand.java @@ -103,7 +103,8 @@ public class DeviceCommand extends InsteonCommand { "set a button radio group for a configured Insteon KeypadLinc device"), buildCommandUsage(CLEAR_BUTTON_RADIO_GROUP + " [ ... ]", "clear a button radio group for a configured Insteon KeypadLinc device"), - buildCommandUsage(REFRESH + " ", "refresh data for a configured Insteon device")); + buildCommandUsage(REFRESH + " " + ALL_OPTION + "|", + "refresh data for a specific or all configured Insteon devices")); } @Override @@ -222,7 +223,11 @@ public class DeviceCommand extends InsteonCommand { break; case REFRESH: if (args.length == 2) { - refreshDevice(console, args[1]); + if (ALL_OPTION.equals(args[1])) { + refreshDevices(console); + } else { + refreshDevice(console, args[1], true); + } } else { printUsage(console, args[0]); } @@ -246,7 +251,6 @@ public class DeviceCommand extends InsteonCommand { strings = getAllDeviceHandlers().map(InsteonThingHandler::getThingId).toList(); break; case LIST_DATABASE: - case REFRESH: strings = getInsteonDeviceHandlers().map(InsteonDeviceHandler::getThingId).toList(); break; case ADD_DATABASE_CONTROLLER: @@ -272,6 +276,7 @@ public class DeviceCommand extends InsteonCommand { break; case LIST_MISSING_LINKS: case ADD_MISSING_LINKS: + case REFRESH: strings = Stream.concat(Stream.of(ALL_OPTION), getInsteonDeviceHandlers().map(InsteonDeviceHandler::getThingId)).toList(); break; @@ -510,7 +515,7 @@ public class DeviceCommand extends InsteonCommand { if (!device.isAwake() || !device.isResponding()) { console.println("Scheduling " + deviceLinkCount + " missing links for device " + device.getAddress() + " to be added to its link database the next time it is " - + (device.isBatteryPowered() ? "awake" : "responding") + "."); + + (device.isBatteryPowered() ? "awake" : "online") + "."); } else { console.println("Adding " + deviceLinkCount + " missing links for device " + device.getAddress() + " to its link database..."); @@ -605,7 +610,7 @@ public class DeviceCommand extends InsteonCommand { if (!device.isAwake() || !device.isResponding() || !getModem().getDB().isComplete()) { console.println("Scheduling " + count + " pending changes for device " + device.getAddress() + " to be applied to its link database the next time it is " - + (device.isBatteryPowered() ? "awake" : "responding") + "."); + + (device.isBatteryPowered() ? "awake" : "online") + "."); } else { console.println("Applying " + count + " pending changes to link database for device " + device.getAddress() + "..."); @@ -694,7 +699,11 @@ public class DeviceCommand extends InsteonCommand { } } - private void refreshDevice(Console console, String thingId) { + private void refreshDevices(Console console) { + getInsteonDeviceHandlers().forEach(handler -> refreshDevice(console, handler.getThingId(), false)); + } + + private void refreshDevice(Console console, String thingId, boolean immediate) { InsteonDevice device = getInsteonDevice(thingId); if (device == null) { console.println("The device " + thingId + " is not configured or enabled!"); @@ -706,10 +715,10 @@ public class DeviceCommand extends InsteonCommand { device.getLinkDB().setReload(true); device.resetFeaturesQueryStatus(); - if (!device.isAwake() || !device.isResponding() || !getModem().getDB().isComplete()) { - console.println( - "The device " + device.getAddress() + " is scheduled to be refreshed the next time it is " - + (device.isBatteryPowered() ? "awake" : "responding") + "."); + if (!device.isAwake() || !device.isResponding() || !getModem().getDB().isComplete() || !immediate) { + console.println("The device " + device.getAddress() + + " is scheduled to be refreshed the next time it is " + + (device.isBatteryPowered() ? "awake" : !device.isResponding() ? "online" : "polled") + "."); } else { console.println("Refreshing device " + device.getAddress() + "..."); device.doPoll(0L);