bluetooth-numbers icon indicating copy to clipboard operation
bluetooth-numbers copied to clipboard

reverse lookup

Open dlech opened this issue 1 year ago • 5 comments

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.

dlech avatar Nov 15 '23 23:11 dlech

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

vincentdavis avatar Dec 10 '23 15:12 vincentdavis

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

koenvervloesem avatar Dec 12 '23 08:12 koenvervloesem

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?

dlech avatar Dec 12 '23 09:12 dlech

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

@vincentdavis:

  • What use cases do you have for returning multiple matches?
  • Do you think you could rework your code to generate those enums? See https://github.com/koenvervloesem/bluetooth-numbers/blob/main/scripts/generate_modules.py for how the other modules are generated now.

koenvervloesem avatar Dec 12 '23 09:12 koenvervloesem

@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.

vincentdavis avatar Dec 12 '23 15:12 vincentdavis