Add support for SDDP IDENTIFY packets (#4263)

Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
This commit is contained in:
mlobstein 2024-06-01 03:15:59 -05:00 committed by GitHub
parent 8aa6b28104
commit 940a9905db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 1 deletions

View File

@ -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<String, String> headers = new HashMap<>();
for (int i = 1; i < lines.size(); i++) {

View File

@ -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<SddpDevice> 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,