Skip to content

Commit 8834dc1

Browse files
committed
added trigger function closure support
1 parent f8b234c commit 8834dc1

File tree

8 files changed

+467
-319
lines changed

8 files changed

+467
-319
lines changed

custom_components/pyscript/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async def reload_scripts_handler(call):
6868
for global_ctx_name, global_ctx in GlobalContextMgr.items():
6969
if not global_ctx_name.startswith("file."):
7070
continue
71-
await global_ctx.stop()
71+
global_ctx.stop()
7272
global_ctx.set_auto_start(False)
7373
ctx_delete[global_ctx_name] = global_ctx
7474
for global_ctx_name, global_ctx in ctx_delete.items():
@@ -79,7 +79,7 @@ async def reload_scripts_handler(call):
7979
for global_ctx_name, global_ctx in GlobalContextMgr.items():
8080
if not global_ctx_name.startswith("file."):
8181
continue
82-
await global_ctx.start()
82+
global_ctx.start()
8383

8484
hass.services.async_register(DOMAIN, SERVICE_RELOAD, reload_scripts_handler)
8585

@@ -130,15 +130,15 @@ async def start_triggers(event):
130130
for global_ctx_name, global_ctx in GlobalContextMgr.items():
131131
if not global_ctx_name.startswith("file."):
132132
continue
133-
await global_ctx.start()
133+
global_ctx.start()
134134
global_ctx.set_auto_start(True)
135135

136136
async def stop_triggers(event):
137137
_LOGGER.debug("stopping triggers")
138138
for global_ctx_name, global_ctx in GlobalContextMgr.items():
139139
if not global_ctx_name.startswith("file."):
140140
continue
141-
await global_ctx.stop()
141+
global_ctx.stop()
142142

143143
hass.bus.async_listen(EVENT_HOMEASSISTANT_STARTED, start_triggers)
144144
hass.bus.async_listen(EVENT_HOMEASSISTANT_STOP, stop_triggers)
@@ -179,10 +179,12 @@ def read_file(path):
179179
if not ast_ctx.parse(source, filename=file):
180180
exc = ast_ctx.get_exception_long()
181181
ast_ctx.get_logger().error(exc)
182+
global_ctx.stop()
182183
continue
183184
await ast_ctx.eval()
184185
exc = ast_ctx.get_exception_long()
185186
if exc is not None:
186187
ast_ctx.get_logger().error(exc)
188+
global_ctx.stop()
187189
continue
188190
GlobalContextMgr.set(global_ctx_name, global_ctx)

0 commit comments

Comments
 (0)