Config_flow unable to detect if optional string field is set to null after previously having a value

I have a had this a few times and I cannot find a good solution.

I have this line
vol.Optional(“nfl_api_key”,“nfl_api_key”)): vol.Any(None, str),

Now if there was an existing value for nfl_api_key then if the user nulls it out the config flow does not detect this action and keeps the value as it was.

If I replace the value with a space it detects the change.

That is how it works as if you leave it empty the return from the form will send in the default value as you defined it to be the nfl_api_key.

Better to use self.add_suggested_values_to_schema() than defaults in such case Data entry flow | Home Assistant Developer Docs

1 Like