From ae4a8ecc43b2c72bb48ade78caa01e09394326fd Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Thu, 5 Jan 2023 18:08:41 -0700 Subject: [PATCH] check for AccessoryInformationService by UUID, not by class in case someone is using some form of decorator or replacement class, but is still exposing the proper type --- .../java/io/github/hapjava/server/impl/HomekitRegistry.java | 3 ++- .../hapjava/services/impl/AccessoryInformationService.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java b/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java index 3e3be9b6b..3c70cfb9e 100644 --- a/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java +++ b/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java @@ -43,7 +43,8 @@ public synchronized void reset() { try { newServices = new ArrayList<>(2); Collection services = accessory.getServices(); - if (!services.stream().anyMatch(s -> s instanceof AccessoryInformationService)) { + if (!services.stream() + .anyMatch(s -> s.getType().equals(AccessoryInformationService.TYPE))) { newServices.add(new AccessoryInformationService(accessory)); } for (Service service : services) { diff --git a/src/main/java/io/github/hapjava/services/impl/AccessoryInformationService.java b/src/main/java/io/github/hapjava/services/impl/AccessoryInformationService.java index 8aa7f3635..1fdb30d2a 100644 --- a/src/main/java/io/github/hapjava/services/impl/AccessoryInformationService.java +++ b/src/main/java/io/github/hapjava/services/impl/AccessoryInformationService.java @@ -14,6 +14,7 @@ /** Accessory Information service. */ public class AccessoryInformationService extends AbstractServiceImpl { + public static final String TYPE = "0000003E-0000-1000-8000-0026BB765291"; public AccessoryInformationService( IdentifyCharacteristic identify, @@ -22,7 +23,7 @@ public AccessoryInformationService( NameCharacteristic name, SerialNumberCharacteristic serialNumber, FirmwareRevisionCharacteristic firmwareRevision) { - super("0000003E-0000-1000-8000-0026BB765291"); + super(TYPE); addCharacteristic(identify); addCharacteristic(manufacturer); addCharacteristic(model);