When using optional values in an options flow, and giving them default values, there's no real way to remove them - if the user deletes the value, the default one (which would usually be populated with the previous value) will be used.
The Monoprice options flow is an example of this at work - in order to remove a value you have to replace it with whitespace instead of deleting, thus working around the default value, and the integration will take then care of ignoring the whitespace.
My proposal is to have some mechanism to change that behavior. The two options I can think of:
allow_empty indicationNeither is supported by Voluptuous, so we will need some other mechanism to pass this information along.
I have two alternatives mentioned above, and would love to hear more.
Although I initially proposed allow_empty, I think that I have changed my mind. The problem here is that there is a default value. Instead of default value, we should pass the current value instead of hacking this in with default value.
But that would still mean you can not remove the current value of an optional field, as an empty value would be replaced with the default which is the current(/previous) value?
The problem here is that if the user enters an empty value, it should ignore that source. However to fill in the initial value we need to define a default, which will replace the empty value if send to the backend.
@bramkragten the proposal is to separate default from current, so you can pre-populate the current value without setting a default.
So this is something we should probably put in the backend, but I'm fine with keep discussing it here. I guess we can pass it via the description variable in vol.Optional and vol.Required to the frontend.
vol.Schema({
vol.Optional("port", description={"current_value": 1234}): int
})
As long as Voluptuous doesn't support it natively, I think that's the best approach.
@balloob what's the best way forward here? I also encountered this in https://github.com/home-assistant/core/pull/33621
I think that we should add support for current_value to ha-form.
An attempt to tackle this: https://github.com/home-assistant/frontend/pull/5603