rm-hull/luma.led_matrix

Human-readable list of supported devices

Opened this issue · 9 comments

device.py contains:

__all__ = ["max7219", "ws2812", "neopixel", "neosegment", "apa102"]

but this cannot be used in the documentation project headline for example. Having a method that returns proper names of these devices instead would be useful.

I seem to think we (mis)used Python's __all__ variable so that the demos could introspect which devices were available. [https://docs.python.org/3/tutorial/modules.html#importing-from-a-package]

What do mean by proper names?

@rm-hull the names in the project description is what I'm trying to get into the documentation

 (MAX7219) and RGB NeoPixels (WS2812 / APA102) 

I suggest something like __devices__ or __deviceNames..

__all__ = ["max7219", "ws2812", "neopixel", "neosegment", "apa102"]

__deviceNames__ = {
    "max7219": "MAX7219",
    "ws2812": "WS2812",
    "neopixel": "Neopixel",
    "neosegment": "Neosegment",
    "apa102": "APA102"
}

And then some method that retrieves the device name by classname etc.

Or we could add a label class var to the devices with the label name.

class max7219(device):
    """
    Serial interface to a series of 8x8 LED matrixes daisychained together with
    MAX7219 chips.
    On creation, an initialization sequence is pumped to the display to properly
    configure it. Further control commands can then be called to affect the
    brightness and other settings.
    """

    label = 'MAX7219'

Note that whatever approach has to work for all other libraries as well.

Thoughts @rm-hull?

How about

__deviceNames__ = { ... }

__all__ = __deviceNames__.keys()

?

That's fine with me as well. I'll make a PR.

Actually, I'd rather not mess around with __all__ and make it depend on other code. I've seen this result in strange bugs (GC) that we don't want to get into. I'd rather keep __all__ hard-coded + new __deviceNames__ with duplication, or use the device.label thing. Thoughts @rm-hull ?

Ok, no problem. Don’t mind which approach tbh ... maybe go with

keep __all__ hard-coded + new __deviceNames__ with duplication

to keep them located together