Skip to content

Commit

Permalink
[hueemulation] Fix broken fallback address (openhab#7305)
Browse files Browse the repository at this point in the history
With the changes in openhab#6967 the HueEmulationServiceOSGiTest always fails for me.
The reason is that if the discoveryIps are not configured, it is no longer guaranteed it will use the primary IPv4 host address as fallback.
In my case the iterator on the HashSet would return an IPv6 address as first address.
By using a LinkedHashSet the order is preserved and it will again use the primary IPv4 host address as fallback.

Signed-off-by: Wouter Born <[email protected]>
Signed-off-by: Daan Meijer <[email protected]>
  • Loading branch information
wborn authored and DaanMeijer committed Sep 1, 2020
1 parent b2e6cd5 commit 77a030b
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
Expand Down Expand Up @@ -197,7 +197,7 @@ public void modified(Map<String, Object> properties) {
discoveryIps = Collections.unmodifiableSet(Stream.of(config.discoveryIps.split(",")).map(String::trim)
.map(this::byName).filter(e -> e != null).collect(Collectors.toSet()));
} else {
discoveryIps = new HashSet<>();
discoveryIps = new LinkedHashSet<>();
configuredAddress = byName(networkAddressService.getPrimaryIpv4HostAddress());
if (configuredAddress != null) {
discoveryIps.add(configuredAddress);
Expand All @@ -211,7 +211,7 @@ public void modified(Map<String, Object> properties) {
}
}

if (discoveryIps.size() < 1) {
if (discoveryIps.isEmpty()) {
try {
logger.info("No discovery ip specified. Trying to determine the host address");
configuredAddress = InetAddress.getLocalHost();
Expand Down Expand Up @@ -318,7 +318,7 @@ public String mapItemUIDtoHueID(Item item) {
}

public boolean isReady() {
return discoveryIps.size() > 0;
return !discoveryIps.isEmpty();
}

public HueEmulationConfig getConfig() {
Expand Down

0 comments on commit 77a030b

Please sign in to comment.