koenvervloesem / bluetooth-numbers

An up-to-date listing of all the various Bluetooth Specification-related elements (Company IDs, Service UUIDs, Characteristic UUIDs and Descriptor UUIDs), that you can use in your Python projects instead of rolling your own.
https://bluetooth-numbers.readthedocs.io
MIT License
16 stars 3 forks source link

reverse lookup #42

Open dlech opened 12 months ago

dlech commented 12 months ago

It would be useful to have enums or a second dictionary for each data type to be able to look up the number by a human-readable name.

vincentdavis commented 11 months ago

I have an idea for this and am working on it, hope to have something soon.

koenvervloesem commented 11 months ago

@dlech Could you maybe take a look at https://github.com/koenvervloesem/bluetooth-numbers/pull/43 for some suggestions before we merge this?

dlech commented 11 months ago

I was hoping for an enum in order to get autocomplete. Without that, we still have to look up names somewhere, which doesn't really save any time and we might as well hard-code our own constants.

I'm not sure I see the use of returning multiple matches. For all of the use cases I have, I only want one value returned.

For example, I want to be able to write:

LEGO_CID = Companies.LEGO_SYSTEM_AS
# instead of
LEGO_CID = 0x0397

How would this look with the proposed PR?

koenvervloesem commented 11 months ago

Good points. I like the idea of having autocomplete for this.

@vincentdavis:

vincentdavis commented 11 months ago

@koenvervloesem @dlech I like the auto-complete, enum idea. My personal use case is that I am working on ble scanner to find devices, services, ... that are related to cycling power or heartrate. Rather than keep track of multiple sources of SIG/uuids I would like to use bluetooth_numbers.reverse_lookup like a reference tool. by the way, reverse_lookup('LEGO SYSTEM AS', uuid_type=['company']) would return set(0x0397) if there is only one match, and if there is more than one that would be good to know.

If I already know that Companies.LEGO_SYSTEM_AS is a valid Company, then I probably already know the uuid is 0x0397 Thats not to dicount the much cleaner, more readable code of using LEGO_CID = Companies.LEGO_SYSTEM_AS

I would like to keep the reverse_lookup as a useful reference tool. I will work on implementing an enum-type solution as this would also be useful to me.