Not really sure if this in important enough to actually do - but if the consensus is that it's a good idea, I can add it pretty easily...
It would be nice if this interface included a listener for changes to the addresses (propertychangelistener or custom listener).
If there is a binding (let's say the NEEO Brain binding) that registers a callback URL with the remote device and our primary address changes, that callback needs to be updated. Currently, the only way to 'update' that callback is to restart the binding - but if there was a listener on the interface, then it can be done automatically.
Thoughts?
What is your plan that your implementation looks like?
AFAIK the JVM does not provide a method to watch for that changes.
Do you consider to schedule a job that checks the address of an interface every x seconds and identify the change yourself?
Then we should perhaps think about "interface gone" and "interface added", too (up / down, too?).
I will admit - I haven't looked into it yet because I really an unsure whether this is a good idea. Basically I was thinking when someone set's the address via the paperui, there should be a callback with the old/new value. I wasn't thinking at the hardware level at all - just at the configuration level..
I have a need on something like this and is starting to work on it. The API should be just a plain change listener. The implementation is probably just scheduled polling.
I have misunderstood the requirement. The PR is hardware level detection of network interface rather than the values changed in the paper ui.
@tmrobert8 Did you have a look at #5802 yet? Does this suit your needs for a address change listener? I guess your use-case can be covered by that. Would you like to give it a try and close this issue afterwards, please?
Yes it does. I'll pull the latest and give it a try. Will close afterwards
@triller-telekom @garytse
Actually this does NOT (atleast from what I was envisioning) - what I was hoping a listener that will notify me of primary ip address change (ie that is set via PaperUI->Configuration->System->Network Settings->Primary Address). The design Gary put together would work however - just add a "onPrimaryAddressChange(String oldIpAddress, String new ipAddress)" then call it on the poll method if the address has changed since the last poll
@garytse Such a method would be API breaking. Do you think its worth adding it to your interface?
I see no harm adding it; mDNS and jUPnP discovery may need to adapt the change simultaneously. I'm on holiday so won't be touching this for a while. Feel free to change.
The implementation may be a little more tricky -- it's harder to tell which IP is updated to what new IP; I could only think of associating that with the MAC.
Take for example, when a WiFi switches the network, both IPv4 and IPv6 address are changed.
I think @tmrobert8 was planning to watch for changes on the primaryAddress field, i.e. notifying listeners once this is set.
Would you like to come up with a PR for that @tmrobert8 ?
Will do
@triller-telekom
Ok - this is going to sound really stupid but I've forked the repository, created my new branch and made my changes locally (note: this is the first time I've tried to modify the smarthome stuff - so consider me a newbie here).
I'm using the openHAB eclipse environment btw. I've modified my binding to use the NetworkAddressChangeListener - everything in eclipse compiles fine but when I run it - I get
Scheduled runnable ended with an exceptionjava.lang.NoClassDefFoundError: org/eclipse/smarthome/core/net/NetworkAddressChangeListener
(btw - someone should add a space between exceptionjava in that message - but that's a different issue).
How do I expose the changes to the smarthome project to the openhab bindings?
@tmrobert8 No worries, there are no dump questions :)
You have changed the NetworkAddressChangeListener which is in the bundle org.eclipse.smarthome.core. The openHAB IDE is configured to use pre-compiled bundles for all bundles which are from ESH. So what you ened to to to make it pick up your change is:
org.eclipse.smarthome.core and remove it from the targetplatform branch and check its chekbox for the workspace branch.If you run openHAB with this modified run configuration it will pick up all the changes you did in your workspace to that bundle. Hope that helps.
@triller-telekom
Thanks - that helped! (also need to do that on the upnp and mdns ones since they reference it as well) - all good now.
Last question before I submit the PR - what's the naming standard (if there is one) for the branch name?
@tmrobert8 branch name does not matter, its local to your fork of the repo.
Good enough - PR https://github.com/eclipse/smarthome/pull/5919
Since #5919 has been merged, this can be closed now.
@kaikreuzer Please close this issue, thanks.