Skip to content

Commit 6605027

Browse files
committed
These are now in the OSError heirarchy
1 parent 5abca8d commit 6605027

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

adafruit_esp32spi/adafruit_esp32spi.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def start_scan_networks(self):
377377
print("Start scan")
378378
resp = self._send_command_get_response(_START_SCAN_NETWORKS)
379379
if resp[0][0] != 1:
380-
raise RuntimeError("Failed to start AP scan")
380+
raise OSError("Failed to start AP scan")
381381

382382
def get_scan_networks(self):
383383
"""The results of the latest SSID scan. Returns a list of dictionaries with
@@ -631,8 +631,8 @@ def create_AP(
631631
return stat
632632
time.sleep(0.05)
633633
if stat == WL_AP_FAILED:
634-
raise RuntimeError("Failed to create AP", ssid)
635-
raise RuntimeError("Unknown error 0x%02x" % stat)
634+
raise ConnectionError("Failed to create AP", ssid)
635+
raise OSError("Unknown error 0x%02x" % stat)
636636

637637
def pretty_ip(self, ip): # pylint: disable=no-self-use, invalid-name
638638
"""Converts a bytearray IP address to a dotted-quad string for printing"""
@@ -652,7 +652,7 @@ def get_host_by_name(self, hostname):
652652
hostname = bytes(hostname, "utf-8")
653653
resp = self._send_command_get_response(_REQ_HOST_BY_NAME_CMD, (hostname,))
654654
if resp[0][0] != 1:
655-
raise RuntimeError("Failed to request hostname")
655+
raise ConnectionError("Failed to request hostname")
656656
resp = self._send_command_get_response(_GET_HOST_BY_NAME_CMD)
657657
return resp[0]
658658

@@ -708,7 +708,7 @@ def socket_open(self, socket_num, dest, port, conn_mode=TCP_MODE):
708708
(dest, port_param, self._socknum_ll[0], (conn_mode,)),
709709
)
710710
if resp[0][0] != 1:
711-
raise RuntimeError("Could not connect to remote server")
711+
raise ConnectionError("Could not connect to remote server")
712712
if conn_mode == ESP_SPIcontrol.TLS_MODE:
713713
self._tls_socket = socket_num
714714

@@ -824,7 +824,7 @@ def socket_close(self, socket_num):
824824
self._socknum_ll[0][0] = socket_num
825825
try:
826826
self._send_command_get_response(_STOP_CLIENT_TCP_CMD, self._socknum_ll)
827-
except RuntimeError:
827+
except OSError:
828828
pass
829829
if socket_num == self._tls_socket:
830830
self._tls_socket = None
@@ -842,7 +842,7 @@ def start_server(
842842
resp = self._send_command_get_response(_START_SERVER_TCP_CMD, params)
843843

844844
if resp[0][0] != 1:
845-
raise RuntimeError("Could not start server")
845+
raise OSError("Could not start server")
846846

847847
def server_state(self, socket_num):
848848
"""Get the state of the ESP32's internal reference server socket number"""
@@ -863,7 +863,7 @@ def set_esp_debug(self, enabled):
863863
written to the ESP32's UART."""
864864
resp = self._send_command_get_response(_SET_DEBUG_CMD, ((bool(enabled),),))
865865
if resp[0][0] != 1:
866-
raise RuntimeError("Failed to set debug mode")
866+
raise OSError("Failed to set debug mode")
867867

868868
def set_pin_mode(self, pin, mode):
869869
"""Set the io mode for a GPIO pin.
@@ -879,7 +879,7 @@ def set_pin_mode(self, pin, mode):
879879
pin_mode = mode
880880
resp = self._send_command_get_response(_SET_PIN_MODE_CMD, ((pin,), (pin_mode,)))
881881
if resp[0][0] != 1:
882-
raise RuntimeError("Failed to set pin mode")
882+
raise OSError("Failed to set pin mode")
883883

884884
def set_digital_write(self, pin, value):
885885
"""Set the digital output value of pin.
@@ -891,7 +891,7 @@ def set_digital_write(self, pin, value):
891891
_SET_DIGITAL_WRITE_CMD, ((pin,), (value,))
892892
)
893893
if resp[0][0] != 1:
894-
raise RuntimeError("Failed to write to pin")
894+
raise OSError("Failed to write to pin")
895895

896896
def set_analog_write(self, pin, analog_value):
897897
"""Set the analog output value of pin, using PWM.
@@ -904,7 +904,7 @@ def set_analog_write(self, pin, analog_value):
904904
_SET_ANALOG_WRITE_CMD, ((pin,), (value,))
905905
)
906906
if resp[0][0] != 1:
907-
raise RuntimeError("Failed to write to pin")
907+
raise OSError("Failed to write to pin")
908908

909909
def set_digital_read(self, pin):
910910
"""Get the digital input value of pin. Returns the boolean value of the pin.
@@ -953,10 +953,10 @@ def get_time(self):
953953
raise ValueError("_GET_TIME returned 0")
954954
return resp_time
955955
if self.status in (WL_AP_LISTENING, WL_AP_CONNECTED):
956-
raise RuntimeError(
956+
raise OSError(
957957
"Cannot obtain NTP while in AP mode, must be connected to internet"
958958
)
959-
raise RuntimeError("Must be connected to WiFi before obtaining NTP.")
959+
raise OSError("Must be connected to WiFi before obtaining NTP.")
960960

961961
def set_certificate(self, client_certificate):
962962
"""Sets client certificate. Must be called
@@ -967,7 +967,7 @@ def set_certificate(self, client_certificate):
967967
if self._debug:
968968
print("** Setting client certificate")
969969
if self.status == WL_CONNECTED:
970-
raise RuntimeError(
970+
raise ValueError(
971971
"set_certificate must be called BEFORE a connection is established."
972972
)
973973
if isinstance(client_certificate, str):
@@ -977,7 +977,7 @@ def set_certificate(self, client_certificate):
977977
assert len(client_certificate) < 1300, ".PEM must be less than 1300 bytes."
978978
resp = self._send_command_get_response(_SET_CLI_CERT, (client_certificate,))
979979
if resp[0][0] != 1:
980-
raise RuntimeError("Failed to set client certificate")
980+
raise OSError("Failed to set client certificate")
981981
self.set_crt = True
982982
return resp[0]
983983

@@ -990,7 +990,7 @@ def set_private_key(self, private_key):
990990
if self._debug:
991991
print("** Setting client's private key.")
992992
if self.status == WL_CONNECTED:
993-
raise RuntimeError(
993+
raise ValueError(
994994
"set_private_key must be called BEFORE a connection is established."
995995
)
996996
if isinstance(private_key, str):
@@ -1000,6 +1000,6 @@ def set_private_key(self, private_key):
10001000
assert len(private_key) < 1700, ".PEM must be less than 1700 bytes."
10011001
resp = self._send_command_get_response(_SET_PK, (private_key,))
10021002
if resp[0][0] != 1:
1003-
raise RuntimeError("Failed to set private key.")
1003+
raise OSError("Failed to set private key.")
10041004
self.set_psk = True
10051005
return resp[0]

0 commit comments

Comments
 (0)