Hello,
I’m having a problem with the config_flow of my first integration.
I want to allow users to modify the integration options (username, password, pin_code, alarmpanel_code).
When the device is created, no problem, everything is created, the “static” part in config_entry.data`` and the “dynamic” part in
config_entry.options``.
"data":{"serial_id":"11223344556677"}
"options":{"alarmpanel_code":null,"api_key":"adbcc682-1111-4444-2222-50e32262a17a","password":"MyPassword","pin_code":1111,"secret_key":"ZZZZZZZZPKeyV8kFj0x2tlZfVeAGk2-AAAAA_poqXM274","username":"[email protected]"}
On the other hand, when I want to modify an option (for example alarmpanel_code), updating config_entry.options works fine, but it also changes config_entry.data by putting what appear to be the values of config_entry.options before the option is modified (as you can see, alarmpanel_code in config_entry.data is null but changed in options.
"data":{"alarmpanel_code":null,"api_key":"adbcc682-1111-4444-2222-50e32262a17a","password":"MyPassword","pin_code":1111,"secret_key":"ZZZZZZZZPKeyV8kFj0x2tlZfVeAGk2-AAAAA_poqXM274","serial_id":"11223344556677","username":"[email protected]"}
"options":{"alarmpanel_code":123,"api_key":"adbcc682-1111-4444-2222-50e32262a17a","password":"MyPassword","pin_code":1111,"secret_key":"ZZZZZZZZPKeyV8kFj0x2tlZfVeAGk2-AAAAA_poqXM274","username":"[email protected]"}
At first I thought I’d filled in my variables incorrectly, but no, everything’s fine.
2025-02-27 23:56:15.612 DEBUG (MainThread) [custom_components.diagral.config_flow] Submitting data entry to HA : {'serial_id': '11223344556677'}
2025-02-27 23:56:15.612 DEBUG (MainThread) [custom_components.diagral.config_flow] Submitting options entry to HA : {'username': '[email protected]', 'password': 'MyPassword', 'pin_code': 1111, 'api_key': 'adbcc682-1111-4444-2222-50e32262a17a', 'secret_key': 'ZZZZZZZZPKeyV8kFj0x2tlZfVeAGk2-AAAAA_poqXM274', 'alarmpanel_code': 123}
The part of my code that updates the options is as follows:
if user_input is not None:
# Check if the user has changed the alarm panel code
if (
user_input[CONF_ALARMPANEL_CODE] is not None
and user_input[CONF_ALARMPANEL_CODE]
!= self.options[CONF_ALARMPANEL_CODE]
):
# Check if the user has entered a valid alarm panel code
if not is_valid_pin(user_input[CONF_ALARMPANEL_CODE]):
errors[CONF_ALARMPANEL_CODE] = "invalid_alarmpanel_code"
else:
self._alarmpanel_code_changed = True
self.options[CONF_ALARMPANEL_CODE] = user_input[
CONF_ALARMPANEL_CODE
]
if (
self._username_changed
or self._password_changed
or self._pincode_changed
or self._alarmpanel_code_changed
):
_LOGGER.debug(
"Submitting data entry to HA : %s", self.config_entry.data
)
_LOGGER.debug("Submitting options entry to HA : %s", self.options)
return self.async_create_entry(title="", data=self.options)
_LOGGER.debug("No configuration changes detected, skipping update.")
return self.async_abort(reason="no_changes")
I don’t understand where this is coming from. Why are keys and values from config_entry.options added to config_entry.data when updating options?
I’ve already tested a lot of things. Dived deep into Github to see how others were doing, but nothing worked.
Thanks in advance for your assistance on this strange behavior.
PS : I working on dev branch (version from 3 days ago)