Skip to content

Commit 987b894

Browse files
authored
[nanoleaf] Suppress ipv6 addr in controller discovery (openhab#17724)
* stabilize nanoleaf binding:suppress ipv6 addresses in controller discovery Signed-off-by: Stefan Höhn <[email protected]>
1 parent da97e57 commit 987b894

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

bundles/org.openhab.binding.nanoleaf/README.md

+2-16
Original file line numberDiff line numberDiff line change
@@ -132,22 +132,8 @@ The controller thing has the following parameters:
132132
**Important note on the topic of IPV6 ip addresses:**
133133

134134
With firmware version 8.5.2 or newer, panels may change between being OFFLINE and ONLINE.
135-
This is due to the fact that if they are discovered with IPv6 addresses, the binding is not able to correctly send API requests to the devices.
136-
It is therefore recommended to disable IPv6 on the openHAB server.
137-
138-
This can e.g. be achieved on openHABian the following way:
139-
140-
```shell
141-
sudo nano /etc/sysctl.conf`
142-
```
143-
144-
Add the following at the bottom of the file:
145-
146-
```ini
147-
net.ipv6.conf.all.disable_ipv6 = 1
148-
net.ipv6.conf.default.disable_ipv6 = 1
149-
net.ipv6.conf.lo.disable_ipv6 = 1
150-
```
135+
This is because if they are discovered with IPv6 addresses, the binding is not able to correctly send API requests to the devices which leads to an unstable behaviour.
136+
To avoid this, the binding will only discover devices based on their IPv4 address.
151137

152138
Reboot your server after the change.
153139

bundles/org.openhab.binding.nanoleaf/src/main/java/org/openhab/binding/nanoleaf/internal/discovery/NanoleafMDNSDiscoveryParticipant.java

+11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
import static org.openhab.binding.nanoleaf.internal.NanoleafBindingConstants.*;
1616

17+
import java.net.InetAddress;
18+
import java.net.UnknownHostException;
1719
import java.util.HashMap;
1820
import java.util.Map;
1921
import java.util.Set;
@@ -66,6 +68,15 @@ public String getServiceType() {
6668
}
6769
final Map<String, Object> properties = new HashMap<>(2);
6870
String host = service.getHostAddresses()[0];
71+
try {
72+
if (InetAddress.getByName(host).getAddress().length != 4) {
73+
logger.debug("Ignoring IPv6 address for nanoleaf controllers: {}", host);
74+
return null;
75+
}
76+
} catch (UnknownHostException e) {
77+
logger.warn("Error while checking IP address for nanoleaf controller: {}", host);
78+
return null;
79+
}
6980
properties.put(CONFIG_ADDRESS, host);
7081
int port = service.getPort();
7182
properties.put(CONFIG_PORT, port);

0 commit comments

Comments
 (0)