Skip to content

Commit 199a862

Browse files
author
BiffoBear
committed
Finished with typing. Need to check docs and remove TODOs
1 parent 18d11c1 commit 199a862

File tree

5 files changed

+117
-75
lines changed

5 files changed

+117
-75
lines changed

adafruit_wiznet5k/adafruit_wiznet5k.py

Lines changed: 73 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,16 @@ def max_sockets(self) -> int:
287287

288288
@property
289289
def chip(self) -> str:
290-
"""Ethernet controller chip type.
290+
"""
291+
Ethernet controller chip type.
291292
292293
:return str: The chip type."""
293294
return self._chip_type
294295

295296
@property
296297
def ip_address(self) -> bytearray:
297-
"""Configured IP address.
298+
"""
299+
Configured IP address.
298300
299301
:return bytearray.
300302
"""
@@ -305,11 +307,12 @@ def pretty_ip(
305307
# pylint: disable=no-self-use, invalid-name
306308
ip: bytearray,
307309
) -> str:
308-
"""Convert a bytearray IP address to a dotted-quad string for printing.
310+
"""
311+
Convert a bytearray IP address to a dotted-quad string for printing.
309312
310313
:param bytearray ip: A four byte IP address.
311314
312-
:return str: The IP address in 0.0.0.0 format.
315+
:return str: The IP address (a string of the form '255.255.255.255').
313316
"""
314317
return "%d.%d.%d.%d" % (ip[0], ip[1], ip[2], ip[3])
315318

@@ -318,9 +321,10 @@ def unpretty_ip(
318321
# pylint: disable=no-self-use, invalid-name
319322
ip: str,
320323
) -> bytes:
321-
"""Convert a dotted-quad string to a four byte IP address.
324+
"""
325+
Convert a dotted-quad string to a four byte IP address.
322326
323-
:param str ip: The IP address in the form 0.0.0.0 to be converted.
327+
:param str ip: The IP address (a string of the form '255.255.255.255') to be converted.
324328
325329
:return bytes: The IP address in four bytes.
326330
"""
@@ -329,14 +333,16 @@ def unpretty_ip(
329333

330334
@property
331335
def mac_address(self) -> bytearray:
332-
"""Ethernet hardware's MAC address.
336+
"""
337+
Ethernet hardware's MAC address.
333338
334339
:return bytearray: The six byte MAC address."""
335340
return self.read(REG_SHAR, 0x00, 6)
336341

337342
@mac_address.setter
338343
def mac_address(self, address: Sequence[Union[int, bytes]]) -> None:
339-
"""Sets the hardware MAC address.
344+
"""
345+
Sets the hardware MAC address.
340346
341347
:param tuple address: Hardware MAC address.
342348
"""
@@ -347,8 +353,12 @@ def pretty_mac(
347353
# pylint: disable=no-self-use, invalid-name
348354
mac: bytearray,
349355
) -> str:
350-
"""Converts a bytearray MAC address to a
351-
dotted-quad string for printing
356+
"""
357+
Convert a bytearray MAC address to a ':' seperated string for display.
358+
359+
:param bytearray mac: The MAC address.
360+
361+
:return str: Mac Address in the form 00:00:00:00:00:00
352362
353363
"""
354364
return "%s:%s:%s:%s:%s:%s" % (
@@ -361,7 +371,8 @@ def pretty_mac(
361371
)
362372

363373
def remote_ip(self, socket_num: int) -> Union[str, bytearray]:
364-
"""IP address of the host which sent the current incoming packet.
374+
"""
375+
IP address of the host which sent the current incoming packet.
365376
366377
:param int socket_num: ID number of the socket to check.
367378
@@ -388,7 +399,8 @@ def link_status(self) -> int:
388399
return 0
389400

390401
def remote_port(self, socket_num: int) -> Union[int, bytearray]:
391-
"""Port of the host which sent the current incoming packet.
402+
"""
403+
Port of the host which sent the current incoming packet.
392404
393405
:param int socket_num: ID number of the socket to check.
394406
@@ -405,7 +417,8 @@ def remote_port(self, socket_num: int) -> Union[int, bytearray]:
405417
def ifconfig(
406418
self,
407419
) -> Tuple[bytearray, bytearray, bytearray, Tuple[int, int, int, int]]: # *1
408-
"""Network configuration information.
420+
"""
421+
Network configuration information.
409422
410423
:return Tuple[bytearray, bytearray, bytearray, Tuple[int, int, int, int]]: \
411424
The IP address, subnet mask, gateway address and DNS server address."""
@@ -420,7 +433,8 @@ def ifconfig(
420433
def ifconfig(
421434
self, params: Tuple[bytearray, bytearray, bytearray, Tuple[int, int, int, int]]
422435
) -> None:
423-
"""Set network configuration.
436+
"""
437+
Set network configuration.
424438
425439
:params Tuple[bytearray, bytearray, bytearray, Tuple[int, int, int, int]]: \
426440
Configuration settings - (ip_address, subnet_mask, gateway_address, dns_server).
@@ -435,7 +449,8 @@ def ifconfig(
435449
self._dns = dns_server
436450

437451
def _w5100_init(self) -> int:
438-
"""Detects and initializes a Wiznet5k ethernet module.
452+
"""
453+
Detect and initialize a Wiznet5k ethernet module.
439454
440455
:return int: 1 if the initialization succeeds, 0 if it fails.
441456
"""
@@ -460,7 +475,8 @@ def _w5100_init(self) -> int:
460475
return 1
461476

462477
def detect_w5500(self) -> int:
463-
"""Detects W5500 chip.
478+
"""
479+
Detect W5500 chip.
464480
465481
:return int: 1 if a W5500 chip is detected, -1 if not.
466482
"""
@@ -488,7 +504,8 @@ def detect_w5500(self) -> int:
488504
return 1
489505

490506
def detect_w5100s(self) -> int:
491-
"""Detects W5100S chip.
507+
"""
508+
Detect W5100S chip.
492509
493510
:return int: 1 if a W5100 chip is detected, -1 if not.
494511
"""
@@ -502,8 +519,9 @@ def detect_w5100s(self) -> int:
502519
return 1
503520

504521
def sw_reset(self) -> int:
505-
"""Perform a soft-reset on the Wiznet chip
506-
by writing to its MR register reset bit.
522+
"""Perform a soft-reset on the Wiznet chip.
523+
524+
Perform a soft reset by writing to the chip's MR register reset bit.
507525
508526
:return int: 0 if the reset succeeds, -1 if not.
509527
"""
@@ -518,12 +536,12 @@ def sw_reset(self) -> int:
518536
return 0
519537

520538
def _read_mr(self) -> bytearray:
521-
"""Reads from the Mode Register (MR)."""
539+
"""Read from the Mode Register (MR)."""
522540
res = self.read(REG_MR, 0x00)
523541
return res
524542

525543
def _write_mr(self, data: int) -> None:
526-
"""Writes to the mode register (MR)."""
544+
"""Write to the mode register (MR)."""
527545
self.write(REG_MR, 0x04, data)
528546

529547
def read(
@@ -533,7 +551,8 @@ def read(
533551
length: int = 1,
534552
buffer: Optional[WriteableBuffer] = None,
535553
) -> Union[WriteableBuffer, bytearray]:
536-
"""Read data from a register address.
554+
"""
555+
Read data from a register address.
537556
538557
:param int addr: Register address to read.
539558
:param int callback: Callback reference.
@@ -563,7 +582,8 @@ def read(
563582
def write(
564583
self, addr: int, callback: int, data: Union[int, Sequence[Union[int, bytes]]]
565584
) -> None:
566-
"""Write data to a register address.
585+
"""
586+
Write data to a register address.
567587
568588
:param int addr: Destination address.
569589
:param int callback: Callback reference.
@@ -590,7 +610,8 @@ def write(
590610
# Socket-Register API
591611

592612
def socket_available(self, socket_num: int, sock_type: int = SNMR_TCP) -> int:
593-
"""Return the number of bytes available to be read from the socket.
613+
"""
614+
Return the number of bytes available to be read from the socket.
594615
595616
:param int socket_num: Socket to check for available bytes.
596617
:param int sock_type: Socket type. Use SNMR_TCP for TCP or SNMR_UDP for UDP, \
@@ -625,7 +646,8 @@ def socket_available(self, socket_num: int, sock_type: int = SNMR_TCP) -> int:
625646
return 0
626647

627648
def socket_status(self, socket_num: int) -> Union[bytearray, None]:
628-
"""Returns the socket connection status.
649+
"""
650+
Return the socket connection status.
629651
630652
Can be: SNSR_SOCK_CLOSED, SNSR_SOCK_INIT, SNSR_SOCK_LISTEN, SNSR_SOCK_SYNSENT,
631653
SNSR_SOCK_SYNRECV, SNSR_SYN_SOCK_ESTABLISHED, SNSR_SOCK_FIN_WAIT,
@@ -645,7 +667,8 @@ def socket_connect(
645667
port: int,
646668
conn_mode: int = SNMR_TCP,
647669
) -> int:
648-
"""Open and verify a connection from a socket to a destination IP address
670+
"""
671+
Open and verify a connection from a socket to a destination IP address
649672
or hostname. A TCP connection is made by default. A UDP connection can also
650673
be made.
651674
@@ -692,8 +715,7 @@ def _send_socket_cmd(self, socket: int, cmd: int) -> None:
692715
print("waiting for sncr to clear...")
693716

694717
def get_socket(self) -> int:
695-
"""Requests, allocates and returns a socket from the W5k
696-
chip.
718+
"""Request, allocate and return a socket from the W5k chip.
697719
698720
Cycles through the sockets to find the first available one, if any.
699721
@@ -716,7 +738,8 @@ def get_socket(self) -> int:
716738
def socket_listen(
717739
self, socket_num: int, port: int, conn_mode: int = SNMR_TCP
718740
) -> None:
719-
"""Start listening on a socket's port.
741+
"""
742+
Listen on a socket's port.
720743
721744
:param int socket_num: ID of socket to listen on.
722745
:param int port: Port to listen on (0 - 65,535).
@@ -748,15 +771,16 @@ def socket_listen(
748771
def socket_accept(
749772
self, socket_num: int
750773
) -> Tuple[int, Tuple[Union[str, bytearray], Union[int, bytearray]]]:
751-
"""Gets the dest IP and port from an incoming connection.
774+
"""
775+
Destination IP address and port from an incoming connection.
752776
753-
Returns the next socket number so listening can continue, along with
777+
Return the next socket number so listening can continue, along with
754778
the IP address and port of the incoming connection.
755779
756780
:param int socket_num: Socket number with connection to check.
757781
758782
:return Tuple[int, Tuple[Union[str, bytearray], Union[int, bytearray]]]:
759-
If successful, the next (socket number, (destination IP address, destination port)).
783+
If successful, the next (socket number, (destination IP address, destination port)).
760784
761785
If errors occur, the destination IP address and / or the destination port may be
762786
returned as bytearrays.
@@ -773,7 +797,8 @@ def socket_accept(
773797
return next_socknum, (dest_ip, dest_port)
774798

775799
def socket_open(self, socket_num: int, conn_mode: int = SNMR_TCP) -> int:
776-
"""Opens a network socket.
800+
"""
801+
Open an IP socket.
777802
778803
The socket may connect via TCP or UDP protocols.
779804
@@ -823,7 +848,8 @@ def socket_open(self, socket_num: int, conn_mode: int = SNMR_TCP) -> int:
823848
return 1
824849

825850
def socket_close(self, socket_num: int) -> None:
826-
"""Close a socket.
851+
"""
852+
Close a socket.
827853
828854
:param int socket_num: The socket to close.
829855
"""
@@ -833,7 +859,8 @@ def socket_close(self, socket_num: int) -> None:
833859
self._read_sncr(socket_num)
834860

835861
def socket_disconnect(self, socket_num: int) -> None:
836-
"""Disconnect a TCP or UDP connection.
862+
"""
863+
Disconnect a TCP or UDP connection.
837864
838865
:param int socket_num: The socket to close.
839866
"""
@@ -845,7 +872,8 @@ def socket_disconnect(self, socket_num: int) -> None:
845872
def socket_read(
846873
self, socket_num: int, length: int
847874
) -> Tuple[int, Union[int, bytearray]]:
848-
"""Read data from a TCP socket.
875+
"""
876+
Read data from a TCP socket.
849877
850878
:param int socket_num: The socket to read data from.
851879
:param int length: The number of bytes to read from the socket.
@@ -915,7 +943,8 @@ def socket_read(
915943
def read_udp(
916944
self, socket_num: int, length: int
917945
) -> Union[int, Tuple[int, Union[int, bytearray]]]:
918-
"""Read UDP socket's current message bytes.
946+
"""
947+
Read UDP socket's current message bytes.
919948
920949
:param int socket_num: The socket to read data from.
921950
:param int length: The number of bytes to read from the socket.
@@ -938,7 +967,8 @@ def read_udp(
938967
def socket_write(
939968
self, socket_num: int, buffer: bytearray, timeout: float = 0
940969
) -> int:
941-
"""Write data to a socket.
970+
"""
971+
Write data to a socket.
942972
943973
:param int socket_num: The socket to write to.
944974
:param bytearray buffer: The data to write to the socket.
@@ -1020,7 +1050,7 @@ def socket_write(
10201050

10211051
# Socket-Register Methods
10221052
def _get_rx_rcv_size(self, sock: int) -> int:
1023-
"""Get size of received and saved in socket buffer."""
1053+
"""Size of received and saved in socket buffer."""
10241054
val = 0
10251055
val_1 = self._read_snrx_rsr(sock)
10261056
while val != val_1:
@@ -1030,7 +1060,7 @@ def _get_rx_rcv_size(self, sock: int) -> int:
10301060
return int.from_bytes(val, "big")
10311061

10321062
def _get_tx_free_size(self, sock: int) -> int:
1033-
"""Get free size of socket's tx buffer block."""
1063+
"""Free size of socket's tx buffer block."""
10341064
val = 0
10351065
val_1 = self._read_sntx_fsr(sock)
10361066
while val != val_1:
@@ -1068,17 +1098,17 @@ def _read_snrx_rsr(self, sock: int) -> Union[bytearray, None]:
10681098
return data
10691099

10701100
def _write_sndipr(self, sock: int, ip_addr: bytearray) -> None:
1071-
"""Writes to socket destination IP Address."""
1101+
"""Write to socket destination IP Address."""
10721102
for octet in range(4):
10731103
self._write_socket(sock, REG_SNDIPR + octet, ip_addr[octet])
10741104

10751105
def _write_sndport(self, sock: int, port: int) -> None:
1076-
"""Writes to socket destination port."""
1106+
"""Write to socket destination port."""
10771107
self._write_socket(sock, REG_SNDPORT, port >> 8)
10781108
self._write_socket(sock, REG_SNDPORT + 1, port & 0xFF)
10791109

10801110
def _read_snsr(self, sock: int) -> Union[bytearray, None]:
1081-
"""Reads Socket n Status Register."""
1111+
"""Read Socket n Status Register."""
10821112
return self._read_socket(sock, REG_SNSR)
10831113

10841114
def _write_snmr(self, sock: int, protocol: int) -> None:

adafruit_wiznet5k/adafruit_wiznet5k_dhcp.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ def send_dhcp_message(
152152
time_elapsed: float,
153153
renew: bool = False,
154154
) -> None:
155-
"""Assemble and send a DHCP message packet to a socket.
155+
"""
156+
Assemble and send a DHCP message packet to a socket.
156157
157158
:param int state: DHCP Message state.
158159
:param float time_elapsed: Number of seconds elapsed since DHCP process started
@@ -367,9 +368,11 @@ def parse_dhcp_response(
367368

368369
# pylint: disable=too-many-branches, too-many-statements
369370
def _dhcp_state_machine(self) -> None:
370-
"""DHCP state machine without wait loops to enable cooperative multitasking
371+
"""
372+
DHCP state machine without wait loops to enable cooperative multitasking
371373
This state machine is used both by the initial blocking lease request and
372-
the non-blocking DHCP maintenance function."""
374+
the non-blocking DHCP maintenance function.
375+
"""
373376
if self._eth.link_status:
374377
if self._dhcp_state == STATE_DHCP_DISCONN:
375378
self._dhcp_state = STATE_DHCP_START

0 commit comments

Comments
 (0)