Description
As far as I can tell, PR #65 broke the MagTag() constructor.
From the "Simple test" example in the docs, you are instructed to use the MagTag
constructor to get an instance to the MagTag class, which you need to access MagTag-specific APIs:
from adafruit_magtag.magtag import MagTag
magtag = MagTag()
magtag.add_text(
text_position=(
50,
(magtag.graphics.display.height // 2) - 1,
),
text_scale=3,
)
that constructor ends up calling the Network class, which then ends up calling the constructor from PortalBase' Network:
This is called without any secrets, and that's fine because PortalBase defaults to None
. However, if you don't pass None
, this piece of code will still be executed:
Adafruit_CircuitPython_PortalBase/adafruit_portalbase/network.py
Lines 114 to 119 in fc73ddc
secrets
here is the global secrets import. This code assumes that ssid
and password
will always be defined at the root level of the secrets. However, this assumption isn't really documented anywhere, and I've been previously fine with having a secrets structure of, for example,
secrets = {
"api_root": "https://example.com",
"wifi": {
"ssid": "example",
"password": "example"
}
}
If you have a structure like mine, the aforementioned access of self._secrets["ssid"]
and self._secrets["password"]
will fail with a KeyError
.
In my very humble opinion, this whole code should make sure that the secrets are actually there, and if not, it probably should just not attempt to connect to a network. Users can connect manually via wifi.radio.connect
anyway, and provide the credentials there. Moreover, even if "you need to provide the SSID and password in the secrets root if you want to use networking" would be a acceptable compromise, this would still break the library for users who want to use MagTag-specific things, but aren't actually interested in networking. So either way, a bit of extra protection probably doesn't hurt. :)
I would submit a PR, but unfortunately I'm not set up to build CircuitPython myself, and it looks like it's quite a task to get that done... :(
/cc @tekktrik