import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
-import org.openhab.binding.hue.internal.handler.HueBridgeHandler;
/**
- * Configuration for the {@link HueBridgeHandler}.
+ * Configuration for the {@link org.openhab.binding.hue.internal.handler.HueBridgeHandler}.
*
* @author Christoph Weitkamp - Initial contribution
*/
// Methods that convert gson exceptions into ApiExceptions
private <T> T safeFromJson(String json, Type typeOfT) throws ApiException {
try {
- return gson.fromJson(json, typeOfT);
+ @Nullable
+ T safe = gson.fromJson(json, typeOfT);
+ if (safe == null) {
+ throw new ApiException("JSON is null or empty");
+ }
+ return safe;
} catch (JsonParseException e) {
throw new ApiException("API returned unexpected result: " + e.getMessage());
}
private <T> T safeFromJson(String json, Class<T> classOfT) throws ApiException {
try {
- return gson.fromJson(json, classOfT);
+ @Nullable
+ T safe = gson.fromJson(json, classOfT);
+ if (safe == null) {
+ throw new ApiException("JSON is null or empty");
+ }
+ return safe;
} catch (JsonParseException e) {
throw new ApiException("API returned unexpected result: " + e.getMessage());
}
*/
package org.openhab.binding.hue.internal.discovery;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+
import com.google.gson.annotations.SerializedName;
/**
* @author Awelkiyar Wehabrebi - Initial contribution and API
* @author Christoph Knauf - Refactorings
*/
+@NonNullByDefault
public class BridgeJsonParameters {
- private String id;
+ private @Nullable String id;
@SerializedName("internalipaddress")
- private String internalIpAddress;
+ private @Nullable String internalIpAddress;
@SerializedName("macaddress")
- private String macAddress;
- private String name;
+ private @Nullable String macAddress;
+ private @Nullable String name;
+ @SuppressWarnings("unused")
private BridgeJsonParameters() {
// This no arguments constructor is required for Gson deserialization
}
this.name = name;
}
- public String getInternalIpAddress() {
+ public @Nullable String getInternalIpAddress() {
return internalIpAddress;
}
- public String getId() {
+ public @Nullable String getId() {
return id;
}
- public String getMacAddress() {
+ public @Nullable String getMacAddress() {
return macAddress;
}
- public String getName() {
+ public @Nullable String getName() {
return name;
}
}
*/
private void discoverHueBridges() {
for (BridgeJsonParameters bridge : getBridgeList()) {
- if (isReachableAndValidHueBridge(bridge)) {
- String host = bridge.getInternalIpAddress();
- String serialNumber = bridge.getId().toLowerCase();
- ThingUID uid = new ThingUID(THING_TYPE_BRIDGE, serialNumber);
- ThingUID legacyUID = null;
- String label = String.format(DISCOVERY_LABEL_PATTERN, host);
-
- if (isClip2Supported(host)) {
- legacyUID = uid;
- uid = new ThingUID(THING_TYPE_BRIDGE_API2, serialNumber);
- Optional<Thing> legacyThingOptional = getLegacyBridge(host);
- if (legacyThingOptional.isPresent()) {
- Thing legacyThing = legacyThingOptional.get();
- String label2 = legacyThing.getLabel();
- label = Objects.nonNull(label2) ? label2 : label;
- }
+ if (!isReachableAndValidHueBridge(bridge)) {
+ continue;
+ }
+ String host = bridge.getInternalIpAddress();
+ if (host == null) {
+ continue;
+ }
+ String id = bridge.getId();
+ if (id == null) {
+ continue;
+ }
+ String serialNumber = id.toLowerCase();
+ ThingUID uid = new ThingUID(THING_TYPE_BRIDGE, serialNumber);
+ ThingUID legacyUID = null;
+ String label = String.format(DISCOVERY_LABEL_PATTERN, host);
+
+ if (isClip2Supported(host)) {
+ legacyUID = uid;
+ uid = new ThingUID(THING_TYPE_BRIDGE_API2, serialNumber);
+ Optional<Thing> legacyThingOptional = getLegacyBridge(host);
+ if (legacyThingOptional.isPresent()) {
+ Thing legacyThing = legacyThingOptional.get();
+ String label2 = legacyThing.getLabel();
+ label = Objects.nonNull(label2) ? label2 : label;
}
+ }
- DiscoveryResultBuilder builder = DiscoveryResultBuilder.create(uid) //
- .withLabel(label) //
- .withProperty(HOST, host) //
- .withProperty(Thing.PROPERTY_SERIAL_NUMBER, serialNumber) //
- .withRepresentationProperty(Thing.PROPERTY_SERIAL_NUMBER);
-
- if (Objects.nonNull(legacyUID)) {
- builder.withProperty(PROPERTY_LEGACY_THING_UID, legacyUID.getAsString());
- }
+ DiscoveryResultBuilder builder = DiscoveryResultBuilder.create(uid) //
+ .withLabel(label) //
+ .withProperty(HOST, host) //
+ .withProperty(Thing.PROPERTY_SERIAL_NUMBER, serialNumber) //
+ .withRepresentationProperty(Thing.PROPERTY_SERIAL_NUMBER);
- thingDiscovered(builder.build());
+ if (Objects.nonNull(legacyUID)) {
+ builder.withProperty(PROPERTY_LEGACY_THING_UID, legacyUID.getAsString());
}
+
+ thingDiscovered(builder.build());
}
}
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
import org.openhab.core.config.discovery.DiscoveryService;
import org.openhab.core.config.discovery.upnp.UpnpDiscoveryParticipant;
-import org.openhab.core.config.discovery.upnp.internal.UpnpDiscoveryService;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
/**
* The {@link HueBridgeUPNPDiscoveryParticipant} is responsible for discovering new and removed Hue Bridges. It uses the
- * central {@link UpnpDiscoveryService}.
+ * central {@link org.openhab.core.config.discovery.upnp.internal.UpnpDiscoveryService}.
*
* The discovery through UPnP was replaced by mDNS discovery for recent bridges (V2).
* For old bridges (V1), the UPnP discovery is still required (as mDNS is not implemented).
*/
package org.openhab.binding.hue.internal.dto;
-import java.util.Comparator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
}
/**
- * compare API versions according to {@link Comparator#compare(Object, Object)}
+ * compare API versions according to {@link java.util.Comparator#compare(Object, Object)}
*
* @param other
* @return
import java.util.List;
import java.util.Map;
+import com.google.gson.annotations.SerializedName;
+
/**
* Detailed bridge info available if authenticated.
*
private String gateway;
private String proxyaddress;
private int proxyport;
- private Date UTC;
+ @SerializedName("UTC")
+ private Date utc;
private boolean linkbutton;
private Map<String, User> whitelist;
private SoftwareUpdate swupdate;
* @return time on the bridge
*/
public Date getUTCTime() {
- return UTC;
+ return utc;
}
/**
public List<FullLight> getLights() {
ArrayList<FullLight> lightsList = new ArrayList<>();
- for (String id : lights.keySet()) {
- FullLight light = lights.get(id);
+ for (Map.Entry<String, FullLight> entry : lights.entrySet()) {
+ String id = entry.getKey();
+ FullLight light = entry.getValue();
light.setId(id);
lightsList.add(light);
}
public List<FullGroup> getGroups() {
ArrayList<FullGroup> groupsList = new ArrayList<>();
- for (String id : groups.keySet()) {
- FullGroup group = groups.get(id);
+ for (Map.Entry<String, FullGroup> entry : groups.entrySet()) {
+ String id = entry.getKey();
+ FullGroup group = entry.getValue();
group.setId(id);
groupsList.add(group);
}
package org.openhab.binding.hue.internal.dto;
import java.lang.reflect.Type;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+
import com.google.gson.reflect.TypeToken;
/**
* @author Denis Dudnik - moved Jue library source code inside the smarthome Hue binding
* @author Laurent Garnier - field state added
*/
+@NonNullByDefault
public class FullGroup extends Group {
public static final Type GSON_TYPE = new TypeToken<Map<String, FullGroup>>() {
}.getType();
- private State action;
- private List<String> lights;
- private State groupState; // Will not be set by hue API
+ private @Nullable State action;
+ private @Nullable List<String> lights;
+ private @Nullable State groupState; // Will not be set by hue API
FullGroup() {
super();
*
* @return last state update
*/
- public State getAction() {
+ public @Nullable State getAction() {
return action;
}
* @return lights in the group
*/
public List<String> getLightIds() {
- return lights;
+ List<String> lights = this.lights;
+ return lights != null ? lights : new ArrayList<>();
}
/**
* @return current state
*/
public State getState() {
+ State groupState = this.groupState;
+ if (groupState == null) {
+ throw new IllegalStateException("Group state not initialized when requested");
+ }
return groupState;
}
}
public @Nullable String getNormalizedModelID() {
+ String modelid = this.modelid;
return modelid != null ? modelid.replaceAll(NORMALIZE_ID_REGEX, "_") : modelid;
}
package org.openhab.binding.hue.internal.dto;
import java.lang.reflect.Type;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
private @NonNullByDefault({}) String id;
private @NonNullByDefault({}) String name;
@SerializedName("lights")
- private @NonNullByDefault({}) List<String> lightIds;
+ private @Nullable List<String> lightIds;
@SerializedName("group")
private @Nullable String groupId;
private boolean recycle;
* @return list of lights that the scene applies to
*/
public List<String> getLightIds() {
- return lightIds;
+ List<String> lightIds = this.lightIds;
+ return lightIds != null ? lightIds : new ArrayList<String>();
}
/**
* </ol>
*/
public boolean isApplicableTo(FullGroup group) {
- if (getGroupId() == null) {
+ String groupId = this.groupId;
+ if (groupId == null) {
return getLightIds().stream().allMatch(id -> group.getLightIds().contains(id));
} else {
- String groupId = getGroupId();
- return groupId != null ? group.getId().contentEquals(groupId) : false;
+ return group.getId().contentEquals(groupId);
}
}
import java.util.List;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
*
* @author Q42 - Initial contribution
* @author Andre Fuechsel - search for lights with given serial number added
* @author Denis Dudnik - moved Jue library source code inside the smarthome Hue binding
*/
-@SuppressWarnings("unused")
+@NonNullByDefault
public class SearchForLightsRequest {
+ @SuppressWarnings("unused")
private List<String> deviceid;
public SearchForLightsRequest(List<String> deviceid) {
- if (deviceid != null && (deviceid.isEmpty() || deviceid.size() > 16)) {
+ if (deviceid.isEmpty() || deviceid.size() > 16) {
throw new IllegalArgumentException("Group cannot be empty and cannot have more than 16 lights");
}
- if (deviceid != null) {
- this.deviceid = deviceid;
- }
+ this.deviceid = deviceid;
}
}
package org.openhab.binding.hue.internal.dto;
import java.util.List;
-import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
}
this.name = name;
- this.lights = lights == null ? null : lights.stream().map(l -> l.getId()).collect(Collectors.toList());
+ this.lights = lights == null ? null : lights.stream().map(l -> l.getId()).toList();
}
}
sensorStatusListener.onSensorRemoved();
}
- if (discovery != null && sensor != null) {
+ if (discovery != null) {
discovery.removeSensorDiscovery(sensor);
}
});
lightStatusListener.onLightRemoved();
}
- if (discovery != null && light != null) {
+ if (discovery != null) {
discovery.removeLightDiscovery(light);
}
});
groupStatusListener.onGroupRemoved();
}
- if (discovery != null && group != null) {
+ if (discovery != null) {
discovery.removeGroupDiscovery(group);
}
});
private void setBridgeSceneChannelStateOptions(List<Scene> scenes, Map<String, FullGroup> groups) {
Map<String, String> groupNames = groups.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().getName()));
- List<StateOption> stateOptions = scenes.stream().map(scene -> scene.toStateOption(groupNames))
- .collect(Collectors.toList());
+ List<StateOption> stateOptions = scenes.stream().map(scene -> scene.toStateOption(groupNames)).toList();
stateDescriptionOptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), CHANNEL_SCENE),
stateOptions);
consoleScenesList = scenes.stream().map(scene -> "Id is \"" + scene.getId() + "\" for scene \""
- + scene.toStateOption(groupNames).getLabel() + "\"").collect(Collectors.toList());
+ + scene.toStateOption(groupNames).getLabel() + "\"").toList();
}
};
FullGroup group = handler.getGroupById(groupId);
if (group != null) {
stateOptions = updatedScenes.stream().filter(scene -> scene.isApplicableTo(group))
- .map(Scene::toStateOption).collect(Collectors.toList());
- consoleScenesList = updatedScenes
- .stream().filter(scene -> scene.isApplicableTo(group)).map(scene -> "Id is \"" + scene.getId()
- + "\" for scene \"" + scene.toStateOption().getLabel() + "\"")
- .collect(Collectors.toList());
+ .map(Scene::toStateOption).toList();
+ consoleScenesList = updatedScenes.stream().filter(scene -> scene.isApplicableTo(group))
+ .map(scene -> "Id is \"" + scene.getId() + "\" for scene \"" + scene.toStateOption().getLabel()
+ + "\"")
+ .toList();
}
}
stateDescriptionOptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), CHANNEL_SCENE),
StateDescriptionFragment oldStateDescriptionFragment = stateDescriptionFragments.get(channelUID);
if (!stateDescriptionFragment.equals(oldStateDescriptionFragment)) {
stateDescriptionFragments.put(channelUID, stateDescriptionFragment);
+ ItemChannelLinkRegistry itemChannelLinkRegistry = this.itemChannelLinkRegistry;
postEvent(ThingEventFactory.createChannelDescriptionChangedEvent(channelUID,
itemChannelLinkRegistry != null ? itemChannelLinkRegistry.getLinkedItemNames(channelUID) : Set.of(),
stateDescriptionFragment, oldStateDescriptionFragment));
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.library.unit.Units;
+import org.openhab.core.util.ColorUtil;
/**
* The {@link LightStateConverter} is responsible for mapping to/from jue types.
private static HSBType fromXYtoHSBType(State lightState) {
float[] xy = lightState.getXY();
- HSBType hsb = HSBType.fromXY(xy[0], xy[1]);
+ HSBType hsb = ColorUtil.xyToHsb(new double[] { xy[0], xy[1] });
int brightnessInPercent = (int) Math.ceil(lightState.getBrightness() / BRIGHTNESS_FACTOR);
brightnessInPercent = restrictToBounds(brightnessInPercent);
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import java.util.Arrays;
import java.util.List;
import org.eclipse.jdt.annotation.NonNullByDefault;
@Test
public void testIsApplicableToHasGroupIdMatchingGroup() {
String groupId = "groupId";
- List<String> lights = Arrays.asList("1", "2");
+ List<String> lights = List.of("1", "2");
Scene scene = new Scene(PLACEHOLDER, PLACEHOLDER, groupId, lights, false);
FullGroup group = new FullGroup(groupId, PLACEHOLDER, PLACEHOLDER, PLACEHOLDER_STATE, lights,
public void testIsApplicableToHasGroupIdNotMatchingGroup() {
String groupId = "groupId";
String otherGroupId = "otherGroupId";
- List<String> lights = Arrays.asList("1", "2");
- List<String> otherLights = Arrays.asList("1", "2", "3");
+ List<String> lights = List.of("1", "2");
+ List<String> otherLights = List.of("1", "2", "3");
Scene scene = new Scene(PLACEHOLDER, PLACEHOLDER, groupId, lights, false);
*/
@Test
public void testIsApplicableToNoGroupIdSceneLightsContainedInGroup() {
- List<String> lights = Arrays.asList("1", "2");
- List<String> moreLights = Arrays.asList("1", "2", "3");
+ List<String> lights = List.of("1", "2");
+ List<String> moreLights = List.of("1", "2", "3");
Scene scene = new Scene(PLACEHOLDER, PLACEHOLDER, null, lights, false);
*/
@Test
public void testIsApplicableToNoGroupIdSceneLightsNotContainedInGroup() {
- List<String> lights = Arrays.asList("1", "2");
- List<String> lessLights = Arrays.asList("1");
- List<String> differentLights = Arrays.asList("3");
+ List<String> lights = List.of("1", "2");
+ List<String> lessLights = List.of("1");
+ List<String> differentLights = List.of("3");
Scene scene = new Scene(PLACEHOLDER, PLACEHOLDER, null, lights, false);
import static org.junit.jupiter.api.Assertions.*;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.binding.ThingHandler;
/**
+ * @author Markus Rathgeb - Initial contribution
* @author Markus Rathgeb - migrated to plain Java test
*/
+@NonNullByDefault
public class AbstractHueOSGiTestParent extends JavaOSGiTest {
/**
} else {
assertNotNull(tmp);
assertEquals(clazz, tmp.getClass());
- throw new RuntimeException();
+ throw new IllegalStateException();
}
});
}
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.http.HttpStatus;
import org.junit.jupiter.api.AfterEach;
* @author Denis Dudnik - switched to internally integrated source of Jue library
* @author Markus Rathgeb - migrated to plain Java test
*/
+@NonNullByDefault
public class HueDeviceDiscoveryServiceOSGiTest extends AbstractHueOSGiTestParent {
- protected DiscoveryListener discoveryListener;
- protected ThingRegistry thingRegistry;
- protected Bridge hueBridge;
- protected HueBridgeHandler hueBridgeHandler;
- protected HueDeviceDiscoveryService discoveryService;
+ protected @Nullable DiscoveryListener discoveryListener;
+ protected @NonNullByDefault({}) ThingRegistry thingRegistry;
+ protected @NonNullByDefault({}) Bridge hueBridge;
+ protected @NonNullByDefault({}) HueBridgeHandler hueBridgeHandler;
+ protected @NonNullByDefault({}) HueDeviceDiscoveryService discoveryService;
- protected final ThingTypeUID BRIDGE_THING_TYPE_UID = new ThingTypeUID("hue", "bridge");
- protected final ThingUID BRIDGE_THING_UID = new ThingUID(BRIDGE_THING_TYPE_UID, "testBridge");
+ protected static final ThingTypeUID BRIDGE_THING_TYPE_UID = new ThingTypeUID("hue", "bridge");
+ protected static final ThingUID BRIDGE_THING_UID = new ThingUID(BRIDGE_THING_TYPE_UID, "testBridge");
@BeforeEach
public void setUp() {
}
@Override
- public Collection<ThingUID> removeOlderResults(DiscoveryService source, long timestamp,
- Collection<ThingTypeUID> thingTypeUIDs, ThingUID bridgeUID) {
+ public @Nullable Collection<ThingUID> removeOlderResults(DiscoveryService source, long timestamp,
+ @Nullable Collection<ThingTypeUID> thingTypeUIDs, @Nullable ThingUID bridgeUID) {
return null;
}
});
import java.util.Map;
import java.util.stream.Collectors;
-import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openhab.core.config.discovery.DiscoveryListener;
* @author Christoph Knauf - Initial contribution
* @author Markus Rathgeb - migrated to plain Java test
*/
+@NonNullByDefault
public class HueBridgeNupnpDiscoveryOSGITest extends JavaOSGiTest {
- HueBridgeNupnpDiscovery sut;
- VolatileStorageService volatileStorageService = new VolatileStorageService();
- DiscoveryListener discoveryListener;
- Inbox inbox;
-
- final ThingTypeUID BRIDGE_THING_TYPE_UID = new ThingTypeUID("hue", "bridge");
- final String ip1 = "192.168.31.17";
- final String ip2 = "192.168.30.28";
- final String sn1 = "001788fffe20057f";
- final String sn2 = "001788fffe141b41";
- final ThingUID BRIDGE_THING_UID_1 = new ThingUID(BRIDGE_THING_TYPE_UID, sn1);
- final ThingUID BRIDGE_THING_UID_2 = new ThingUID(BRIDGE_THING_TYPE_UID, sn2);
- final String validBridgeDiscoveryResult = "[{\"id\":\"" + sn1 + "\",\"internalipaddress\":" + ip1 + "},{\"id\":\""
- + sn2 + "\",\"internalipaddress\":" + ip2 + "}]";
- String discoveryResult;
- 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 void checkDiscoveryResult(DiscoveryResult result, String expIp, String expSn) {
+ private @NonNullByDefault({}) HueBridgeNupnpDiscovery sut;
+ private VolatileStorageService volatileStorageService = new VolatileStorageService();
+ private @Nullable DiscoveryListener discoveryListener;
+ private @NonNullByDefault({}) Inbox inbox;
+
+ 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 SN1 = "001788fffe20057f";
+ private static final String SN2 = "001788fffe141b41";
+ 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 final String validBridgeDiscoveryResult = "[{\"id\":\"" + SN1 + "\",\"internalipaddress\":" + IP1
+ + "},{\"id\":\"" + SN2 + "\",\"internalipaddress\":" + IP2 + "}]";
+ 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 void checkDiscoveryResult(@Nullable DiscoveryResult result, String expIp, String expSn) {
+ if (result == null) {
+ return;
+ }
assertThat(result.getBridgeUID(), nullValue());
assertThat(result.getLabel(), is(String.format(DISCOVERY_LABEL_PATTERN, expIp)));
assertThat(result.getProperties().get("ipAddress"), is(expIp));
}
@Override
- protected String doGetRequest(String url) throws IOException {
+ protected @Nullable String doGetRequest(String url) throws IOException {
if (url.contains("meethue")) {
return discoveryResult;
- } else if (url.contains(ip1)) {
- return expBridgeDescription.replaceAll("$SN", sn1);
- } else if (url.contains(ip2)) {
- return expBridgeDescription.replaceAll("$SN", sn2);
+ } else if (url.contains(IP1)) {
+ return expBridgeDescription.replaceAll("$SN", SN1);
+ } else if (url.contains(IP2)) {
+ return expBridgeDescription.replaceAll("$SN", SN2);
}
throw new IOException();
}
@Override
- protected boolean isClip2Supported(@NonNull String ipAddress) {
+ protected boolean isClip2Supported(String ipAddress) {
return false;
}
}
}
@Override
- public Collection<ThingUID> removeOlderResults(DiscoveryService source, long timestamp,
- Collection<ThingTypeUID> thingTypeUIDs, ThingUID bridgeUID) {
+ public @Nullable Collection<ThingUID> removeOlderResults(DiscoveryService source, long timestamp,
+ @Nullable Collection<ThingTypeUID> thingTypeUIDs, @Nullable ThingUID bridgeUID) {
return null;
}
});
waitForAssert(() -> {
assertThat(results.size(), is(2));
assertThat(results.get(BRIDGE_THING_UID_1), is(notNullValue()));
- checkDiscoveryResult(results.get(BRIDGE_THING_UID_1), ip1, sn1);
+ 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);
+ checkDiscoveryResult(results.get(BRIDGE_THING_UID_2), IP2, SN2);
final List<DiscoveryResult> inboxResults = inbox.stream().filter(forThingTypeUID(BRIDGE_THING_TYPE_UID))
.collect(Collectors.toList());
}
@Override
- public Collection<ThingUID> removeOlderResults(DiscoveryService source, long timestamp,
- Collection<ThingTypeUID> thingTypeUIDs, ThingUID bridgeUID) {
+ public @Nullable Collection<ThingUID> removeOlderResults(DiscoveryService source, long timestamp,
+ @Nullable Collection<ThingTypeUID> thingTypeUIDs, @Nullable ThingUID bridgeUID) {
return null;
}
});
// invalid bridge description
expBridgeDescription = "";
- discoveryResult = "[{\"id\":\"001788fffe20057f\",\"internalipaddress\":" + ip1 + "}]";
+ discoveryResult = "[{\"id\":\"001788fffe20057f\",\"internalipaddress\":" + IP1 + "}]";
sut.startScan();
waitForAssert(() -> {
assertThat(results.size(), is(0));
import java.lang.reflect.Field;
import java.util.concurrent.ScheduledExecutorService;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jetty.client.HttpClient;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
* @author Michael Grammling - Initial contribution
* @author Denis Dudnik - switched to internally integrated source of Jue library
*/
+@NonNullByDefault
public class HueBridgeHandlerOSGiTest extends AbstractHueOSGiTestParent {
private static final ThingTypeUID BRIDGE_THING_TYPE_UID = new ThingTypeUID(BINDING_ID, "bridge");
private static final String TEST_USER_NAME = "eshTestUser";
private static final String DUMMY_HOST = "1.2.3.4";
- private ThingRegistry thingRegistry;
-
- private ScheduledExecutorService scheduler;
+ private @NonNullByDefault({}) ThingRegistry thingRegistry;
+ private @NonNullByDefault({}) ScheduledExecutorService scheduler;
@BeforeEach
public void setUp() {