Custom AddOn: Retrieve Configuration Settings in PaperUI Programmically


(Felix Lo) #1

Hi,

I know how to retrieve configuration of a custom addon in /service/ folder. But, how do I retrieve those custom (i.e. custom UI) saved in PaperUI? My code to retrieve settings saved in xxxx.cfg are as below, which return a list of property map. Thanks

bundleContext = componentContext.getBundleContext();

            ConfigurationAdmin confAdmin = (ConfigurationAdmin) bundleContext
                    .getService(bundleContext.getServiceReference(ConfigurationAdmin.class.getName()));
            Configuration conf;

            serviceId = componentContext.getProperties().get("service.pid").toString();
            conf = confAdmin.getConfiguration(serviceId, null);


(Felix Lo) #2

I have looked at OpenHabCloud connector and HabPanel examples, but couldn’t figure out why the configs are not passed to my code. Here are what I have extracted from OpenHabCloud and i also followed OSGI-INF file format as well. Please give me some pointers what I am missing. Cheers

Actual Java Code

 protected void activate(BundleContext context, Map<String, ?> config) {
        clientVersion = StringUtils.substringBefore(context.getBundle().getVersion().toString(), ".qualifier");
        localPort = HttpServiceUtil.getHttpServicePort(context);
        if (localPort == -1) {
            logger.warn("openHAB Cloud connector not started, since no local HTTP port could be determined");
        } else {
            logger.debug("openHAB Cloud connector activated");
            checkJavaVersion();
            modified(config);
        }
    }

OSGI-INF

<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" configuration-policy="optional" deactivate="deactivate" immediate="true" name="org.openhab.openhabcloud">
   <implementation class="org.openhab.io.openhabcloud.internal.CloudService"/>
   <service>
       <provide interface="org.eclipse.smarthome.core.events.EventSubscriber"/>
       <provide interface="org.eclipse.smarthome.model.script.engine.action.ActionService"/>
   </service>
   <reference bind="setItemRegistry" cardinality="1..1" interface="org.eclipse.smarthome.core.items.ItemRegistry" name="ItemRegistry" policy="dynamic" unbind="unsetItemRegistry"/>
   <reference bind="setEventPublisher" cardinality="0..1" interface="org.eclipse.smarthome.core.events.EventPublisher" name="EventPublisher" policy="dynamic" unbind="unsetEventPublisher"/>
   <property name="service.pid" type="String" value="org.openhab.openhabcloud"/>
   <property name="service.config.description.uri" type="String" value="io:openhabcloud"/>
   <property name="service.config.label" type="String" value="openHAB Cloud"/>
   <property name="service.config.category" type="String" value="io"/>
</scr:component>