Retrieve settings from /services/xxx.cfg

Hi,

Anyone knows how to read those configurations written in xxx.cfg file within an addon development? Some example reference will be much appreciated .Thanks

This is handled through the OSGi ManagedService interface so you don’t read the files directly.

I’m not really sure it’s wise to use this configuration method in OH2 except possibly for ‘static’ configuration since it won’t be configurable through the UI (although @kai may correct me if I’m wrong).

Small correction: It is actually not anymore advised to use ManagedService for Configuration Admin settings, see this discussion.

That’s right, it should only be used for static configuration. All configs that depend on a specific instance that you connect to should be moved into the Thing configuration. Nonetheless, I would like to have the cfg files also covered by the UI one day, so their meta-info should be already provided in the binding.xml like it is done here.

That’s what i thought so since the Thing comes in OH2. However, after reading some OH2 documents, I had a feeling that it was still being emphasized. Anyway, it is good to know reaffirmation from you guys. Cheers

Hi Kai,

Do you mind to show an example how this could be done? If i understand it correctly, you mean i need to implement an override mehod called protected void activate(ComponentContext componentContext) from my class inhertited from BaseThingHandlerFactory? But, from there, how do i get the configurations? Cheers

See e.g. https://github.com/openhab/openhab2/blob/master/addons/io/org.openhab.io.myopenhab/src/main/java/org/openhab/io/myopenhab/internal/MyOpenHABService.java#L97.

When using activate(ComponentContext componentContext) as in BaseThingHandlerFactory, you can do a componentContext.getProperties() in order to get hold of the config properties.