I am adding config flow to a custom component and using an import flow to take the setting from configuration.yaml (if they exist). This is all working fine except the ability to set options values from those that are setup in the config.yaml.
I have the options flow working which is fine to set these options values if adding via UI from scratch but I cannot work out how to set options values in the import flow from config.yaml as these cannot be set when creating the entity.
I have tried creating the config entry and then updating it with options values but because you cannot/should not await the creation then this does not work as I think it is trying to update before it is created.
Has anybody got a way of doing this to save me banging my head any more! Thanks in advance.
Took your advice and been looking at components that have moved over but none I have looked at so far seem to import any options settings, including blink. Will keep looking and hope that someone knows how to do this before I get back to HA v0.001!
Seems you cannot import the options during config flow but need to put them in the data field and then copy them to options once config entry is created. Not perfect as will leave duff data when you change the options but it works!
You can’t set options during import. Only after the config entry has been loaded by hass. I update options in axis component and have done the same in both deconz and unifi a few releases back
Excellent example, as I needed to do the same thing!
You can remove the options from data when importing into options. Leaving an example here is case more people are looking for this:
options = dict(entry.options)
data = {}
importable_options = [CONF_COMMAND_OFF, CONF_COMMAND_ON]
found = False
for key in entry.data:
if key in importable_options and key not in options:
options[key] = entry.data[key]
found = True
else:
data[key] = entry.data[key]
if found:
hass.config_entries.async_update_entry(entry, data=data, options=options)