Skip to content

Commit b67957d

Browse files
committed
reload via Configuration -> Integrations UI menu now starts triggers, reported by Fabio C.
1 parent ecaae86 commit b67957d

File tree

7 files changed

+19
-1
lines changed

7 files changed

+19
-1
lines changed

custom_components/pyscript/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,12 @@ def check_event(event, do_reload: bool) -> bool:
226226
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
227227
"""Initialize the pyscript config entry."""
228228
global_ctx_only = None
229+
doing_reload = False
229230
if Function.hass:
230231
#
231232
# reload yaml if this isn't the first time (ie, on reload)
232233
#
234+
doing_reload = True
233235
if await update_yaml_config(hass, config_entry):
234236
global_ctx_only = "*"
235237

@@ -355,6 +357,9 @@ async def hass_stop(event: HAEvent) -> None:
355357

356358
await watchdog_start(hass, pyscript_folder, reload_scripts_handler)
357359

360+
if doing_reload:
361+
start_global_contexts(global_ctx_only="*")
362+
358363
return True
359364

360365

docs/new_features.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Breaking changes since 1.2.1 include:
6262
Bug fixes since 1.2.1 include:
6363

6464
- Fixed ``@state_trigger`` with only a ``.old`` variable, which previously never triggered; reported by stigvi.
65-
- Reload with global_ctx="*" now starts triggers, reported by Fabio C.
65+
- Reload with global_ctx="*" and reload via Configuration -> Integrations UI menu now start triggers, reported by Fabio C.
6666
- Fixed subscripts when running python 3.9.x.
6767
- Timeouts that implement time triggers might infrequenctly occur a tiny time before the target time. A fix was added
6868
to do an additional short timeout when there is an early timeout, to make sure any time trigger occurs at or shortly

tests/test_decorator_errors.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from datetime import datetime as dt
55

66
from custom_components.pyscript.const import DOMAIN
7+
from custom_components.pyscript.function import Function
78
import custom_components.pyscript.trigger as trigger
89
from pytest_homeassistant_custom_component.async_mock import mock_open, patch
910

@@ -17,6 +18,8 @@ async def setup_script(hass, notify_q, now, source):
1718
"/hello.py",
1819
]
1920

21+
Function.hass = None
22+
2023
with patch("custom_components.pyscript.os.path.isdir", return_value=True), patch(
2124
"custom_components.pyscript.glob.iglob", return_value=scripts
2225
), patch("custom_components.pyscript.global_ctx.open", mock_open(read_data=source)), patch(

tests/test_decorators.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from datetime import datetime as dt
55

66
from custom_components.pyscript.const import DOMAIN
7+
from custom_components.pyscript.function import Function
78
import custom_components.pyscript.trigger as trigger
89
from pytest_homeassistant_custom_component.async_mock import mock_open, patch
910

@@ -17,6 +18,8 @@ async def setup_script(hass, notify_q, now, source):
1718
"/hello.py",
1819
]
1920

21+
Function.hass = None
22+
2023
with patch("custom_components.pyscript.os.path.isdir", return_value=True), patch(
2124
"custom_components.pyscript.glob.iglob", return_value=scripts
2225
), patch("custom_components.pyscript.global_ctx.open", mock_open(read_data=source)), patch(

tests/test_function.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ async def setup_script(hass, notify_q, notify_q2, now, source, config=None):
107107

108108
file_contents = {f"{conf_dir}/hello.py": source}
109109

110+
Function.hass = None
111+
110112
mock_open = MockOpen()
111113
for key, value in file_contents.items():
112114
mock_open[key].read_data = value

tests/test_init.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ async def setup_script(hass, notify_q, now, source, script_name="/hello.py"):
2424

2525
scripts = [script_name]
2626

27+
Function.hass = None
28+
2729
with patch("custom_components.pyscript.os.path.isdir", return_value=True), patch(
2830
"custom_components.pyscript.glob.iglob", return_value=scripts
2931
), patch("custom_components.pyscript.global_ctx.open", mock_open(read_data=source)), patch(

tests/test_unique.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from datetime import datetime as dt
55

66
from custom_components.pyscript.const import DOMAIN
7+
from custom_components.pyscript.function import Function
78
import custom_components.pyscript.trigger as trigger
89
from pytest_homeassistant_custom_component.async_mock import mock_open, patch
910

@@ -17,6 +18,8 @@ async def setup_script(hass, notify_q, now, source):
1718
"/some/config/dir/pyscripts/hello.py",
1819
]
1920

21+
Function.hass = None
22+
2023
with patch("custom_components.pyscript.os.path.isdir", return_value=True), patch(
2124
"custom_components.pyscript.glob.iglob", return_value=scripts
2225
), patch("custom_components.pyscript.global_ctx.open", mock_open(read_data=source)), patch(

0 commit comments

Comments
 (0)