ukBaz / python-bluezero

A simple Python interface to Bluez
MIT License
387 stars 112 forks source link

advertisement: allow user provider callbacks #366

Closed karlp closed 2 years ago

karlp commented 2 years ago

Instead of two hardcoded registration success/error callbacks that issue console prints, allow user code to provide callbacks if desired.

Fixes: https://github.com/ukBaz/python-bluezero/issues/365

Signed-off-by: Karl Palsson karlp@tweak.net.au

ukBaz commented 2 years ago

I agree that having the option user provided callbacks is a better solution.

This library is aimed at STEM student activities and worry that **kwargs is unnecessary complication. My initial thought is to have the two extra parameters specifically called out in the signature. e.g:

def register_advertisement(self, advertisement, options=dbus.Array(), reply_handler=None, error_handler=None):

I don't know if specifying None is the best idea for specifying to use the default callbacks. Thoughts?

karlp commented 2 years ago

Eh, None=built in is fine too, if people want null, they can specify their own empty handlers, that's the same thing they'd have to do with my PR as well. The handlers can't really do anything other than log anway, so it might be feasible to jsut drop them outright?

Another option would be to use logging.debug() so it can be turned on or off at app level, but that's "more complicated" perhaps?

ukBaz commented 2 years ago

I am in the process of cleaning up the repository and deciding if PR's should be merged or closed. I'm not happy with this in its current form and the discussion has stopped on it so it falls in to the "close" category.