|
5 | 5 |
|
6 | 6 | from homeassistant import config_entries |
7 | 7 |
|
8 | | -from .const import CONF_ALLOW_ALL_IMPORTS, DOMAIN |
| 8 | +from .const import CONF_ALL_KEYS, CONF_ALLOW_ALL_IMPORTS, DOMAIN |
9 | 9 |
|
10 | 10 | PYSCRIPT_SCHEMA = vol.Schema( |
11 | 11 | {vol.Optional(CONF_ALLOW_ALL_IMPORTS, default=False): bool}, extra=vol.ALLOW_EXTRA, |
@@ -38,20 +38,15 @@ async def async_step_import(self, import_config: Dict[str, Any] = None) -> None: |
38 | 38 | entry = entries[0] |
39 | 39 | updated_data = entry.data.copy() |
40 | 40 |
|
41 | | - # Update "allow_all_imports" if it has been changed |
42 | | - if entry.data.get(CONF_ALLOW_ALL_IMPORTS, False) != import_config.get( |
43 | | - CONF_ALLOW_ALL_IMPORTS, False |
44 | | - ): |
45 | | - updated_data[CONF_ALLOW_ALL_IMPORTS] = import_config.get(CONF_ALLOW_ALL_IMPORTS, False) |
| 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) |
46 | 48 |
|
47 | | - # Update "apps" if it has been changed |
48 | | - if entry.data.get("apps") != import_config.get("apps"): |
49 | | - if import_config.get("apps"): |
50 | | - updated_data["apps"] = import_config["apps"] |
51 | | - else: |
52 | | - updated_data.pop("apps") |
53 | | - |
54 | | - # Update and reload entry |
| 49 | + # Update and reload entry if data needs to be updated |
55 | 50 | if updated_data != entry.data: |
56 | 51 | self.hass.config_entries.async_update_entry(entry=entry, data=updated_data) |
57 | 52 | await self.hass.config_entries.async_reload(entry.entry_id) |
|
0 commit comments