|
11 | 11 | from homeassistant.helpers import service as ha_service |
12 | 12 | from homeassistant.helpers.entity_registry import EntityRegistry |
13 | 13 |
|
14 | | -from .loader import * |
| 14 | +from pyscript_mock import * |
| 15 | +# noinspection PyBroadException |
| 16 | +try: |
| 17 | + """works in pyscript environment only""" |
| 18 | + # noinspection PyUnresolvedReferences,PyUnboundLocalVariable |
| 19 | + task.current_task() |
| 20 | +except: |
| 21 | + from pyscript_builtins import * |
15 | 22 |
|
16 | 23 |
|
17 | 24 | class Generator: |
@@ -303,15 +310,20 @@ def autocomplete_generator(): |
303 | 310 |
|
304 | 311 | error_list = [] |
305 | 312 |
|
306 | | - empty_module = hass.config.path(FOLDER + f"/modules/{module_name}.py") |
307 | | - if not os.path.exists(empty_module): |
308 | | - error_list.append(f"{empty_module} does not exists") |
| 313 | + """Check for old loader files""" |
| 314 | + old_files = (hass.config.path(FOLDER + f"/modules/{module_name}.py"), hass.config.path(FOLDER + f"/{module_name}/")) |
| 315 | + for old_file in old_files: |
| 316 | + if os.path.exists(old_file): |
| 317 | + error_list.append(f"{old_file} exists, please remove it") |
309 | 318 |
|
310 | | - target_path = cfg.get("target_path") |
311 | | - if not target_path: |
312 | | - target_path = hass.config.path(FOLDER + f"/{module_name}/") |
313 | | - if not os.access(target_path, os.W_OK): |
314 | | - error_list.append(f"{target_path} does not exist or is not writable") |
| 319 | + target_path = hass.config.path(FOLDER + f"/modules/{module_name}/") |
| 320 | + try: |
| 321 | + os.makedirs(target_path, exist_ok=True) |
| 322 | + except OSError: |
| 323 | + error_list.append(f"Creation of the directory {target_path} failed") |
| 324 | + |
| 325 | + if os.path.exists(target_path) and not os.access(target_path, os.W_OK): |
| 326 | + error_list.append(f"{target_path} is not writable") |
315 | 327 |
|
316 | 328 | include = cfg.get("include") or [] |
317 | 329 | include_regexes = [] |
|
0 commit comments