@@ -292,6 +292,13 @@ which calls the ``myservice.flash_light`` service with the indicated parameters.
292292parameter values could be any Python expression, and this call could be inside a loop, an if
293293statement or any other Python code.
294294
295+ Starting in HASS 2023.7, services can return a response, which is a dictionary of values. You need
296+ to set the keyword parameter ``return_response=True `` to get the response. For example:
297+
298+ .. code :: python
299+
300+ service_response = myservice.flash_light(light_name = " front" , light_color = " red" , return_response = True )
301+
295302 The function ``service.call(domain, name, **kwargs) `` can also be used to call a service when you
296303need to compute the domain or service name dynamically. For example, the above service could also be
297304called by:
@@ -302,8 +309,9 @@ called by:
302309
303310 When making a service call, either using the ``service.call `` function or the service name as the
304311function, you can optionally pass the keyword argument ``blocking=True `` if you would like to wait
305- for the service to finish execution before continuing execution in your function. You can also
306- specify a timeout for a blocking service call using the ``limit=<number_of_seconds> `` parameters.
312+ for the service to finish execution before continuing execution in your function. If the service
313+ returns a response (new feature starting in HASS 2023.7), it will be returned by the call if you set
314+ the optional keyword parameter ``return_response=True ``.
307315
308316Firing events
309317-------------
@@ -919,15 +927,20 @@ Notice that `read_file` is called like a regular function, and it automatically
919927``task.executor ``, which runs the compiled native python function in a new thread, and
920928then returns the result.
921929
922- @service(service_name, ...)
923- ^^^^^^^^^^^^^^^^^^^^^^^^^^^
930+ @service(service_name, ..., supports_response="none" )
931+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
924932
925933The ``@service `` decorator causes the function to be registered as a service so it can be called
926934externally. The string ``service_name `` argument is optional and defaults to ``"pyscript.FUNC_NAME" ``,
927935where ``FUNC_NAME `` is the name of the function. You can override that default by specifying
928936a string with a single period of the form ``"DOMAIN.SERVICE" ``. Multiple arguments and multiple
929937``@service `` decorators can be used to register multiple names (eg, aliases) for the same function.
930938
939+ The ``supports_response `` keyword argument can be set to one of three string values: ``"none" `` (the
940+ default), ``"only" ``, or ``"optional" ``, depending on whether the service provides no response, always
941+ provides a response, or sometimes provides a response. Services responses were added in HASS 2023.7.
942+ The service response is a dictionary returned by the function.
943+
931944Other trigger decorators like ``@state_active `` and ``@time_active `` don't affect the service.
932945Those still allow state, time or other triggers to be specified in addition.
933946
@@ -1057,11 +1070,12 @@ or ``float()``). Attributes keep their native type.
10571070Service Calls
10581071^^^^^^^^^^^^^
10591072
1060- ``service.call(domain, name, blocking=False, limit=10 , **kwargs) ``
1073+ ``service.call(domain, name, blocking=False, return_response=False , **kwargs) ``
10611074 calls the service ``domain.name `` with the given keyword arguments as parameters. If ``blocking ``
10621075 is ``True ``, pyscript will wait for the service to finish executing before continuing the current
1063- routine, or will wait a maximum of the number of seconds specified in the ``limit `` keyword
1064- argument.
1076+ routine. If the service returns a response, set ``return_response `` to ``True `` (which also
1077+ causes blocking), and the response will be returned by the function call. Note that starting
1078+ in HASS 2023.7, the blocking timeout parameter ``limit `` is no longer supported.
10651079``service.has_service(domain, name) ``
10661080 returns whether the service ``domain.name `` exists.
10671081
0 commit comments