@@ -60,7 +60,7 @@ async def test_execute_with_data(hass, caplog):
60
60
hass.states.set('test.entity', data.get('name', 'not set'))
61
61
"""
62
62
63
- hass .async_add_job (execute , hass , "test.py" , source , {"name" : "paulus" })
63
+ hass .async_add_executor_job (execute , hass , "test.py" , source , {"name" : "paulus" })
64
64
await hass .async_block_till_done ()
65
65
66
66
assert hass .states .is_state ("test.entity" , "paulus" )
@@ -76,7 +76,7 @@ async def test_execute_warns_print(hass, caplog):
76
76
print("This triggers warning.")
77
77
"""
78
78
79
- hass .async_add_job (execute , hass , "test.py" , source , {})
79
+ hass .async_add_executor_job (execute , hass , "test.py" , source , {})
80
80
await hass .async_block_till_done ()
81
81
82
82
assert "Don't use print() inside scripts." in caplog .text
@@ -89,7 +89,7 @@ async def test_execute_logging(hass, caplog):
89
89
logger.info('Logging from inside script')
90
90
"""
91
91
92
- hass .async_add_job (execute , hass , "test.py" , source , {})
92
+ hass .async_add_executor_job (execute , hass , "test.py" , source , {})
93
93
await hass .async_block_till_done ()
94
94
95
95
assert "Logging from inside script" in caplog .text
@@ -102,7 +102,7 @@ async def test_execute_compile_error(hass, caplog):
102
102
this is not valid Python
103
103
"""
104
104
105
- hass .async_add_job (execute , hass , "test.py" , source , {})
105
+ hass .async_add_executor_job (execute , hass , "test.py" , source , {})
106
106
await hass .async_block_till_done ()
107
107
108
108
assert "Error loading script test.py" in caplog .text
@@ -115,7 +115,7 @@ async def test_execute_runtime_error(hass, caplog):
115
115
raise Exception('boom')
116
116
"""
117
117
118
- hass .async_add_job (execute , hass , "test.py" , source , {})
118
+ hass .async_add_executor_job (execute , hass , "test.py" , source , {})
119
119
await hass .async_block_till_done ()
120
120
121
121
assert "Error executing script: boom" in caplog .text
@@ -128,7 +128,7 @@ async def test_accessing_async_methods(hass, caplog):
128
128
hass.async_stop()
129
129
"""
130
130
131
- hass .async_add_job (execute , hass , "test.py" , source , {})
131
+ hass .async_add_executor_job (execute , hass , "test.py" , source , {})
132
132
await hass .async_block_till_done ()
133
133
134
134
assert "Not allowed to access async methods" in caplog .text
@@ -143,7 +143,7 @@ async def test_using_complex_structures(hass, caplog):
143
143
logger.info('Logging from inside script: %s %s' % (mydict["a"], mylist[2]))
144
144
"""
145
145
146
- hass .async_add_job (execute , hass , "test.py" , source , {})
146
+ hass .async_add_executor_job (execute , hass , "test.py" , source , {})
147
147
await hass .async_block_till_done ()
148
148
149
149
assert "Logging from inside script: 1 3" in caplog .text
@@ -160,7 +160,7 @@ async def test_accessing_forbidden_methods(hass, caplog):
160
160
"time.tzset()" : "TimeWrapper.tzset" ,
161
161
}.items ():
162
162
caplog .records .clear ()
163
- hass .async_add_job (execute , hass , "test.py" , source , {})
163
+ hass .async_add_executor_job (execute , hass , "test.py" , source , {})
164
164
await hass .async_block_till_done ()
165
165
assert f"Not allowed to access { name } " in caplog .text
166
166
@@ -172,7 +172,7 @@ async def test_iterating(hass):
172
172
hass.states.set('hello.{}'.format(i), 'world')
173
173
"""
174
174
175
- hass .async_add_job (execute , hass , "test.py" , source , {})
175
+ hass .async_add_executor_job (execute , hass , "test.py" , source , {})
176
176
await hass .async_block_till_done ()
177
177
178
178
assert hass .states .is_state ("hello.1" , "world" )
@@ -190,7 +190,7 @@ async def test_unpacking_sequence(hass, caplog):
190
190
hass.states.set('hello.ab_list', '{}'.format(ab_list))
191
191
"""
192
192
193
- hass .async_add_job (execute , hass , "test.py" , source , {})
193
+ hass .async_add_executor_job (execute , hass , "test.py" , source , {})
194
194
await hass .async_block_till_done ()
195
195
196
196
assert hass .states .is_state ("hello.a" , "1" )
@@ -211,7 +211,7 @@ async def test_execute_sorted(hass, caplog):
211
211
hass.states.set('hello.b', a[1])
212
212
hass.states.set('hello.c', a[2])
213
213
"""
214
- hass .async_add_job (execute , hass , "test.py" , source , {})
214
+ hass .async_add_executor_job (execute , hass , "test.py" , source , {})
215
215
await hass .async_block_till_done ()
216
216
217
217
assert hass .states .is_state ("hello.a" , "1" )
@@ -232,7 +232,7 @@ async def test_exposed_modules(hass, caplog):
232
232
datetime.timedelta(minutes=1).total_seconds())
233
233
"""
234
234
235
- hass .async_add_job (execute , hass , "test.py" , source , {})
235
+ hass .async_add_executor_job (execute , hass , "test.py" , source , {})
236
236
await hass .async_block_till_done ()
237
237
238
238
assert hass .states .is_state ("module.time" , "1986" )
@@ -256,7 +256,7 @@ def b():
256
256
257
257
b()
258
258
"""
259
- hass .async_add_job (execute , hass , "test.py" , source , {})
259
+ hass .async_add_executor_job (execute , hass , "test.py" , source , {})
260
260
await hass .async_block_till_done ()
261
261
262
262
assert hass .states .is_state ("hello.a" , "one" )
@@ -400,7 +400,7 @@ async def test_sleep_warns_one(hass, caplog):
400
400
"""
401
401
402
402
with patch ("homeassistant.components.python_script.time.sleep" ):
403
- hass .async_add_job (execute , hass , "test.py" , source , {})
403
+ hass .async_add_executor_job (execute , hass , "test.py" , source , {})
404
404
await hass .async_block_till_done ()
405
405
406
406
assert caplog .text .count ("time.sleep" ) == 1
0 commit comments