3131
3232# pylint: disable=no-name-in-module
3333
34+ from micropython import const
3435from adafruit_esp32spi import adafruit_esp32spi
3536import adafruit_esp32spi .adafruit_esp32spi_requests as requests
3637
37- class WiFiConnType : # pylint: disable=too-few-public-methods
38- """An enum-like class representing the different types of WiFi connections
39- that can be made. The values can be referenced like ``WiFiConnType.normal``.
40- Possible values are
41- - ``ThermocoupleType.normal``
42- - ``ThermocoupleType.enterprise``
43- """
44- # pylint: disable=invalid-name
45- normal = 1
46- enterprise = 2
47-
4838class ESPSPI_WiFiManager :
4939 """
5040 A class to help manage the Wifi connection
5141 """
52- def __init__ (self , esp , secrets , status_pixel = None , attempts = 2 , wificonntype = WiFiConnType .normal ):
42+ NORMAL = const (1 )
43+ ENTERPRISE = const (2 )
44+
45+ def __init__ (self , esp , secrets , status_pixel = None , attempts = 2 , connection_type = NORMAL ):
5346 """
5447 :param ESP_SPIcontrol esp: The ESP object we are using
5548 :param dict secrets: The WiFi and Adafruit IO secrets dict (See examples)
@@ -69,9 +62,9 @@ def __init__(self, esp, secrets, status_pixel=None, attempts=2, wificonntype=WiF
6962 self .ent_ssid = secrets ['ent_ssid' ]
7063 self .ent_ident = secrets ['ent_ident' ]
7164 self .ent_user = secrets ['ent_user' ]
72- self .ent_passwd = secrets ['ent_passwd ' ]
65+ self .ent_password = secrets ['ent_password ' ]
7366 self .attempts = attempts
74- self .wificonntype = wificonntype
67+ self ._connection_type = connection_type
7568 requests .set_interface (self ._esp )
7669 self .statuspix = status_pixel
7770 self .pixel_status (0 )
@@ -96,7 +89,7 @@ def connect(self):
9689 for access_pt in self ._esp .scan_networks ():
9790 print ("\t %s\t \t RSSI: %d" % (str (access_pt ['ssid' ], 'utf-8' ), access_pt ['rssi' ]))
9891 failure_count = 0
99- if self .wificonntype == WiFiConnType . normal :
92+ if self ._connection_type == ESPSPI_WiFiManager . NORMAL :
10093 while not self ._esp .is_connected :
10194 try :
10295 if self .debug :
@@ -112,11 +105,11 @@ def connect(self):
112105 failure_count = 0
113106 self .reset ()
114107 continue
115- elif self .wificonntype == WiFiConnType . enterprise :
108+ elif self ._connection_type == ESPSPI_WiFiManager . ENTERPRISE :
116109 self ._esp .wifi_set_network (bytes (self .ent_ssid , 'utf-8' ))
117110 self ._esp .wifi_set_entidentity (bytes (self .ent_ident , 'utf-8' ))
118111 self ._esp .wifi_set_entusername (bytes (self .ent_user , 'utf-8' ))
119- self ._esp .wifi_set_entpassword (bytes (self .ent_passwd , 'utf-8' ))
112+ self ._esp .wifi_set_entpassword (bytes (self .ent_password , 'utf-8' ))
120113 self ._esp .wifi_set_entenable ()
121114 while not self ._esp .is_connected :
122115 try :
@@ -133,8 +126,7 @@ def connect(self):
133126 self .reset ()
134127 continue
135128 else :
136- print ("Invalid connection type! Exiting..." )
137- exit (1 )
129+ raise TypeError ("Invalid WiFi connection type specified" )
138130
139131 def get (self , url , ** kw ):
140132 """
0 commit comments