Skip to content

Commit 83aba1b

Browse files
committed
added some service response tests
1 parent 88eebeb commit 83aba1b

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

tests/test_apps_modules.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ async def test_service_exists(hass, caplog):
2929
import xyz2
3030
from xyz2 import f_minus
3131
32-
@service
32+
@service(supports_response = "optional")
3333
def func1():
3434
pyscript.done = [xyz2.f_add(1, 2), xyz2.f_mult(3, 4), xyz2.f_add(10, 20), f_minus(50, 20)]
35+
return {"a": 1}
3536
""",
3637
#
3738
# this will fail to load since import doesn't exist
@@ -197,9 +198,12 @@ async def state_changed(event):
197198
assert hass.services.has_service("pyscript", "func14")
198199
assert not hass.services.has_service("pyscript", "func15")
199200

200-
await hass.services.async_call("pyscript", "func1", {})
201+
service_ret = await hass.services.async_call(
202+
"pyscript", "func1", {}, return_response=True, blocking=True
203+
)
201204
ret = await wait_until_done(notify_q)
202205
assert literal_eval(ret) == [1 + 2, 3 * 4, 10 + 20, 50 - 20]
206+
assert service_ret == {"a": 1}
203207

204208
await hass.services.async_call("pyscript", "func20", {})
205209
ret = await wait_until_done(notify_q)

tests/test_function.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1275,16 +1275,16 @@ def func_startup():
12751275
12761276
seq_num += 1
12771277
pyscript.var1 = 1
1278-
pyscript.service1(blocking=True)
1279-
pyscript.done = [seq_num, pyscript.var1]
1278+
r = pyscript.service1(blocking=True, return_response = True)
1279+
pyscript.done = [seq_num, r["var1"]]
12801280
12811281
seq_num += 1
12821282
pyscript.service1(blocking=True)
12831283
pyscript.done = [seq_num, pyscript.var1]
12841284
12851285
seq_num += 1
1286-
service.call("pyscript", "service1", blocking=True)
1287-
pyscript.done = [seq_num, pyscript.var1]
1286+
r = service.call("pyscript", "service1", blocking=True, return_response = True)
1287+
pyscript.done = [seq_num, r["var1"]]
12881288
12891289
seq_num += 1
12901290
service.call("pyscript", "short_sleep", blocking=True)
@@ -1301,9 +1301,10 @@ def short_sleep():
13011301
task.sleep(0.0001)
13021302
pyscript.var1 = int(pyscript.var1) + 1
13031303
1304-
@service
1304+
@service(supports_response = "optional")
13051305
def service1():
13061306
pyscript.var1 = int(pyscript.var1) + 1
1307+
return {"var1": pyscript.var1}
13071308
13081309
""",
13091310
config={DOMAIN: {CONF_ALLOW_ALL_IMPORTS: True, CONF_HASS_IS_GLOBAL: True}},

0 commit comments

Comments
 (0)