Fix NUPnP discovery after firmware change (#15622)

Fixes #15598

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen
2023-09-23 19:05:32 +02:00
committed by GitHub
parent e562c22a2f
commit c9e6417754
2 changed files with 21 additions and 9 deletions

View File

@@ -55,15 +55,20 @@ public class HueBridgeNupnpDiscoveryOSGITest extends JavaOSGiTest {
private static final ThingTypeUID BRIDGE_THING_TYPE_UID = new ThingTypeUID("hue", "bridge");
private static final String IP1 = "192.168.31.17";
private static final String IP2 = "192.168.30.28";
private static final String IP3 = "192.168.30.29";
private static final String SN1 = "001788fffe20057f";
private static final String SN2 = "001788fffe141b41";
private static final String SN3 = "001788fffe141b42";
private static final ThingUID BRIDGE_THING_UID_1 = new ThingUID(BRIDGE_THING_TYPE_UID, SN1);
private static final ThingUID BRIDGE_THING_UID_2 = new ThingUID(BRIDGE_THING_TYPE_UID, SN2);
private static final ThingUID BRIDGE_THING_UID_3 = new ThingUID(BRIDGE_THING_TYPE_UID, SN3);
private final String validBridgeDiscoveryResult = "[{\"id\":\"" + SN1 + "\",\"internalipaddress\":" + IP1
+ "},{\"id\":\"" + SN2 + "\",\"internalipaddress\":" + IP2 + "}]";
+ "},{\"id\":\"" + SN2 + "\",\"internalipaddress\":" + IP2 + "},{\"id\":\"" + SN3
+ "\",\"internalipaddress\":" + IP3 + "}]";
private @Nullable String discoveryResult;
private String expBridgeDescription = "{\"name\":\"Philips hue\",\"datastoreversion\":\"149\",\"swversion\":\"1957113050\",\"apiversion\":\"1.57.0\",\"mac\":\"00:11:22:33:44\",\"bridgeid\":\"$SN\",\"factorynew\":false,\"replacesbridgeid\":null,\"modelid\":\"BSB002\",\"starterkitid\":\"\"}";
private String expBridgeDescription1 = "{\"name\":\"Philips hue\",\"datastoreversion\":\"149\",\"swversion\":\"1957113050\",\"apiversion\":\"1.57.0\",\"mac\":\"00:11:22:33:44\",\"bridgeid\":\"$SN\",\"factorynew\":false,\"replacesbridgeid\":null,\"modelid\":\"BSB002\",\"starterkitid\":\"\"}";
private String expBridgeDescription2 = "{\"name\":\"Hue Bridge\",\"datastoreversion\":\"161\",\"swversion\":\"1959194040\",\"apiversion\":\"1.59.0\",\"mac\":\"00:11:22:33:44\",\"bridgeid\":\"$SN\",\"factorynew\":false,\"replacesbridgeid\":null,\"modelid\":\"BSB002\",\"starterkitid\":\"\"}";
private void checkDiscoveryResult(@Nullable DiscoveryResult result, String expIp, String expSn) {
if (result == null) {
@@ -98,9 +103,11 @@ public class HueBridgeNupnpDiscoveryOSGITest extends JavaOSGiTest {
if (url.contains("meethue")) {
return discoveryResult;
} else if (url.contains(IP1)) {
return expBridgeDescription.replaceAll("$SN", SN1);
return expBridgeDescription1.replaceAll("$SN", SN1);
} else if (url.contains(IP2)) {
return expBridgeDescription.replaceAll("$SN", SN2);
return expBridgeDescription1.replaceAll("$SN", SN2);
} else if (url.contains(IP3)) {
return expBridgeDescription2.replaceAll("$SN", SN3);
}
throw new IOException();
}
@@ -162,20 +169,24 @@ public class HueBridgeNupnpDiscoveryOSGITest extends JavaOSGiTest {
sut.startScan();
waitForAssert(() -> {
assertThat(results.size(), is(2));
assertThat(results.size(), is(3));
assertThat(results.get(BRIDGE_THING_UID_1), is(notNullValue()));
checkDiscoveryResult(results.get(BRIDGE_THING_UID_1), IP1, SN1);
assertThat(results.get(BRIDGE_THING_UID_2), is(notNullValue()));
checkDiscoveryResult(results.get(BRIDGE_THING_UID_2), IP2, SN2);
assertThat(results.get(BRIDGE_THING_UID_3), is(notNullValue()));
checkDiscoveryResult(results.get(BRIDGE_THING_UID_3), IP3, SN3);
final List<DiscoveryResult> inboxResults = inbox.stream().filter(forThingTypeUID(BRIDGE_THING_TYPE_UID))
.collect(Collectors.toList());
assertTrue(inboxResults.size() >= 2);
assertTrue(inboxResults.size() >= 3);
assertThat(inboxResults.stream().filter(result -> result.getThingUID().equals(BRIDGE_THING_UID_1))
.findFirst().orElse(null), is(notNullValue()));
assertThat(inboxResults.stream().filter(result -> result.getThingUID().equals(BRIDGE_THING_UID_2))
.findFirst().orElse(null), is(notNullValue()));
assertThat(inboxResults.stream().filter(result -> result.getThingUID().equals(BRIDGE_THING_UID_3))
.findFirst().orElse(null), is(notNullValue()));
});
}
@@ -259,7 +270,7 @@ public class HueBridgeNupnpDiscoveryOSGITest extends JavaOSGiTest {
});
// invalid bridge description
expBridgeDescription = "";
expBridgeDescription1 = "";
discoveryResult = "[{\"id\":\"001788fffe20057f\",\"internalipaddress\":" + IP1 + "}]";
sut.startScan();
waitForAssert(() -> {