Skip to content

Commit

Permalink
[homekit] Improve output of console's homekit show command (openhab…
Browse files Browse the repository at this point in the history
…#13569)

* [homekit] Improve output of console's `homekit show` command

 * include the full JSON from all the characteristics, so you can confirm
   everything is configured correctly.
 * only use simple class names; the fully qualified package is just a
   distraction.
 * show linked services if they exist
 * include the class name of services, not just the GUID

Signed-off-by: Cody Cutrer <cody@cutrer.us>
Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
  • Loading branch information
ccutrer authored and andrasU committed Nov 12, 2022
1 parent fa86a1b commit b582829
Showing 1 changed file with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.github.hapjava.services.Service;

/**
* Console commands for interacting with the HomeKit integration
*
Expand Down Expand Up @@ -119,18 +121,32 @@ private void listAccessories(Console console) {
});
}

private void printService(Console console, Service service, int indent) {
console.println(" ".repeat(indent) + "Service Type: " + service.getClass().getSimpleName() + " ("
+ service.getType() + ")");
console.println(" ".repeat(indent + 2) + "Characteristics:");
service.getCharacteristics().forEach((c) -> {
try {
console.println(
" ".repeat(indent + 4) + c.getClass().getSimpleName() + ": " + c.toJson(0).get().toString());
} catch (InterruptedException | ExecutionException e) {
}
});
if (service.getLinkedServices().isEmpty()) {
return;
}
console.println(" ".repeat(indent + 2) + "Linked Services:");
service.getLinkedServices().forEach((s) -> printService(console, s, indent + 2));
}

private void printAccessory(String id, Console console) {
homekit.getAccessories().forEach(v -> {
try {
if (("" + v.getId()).contains(id) || ((v.getName().get() != null)
&& (v.getName().get().toUpperCase().contains(id.toUpperCase())))) {
console.println(v.getId() + " " + v.getName().get());
console.println("Services:");
v.getServices().forEach(s -> {
console.println(" Service Type: " + s.getType());
console.println(" Characteristics: ");
s.getCharacteristics().forEach(c -> console.println(" : " + c.getClass()));
});
v.getServices().forEach(s -> printService(console, s, 2));
console.println("");
}
} catch (InterruptedException | ExecutionException e) {
Expand Down

0 comments on commit b582829

Please sign in to comment.