77
88import voluptuous as vol
99
10- from homeassistant .config import async_hass_config_yaml , async_process_component_config
10+ from homeassistant .config import async_hass_config_yaml
1111from homeassistant .config_entries import SOURCE_IMPORT
1212from homeassistant .const import (
1313 EVENT_HOMEASSISTANT_STARTED ,
1717)
1818from homeassistant .exceptions import HomeAssistantError
1919import homeassistant .helpers .config_validation as cv
20- from homeassistant .loader import async_get_integration , bind_hass
20+ from homeassistant .loader import bind_hass
2121
2222from .const import CONF_ALLOW_ALL_IMPORTS , DOMAIN , FOLDER , LOGGER_PATH , SERVICE_JUPYTER_KERNEL_START
2323from .eval import AstEval
@@ -81,11 +81,14 @@ async def reload_scripts_handler(call):
8181 _LOGGER .error (err )
8282 return
8383
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+ )
8790
88- State .set_pyscript_config (config . get ( DOMAIN , {}) )
91+ State .set_pyscript_config (config_entry . data )
8992
9093 ctx_delete = {}
9194 for global_ctx_name , global_ctx in GlobalContextMgr .items ():
@@ -97,7 +100,7 @@ async def reload_scripts_handler(call):
97100 for global_ctx_name , global_ctx in ctx_delete .items ():
98101 await GlobalContextMgr .delete (global_ctx_name )
99102
100- await load_scripts (hass , config )
103+ await load_scripts (hass , config_entry . data )
101104
102105 for global_ctx_name , global_ctx in GlobalContextMgr .items ():
103106 idx = global_ctx_name .find ("." )
@@ -188,14 +191,14 @@ async def async_unload_entry(hass, config_entry):
188191
189192
190193@bind_hass
191- async def load_scripts (hass , config ):
194+ async def load_scripts (hass , data ):
192195 """Load all python scripts in FOLDER."""
193196
194197 pyscript_dir = hass .config .path (FOLDER )
195198
196- def glob_files (load_paths , config ):
199+ def glob_files (load_paths , data ):
197200 source_files = []
198- apps_config = config . get ( DOMAIN , {}) .get ("apps" , None )
201+ apps_config = data .get ("apps" , None )
199202 for path , match , check_config in load_paths :
200203 for this_path in sorted (glob .glob (os .path .join (pyscript_dir , path , match ))):
201204 rel_import_path = None
@@ -227,7 +230,7 @@ def glob_files(load_paths, config):
227230 ["" , "*.py" , False ],
228231 ]
229232
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 )
231234 for global_ctx_name , source_file , rel_import_path , fq_mod_name in source_files :
232235 global_ctx = GlobalContext (
233236 global_ctx_name ,
0 commit comments