Skip to content

Commit 5abca8d

Browse files
committed
More error specificity
1 parent de04df1 commit 5abca8d

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

adafruit_esp32spi/adafruit_esp32spi.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ def is_connected(self):
539539
"""Whether the ESP32 is connected to an access point"""
540540
try:
541541
return self.status == WL_CONNECTED
542-
except RuntimeError:
542+
except OSError:
543543
self.reset()
544544
return False
545545

@@ -548,15 +548,15 @@ def ap_listening(self):
548548
"""Returns if the ESP32 is in access point mode and is listening for connections"""
549549
try:
550550
return self.status == WL_AP_LISTENING
551-
except RuntimeError:
551+
except OSError:
552552
self.reset()
553553
return False
554554

555555
def disconnect(self):
556556
"""Disconnect from the access point"""
557557
resp = self._send_command_get_response(_DISCONNECT_CMD)
558558
if resp[0][0] != 1:
559-
raise RuntimeError("Failed to disconnect")
559+
raise OSError("Failed to disconnect")
560560

561561
def connect(self, secrets):
562562
"""Connect to an access point using a secrets dictionary
@@ -589,10 +589,10 @@ def connect_AP(self, ssid, password, timeout_s=10): # pylint: disable=invalid-n
589589
return stat
590590
time.sleep(0.05)
591591
if stat in (WL_CONNECT_FAILED, WL_CONNECTION_LOST, WL_DISCONNECTED):
592-
raise RuntimeError("Failed to connect to ssid", ssid)
592+
raise ConnectionError("Failed to connect to ssid", ssid)
593593
if stat == WL_NO_SSID_AVAIL:
594-
raise RuntimeError("No such ssid", ssid)
595-
raise RuntimeError("Unknown error 0x%02X" % stat)
594+
raise ConnectionError("No such ssid", ssid)
595+
raise OSError("Unknown error 0x%02X" % stat)
596596

597597
def create_AP(
598598
self, ssid, password, channel=1, timeout=10
@@ -607,11 +607,11 @@ def create_AP(
607607
:param int timeout: number of seconds until we time out and fail to create AP
608608
"""
609609
if len(ssid) > 32:
610-
raise RuntimeError("ssid must be no more than 32 characters")
610+
raise ValueError("ssid must be no more than 32 characters")
611611
if password and (len(password) < 8 or len(password) > 64):
612-
raise RuntimeError("password must be 8 - 63 characters")
612+
raise ValueError("password must be 8 - 63 characters")
613613
if channel < 1 or channel > 14:
614-
raise RuntimeError("channel must be between 1 and 14")
614+
raise ValueError("channel must be between 1 and 14")
615615

616616
if isinstance(channel, int):
617617
channel = bytes(channel)

0 commit comments

Comments
 (0)