8
8
9
9
import time
10
10
import os
11
+ import ssl
11
12
import microcontroller
12
13
import supervisor
13
- import ssl
14
14
import socketpool
15
15
import wifi
16
16
import board
23
23
import adafruit_requests
24
24
import adafruit_max1704x
25
25
26
-
27
-
28
26
# Initialize the power pin for the sensor
29
27
sensor_power = digitalio .DigitalInOut (board .A2 )
30
28
sensor_power .direction = digitalio .Direction .OUTPUT
@@ -75,6 +73,7 @@ def power_sensor_off():
75
73
76
74
def parse_time (time_str ):
77
75
"""Convert time string (HH:MM format) to hours and minutes."""
76
+ # pylint: disable=redefined-outer-name
78
77
parts = time_str .split (':' )
79
78
return int (parts [0 ]), int (parts [1 ])
80
79
@@ -121,7 +120,9 @@ def set_pixel_color(distance):
121
120
avg_distance = get_average_distance ()
122
121
123
122
if avg_distance is not None :
123
+
124
124
if avg_distance >= 22 :
125
+ # pylint: disable=invalid-name
125
126
avg_distance = 22
126
127
print (f"Average distance: { avg_distance :.1f} cm" )
127
128
# Set color based on average distance
@@ -134,6 +135,7 @@ def set_pixel_color(distance):
134
135
135
136
# Try connecting to WiFi
136
137
try :
138
+
137
139
print ("Connecting to %s" % os .getenv ("CIRCUITPY_WIFI_SSID" ))
138
140
# Show pink while attempting to connect
139
141
pixel .fill (PINK )
@@ -142,6 +144,7 @@ def set_pixel_color(distance):
142
144
# Show cyan on successful connection
143
145
pixel .fill (CYAN )
144
146
time .sleep (1 ) # Brief pause to show the connection success
147
+ # pylint: disable=broad-except
145
148
except Exception as e :
146
149
print ("Failed to connect to WiFi. Error:" , e , "\n Board will hard reset in 30 seconds." )
147
150
pixel .fill (OFF )
@@ -174,6 +177,7 @@ def set_pixel_color(distance):
174
177
aio_username = os .getenv ("ADAFRUIT_AIO_USERNAME" )
175
178
aio_key = os .getenv ("ADAFRUIT_AIO_KEY" )
176
179
timezone = os .getenv ("TIMEZONE" )
180
+ # pylint: disable=line-too-long
177
181
TIME_URL = f"https://io.adafruit.com/api/v2/{ aio_username } /integrations/time/strftime?x-aio-key={ aio_key } &tz={ timezone } "
178
182
TIME_URL += "&fmt=%25Y-%25m-%25d+%25H%3A%25M%3A%25S.%25L+%25j+%25u+%25z+%25Z"
179
183
@@ -222,6 +226,7 @@ def set_pixel_color(distance):
222
226
time .sleep (DISPLAY_DURATION )
223
227
224
228
# Use normal check interval during operating hours
229
+ # # pylint: disable=invalid-name
225
230
sleep_seconds = SLEEP_DURATION
226
231
print (f"Next check in { NORMAL_CHECK_MINUTES } minutes" )
227
232
else :
@@ -245,6 +250,7 @@ def set_pixel_color(distance):
245
250
246
251
response .close ()
247
252
253
+ # pylint: disable=broad-except
248
254
except Exception as e :
249
255
print ("Failed to get or send data, or connect. Error:" , e ,
250
256
"\n Board will hard reset in 30 seconds." )
@@ -255,13 +261,15 @@ def set_pixel_color(distance):
255
261
else :
256
262
print ("Failed to get valid distance readings" )
257
263
pixel .fill (OFF )
264
+ # pylint: disable=invalid-name
258
265
sleep_seconds = SLEEP_DURATION # Use normal interval if we couldn't get readings
259
266
260
267
# Prepare for deep sleep
261
- pixel .brightness = 0 # Turn off NeoPixel
262
268
power_sensor_off () # Make sure sensor is powered off before sleep
269
+ pixel .brightness = 0 # Turn off NeoPixel
263
270
264
271
# Flush the serial output before sleep
272
+ # pylint: disable=pointless-statement
265
273
supervisor .runtime .serial_bytes_available
266
274
time .sleep (0.05 )
267
275
0 commit comments