Skip to content

Commit 1082a37

Browse files
committed
Secrets Cleanup: C and E - change wave updates
1 parent 25db1ba commit 1082a37

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

CircuitPython_WeatherCloud/code.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
button = digitalio.DigitalInOut(board.A1)
2222
button.switch_to_input(pull=digitalio.Pull.UP)
2323

24-
with open("sound/Rain.wav", "rb") as wave_file:
25-
wave = audiocore.WaveFile(wave_file)
24+
wave_file = open("sound/Rain.wav", "rb") # pylint: disable=consider-using-with
25+
wave = audiocore.WaveFile(wave_file)
2626
audio = audioio.AudioOut(board.A0)
2727

2828
# Get WiFi details, ensure these are setup in settings.toml
@@ -137,22 +137,17 @@
137137
print(weather_type) # See https://openweathermap.org/weather-conditions
138138
# default to no rain or thunder
139139
raining = snowing = thundering = has_sound = False
140+
wave_filename = None
140141
if weather_type == 'Sunny':
141142
palette = sunny_palette
142-
with open("sound/Clear.wav", "rb") as wave_file:
143-
wave = audiocore.WaveFile(wave_file)
144-
has_sound = True
143+
wave_filename = "sound/Clear.wav"
145144
if weather_type == 'Clouds':
146145
palette = cloudy_palette
147-
with open("sound/Clouds.wav", "rb") as wave_file:
148-
wave = audiocore.WaveFile(wave_file)
149-
has_sound = True
146+
wave_filename = "sound/Clouds.wav"
150147
if weather_type == 'Rain':
151148
palette = cloudy_palette
152-
with open("sound/Rain.wav", "rb") as wave_file:
153-
wave = audiocore.WaveFile(wave_file)
149+
wave_filename = "sound/Rain.wav"
154150
raining = True
155-
has_sound = True
156151
if weather_type == 'Thunderstorm':
157152
palette = thunder_palette
158153
raining = thundering = True
@@ -161,9 +156,11 @@
161156
next_bolt_time = time.monotonic() + random.randint(1, 5)
162157
if weather_type == 'Snow':
163158
palette = cloudy_palette
164-
with open("sound/Snow.wav", "rb") as wave_file:
165-
wave = audiocore.WaveFile(wave_file)
159+
wave_filename = "sound/Snow.wav"
166160
snowing = True
161+
if wave_filename:
162+
wave_file = open(wave_filename, "rb") # pylint: disable=consider-using-with
163+
wave = audiocore.WaveFile(wave_file)
167164
has_sound = True
168165
weather_refresh = time.monotonic()
169166
except RuntimeError as e:
@@ -215,7 +212,7 @@
215212
elif Thunder == 2:
216213
wave_filename = "sound/Thunderstorm2.wav"
217214
if wave_filename:
218-
with open(wave_filename, "rb") as wave_file:
219-
wave = audiocore.WaveFile(wave_file)
215+
wave_file = open(wave_filename, "rb") # pylint: disable=consider-using-with
216+
wave = audiocore.WaveFile(wave_file)
220217
audio.play(wave)
221218
next_bolt_time = time.monotonic() + random.randint(5, 15) # between 5 and 15 s

0 commit comments

Comments
 (0)