|
21 | 21 | button = digitalio.DigitalInOut(board.A1)
|
22 | 22 | button.switch_to_input(pull=digitalio.Pull.UP)
|
23 | 23 |
|
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) |
26 | 26 | audio = audioio.AudioOut(board.A0)
|
27 | 27 |
|
28 | 28 | # Get WiFi details, ensure these are setup in settings.toml
|
|
137 | 137 | print(weather_type) # See https://openweathermap.org/weather-conditions
|
138 | 138 | # default to no rain or thunder
|
139 | 139 | raining = snowing = thundering = has_sound = False
|
| 140 | + wave_filename = None |
140 | 141 | if weather_type == 'Sunny':
|
141 | 142 | 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" |
145 | 144 | if weather_type == 'Clouds':
|
146 | 145 | 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" |
150 | 147 | if weather_type == 'Rain':
|
151 | 148 | 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" |
154 | 150 | raining = True
|
155 |
| - has_sound = True |
156 | 151 | if weather_type == 'Thunderstorm':
|
157 | 152 | palette = thunder_palette
|
158 | 153 | raining = thundering = True
|
|
161 | 156 | next_bolt_time = time.monotonic() + random.randint(1, 5)
|
162 | 157 | if weather_type == 'Snow':
|
163 | 158 | 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" |
166 | 160 | snowing = True
|
| 161 | + if wave_filename: |
| 162 | + wave_file = open(wave_filename, "rb") # pylint: disable=consider-using-with |
| 163 | + wave = audiocore.WaveFile(wave_file) |
167 | 164 | has_sound = True
|
168 | 165 | weather_refresh = time.monotonic()
|
169 | 166 | except RuntimeError as e:
|
|
215 | 212 | elif Thunder == 2:
|
216 | 213 | wave_filename = "sound/Thunderstorm2.wav"
|
217 | 214 | 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) |
220 | 217 | audio.play(wave)
|
221 | 218 | next_bolt_time = time.monotonic() + random.randint(5, 15) # between 5 and 15 s
|
0 commit comments