Skip to content

Commit ef99788

Browse files
committed
handle key removal
1 parent a127a5f commit ef99788

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

custom_components/pyscript/config_flow.py

+10
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,20 @@ async def async_step_import(self, import_config: Dict[str, Any] = None) -> None:
3939
entry = entries[0]
4040
updated_data = entry.data.copy()
4141

42+
# Update values for all keys, excluding `allow_all_imports` for entries
43+
# set up through the UI.
4244
for k, v in import_config.items():
4345
if entry.source == SOURCE_IMPORT or k != CONF_ALLOW_ALL_IMPORTS:
4446
updated_data[k] = v
4547

48+
# Remove values for all keys in entry.data that are not in the imported config,
49+
# excluding `allow_all_imports` for entries set up through the UI.
50+
for key in entry.data:
51+
if (
52+
entry.source == SOURCE_IMPORT or key != CONF_ALLOW_ALL_IMPORTS
53+
) and key not in import_config:
54+
updated_data.pop(key)
55+
4656
# Update and reload entry if data needs to be updated
4757
if updated_data != entry.data:
4858
self.hass.config_entries.async_update_entry(entry=entry, data=updated_data)

0 commit comments

Comments
 (0)