Skip to content

Commit de04df1

Browse files
committed
These now derive also from OSError types - without timeouts being specific.
1 parent 4455889 commit de04df1

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

adafruit_esp32spi/adafruit_esp32spi.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def _wait_for_ready(self):
194194
print(".", end="")
195195
time.sleep(0.05)
196196
else:
197-
raise RuntimeError("ESP32 not responding")
197+
raise TimeoutError("ESP32 not responding")
198198
if self._debug >= 3:
199199
print()
200200

@@ -242,7 +242,7 @@ def _send_command(self, cmd, params=None, *, param_len_16=False):
242242
if self._ready.value: # ok ready to send!
243243
break
244244
else:
245-
raise RuntimeError("ESP32 timed out on SPI select")
245+
raise TimeoutError("ESP32 timed out on SPI select")
246246
spi.write(
247247
self._sendbuf, start=0, end=packet_len
248248
) # pylint: disable=no-member
@@ -271,17 +271,17 @@ def _wait_spi_char(self, spi, desired):
271271
for _ in range(10):
272272
r = self._read_byte(spi)
273273
if r == _ERR_CMD:
274-
raise RuntimeError("Error response to command")
274+
raise BrokenPipeError("Error response to command")
275275
if r == desired:
276276
return True
277277
time.sleep(0.01)
278-
raise RuntimeError("Timed out waiting for SPI char")
278+
raise TimeoutError("Timed out waiting for SPI char")
279279

280280
def _check_data(self, spi, desired):
281281
"""Read a byte and verify its the value we want"""
282282
r = self._read_byte(spi)
283283
if r != desired:
284-
raise RuntimeError("Expected %02X but got %02X" % (desired, r))
284+
raise BrokenPipeError("Expected %02X but got %02X" % (desired, r))
285285

286286
def _wait_response_cmd(self, cmd, num_responses=None, *, param_len_16=False):
287287
"""Wait for ready, then parse the response"""
@@ -294,7 +294,7 @@ def _wait_response_cmd(self, cmd, num_responses=None, *, param_len_16=False):
294294
if self._ready.value: # ok ready to send!
295295
break
296296
else:
297-
raise RuntimeError("ESP32 timed out on SPI select")
297+
raise TimeoutError("ESP32 timed out on SPI select")
298298

299299
self._wait_spi_char(spi, _START_CMD)
300300
self._check_data(spi, cmd | _REPLY_FLAG)
@@ -440,7 +440,7 @@ def set_dns_config(self, dns1, dns2):
440440
_SET_DNS_CONFIG, [b"\x00", self.unpretty_ip(dns1), self.unpretty_ip(dns2)]
441441
)
442442
if resp[0][0] != 1:
443-
raise RuntimeError("Failed to set dns with esp32")
443+
raise OSError("Failed to set dns with esp32")
444444

445445
def set_hostname(self, hostname):
446446
"""Tells the ESP32 to set hostname for DHCP.
@@ -449,57 +449,57 @@ def set_hostname(self, hostname):
449449
"""
450450
resp = self._send_command_get_response(_SET_HOSTNAME, [hostname.encode()])
451451
if resp[0][0] != 1:
452-
raise RuntimeError("Failed to set hostname with esp32")
452+
raise OSError("Failed to set hostname with esp32")
453453

454454
def wifi_set_network(self, ssid):
455455
"""Tells the ESP32 to set the access point to the given ssid"""
456456
resp = self._send_command_get_response(_SET_NET_CMD, [ssid])
457457
if resp[0][0] != 1:
458-
raise RuntimeError("Failed to set network")
458+
raise OSError("Failed to set network")
459459

460460
def wifi_set_passphrase(self, ssid, passphrase):
461461
"""Sets the desired access point ssid and passphrase"""
462462
resp = self._send_command_get_response(_SET_PASSPHRASE_CMD, [ssid, passphrase])
463463
if resp[0][0] != 1:
464-
raise RuntimeError("Failed to set passphrase")
464+
raise OSError("Failed to set passphrase")
465465

466466
def wifi_set_entidentity(self, ident):
467467
"""Sets the WPA2 Enterprise anonymous identity"""
468468
resp = self._send_command_get_response(_SET_ENT_IDENT_CMD, [ident])
469469
if resp[0][0] != 1:
470-
raise RuntimeError("Failed to set enterprise anonymous identity")
470+
raise OSError("Failed to set enterprise anonymous identity")
471471

472472
def wifi_set_entusername(self, username):
473473
"""Sets the desired WPA2 Enterprise username"""
474474
resp = self._send_command_get_response(_SET_ENT_UNAME_CMD, [username])
475475
if resp[0][0] != 1:
476-
raise RuntimeError("Failed to set enterprise username")
476+
raise OSError("Failed to set enterprise username")
477477

478478
def wifi_set_entpassword(self, password):
479479
"""Sets the desired WPA2 Enterprise password"""
480480
resp = self._send_command_get_response(_SET_ENT_PASSWD_CMD, [password])
481481
if resp[0][0] != 1:
482-
raise RuntimeError("Failed to set enterprise password")
482+
raise OSError("Failed to set enterprise password")
483483

484484
def wifi_set_entenable(self):
485485
"""Enables WPA2 Enterprise mode"""
486486
resp = self._send_command_get_response(_SET_ENT_ENABLE_CMD)
487487
if resp[0][0] != 1:
488-
raise RuntimeError("Failed to enable enterprise mode")
488+
raise OSError("Failed to enable enterprise mode")
489489

490490
def _wifi_set_ap_network(self, ssid, channel):
491491
"""Creates an Access point with SSID and Channel"""
492492
resp = self._send_command_get_response(_SET_AP_NET_CMD, [ssid, channel])
493493
if resp[0][0] != 1:
494-
raise RuntimeError("Failed to setup AP network")
494+
raise OSError("Failed to setup AP network")
495495

496496
def _wifi_set_ap_passphrase(self, ssid, passphrase, channel):
497497
"""Creates an Access point with SSID, passphrase, and Channel"""
498498
resp = self._send_command_get_response(
499499
_SET_AP_PASSPHRASE_CMD, [ssid, passphrase, channel]
500500
)
501501
if resp[0][0] != 1:
502-
raise RuntimeError("Failed to setup AP password")
502+
raise OSError("Failed to setup AP password")
503503

504504
@property
505505
def ssid(self):

0 commit comments

Comments
 (0)