I created a simple add on to backup my Home Assistant backups to Azure using Restic. One thing that I noticed yesterday when I installed the add-on after testing locally was that the configuration page in HA wasn’t quite doing what I’d expect. In my config.yaml I’ve defined the following
What I noticed is that folder was in fact optional on the configuration screen, but when I tried to start the add-on I got an error that there wasn’t a value set. As soon as I filled in the folder value everything was fine but I’m not sure why that’s not actually optional. I’d also tried "str?" as the schema and received the same result.
The other thing that I noticed is that key wasn’t being treated as a password, in fact it was being displayed in plain text on the screen. I have a sneaking suspicion that these two issues are related, but I’m not sure how to fix it. Any tips?
Try removing the fields you set to null in options. If the field exists it’s value is validated, even if it’s null. Optional means the field can be omitted without error but setting it to null isn’t the same thing. Plus I believe the values in options are merged with the user input on save to allow developers to change a default in an update if necessary.
And here I thought that options and schema had to match. Changing to what you suggested did the trick for folder, but key is still showing as a plain text string and not a password. Any thoughts on what I might be doing wrong there?
Tbh I wasn’t sure about that one. I actually wasn’t sure if displaying a password prompt was supported since I didn’t remember ever seeing one. But I wasn’t sure since most of my addons either have no configuration options or configuration options that only work in YAML (because they include nested objects or arrays) so I went looking through my own.
I did manage to find one though. I forgot the Hassio Google Drive Backup addon actually technically has UI-configurable options despite having a massive amount of options since they encourage you to do all configuration within the addon rather then on that tab. I noticed something interesting looking at it though, backup_password displays as a password prompt as you can see:
But it actually isn’t declared as type password, it’s type str?
So I think it might make that decision based off the name rather then the type. If you change that option to repo_password do you get a password prompt then?
I will admit this is confusing for sure. Clearly the schema is being accounted for in this UI since numbers and strings show different selectors but just not the password one for some reason.
It’s not entirely unimplemented since values in fields in the schema marked as type password are automatically run through the “Have I Been Pwned” check to see if they are vulnerable whereas fields marked as type str are not. But I agree that the UI should use that metadata as well and show a password prompt here.
Although I will note that the user always has a choice to switch from UI display to YAML mode. And in YAML mode there’s no way to hide the values for passwords from there. If it’s important to you and your users that the password here is unviewable by someone looking at this UI you might want to remind them in documentation that they can use !secret references in addon config in YAML mode.