I don’t now if that’s the right category to get some help to integrate the NetworkAddressService to get the primary IP.
Preparation in the Code:
import org.eclipse.smarthome.core.net.NetworkAddressService;
Class:
private NetworkAddressService networkAddressService;
Code inside the ThingFactoryClass class (tried also others):
@Reference
protected void setNetworkAddressService(NetworkAddressService networkAddressService) {
this.networkAddressService = networkAddressService;
}
protected void unsetNetworkAddressService(NetworkAddressService networkAddressService) {
this.networkAddressService = null;
}
Usage:
networkAddressService.getPrimaryIpv4HostAddress()
Sounds easy, but the problem is that the setNetworkAddressService() is never called. The binding gets loaded, but I reach never the breakpoint I set on the routine.
I checked OSGI-INF/ThingFactory.xml
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.2.0" activate="activate" configuration-pid="telekomtv" immediate="true" name="org.openhab.binding.telekomtv.internal.TelekomTVHandlerFactory">
<service servicefactory="false">
<provide interface="org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory"/>
<provide interface="org.openhab.binding.telekomtv.internal.TelekomTVHandlerFactory"/>
</service>
<reference bind="setNetworkAddressService" interface="org.eclipse.smarthome.core.net.NetworkAddressService" name="NetworkAddressService" unbind="unsetNetworkAddressService"/>
<implementation class="org.openhab.binding.telekomtv.internal.TelekomTVHandlerFactory"/>
</scr:component>
so the @Reference works. Otherwise Eclipse told me that this is not a public interface.
Is it correct that I need to add a rule to the Java Build Path to get access to
I checked out ESH API Reference->NetworkAddressService documentation, but it does not contain no information how integrate the class. Need some help.