From a6972ca1e247e730ea425da306534f5b2faab653 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Thu, 7 Feb 2019 10:50:21 -0700 Subject: [PATCH 1/2] bring Characteristic JSON in line with spec * events is actually called ev * there is no bonjour field --- .../com/beowulfe/hap/characteristics/BaseCharacteristic.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/beowulfe/hap/characteristics/BaseCharacteristic.java b/src/main/java/com/beowulfe/hap/characteristics/BaseCharacteristic.java index a4ba443b1..a25a64c1b 100644 --- a/src/main/java/com/beowulfe/hap/characteristics/BaseCharacteristic.java +++ b/src/main/java/com/beowulfe/hap/characteristics/BaseCharacteristic.java @@ -97,8 +97,7 @@ protected CompletableFuture makeBuilder(int instanceId) { .add("type", type) .add("perms", perms.build()) .add("format", format) - .add("events", false) - .add("bonjour", false) + .add("ev", false) .add("description", description); setJsonValue(builder, value); return builder; From b6501ccb67432424ac1549761e90aff4999d3c8e Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Thu, 7 Feb 2019 11:18:47 -0700 Subject: [PATCH 2/2] use short types in JSON HAP spec allows shortening UUIDs if they're well known Apple ones doing this drastically reduces response sizes --- .../com/beowulfe/hap/characteristics/BaseCharacteristic.java | 4 +++- .../java/com/beowulfe/hap/impl/json/AccessoryController.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/beowulfe/hap/characteristics/BaseCharacteristic.java b/src/main/java/com/beowulfe/hap/characteristics/BaseCharacteristic.java index a25a64c1b..46cdf7dc2 100644 --- a/src/main/java/com/beowulfe/hap/characteristics/BaseCharacteristic.java +++ b/src/main/java/com/beowulfe/hap/characteristics/BaseCharacteristic.java @@ -22,6 +22,7 @@ public abstract class BaseCharacteristic implements Characteristic { private final Logger logger = LoggerFactory.getLogger(BaseCharacteristic.class); private final String type; + private final String shortType; private final String format; private final boolean isWritable; private final boolean isReadable; @@ -46,6 +47,7 @@ public BaseCharacteristic( } this.type = type; + this.shortType = this.type.replaceAll("^0*([0-9a-fA-F]+)-0000-1000-8000-0026BB765291$", "$1"); this.format = format; this.isWritable = isWritable; this.isReadable = isReadable; @@ -94,7 +96,7 @@ protected CompletableFuture makeBuilder(int instanceId) { JsonObjectBuilder builder = Json.createObjectBuilder() .add("iid", instanceId) - .add("type", type) + .add("type", shortType) .add("perms", perms.build()) .add("format", format) .add("ev", false) diff --git a/src/main/java/com/beowulfe/hap/impl/json/AccessoryController.java b/src/main/java/com/beowulfe/hap/impl/json/AccessoryController.java index 67304e615..b45e1f6ca 100644 --- a/src/main/java/com/beowulfe/hap/impl/json/AccessoryController.java +++ b/src/main/java/com/beowulfe/hap/impl/json/AccessoryController.java @@ -65,8 +65,10 @@ public HttpResponse listing() throws Exception { } private CompletableFuture toJson(Service service, int interfaceId) throws Exception { + String shortType = + service.getType().replaceAll("^0*([0-9a-fA-F]+)-0000-1000-8000-0026BB765291$", "$1"); JsonObjectBuilder builder = - Json.createObjectBuilder().add("iid", ++interfaceId).add("type", service.getType()); + Json.createObjectBuilder().add("iid", ++interfaceId).add("type", shortType); List characteristics = service.getCharacteristics(); Collection> characteristicFutures = new ArrayList<>(characteristics.size());