45
45
"""WiFi settings are kept in secrets.py, please add them there!
46
46
the secrets dictionary must contain 'ssid' and 'password' at a minimum"""
47
47
)
48
- raise
49
48
50
49
__version__ = "0.0.0-auto.0"
51
50
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PortalBase.git"
@@ -87,28 +86,29 @@ class NetworkBase:
87
86
:param bool extract_values: If true, single-length fetched values are automatically extracted
88
87
from lists and tuples. Defaults to ``True``.
89
88
:param debug: Turn on debug print outs. Defaults to False.
89
+ :param list secrets_data: An optional list in place of the data contained in the secrets.py file
90
90
91
91
"""
92
92
93
93
# pylint: disable=too-many-instance-attributes, too-many-locals, too-many-branches, too-many-statements
94
94
def __init__ (
95
- self ,
96
- wifi_module ,
97
- * ,
98
- extract_values = True ,
99
- debug = False ,
95
+ self , wifi_module , * , extract_values = True , debug = False , secrets_data = None
100
96
):
101
97
self ._wifi = wifi_module
102
98
self ._debug = debug
103
99
self .json_transform = []
104
100
self ._extract_values = extract_values
105
-
106
101
self ._json_types = [
107
102
"application/json" ,
108
103
"application/javascript" ,
109
104
"application/geo+json" ,
110
105
]
111
106
107
+ if secrets_data is not None :
108
+ self ._secrets = secrets_data
109
+ else :
110
+ self ._secrets = secrets
111
+
112
112
# This may be removed. Using for testing
113
113
self .requests = None
114
114
@@ -175,15 +175,15 @@ def get_local_time(self, location=None):
175
175
self .connect ()
176
176
api_url = None
177
177
try :
178
- aio_username = secrets ["aio_username" ]
179
- aio_key = secrets ["aio_key" ]
178
+ aio_username = self . _secrets ["aio_username" ]
179
+ aio_key = self . _secrets ["aio_key" ]
180
180
except KeyError :
181
181
raise KeyError (
182
182
"\n \n Our time service requires a login/password to rate-limit. Please register for a free adafruit.io account and place the user/key in your secrets file under 'aio_username' and 'aio_key'" # pylint: disable=line-too-long
183
183
) from KeyError
184
184
185
185
if location is None :
186
- location = secrets .get ("timezone" , location )
186
+ location = self . _secrets .get ("timezone" , location )
187
187
if location :
188
188
print ("Getting time for timezone" , location )
189
189
api_url = (TIME_SERVICE + "&tz=%s" ) % (aio_username , aio_key , location )
@@ -301,8 +301,11 @@ def connect(self):
301
301
self ._wifi .neo_status (STATUS_CONNECTING )
302
302
while not self ._wifi .is_connected :
303
303
# secrets dictionary must contain 'ssid' and 'password' at a minimum
304
- print ("Connecting to AP" , secrets ["ssid" ])
305
- if secrets ["ssid" ] == "CHANGE ME" or secrets ["password" ] == "CHANGE ME" :
304
+ print ("Connecting to AP" , self ._secrets ["ssid" ])
305
+ if (
306
+ self ._secrets ["ssid" ] == "CHANGE ME"
307
+ or self ._secrets ["password" ] == "CHANGE ME"
308
+ ):
306
309
change_me = "\n " + "*" * 45
307
310
change_me += "\n Please update the 'secrets.py' file on your\n "
308
311
change_me += "CIRCUITPY drive to include your local WiFi\n "
@@ -312,7 +315,7 @@ def connect(self):
312
315
raise OSError (change_me )
313
316
self ._wifi .neo_status (STATUS_NO_CONNECTION ) # red = not connected
314
317
try :
315
- self ._wifi .connect (secrets ["ssid" ], secrets ["password" ])
318
+ self ._wifi .connect (self . _secrets ["ssid" ], self . _secrets ["password" ])
316
319
self .requests = self ._wifi .requests
317
320
except RuntimeError as error :
318
321
print ("Could not connect to internet" , error )
@@ -323,8 +326,8 @@ def _get_io_client(self):
323
326
self .connect ()
324
327
325
328
try :
326
- aio_username = secrets ["aio_username" ]
327
- aio_key = secrets ["aio_key" ]
329
+ aio_username = self . _secrets ["aio_username" ]
330
+ aio_key = self . _secrets ["aio_key" ]
328
331
except KeyError :
329
332
raise KeyError (
330
333
"Adafruit IO secrets are kept in secrets.py, please add them there!\n \n "
0 commit comments