I’m currently developing my first binding and I still have a lot to learn. However I’ve got one question that I could not find in the docs so far: Given that I have a perfectly fine initialised thing/thing handler. What happens to this thing (in terms of lifecycle events) when I change a property of the thing in the UI? Does this create some kind of trigger event that I can use to reinitialize the thing handler if necessary? Or will the handler be disposed and reinitialised by the framework anyway (my first experiments seem to lead to the conclusion that the latter is not the case)? Thank you for your insights
As far I remember thing properties are read only and can not be influenced by end user. What user can change are configurations which are defined in thing xml / config descriptor. Update to such config triggers thing lifecycle (destruct/initialize).
The @Modified annotation is something which works on different level - namely on OSGi services. This is a different mechanism which will impact ThingHandlerFactory if peoperly applied.
If I assume you mean CONFIG is changed by the user after the thing is online.
The dispose() is called allowing you to do any cleanup, then the initialise() is called allowing you to update the CONFIG class and perform any needed code.
The dispose() should stop any extra created threads and it gets called if you remove a thing, or if a CONFIG gets changed.
There is a lifecycle flow chart in the docs somewhere.
I use the pause button on the thing to test this life cycle or can change a config.
Everything works fine when I create an item either manually or through discovery. However when I change e.g. the parameter appLockTimeout in the UI the initialize method gets called twice by the framework.
In the first call the config matches the changed config in the UI. In the second call, the config options are back at their defaults. I’m pretty sure that I’m missing something rather obvious there but I have no idea what that could be!?
Edit: I realised that this only happens to my bridge. Other things get initialised only once. The special thing about this bridge is that it is itself bound to another bridge. However I don’t really see how this would have an impact on the way things get initialised. I also thought there might be an exception thrown somewhere but this does not seem to be the case (tried with a surrounding try catch for the whole method code).
Edit2: I added another config parameter. What should I say: When I change this parameter it works as expected. When I change any of the ones in my code above I still get the double initialisation issue…
I finally got behind the mystery. The properties were always reset through discovery results happening in the background. I wasn’t expecting that a new discovery result would simply overwrite the user defined properties. However now that I know this was simple to solve: I just removed these properties in the discovery service and now I can change the properties manually.
One exception remains the base topic but that property cannot be left empty in the discovery. Other mqtt apps behave the same way.