How to update thing properties?

Hi,

I am new to openHAB2, but have worked with Karaf in the past and I’m familiar with OSGi in general.

I am writing a binding for a legacy lighting gateway. When first configuring the binding to communicate with the gateway over an http REST api, the first step is to press a sync button on the lighting gateway, then make a rest API call from openHAB to generate a long lived token that will be used by openHAB for all requests to the gateway in the future (including after an openHAB restart, so it can’t only be in memory).

I have a configuration defined for my lighting gateway as a bridge, and right now I am setting an empty property called “token” in the thing.

When I create the bridge, I can see in the jsondb that it has stored an empty value for my token property.

However, in my code, after getting the access token in the bridge handler, I do this:

updateProperty(BRIDGE_PROPERTY_TOKEN, token);

And if I view my thing in the UI, and press the “show properties” button, it correctly shows my token.

But in the jsondb, I never see the token property of my bridge thing updated to the value I set programtically, and if I restart openHAB, it reverts back to the blank value stored in the json db.

How do I get my in memory change of the property to persist to the db?

Thanks!

Answered my own question…

Things configured via DSL cannot have their properties updated and then persisted, it will only be an in memory change.

For me, this means instead of having a user manually add and configure a gateway based on an IP address, I need to instead use auto discovery, so that instead of creating the bridge via UI/DSL, it is instead created programatically in my discovery service, where the properties can be persisted.