Skip to content

Commit 51ef166

Browse files
committed
Fix response from script
1 parent 6b0afeb commit 51ef166

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

custom_components/python_script/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Some dummy docs for execute_script."""
12
import hashlib
23
import logging
34

@@ -101,12 +102,14 @@ def handler(call: ServiceCall) -> ServiceResponse:
101102
def execute_script(hass: HomeAssistant, data: dict, logger, code) -> ServiceResponse:
102103
try:
103104
_LOGGER.debug("Run python script")
104-
exec(code, {**globals(), **locals()})
105+
vars = {**globals(), **locals()}
106+
exec(code, vars)
105107
response = {
106108
k: v
107-
for k, v in locals().items()
109+
for k, v in vars.items()
108110
if isinstance(v, (dict, list, str, int, float, bool))
109-
and k not in ("__builtins__", "data")
111+
and k not in globals()
112+
and k != "data"
110113
or v is None
111114
}
112115
return response

0 commit comments

Comments
 (0)