Skip to content

Commit

Permalink
Add support for empty signals
Browse files Browse the repository at this point in the history
Meaning signals without data.

Declare them with functions that return None and have
dbus signature "".

```
    @dbus_signal_async()
    def empty_signal(self) -> None:
        raise NotImplementedError
```

Emit them by passing None.

```
test_object.empty_signal.emit(None)
```
  • Loading branch information
igo95862 committed Sep 15, 2022
1 parent 3f70eaf commit 938ca81
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/sdbus/dbus_proxy_async_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ def _emit_message(self, args: T) -> None:
isinstance(args, tuple)):
signal_message.append_data(
self.dbus_signal.signal_signature, *args)
elif self.dbus_signal.signal_signature == '' and args is None:
...
else:
signal_message.append_data(
self.dbus_signal.signal_signature, args)
Expand Down
19 changes: 19 additions & 0 deletions test/test_sd_bus_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ async def test_struct_return_workaround(self) -> Tuple[Tuple[str, str]]:
async def looong_method(self) -> None:
await sleep(100)

@dbus_signal_async()
def empty_signal(self) -> None:
raise NotImplementedError


class DbusErrorTest(DbusFailedError):
dbus_error_name = 'org.example.Error'
Expand Down Expand Up @@ -802,3 +806,18 @@ async def test_properties_get_all_dict(self) -> None:
await test_object_connection.properties_get_all_dict()
)['test_property'],
)

async def test_empty_signal(self) -> None:
test_object, test_object_connection = initialize_object()

loop = get_running_loop()

ai_dbus = test_object_connection.empty_signal.__aiter__()
aw_dbus = ai_dbus.__anext__()
q = test_object.empty_signal._get_local_queue()

loop.call_at(0, test_object.empty_signal.emit, None)

self.assertIsNone(await wait_for(aw_dbus, timeout=1))

self.assertIsNone(await wait_for(q.get(), timeout=1))

0 comments on commit 938ca81

Please sign in to comment.