@@ -98,13 +98,24 @@ def __init__(
98
98
]
99
99
100
100
if secrets_data is not None :
101
- self ._secrets_entries = secrets_data
101
+ self ._secrets = secrets_data
102
102
else :
103
- self ._secrets_entries = secrets
104
-
105
- if not isinstance (self ._secrets_entries , (list , tuple )):
106
- self ._secrets_entries = [self ._secrets_entries ]
107
- self ._secrets = self ._secrets_entries [0 ]
103
+ self ._secrets = secrets
104
+
105
+ if "networks" in self ._secrets :
106
+ if isinstance (self ._secrets ["networks" ], (list , tuple )):
107
+ self ._secrets_network = self ._secrets ["networks" ]
108
+ else :
109
+ raise TypeError (
110
+ "'networks' must be a list/tuple of dicts of 'ssid' and 'password'"
111
+ )
112
+ else :
113
+ self ._secrets_network = [
114
+ {
115
+ "ssid" : self ._secrets ["ssid" ],
116
+ "passwprd" : self ._secrets ["password" ],
117
+ }
118
+ ]
108
119
109
120
self .requests = None
110
121
@@ -329,9 +340,7 @@ def connect(self, max_attempts=10):
329
340
failing or use None to disable. Defaults to 10.
330
341
331
342
"""
332
- for secret_entry in self ._secrets_entries :
333
-
334
- self ._secrets = secret_entry
343
+ for secret_entry in self ._secrets_network :
335
344
336
345
self ._wifi .neo_status (STATUS_CONNECTING )
337
346
attempt = 1
@@ -340,8 +349,8 @@ def connect(self, max_attempts=10):
340
349
# secrets dictionary must contain 'ssid' and 'password' at a minimum
341
350
print ("Connecting to AP" , self ._secrets ["ssid" ])
342
351
if (
343
- self . _secrets ["ssid" ] == "CHANGE ME"
344
- or self . _secrets ["password" ] == "CHANGE ME"
352
+ secret_entry ["ssid" ] == "CHANGE ME"
353
+ or secret_entry ["password" ] == "CHANGE ME"
345
354
):
346
355
change_me = "\n " + "*" * 45
347
356
change_me += "\n Please update the 'secrets.py' file on your\n "
@@ -352,7 +361,7 @@ def connect(self, max_attempts=10):
352
361
raise OSError (change_me )
353
362
self ._wifi .neo_status (STATUS_NO_CONNECTION ) # red = not connected
354
363
try :
355
- self ._wifi .connect (self . _secrets ["ssid" ], self . _secrets ["password" ])
364
+ self ._wifi .connect (secret_entry ["ssid" ], secret_entry ["password" ])
356
365
self .requests = self ._wifi .requests
357
366
break
358
367
except ConnectionError as error :
0 commit comments