Skip to content

Commit 9dfa312

Browse files
committed
remove __init__ from __name__ to restore original behavior; fixes #111
1 parent 70c4146 commit 9dfa312

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

custom_components/pyscript/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ def glob_read_files(load_paths, apps_config):
324324
# the globs result in apps/APP/__init__.py matching twice, so skip the 2nd time
325325
continue
326326

327+
if fq_mod_name.endswith(".__init__"):
328+
fq_mod_name = fq_mod_name[: -len(".__init__")]
329+
327330
if check_config:
328331
app_name = fq_mod_name
329332
i = fq_mod_name.find(".")

tests/test_reload.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ async def state_changed(event):
123123
assert "modules/xyz2/other global_ctx=modules.xyz2.other;" in caplog.text
124124
assert "hello global_ctx=file.hello xyz=123 xyz2.xyz=123" in caplog.text
125125
assert "world2.other global_ctx=apps.world2.other" in caplog.text
126-
assert "world2.__init__ global_ctx=apps.world2.__init__ var1=100, other_abc=987" in caplog.text
126+
assert "world2 global_ctx=apps.world2.__init__ var1=100, other_abc=987" in caplog.text
127127

128128
#
129129
# add a new script file
@@ -192,7 +192,7 @@ def func20():
192192
#
193193
conf["apps"]["world2"]["var1"] = 200
194194
await hass.services.async_call("pyscript", "reload", {}, blocking=True)
195-
assert "world2.__init__ global_ctx=apps.world2.__init__ var1=200, other_abc=987" in caplog.text
195+
assert "world2 global_ctx=apps.world2.__init__ var1=200, other_abc=987" in caplog.text
196196

197197
#
198198
# change a module inside an app
@@ -208,15 +208,15 @@ def func20():
208208
f"{conf_dir}/apps/world2/other.py"
209209
]
210210
await hass.services.async_call("pyscript", "reload", {}, blocking=True)
211-
assert "world2.__init__ global_ctx=apps.world2.__init__ var1=200, other_abc=654" in caplog.text
211+
assert "world2 global_ctx=apps.world2.__init__ var1=200, other_abc=654" in caplog.text
212212

213213
#
214214
# now confirm certain files reloaded the correct number of times,
215215
# and reload everything a few times
216216
#
217217
for i in range(3):
218218
assert caplog.text.count("world global_ctx=apps.world xyz=") == 2 + i
219-
assert caplog.text.count("world2.__init__ global_ctx=apps.world2.__init__ var1=") == 3 + i
219+
assert caplog.text.count("world2 global_ctx=apps.world2.__init__ var1=") == 3 + i
220220
assert caplog.text.count("hello global_ctx=file.hello xyz=") == 4 + i
221221
assert caplog.text.count("modules/xyz2/other global_ctx=modules.xyz2.other") == 2 + i
222222
assert caplog.text.count("modules/xyz2 global_ctx=modules.xyz2.__init__") == 2 + i

0 commit comments

Comments
 (0)