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