Skip to content

Commit

Permalink
Console commands: enhanced parsing of bridge/thing UID (openhab#7846)
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
  • Loading branch information
lolodomo authored and andrewfg committed Aug 31, 2020
1 parent 413c064 commit 6c12232
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,30 @@ public FreeboxCommandExtension(final @Reference ThingRegistry thingRegistry) {
@Override
public void execute(String[] args, Console console) {
if (args.length == 2) {
FreeboxHandler handler = null;
Thing thing = null;
try {
ThingUID thingUID = new ThingUID(args[0]);
Thing thing = thingRegistry.get(thingUID);
if (thing != null) {
ThingHandler thingHandler = thing.getHandler();
if (thingHandler instanceof FreeboxHandler) {
handler = (FreeboxHandler) thingHandler;
}
}
thing = thingRegistry.get(thingUID);
} catch (IllegalArgumentException e) {
handler = null;
thing = null;
}
if (handler == null) {
ThingHandler thingHandler = null;
FreeboxHandler handler = null;
if (thing != null) {
thingHandler = thing.getHandler();
if (thingHandler instanceof FreeboxHandler) {
handler = (FreeboxHandler) thingHandler;
}
}
if (thing == null) {
console.println("Bad thing id '" + args[0] + "'");
printUsage(console);
} else if (thingHandler == null) {
console.println("No handler initialized for the thing id '" + args[0] + "'");
printUsage(console);
} else if (handler == null) {
console.println("'" + args[0] + "' is not a freebox bridge id");
printUsage(console);
} else {
switch (args[1]) {
case APP_TOKEN:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,30 @@ public LGWebOSCommandExtension(final @Reference ThingRegistry thingRegistry) {
@Override
public void execute(String[] args, Console console) {
if (args.length == 2) {
LGWebOSHandler handler = null;
Thing thing = null;
try {
ThingUID thingUID = new ThingUID(args[0]);
Thing thing = thingRegistry.get(thingUID);
if (thing != null) {
ThingHandler thingHandler = thing.getHandler();
if (thingHandler instanceof LGWebOSHandler) {
handler = (LGWebOSHandler) thingHandler;
}
}
thing = thingRegistry.get(thingUID);
} catch (IllegalArgumentException e) {
handler = null;
thing = null;
}
if (handler == null) {
ThingHandler thingHandler = null;
LGWebOSHandler handler = null;
if (thing != null) {
thingHandler = thing.getHandler();
if (thingHandler instanceof LGWebOSHandler) {
handler = (LGWebOSHandler) thingHandler;
}
}
if (thing == null) {
console.println("Bad thing id '" + args[0] + "'");
printUsage(console);
} else if (thingHandler == null) {
console.println("No handler initialized for the thing id '" + args[0] + "'");
printUsage(console);
} else if (handler == null) {
console.println("'" + args[0] + "' is not a LG webOS thing id");
printUsage(console);
} else {
switch (args[1]) {
case APPLICATIONS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,30 @@ public LinkyCommandExtension(final @Reference ThingRegistry thingRegistry) {
@Override
public void execute(String[] args, Console console) {
if (args.length >= 2) {
LinkyHandler handler = null;
Thing thing = null;
try {
ThingUID thingUID = new ThingUID(args[0]);
Thing thing = thingRegistry.get(thingUID);
if (thing != null) {
ThingHandler thingHandler = thing.getHandler();
if (thingHandler instanceof LinkyHandler) {
handler = (LinkyHandler) thingHandler;
}
}
thing = thingRegistry.get(thingUID);
} catch (IllegalArgumentException e) {
handler = null;
thing = null;
}
ThingHandler thingHandler = null;
LinkyHandler handler = null;
if (thing != null) {
thingHandler = thing.getHandler();
if (thingHandler instanceof LinkyHandler) {
handler = (LinkyHandler) thingHandler;
}
}
if (handler == null) {
if (thing == null) {
console.println("Bad thing id '" + args[0] + "'");
printUsage(console);
} else if (thingHandler == null) {
console.println("No handler initialized for the thing id '" + args[0] + "'");
printUsage(console);
} else if (handler == null) {
console.println("'" + args[0] + "' is not a Linky thing id");
printUsage(console);
} else if (REPORT.equals(args[1])) {
LocalDate now = LocalDate.now();
LocalDate start = now.minusDays(7);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,29 @@ public PowermaxCommandExtension() {
@Override
public void execute(String[] args, Console console) {
if (args.length >= 2) {
PowermaxBridgeHandler handler = null;
Thing thing = null;
try {
ThingUID bridgeUID = new ThingUID(args[0]);
Thing thing = thingRegistry.get(bridgeUID);
if (thing != null) {
ThingHandler thingHandler = thing.getHandler();
if (thingHandler instanceof PowermaxBridgeHandler) {
handler = (PowermaxBridgeHandler) thingHandler;
}
ThingUID thingUID = new ThingUID(args[0]);
thing = thingRegistry.get(thingUID);
} catch (IllegalArgumentException e) {
thing = null;
}
ThingHandler thingHandler = null;
PowermaxBridgeHandler handler = null;
if (thing != null) {
thingHandler = thing.getHandler();
if (thingHandler instanceof PowermaxBridgeHandler) {
handler = (PowermaxBridgeHandler) thingHandler;
}
} catch (Exception e) {
handler = null;
}
if (handler == null) {
console.println("Bad bridge id '" + args[0] + "'");
if (thing == null) {
console.println("Bad thing id '" + args[0] + "'");
printUsage(console);
} else if (thingHandler == null) {
console.println("No handler initialized for the thing id '" + args[0] + "'");
printUsage(console);
} else if (handler == null) {
console.println("'" + args[0] + "' is not a powermax bridge id");
printUsage(console);
} else {
switch (args[1]) {
Expand Down

0 comments on commit 6c12232

Please sign in to comment.