Skip to content

Fix add gatt by adding new **primary** services#173

Merged
kevincar merged 2 commits intokevincar:masterfrom
EasyRiderr:fix_add_gatt
Jan 22, 2026
Merged

Fix add gatt by adding new **primary** services#173
kevincar merged 2 commits intokevincar:masterfrom
EasyRiderr:fix_add_gatt

Conversation

@EasyRiderr
Copy link
Copy Markdown
Contributor

The server.add_gatt() method is expected to add several services to the server, meaning the server is expected to advertise and expose these added services (see #142).

As a starting point, this PR refactors the test/test_server.py file to facilitate code reuse and adds an async def test_server_add_gatt() function to highlight this issue.

You can see the test results (before the fix is implemented) attached: trace_before.log. Tests are failing because the second characteristic (and service is not advertised, nor exposed).

On Ubuntu, BlueZ only advertise or expose the primary BLE services, so to fix the add_gatt method, I've just forced the primary parameter to True, while its default value is False. It fixes the issue #142 as you can see it test results attached:
trace_after.log

⚠️ Code has been tested only Ubuntu.

Also refactor the test_server file to reuse the server callbacks
definition and common tests on read, write and notify.

Signed-off-by: Yoan Dumas <yo_dumas@hotmail.fr>
On Ubuntu with bluez, only the primary services are advertised and
exposed on the BLE.

Signed-off-by: Yoan Dumas <yo_dumas@hotmail.fr>
@kevincar
Copy link
Copy Markdown
Owner

kevincar commented Jan 22, 2026

@EasyRiderr Thanks for these edits!

The edits as you've written are a good workaround for now.

I think the underlying issue is the fact that the primary parameter is typed as Optional. It shouldn't be, and it should default to True on the __init__ function across all backends. This is particularly true because WinRT can only create primary services. In addition, it only makes sense to create secondary services if they can be added to the includes of the primary service, which are only available on BlueZ and CoreBluetooth. I'll make a separate issue to address this specifically, as these edits suffice for now.

@kevincar kevincar merged commit 4eef666 into kevincar:master Jan 22, 2026
9 checks passed
@EasyRiderr EasyRiderr deleted the fix_add_gatt branch January 22, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants