Skip to content

Commit a127a5f

Browse files
committed
simplify config update logic to accept all updates
1 parent c53ae6c commit a127a5f

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

custom_components/pyscript/config_flow.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
import voluptuous as vol
55

66
from homeassistant import config_entries
7+
from homeassistant.config_entries import SOURCE_IMPORT
78

8-
from .const import CONF_ALL_KEYS, CONF_ALLOW_ALL_IMPORTS, DOMAIN
9+
from .const import CONF_ALLOW_ALL_IMPORTS, DOMAIN
910

1011
PYSCRIPT_SCHEMA = vol.Schema(
1112
{vol.Optional(CONF_ALLOW_ALL_IMPORTS, default=False): bool}, extra=vol.ALLOW_EXTRA,
@@ -38,13 +39,9 @@ async def async_step_import(self, import_config: Dict[str, Any] = None) -> None:
3839
entry = entries[0]
3940
updated_data = entry.data.copy()
4041

41-
# Update key if it's value has been changed
42-
for key in CONF_ALL_KEYS:
43-
if entry.data.get(key) != import_config.get(key):
44-
if import_config.get(key) is not None:
45-
updated_data[key] = import_config[key]
46-
else:
47-
updated_data.pop(key)
42+
for k, v in import_config.items():
43+
if entry.source == SOURCE_IMPORT or k != CONF_ALLOW_ALL_IMPORTS:
44+
updated_data[k] = v
4845

4946
# Update and reload entry if data needs to be updated
5047
if updated_data != entry.data:

custom_components/pyscript/const.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
FOLDER = "pyscript"
66

77
CONF_ALLOW_ALL_IMPORTS = "allow_all_imports"
8-
CONF_ALL_KEYS = [CONF_ALLOW_ALL_IMPORTS, "apps"]
98

109
SERVICE_JUPYTER_KERNEL_START = "jupyter_kernel_start"
1110

0 commit comments

Comments
 (0)