You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
base: Improve @shc.handler() to allow defining handler functions with less parameters
This commit includes tests and documentation for this new feature. We also needed
to fix our AsyncMock implementation to work well with inspect.signature() in the
tests.
Fixesmhthies#63
Copy file name to clipboardexpand all lines: docs/base.rst
+22-1
Original file line number
Diff line number
Diff line change
@@ -181,7 +181,7 @@ Putting it all together, a logic handler may look as follows::
181
181
@timer.trigger
182
182
@some_variable.trigger
183
183
@shc.handler()
184
-
async def my_logics(_value, origin):
184
+
async def my_logics(_value, _origin):
185
185
""" Write value of `some_variable` to KNX bus every 5 minutes & when it changes, but only for values > 42 """
186
186
# We cannot use the value provided, since it is not defined when triggered by the timer
187
187
value = await some_variable.read()
@@ -231,6 +231,27 @@ Putting it all together, a logic handler may look as follows::
231
231
# Unfortunately, no .write() or .read() possible here.
232
232
233
233
234
+
.. tip::
235
+
236
+
The :func:`shc.handler` and :func:`shc.blocking_handler` decorators take care of calling the logic handler function with the correct number of arguments:
237
+
If you don't need the ``origin`` list, you can simply omit the second parameter of your wrapped logic handler function::
238
+
239
+
@shc.handler()
240
+
async def my_value_only_handler(value):
241
+
await some_variable.write(value + 3)
242
+
243
+
If you don't need the ``value`` either, you can also omit this parameter.
244
+
Hence, the logic handler from the first example above can be rewritten as::
0 commit comments