[hue] Implement CLIP 2 / API v2 (#13570)
* [hue] Implement CLIP 2 / API v2 --------- Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
This commit is contained in:
committed by
GitHub
parent
dd913e5245
commit
bd4a8385e0
@@ -15,7 +15,8 @@ package org.openhab.binding.hue.internal.discovery;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.openhab.binding.hue.internal.HueBindingConstants.THING_TYPE_BRIDGE;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.openhab.binding.hue.internal.HueBindingConstants.*;
|
||||
import static org.openhab.core.config.discovery.inbox.InboxPredicates.forThingTypeUID;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -25,15 +26,16 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openhab.binding.hue.internal.HueBindingConstants;
|
||||
import org.openhab.core.config.discovery.DiscoveryListener;
|
||||
import org.openhab.core.config.discovery.DiscoveryResult;
|
||||
import org.openhab.core.config.discovery.DiscoveryService;
|
||||
import org.openhab.core.config.discovery.inbox.Inbox;
|
||||
import org.openhab.core.test.java.JavaOSGiTest;
|
||||
import org.openhab.core.test.storage.VolatileStorageService;
|
||||
import org.openhab.core.thing.ThingRegistry;
|
||||
import org.openhab.core.thing.ThingTypeUID;
|
||||
import org.openhab.core.thing.ThingUID;
|
||||
|
||||
@@ -62,7 +64,7 @@ public class HueBridgeNupnpDiscoveryOSGITest extends JavaOSGiTest {
|
||||
|
||||
private void checkDiscoveryResult(DiscoveryResult result, String expIp, String expSn) {
|
||||
assertThat(result.getBridgeUID(), nullValue());
|
||||
assertThat(result.getLabel(), is(String.format(HueBindingConstants.DISCOVERY_LABEL_PATTERN, expIp)));
|
||||
assertThat(result.getLabel(), is(String.format(DISCOVERY_LABEL_PATTERN, expIp)));
|
||||
assertThat(result.getProperties().get("ipAddress"), is(expIp));
|
||||
assertThat(result.getProperties().get("serialNumber"), is(expSn));
|
||||
}
|
||||
@@ -81,6 +83,10 @@ public class HueBridgeNupnpDiscoveryOSGITest extends JavaOSGiTest {
|
||||
|
||||
// Mock class which only overrides the doGetRequest method in order to make the class testable
|
||||
class ConfigurableBridgeNupnpDiscoveryMock extends HueBridgeNupnpDiscovery {
|
||||
public ConfigurableBridgeNupnpDiscoveryMock(ThingRegistry thingRegistry) {
|
||||
super(thingRegistry);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doGetRequest(String url) throws IOException {
|
||||
if (url.contains("meethue")) {
|
||||
@@ -92,6 +98,11 @@ public class HueBridgeNupnpDiscoveryOSGITest extends JavaOSGiTest {
|
||||
}
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isClip2Supported(@NonNull String ipAddress) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
@@ -109,8 +120,8 @@ public class HueBridgeNupnpDiscoveryOSGITest extends JavaOSGiTest {
|
||||
|
||||
@Test
|
||||
public void bridgeThingTypeIsSupported() {
|
||||
assertThat(sut.getSupportedThingTypes().size(), is(1));
|
||||
assertThat(sut.getSupportedThingTypes().iterator().next(), is(THING_TYPE_BRIDGE));
|
||||
assertThat(sut.getSupportedThingTypes().size(), is(2));
|
||||
assertThat(sut.getSupportedThingTypes().contains(THING_TYPE_BRIDGE), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -121,7 +132,7 @@ public class HueBridgeNupnpDiscoveryOSGITest extends JavaOSGiTest {
|
||||
inbox.remove(oldResult.getThingUID());
|
||||
}
|
||||
|
||||
sut = new ConfigurableBridgeNupnpDiscoveryMock();
|
||||
sut = new ConfigurableBridgeNupnpDiscoveryMock(mock(ThingRegistry.class));
|
||||
registerService(sut, DiscoveryService.class.getName());
|
||||
discoveryResult = validBridgeDiscoveryResult;
|
||||
final Map<ThingUID, DiscoveryResult> results = new HashMap<>();
|
||||
@@ -170,7 +181,7 @@ public class HueBridgeNupnpDiscoveryOSGITest extends JavaOSGiTest {
|
||||
inbox.remove(oldResult.getThingUID());
|
||||
}
|
||||
|
||||
sut = new ConfigurableBridgeNupnpDiscoveryMock();
|
||||
sut = new ConfigurableBridgeNupnpDiscoveryMock(mock(ThingRegistry.class));
|
||||
registerService(sut, DiscoveryService.class.getName());
|
||||
final Map<ThingUID, DiscoveryResult> results = new HashMap<>();
|
||||
registerDiscoveryListener(new DiscoveryListener() {
|
||||
|
||||
Reference in New Issue
Block a user