Skip to content

Commit 59228b1

Browse files
committed
QA: Apply auto fixes.
1 parent 3ae630f commit 59228b1

File tree

8 files changed

+76
-83
lines changed

8 files changed

+76
-83
lines changed

examples/plasma_stick/cheerlights.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Find out more about the Cheerlights API at https://cheerlights.com/
1212
"""
1313

14-
URL = 'http://api.thingspeak.com/channels/1417/field/2/last.json'
14+
URL = "http://api.thingspeak.com/channels/1417/field/2/last.json"
1515
UPDATE_INTERVAL = 120 # refresh interval in secs. Be nice to free APIs!
1616

1717
# Set how many LEDs you have
@@ -23,7 +23,7 @@
2323

2424
# if no wifi connection, you get spooky rainbows. Bwahahaha!
2525
def wifi_failed(message=""):
26-
print(f'Wifi connection failed! {message}')
26+
print(f"Wifi connection failed! {message}")
2727
spooky_rainbows()
2828

2929

@@ -33,7 +33,7 @@ def wifi_message(wifi, message):
3333

3434

3535
def spooky_rainbows():
36-
print('SPOOKY RAINBOWS!')
36+
print("SPOOKY RAINBOWS!")
3737
HUE_START = 30 # orange
3838
HUE_END = 140 # green
3939
SPEED = 0.3 # bigger = faster (harder, stronger)
@@ -60,13 +60,13 @@ def spooky_rainbows():
6060

6161
def hex_to_rgb(hex):
6262
# converts a hex colour code into RGB
63-
h = hex.lstrip('#')
63+
h = hex.lstrip("#")
6464
r, g, b = (int(h[i:i + 2], 16) for i in (0, 2, 4))
6565
return r, g, b
6666

6767

6868
# set up the Pico W's onboard LED
69-
pico_led = Pin('LED', Pin.OUT)
69+
pico_led = Pin("LED", Pin.OUT)
7070

7171
# set up the WS2812 / NeoPixel™ LEDs
7272
led_strip = plasma.WS2812(NUM_LEDS, color_order=plasma.COLOR_ORDER_RGB)
@@ -82,11 +82,11 @@ def hex_to_rgb(hex):
8282

8383
while True:
8484
# open the json file
85-
print(f'Requesting URL: {URL}')
85+
print(f"Requesting URL: {URL}")
8686
r = urequests.get(URL)
8787
# open the json data
8888
j = r.json()
89-
print('Data obtained!')
89+
print("Data obtained!")
9090
r.close()
9191

9292
# flash the onboard LED after getting data
@@ -95,7 +95,7 @@ def hex_to_rgb(hex):
9595
pico_led.value(False)
9696

9797
# extract hex colour from the data
98-
hex = j['field2']
98+
hex = j["field2"]
9999

100100
# and convert it to RGB
101101
r, g, b = hex_to_rgb(hex)
@@ -106,8 +106,8 @@ def hex_to_rgb(hex):
106106
# light up the LEDs
107107
for i in range(NUM_LEDS):
108108
led_strip.set_rgb(i, r, g, b)
109-
print(f'LEDs set to {hex}')
109+
print(f"LEDs set to {hex}")
110110

111111
# sleep
112-
print(f'Sleeping for {UPDATE_INTERVAL} seconds.')
112+
print(f"Sleeping for {UPDATE_INTERVAL} seconds.")
113113
time.sleep(UPDATE_INTERVAL)

examples/plasma_stick/moon.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,26 @@
3232
while True:
3333
# get the time from Pico RTC
3434
year, month, day, _, hour, minute, second, _ = RTC().datetime()
35-
print(f'Time is {hour:02d}:{minute:02d}')
35+
print(f"Time is {hour:02d}:{minute:02d}")
3636

3737
# calculate how long to go until midnight
3838
if hour >= 12:
3939
hours_to_go = 23 - hour
4040
minutes_to_go = 59 - minute
4141
seconds_to_go = 59 - second
4242
total_seconds = hours_to_go * 60 * 60 + minutes_to_go * 60 + seconds_to_go
43-
print(f'{total_seconds} seconds until midnight')
43+
print(f"{total_seconds} seconds until midnight")
4444
# or, if it's after midnight
4545
else:
4646
hours_since = 0 + hour
4747
minutes_since = 0 + minute
4848
seconds_since = 0 + second
4949
total_seconds = hours_since * 60 * 60 + minutes_since * 60 + seconds_since
50-
print(f'{total_seconds} seconds since midnight')
50+
print(f"{total_seconds} seconds since midnight")
5151

5252
# gets brighter as witching hour approacheth
5353
brightness = max(0, (COUNT_FROM - total_seconds) / COUNT_FROM)
5454
for i in range(NUM_LEDS):
5555
led_strip.set_hsv(i, HUE / 360.0, SATURATION, brightness)
56-
print(f'Brightness - {brightness * 100} %')
56+
print(f"Brightness - {brightness * 100} %")
5757
time.sleep(10.0)

examples/plasma_stick/moon_rtc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,26 @@ def set_pico_time():
5959
while True:
6060
# get the time from Pico RTC
6161
year, month, day, _, hour, minute, second, _ = RTC().datetime()
62-
print(f'Time is {hour:02d}:{minute:02d}')
62+
print(f"Time is {hour:02d}:{minute:02d}")
6363

6464
# calculate how long to go until midnight
6565
if hour >= 12:
6666
hours_to_go = 23 - hour
6767
minutes_to_go = 59 - minute
6868
seconds_to_go = 59 - second
6969
total_seconds = hours_to_go * 60 * 60 + minutes_to_go * 60 + seconds_to_go
70-
print(f'{total_seconds} seconds until midnight')
70+
print(f"{total_seconds} seconds until midnight")
7171
# or, if it's after midnight
7272
else:
7373
hours_since = 0 + hour
7474
minutes_since = 0 + minute
7575
seconds_since = 0 + second
7676
total_seconds = hours_since * 60 * 60 + minutes_since * 60 + seconds_since
77-
print(f'{total_seconds} seconds since midnight')
77+
print(f"{total_seconds} seconds since midnight")
7878

7979
# gets brighter as witching hour approacheth
8080
brightness = max(0, (COUNT_FROM - total_seconds) / COUNT_FROM)
8181
for i in range(NUM_LEDS):
8282
led_strip.set_hsv(i, HUE / 360.0, SATURATION, brightness)
83-
print(f'Brightness - {brightness * 100} %')
83+
print(f"Brightness - {brightness * 100} %")
8484
time.sleep(10.0)

examples/plasma_stick/weather.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,40 @@
3030

3131
# Weather codes from https://open-meteo.com/en/docs#:~:text=WMO%20Weather%20interpretation%20codes%20(WW)
3232
WEATHERCODES = {
33-
0: 'clear sky',
34-
1: 'mostly clear',
35-
2: 'partly cloudy',
36-
3: 'cloudy',
37-
45: 'fog and depositing rime',
38-
48: 'fog',
39-
51: 'light drizzle',
40-
53: 'moderate drizzle',
41-
55: 'dense drizzle',
42-
56: 'light freezing drizzle',
43-
57: 'dense freezing drizzle',
44-
61: 'slight rain',
45-
63: 'moderate rain',
46-
65: 'heavy rain',
47-
66: 'light freezing rain',
48-
67: 'heavy freezing rain',
49-
71: 'slight snow',
50-
73: 'moderate snow',
51-
75: 'heavy snow',
52-
77: 'snow grains',
53-
80: 'slight rain showers',
54-
81: 'moderate rain showers',
55-
82: 'violent rain showers',
56-
85: 'slight snow showers',
57-
86: 'heavy snow showers',
58-
95: 'thunderstorm',
59-
96: 'thunderstorm with slight hail',
60-
99: 'thunderstorm with heavy hail'
33+
0: "clear sky",
34+
1: "mostly clear",
35+
2: "partly cloudy",
36+
3: "cloudy",
37+
45: "fog and depositing rime",
38+
48: "fog",
39+
51: "light drizzle",
40+
53: "moderate drizzle",
41+
55: "dense drizzle",
42+
56: "light freezing drizzle",
43+
57: "dense freezing drizzle",
44+
61: "slight rain",
45+
63: "moderate rain",
46+
65: "heavy rain",
47+
66: "light freezing rain",
48+
67: "heavy freezing rain",
49+
71: "slight snow",
50+
73: "moderate snow",
51+
75: "heavy snow",
52+
77: "snow grains",
53+
80: "slight rain showers",
54+
81: "moderate rain showers",
55+
82: "violent rain showers",
56+
85: "slight snow showers",
57+
86: "heavy snow showers",
58+
95: "thunderstorm",
59+
96: "thunderstorm with slight hail",
60+
99: "thunderstorm with heavy hail"
6161
}
6262

6363

6464
# if no wifi connection, you get spooky rainbows. Bwahahaha!
6565
def wifi_failed(message=""):
66-
print(f'Wifi connection failed! {message}')
66+
print(f"Wifi connection failed! {message}")
6767
for i in range(NUM_LEDS):
6868
led_strip.set_rgb(i, 255, 0, 0)
6969

@@ -220,7 +220,7 @@ def snow():
220220
target_leds = [[0] * 3 for i in range(NUM_LEDS)]
221221

222222
# set up the Pico W's onboard LED
223-
pico_led = Pin('LED', Pin.OUT)
223+
pico_led = Pin("LED", Pin.OUT)
224224

225225
# set up the WS2812 / NeoPixel™ LEDs
226226
led_strip = plasma.WS2812(NUM_LEDS, color_order=plasma.COLOR_ORDER_RGB)

modules/common/pimoroni.py

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ def read_voltage(self):
2929
def read_current(self):
3030
if self.resistor > 0:
3131
return self.read_voltage() / self.resistor
32-
else:
33-
return self.read_voltage()
32+
return self.read_voltage()
3433

3534

3635
class AnalogMux:
@@ -50,25 +49,24 @@ def __init__(self, addr0, addr1=None, addr2=None, en=None, muxed_pin=None):
5049
def select(self, address):
5150
if address < 0:
5251
raise ValueError("address is less than zero")
53-
elif address > self.max_address:
52+
if address > self.max_address:
5453
raise ValueError("address is greater than number of available addresses")
55-
else:
56-
if self.muxed_pin and self.pulls[address] is None:
57-
self.muxed_pin.init(Pin.IN, None)
54+
if self.muxed_pin and self.pulls[address] is None:
55+
self.muxed_pin.init(Pin.IN, None)
5856

59-
self.addr0_pin.value(address & 0b001)
57+
self.addr0_pin.value(address & 0b001)
6058

61-
if self.addr1_pin is not None:
62-
self.addr1_pin.value(address & 0b010)
59+
if self.addr1_pin is not None:
60+
self.addr1_pin.value(address & 0b010)
6361

64-
if self.addr2_pin is not None:
65-
self.addr2_pin.value(address & 0b100)
62+
if self.addr2_pin is not None:
63+
self.addr2_pin.value(address & 0b100)
6664

67-
if self.en_pin is not None:
68-
self.en_pin.value(1)
65+
if self.en_pin is not None:
66+
self.en_pin.value(1)
6967

70-
if self.muxed_pin and self.pulls[address] is not None:
71-
self.muxed_pin.init(Pin.IN, self.pulls[address])
68+
if self.muxed_pin and self.pulls[address] is not None:
69+
self.muxed_pin.init(Pin.IN, self.pulls[address])
7270

7371
def disable(self):
7472
if self.en_pin is not None:
@@ -79,16 +77,14 @@ def disable(self):
7977
def configure_pull(self, address, pull=None):
8078
if address < 0:
8179
raise ValueError("address is less than zero")
82-
elif address > self.max_address:
80+
if address > self.max_address:
8381
raise ValueError("address is greater than number of available addresses")
84-
else:
85-
self.pulls[address] = pull
82+
self.pulls[address] = pull
8683

8784
def read(self):
8885
if self.muxed_pin is not None:
8986
return self.muxed_pin.value()
90-
else:
91-
raise RuntimeError("there is no muxed pin assigned to this mux")
87+
raise RuntimeError("there is no muxed pin assigned to this mux")
9288

9389

9490
class Button:
@@ -113,10 +109,9 @@ def read(self):
113109
self.pressed = True
114110
self.last_time = current_time
115111
return True
116-
else:
117-
self.pressed_time = 0
118-
self.pressed = False
119-
self.last_time = 0
112+
self.pressed_time = 0
113+
self.pressed = False
114+
self.last_time = 0
120115

121116
if self.repeat_time == 0:
122117
return False
@@ -134,8 +129,7 @@ def read(self):
134129
def raw(self):
135130
if self.invert:
136131
return not self.pin.value()
137-
else:
138-
return self.pin.value()
132+
return self.pin.value()
139133

140134
@property
141135
def is_pressed(self):

modules/common/qwstpad.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class QwSTPad:
2828
CONFIGURATION_PORT1 = const(0x07)
2929

3030
# Mappings
31-
BUTTON_MAPPING = OrderedDict({'A': 0xE, 'B': 0xC, 'X': 0xF, 'Y': 0xD,
32-
'U': 0x1, 'D': 0x4, 'L': 0x2, 'R': 0x3,
33-
'+': 0xB, '-': 0x5
31+
BUTTON_MAPPING = OrderedDict({"A": 0xE, "B": 0xC, "X": 0xF, "Y": 0xD,
32+
"U": 0x1, "D": 0x4, "L": 0x2, "R": 0x3,
33+
"+": 0xB, "-": 0x5
3434
})
3535
LED_MAPPING = (0x6, 0x7, 0x9, 0xA)
3636

modules/wireless/ezwifi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async def _log(self, text, level=LogLevel.INFO):
4949

5050
def on(self, handler_name, handler=None):
5151
if handler_name not in self._events.keys():
52-
raise ValueError(f"Invalid event: \"{handler_name}\"")
52+
raise ValueError(f'Invalid event: "{handler_name}"')
5353

5454
def _on(handler):
5555
self._events[handler_name] = handler

modules/wireless/lte.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ def _netlight_irq(self, pin):
5353
def ipconfig(self, *args, **kwargs):
5454
if len(args):
5555
return self._ppp.ipconfig(*args)
56-
else:
57-
return self._ppp.ipconfig(**kwargs)
56+
return self._ppp.ipconfig(**kwargs)
5857

5958
def iccid(self):
6059
try:
@@ -124,7 +123,7 @@ def connect(self, timeout=60):
124123
self._wait_ready()
125124

126125
self._send_at_command("ATE0") # Disable local echo
127-
self._send_at_command(f"AT+CGDCONT=1,\"IP\",\"{self._apn}\"") # Set apn and activate pdp context
126+
self._send_at_command(f'AT+CGDCONT=1,"IP","{self._apn}"') # Set apn and activate pdp context
128127

129128
# Wait for roaming lte connection to be established
130129
giveup = time.time() + timeout
@@ -136,8 +135,8 @@ def connect(self, timeout=60):
136135
raise CellularError("timed out getting network registration")
137136

138137
# Disable server and client certification validation
139-
self._send_at_command("AT+CSSLCFG=\"authmode\",0,0")
140-
self._send_at_command("AT+CSSLCFG=\"enableSNI\",0,1")
138+
self._send_at_command('AT+CSSLCFG="authmode",0,0')
139+
self._send_at_command('AT+CSSLCFG="enableSNI",0,1')
141140

142141
print(f" - SIM ICCID is {self.iccid()}")
143142

0 commit comments

Comments
 (0)