[nanoleaf] Suppress ipv6 addr in controller discovery (#17724)

* stabilize nanoleaf binding:suppress ipv6 addresses in controller discovery

Signed-off-by: Stefan Höhn <stefan.hoehn@nfon.com>
This commit is contained in:
stefan-hoehn 2024-11-10 13:44:37 +01:00 committed by GitHub
parent da97e57aac
commit 987b894458
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 16 deletions

View File

@ -132,22 +132,8 @@ The controller thing has the following parameters:
**Important note on the topic of IPV6 ip addresses:**
With firmware version 8.5.2 or newer, panels may change between being OFFLINE and ONLINE.
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.
It is therefore recommended to disable IPv6 on the openHAB server.
This can e.g. be achieved on openHABian the following way:
```shell
sudo nano /etc/sysctl.conf`
```
Add the following at the bottom of the file:
```ini
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
```
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.
To avoid this, the binding will only discover devices based on their IPv4 address.
Reboot your server after the change.

View File

@ -14,6 +14,8 @@ package org.openhab.binding.nanoleaf.internal.discovery;
import static org.openhab.binding.nanoleaf.internal.NanoleafBindingConstants.*;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@ -66,6 +68,15 @@ public class NanoleafMDNSDiscoveryParticipant implements MDNSDiscoveryParticipan
}
final Map<String, Object> properties = new HashMap<>(2);
String host = service.getHostAddresses()[0];
try {
if (InetAddress.getByName(host).getAddress().length != 4) {
logger.debug("Ignoring IPv6 address for nanoleaf controllers: {}", host);
return null;
}
} catch (UnknownHostException e) {
logger.warn("Error while checking IP address for nanoleaf controller: {}", host);
return null;
}
properties.put(CONFIG_ADDRESS, host);
int port = service.getPort();
properties.put(CONFIG_PORT, port);