3131
3232# pylint: disable=no-name-in-module
3333
34- import neopixel
3534import adafruit_esp32spi
3635import adafruit_esp32spi .adafruit_esp32spi_requests as requests
3736
3837class ESPSPI_WiFiManager :
3938 """
4039 A class to help manage the Wifi connection
4140 """
42- def __init__ (self , esp , secrets , status_neopixel = None , attempts = 2 ):
41+ def __init__ (self , esp , secrets , status_pixel , attempts = 2 ):
4342 """
4443 :param ESP_SPIcontrol esp: The ESP object we are using
4544 :param dict secrets: The WiFi and Adafruit IO secrets dict (See examples)
45+ :param status_pixel: (Optional) The pixel device - A NeoPixel or DotStar (default=None)
46+ :type status_pixel: NeoPixel or DotStar
4647 :param int attempts: (Optional) Failed attempts before resetting the ESP32 (default=2)
47- :param status_neopixel: (Optional) The neopixel pin - Usually board.NEOPIXEL (default=None)
48- :type status_neopixel: Pin
4948 """
5049 # Read the settings
5150 self ._esp = esp
@@ -54,11 +53,8 @@ def __init__(self, esp, secrets, status_neopixel=None, attempts=2):
5453 self .password = secrets ['password' ]
5554 self .attempts = attempts
5655 requests .set_interface (self ._esp )
57- if status_neopixel :
58- self .neopix = neopixel .NeoPixel (status_neopixel , 1 , brightness = 0.2 )
59- else :
60- self .neopix = None
61- self .neo_status (0 )
56+ self .statuspix = status_pixel
57+ self .pixel_status (0 )
6258
6359 def reset (self ):
6460 """
@@ -84,10 +80,10 @@ def connect(self):
8480 try :
8581 if self .debug :
8682 print ("Connecting to AP..." )
87- self .neo_status ((100 , 0 , 0 ))
83+ self .pixel_status ((100 , 0 , 0 ))
8884 self ._esp .connect_AP (bytes (self .ssid , 'utf-8' ), bytes (self .password , 'utf-8' ))
8985 failure_count = 0
90- self .neo_status ((0 , 100 , 0 ))
86+ self .pixel_status ((0 , 100 , 0 ))
9187 except (ValueError , RuntimeError ) as error :
9288 print ("Failed to connect, retrying\n " , error )
9389 failure_count += 1
@@ -110,9 +106,9 @@ def get(self, url, **kw):
110106 """
111107 if not self ._esp .is_connected :
112108 self .connect ()
113- self .neo_status ((0 , 0 , 100 ))
109+ self .pixel_status ((0 , 0 , 100 ))
114110 return_val = requests .get (url , ** kw )
115- self .neo_status (0 )
111+ self .pixel_status (0 )
116112 return return_val
117113
118114 def post (self , url , ** kw ):
@@ -129,7 +125,7 @@ def post(self, url, **kw):
129125 """
130126 if not self ._esp .is_connected :
131127 self .connect ()
132- self .neo_status ((0 , 0 , 100 ))
128+ self .pixel_status ((0 , 0 , 100 ))
133129 return_val = requests .post (url , ** kw )
134130 return return_val
135131
@@ -147,9 +143,9 @@ def put(self, url, **kw):
147143 """
148144 if not self ._esp .is_connected :
149145 self .connect ()
150- self .neo_status ((0 , 0 , 100 ))
146+ self .pixel_status ((0 , 0 , 100 ))
151147 return_val = requests .put (url , ** kw )
152- self .neo_status (0 )
148+ self .pixel_status (0 )
153149 return return_val
154150
155151 def patch (self , url , ** kw ):
@@ -166,9 +162,9 @@ def patch(self, url, **kw):
166162 """
167163 if not self ._esp .is_connected :
168164 self .connect ()
169- self .neo_status ((0 , 0 , 100 ))
165+ self .pixel_status ((0 , 0 , 100 ))
170166 return_val = requests .patch (url , ** kw )
171- self .neo_status (0 )
167+ self .pixel_status (0 )
172168 return return_val
173169
174170 def delete (self , url , ** kw ):
@@ -185,9 +181,9 @@ def delete(self, url, **kw):
185181 """
186182 if not self ._esp .is_connected :
187183 self .connect ()
188- self .neo_status ((0 , 0 , 100 ))
184+ self .pixel_status ((0 , 0 , 100 ))
189185 return_val = requests .delete (url , ** kw )
190- self .neo_status (0 )
186+ self .pixel_status (0 )
191187 return return_val
192188
193189 def ping (self , host , ttl = 250 ):
@@ -201,17 +197,17 @@ def ping(self, host, ttl=250):
201197 """
202198 if not self ._esp .is_connected :
203199 self .connect ()
204- self .neo_status ((0 , 0 , 100 ))
200+ self .pixel_status ((0 , 0 , 100 ))
205201 response_time = self ._esp .ping (host , ttl = ttl )
206- self .neo_status (0 )
202+ self .pixel_status (0 )
207203 return response_time
208204
209- def neo_status (self , value ):
205+ def pixel_status (self , value ):
210206 """
211207 Change Status NeoPixel if it was defined
212208
213209 :param value: The value to set the Board's Status NeoPixel to
214210 :type value: int or 3-value tuple
215211 """
216- if self .neopix :
217- self .neopix .fill (value )
212+ if self .statuspix :
213+ self .statuspix .fill (value )
0 commit comments