Binding config validation

My binding stores a key pair, used for communication, in its config. They are stored as Strings, because the config can only store strings and numbers, but in fact a valid key is a hexadecimal string exactly 32 bytes long.
So is it possible to add validation hooks to config fields, so that if the user mistypes, some error is presented? Currently i do the validation in @Modified callback and silently revert to an old key if the new one is invalid, but it feels that giving a clear error message would be better.

Another connected question: Is it possible to make some config items read-only even in expert mode? For example, in my case i have a pair of keys, private and public, in my binding config, but only private key is the actual item to store. Public key is derived from it, i put it into the config only to be displayed somewhere, because it also plays a role of host unique ID. Knowing it can be useful for diagnosing problems, should there be any. It makes completely no sense to change it even in expert mode.

There is no option to do this interactively. If something would be made possible it would mean it should be specified in the thing xml. Validation is currently done purely based on the xml so at that point the binding code itself is not touched. And any interaction with code is done via the rest api.

Current implementations check the configuration in initialize method and if not valid set the ThingStatus to OFFLINE with the specific failed validation as message. When the configuration is changed the thing is always reinitialized so initialize is always called and therefor can be used to do these validations.

You can set properties. These are readonly and when present and showing a thing in PaperUI will show a button: Show properties

Are they available for a Thing or for a Binding? Or for both? Where can i find information in the documentation ? Or can you tell me what bindings are using them, so i could find an example implementation ?

You could check the Shelly binding for example.

Thank you. Will do it later after my binding starts doing something and i’ll be ‘polishing’ it.

There is an option with a BridgeHandler which is first after the ‘binding’ in many cases. There is a convenient base class called ConfigStatusBridgeHandler which allows you to separate configuration validation from initialization code. It is not exactly what you asked for, but I found it handy in some cases.

I am not sure of your case but making a part of configuration at the binding level turns it into global variable for all bridges and things of given kind.

Cheers, Łukasz

Hello!
I am making it global because it is global. There’s only a single Danfoss cloud in the world, and the user has only one identity on it, by design.
I could force the user just to add a bridge, but it kinda doesn’t make sense and doesn’t feel intuitive. In existing cases the bridge has some physical manifestation (a controller box, a serial port, etc), and there can be many of them. This is not the case with Danfoss cloud.

A bridge Thing has not to be any physical stuff. Many bindings, e.g. Netatmo, Openwathermap, AmazonEchoControl, etc. use a bridge Thing for account login into a cloud. This is the design you should use for Danfoss cloud also.