From 940a9905db4ab2c1130aa5e66c5e296032d9f287 Mon Sep 17 00:00:00 2001 From: mlobstein Date: Sat, 1 Jun 2024 03:15:59 -0500 Subject: [PATCH] Add support for SDDP IDENTIFY packets (#4263) Signed-off-by: Michael Lobstein --- .../discovery/sddp/SddpDiscoveryService.java | 3 +- .../sddp/test/SddpDiscoveryServiceTests.java | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.core.config.discovery.sddp/src/main/java/org/openhab/core/config/discovery/sddp/SddpDiscoveryService.java b/bundles/org.openhab.core.config.discovery.sddp/src/main/java/org/openhab/core/config/discovery/sddp/SddpDiscoveryService.java index f54181b19..4e1076da5 100644 --- a/bundles/org.openhab.core.config.discovery.sddp/src/main/java/org/openhab/core/config/discovery/sddp/SddpDiscoveryService.java +++ b/bundles/org.openhab.core.config.discovery.sddp/src/main/java/org/openhab/core/config/discovery/sddp/SddpDiscoveryService.java @@ -85,6 +85,7 @@ public class SddpDiscoveryService extends AbstractDiscoveryService private static final String SEARCH_RESPONSE_HEADER = "SDDP/1.0 200 OK"; private static final String NOTIFY_ALIVE_HEADER = "NOTIFY ALIVE SDDP/1.0"; + private static final String NOTIFY_IDENTIFY_HEADER = "NOTIFY IDENTIFY SDDP/1.0"; private static final String NOTIFY_OFFLINE_HEADER = "NOTIFY OFFLINE SDDP/1.0"; private final Logger logger = LoggerFactory.getLogger(SddpDiscoveryService.class); @@ -160,7 +161,7 @@ public class SddpDiscoveryService extends AbstractDiscoveryService if (lines.size() > 1) { String statement = lines.get(0).strip(); boolean offline = statement.startsWith(NOTIFY_OFFLINE_HEADER); - if (offline || statement.startsWith(NOTIFY_ALIVE_HEADER) + if (offline || statement.startsWith(NOTIFY_ALIVE_HEADER) || statement.startsWith(NOTIFY_IDENTIFY_HEADER) || statement.startsWith(SEARCH_RESPONSE_HEADER)) { Map headers = new HashMap<>(); for (int i = 1; i < lines.size(); i++) { diff --git a/bundles/org.openhab.core.config.discovery.sddp/src/test/java/org/openhab/core/config/discovery/sddp/test/SddpDiscoveryServiceTests.java b/bundles/org.openhab.core.config.discovery.sddp/src/test/java/org/openhab/core/config/discovery/sddp/test/SddpDiscoveryServiceTests.java index ee571e3bd..249bb97ad 100644 --- a/bundles/org.openhab.core.config.discovery.sddp/src/test/java/org/openhab/core/config/discovery/sddp/test/SddpDiscoveryServiceTests.java +++ b/bundles/org.openhab.core.config.discovery.sddp/src/test/java/org/openhab/core/config/discovery/sddp/test/SddpDiscoveryServiceTests.java @@ -54,6 +54,18 @@ public class SddpDiscoveryServiceTests { Driver: "projector_JVCKENWOOD_DLA-RS3100_NZ8.c4i" """; + private static final String IDENTIFY_NOTIFICATION = """ + NOTIFY IDENTIFY SDDP/1.0 + From: "192.168.4.237:1902" + Host: "JVC_PROJECTOR-E0DADC152802" + Type: "JVCKENWOOD:Projector" + Primary-Proxy: "projector" + Proxies: "projector" + Manufacturer: "JVCKENWOOD" + Model: "DLA-RS3100_NZ8" + Driver: "projector_JVCKENWOOD_DLA-RS3100_NZ8.c4i" + """; + private static final String BAD_HEADER = """ SDDP/1.0 404 NOT FOUND\r From: "192.168.4.237:1902"\r @@ -115,6 +127,29 @@ public class SddpDiscoveryServiceTests { } } + @Test + void testIdentifyNotification() throws Exception { + try (SddpDiscoveryService service = new SddpDiscoveryService(null, networkAddressService, + mock(TranslationProvider.class), mock(LocaleProvider.class))) { + Optional deviceOptional = service.createSddpDevice(IDENTIFY_NOTIFICATION); + assertTrue(deviceOptional.isPresent()); + SddpDevice device = deviceOptional.orElse(null); + assertNotNull(device); + assertEquals("192.168.4.237:1902", device.from); + assertEquals("JVC_PROJECTOR-E0DADC152802", device.host); + assertTrue(device.maxAge.isBlank()); + assertEquals("JVCKENWOOD:Projector", device.type); + assertEquals("projector", device.primaryProxy); + assertEquals("projector", device.proxies); + assertEquals("JVCKENWOOD", device.manufacturer); + assertEquals("DLA-RS3100_NZ8", device.model); + assertEquals("projector_JVCKENWOOD_DLA-RS3100_NZ8.c4i", device.driver); + assertEquals("192.168.4.237", device.ipAddress); + assertEquals("e0-da-dc-15-28-02", device.macAddress); + assertEquals("1902", device.port); + } + } + @Test void testBadHeader() throws Exception { try (SddpDiscoveryService service = new SddpDiscoveryService(null, networkAddressService,