7
7
8
8
import voluptuous as vol
9
9
10
- from homeassistant .config import async_hass_config_yaml , async_process_component_config
10
+ from homeassistant .config import async_hass_config_yaml
11
11
from homeassistant .config_entries import SOURCE_IMPORT
12
12
from homeassistant .const import (
13
13
EVENT_HOMEASSISTANT_STARTED ,
17
17
)
18
18
from homeassistant .exceptions import HomeAssistantError
19
19
import homeassistant .helpers .config_validation as cv
20
- from homeassistant .loader import async_get_integration , bind_hass
20
+ from homeassistant .loader import bind_hass
21
21
22
22
from .const import CONF_ALLOW_ALL_IMPORTS , DOMAIN , FOLDER , LOGGER_PATH , SERVICE_JUPYTER_KERNEL_START
23
23
from .eval import AstEval
@@ -81,11 +81,14 @@ async def reload_scripts_handler(call):
81
81
_LOGGER .error (err )
82
82
return
83
83
84
- integration = await async_get_integration (hass , DOMAIN )
85
-
86
- config = await async_process_component_config (hass , conf , integration )
84
+ # If data in config doesn't match config entry, trigger a config import
85
+ # so that the config entry can get updated
86
+ if DOMAIN in conf and conf [DOMAIN ] != config_entry .data :
87
+ await hass .config_entries .flow .async_init (
88
+ DOMAIN , context = {"source" : SOURCE_IMPORT }, data = conf [DOMAIN ]
89
+ )
87
90
88
- State .set_pyscript_config (config . get ( DOMAIN , {}) )
91
+ State .set_pyscript_config (config_entry . data )
89
92
90
93
ctx_delete = {}
91
94
for global_ctx_name , global_ctx in GlobalContextMgr .items ():
@@ -97,7 +100,7 @@ async def reload_scripts_handler(call):
97
100
for global_ctx_name , global_ctx in ctx_delete .items ():
98
101
await GlobalContextMgr .delete (global_ctx_name )
99
102
100
- await load_scripts (hass , config )
103
+ await load_scripts (hass , config_entry . data )
101
104
102
105
for global_ctx_name , global_ctx in GlobalContextMgr .items ():
103
106
idx = global_ctx_name .find ("." )
@@ -188,14 +191,14 @@ async def async_unload_entry(hass, config_entry):
188
191
189
192
190
193
@bind_hass
191
- async def load_scripts (hass , config ):
194
+ async def load_scripts (hass , data ):
192
195
"""Load all python scripts in FOLDER."""
193
196
194
197
pyscript_dir = hass .config .path (FOLDER )
195
198
196
- def glob_files (load_paths , config ):
199
+ def glob_files (load_paths , data ):
197
200
source_files = []
198
- apps_config = config . get ( DOMAIN , {}) .get ("apps" , None )
201
+ apps_config = data .get ("apps" , None )
199
202
for path , match , check_config in load_paths :
200
203
for this_path in sorted (glob .glob (os .path .join (pyscript_dir , path , match ))):
201
204
rel_import_path = None
@@ -227,7 +230,7 @@ def glob_files(load_paths, config):
227
230
["" , "*.py" , False ],
228
231
]
229
232
230
- source_files = await hass .async_add_executor_job (glob_files , load_paths , config )
233
+ source_files = await hass .async_add_executor_job (glob_files , load_paths , data )
231
234
for global_ctx_name , source_file , rel_import_path , fq_mod_name in source_files :
232
235
global_ctx = GlobalContext (
233
236
global_ctx_name ,
0 commit comments