Skip to content

Commit 06d7f47

Browse files
author
BiffoBear
committed
Removed TODOs and tidied up.
1 parent cd34d4d commit 06d7f47

File tree

6 files changed

+17
-22
lines changed

6 files changed

+17
-22
lines changed

adafruit_wiznet5k/adafruit_wiznet5k.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def __init__(
150150
is_dhcp: bool = True,
151151
mac: Union[List[int], Tuple[int]] = DEFAULT_MAC,
152152
hostname: Optional[str] = None,
153-
dhcp_timeout: float = 30,
153+
dhcp_timeout: float = 30.0,
154154
debug: bool = False,
155155
) -> None:
156156
"""
@@ -162,7 +162,7 @@ def __init__(
162162
(0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED).
163163
:param str hostname: The desired hostname, with optional {} to fill in the MAC
164164
address, defaults to None.
165-
:param float dhcp_timeout: Timeout in seconds for DHCP response, defaults to 30.
165+
:param float dhcp_timeout: Timeout in seconds for DHCP response, defaults to 30.0.
166166
:param bool debug: Enable debugging output, defaults to False.
167167
"""
168168
self._debug = debug
@@ -406,7 +406,6 @@ def remote_port(self, socket_num: int) -> Union[int, bytearray]:
406406
407407
:return Union[int, bytearray]: The port number of the socket connection.
408408
"""
409-
# TODO: why return the buffer?
410409
if socket_num >= self.max_sockets:
411410
return self._pbuff
412411
for octet in range(2):
@@ -439,7 +438,6 @@ def ifconfig(
439438
:params Tuple[bytearray, bytearray, bytearray, Tuple[int, int, int, int]]: \
440439
Configuration settings - (ip_address, subnet_mask, gateway_address, dns_server).
441440
"""
442-
# TODO: Might be better if params can be str as well
443441
ip_address, subnet_mask, gateway_address, dns_server = params
444442

445443
self.write(REG_SIPR, 0x04, ip_address)
@@ -455,7 +453,6 @@ def _w5100_init(self) -> int:
455453
:return int: 1 if the initialization succeeds, 0 if it fails.
456454
"""
457455
time.sleep(1)
458-
# TODO: Isn't the CS pin initialized in busio?
459456
self._cs.switch_to_output()
460457
self._cs.value = 1
461458

@@ -525,7 +522,6 @@ def sw_reset(self) -> int:
525522
526523
:return int: 0 if the reset succeeds, -1 if not.
527524
"""
528-
# TODO: mode_reg appears to be unused, maybe self._read_mr starts the reset?
529525
mode_reg = self._read_mr()
530526
self._write_mr(0x80)
531527
mode_reg = self._read_mr()
@@ -589,7 +585,6 @@ def write(
589585
:param int callback: Callback reference.
590586
:param Union[int, Sequence[Union[int, bytes]]] data: Data to write to the register address.
591587
"""
592-
# TODO: Call with int means an error in a previous function
593588
with self._device as bus_device:
594589
if self._chip_type == "w5500":
595590
bus_device.write(bytes([addr >> 8])) # pylint: disable=no-member
@@ -688,7 +683,7 @@ def socket_connect(
688683
# initialize a socket and set the mode
689684
res = self.socket_open(socket_num, conn_mode=conn_mode)
690685
if res == 1:
691-
raise RuntimeError("Failed to initalize a connection with the socket.")
686+
raise RuntimeError("Failed to initialize a connection with the socket.")
692687

693688
# set socket destination IP and port
694689
self._write_sndipr(socket_num, dest)
@@ -758,7 +753,7 @@ def socket_listen(
758753
res = self.socket_open(socket_num, conn_mode=conn_mode)
759754
self.src_port = 0
760755
if res == 1:
761-
raise RuntimeError("Failed to initalize the socket.")
756+
raise RuntimeError("Failed to initialize the socket.")
762757
# Send listen command
763758
self._send_socket_cmd(socket_num, CMD_SOCK_LISTEN)
764759
# Wait until ready
@@ -979,7 +974,7 @@ def socket_write(
979974
assert socket_num <= self.max_sockets, "Provided socket exceeds max_sockets."
980975
status = 0
981976
ret = 0
982-
free_size = 0 # TODO: Bug report
977+
free_size = 0
983978
if len(buffer) > SOCK_SIZE:
984979
ret = SOCK_SIZE
985980
else:
@@ -1020,7 +1015,7 @@ def socket_write(
10201015
dst_addr = socket_num * SOCK_SIZE + 0x4000
10211016
self.write(dst_addr, 0x00, txbuf)
10221017
else:
1023-
txbuf = buffer[:ret] # TODO: Bug report
1018+
txbuf = buffer[:ret]
10241019
self.write(dst_addr, 0x00, buffer[:ret])
10251020

10261021
# update sn_tx_wr to the value + data size
@@ -1153,5 +1148,4 @@ def _read_socket(self, sock: int, address: int) -> Optional[bytearray]: # *1
11531148
if self._chip_type == "w5100s":
11541149
cntl_byte = 0
11551150
return self.read(self._ch_base_msb + sock * CH_SIZE + address, cntl_byte)
1156-
# TODO: If the chip is not supported, this should raise an exception.
11571151
return None

adafruit_wiznet5k/adafruit_wiznet5k_dhcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: 2009 Jordan Terell (blog.jordanterrell.com)
1+
# SPDX-FileCopyrightText: 2009 Jordan Terrell (blog.jordanterrell.com)
22
# SPDX-FileCopyrightText: 2020 Brent Rubell for Adafruit Industries
33
# SPDX-FileCopyrightText: 2021 Patrick Van Oosterwijck @ Silicognition LLC
44
#

adafruit_wiznet5k/adafruit_wiznet5k_dns.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __init__(
6868
self._sock.settimeout(1)
6969

7070
self._dns_server = dns_address
71-
self._host = 0
71+
self._host = b""
7272
self._request_id = 0 # request identifier
7373
self._pkt_buf = bytearray()
7474

@@ -136,7 +136,7 @@ def _parse_dns_response(
136136
if not xid == self._request_id:
137137
if self._debug:
138138
print(
139-
"* DNS ERROR: Received request identifer {} \
139+
"* DNS ERROR: Received request identifier {} \
140140
does not match expected {}".format(
141141
xid, self._request_id
142142
)

adafruit_wiznet5k/adafruit_wiznet5k_ntp.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(
3838
self,
3939
iface: WIZNET5K,
4040
ntp_address: str,
41-
utc: int,
41+
utc: float,
4242
debug: bool = False,
4343
) -> None:
4444
"""
@@ -64,7 +64,7 @@ def get_time(self) -> time.struct_time:
6464
"""
6565
Get the time from the NTP server.
6666
67-
:return int: Time in seconds since the epoch.
67+
:return time.struct_time: The local time.
6868
"""
6969
self._sock.bind((None, 50001))
7070
self._sock.sendto(self._pkt_buf_, (self._ntp_server, 123))
@@ -73,6 +73,7 @@ def get_time(self) -> time.struct_time:
7373
if data:
7474
sec = data[40:44]
7575
int_cal = int.from_bytes(sec, "big")
76-
cal = int_cal - 2208988800 + self._utc * 3600
76+
# UTC offset may be a float as some offsets are half hours so force int.
77+
cal = int(int_cal - 2208988800 + self._utc * 3600)
7778
cal = time.localtime(cal)
7879
return cal

adafruit_wiznet5k/adafruit_wiznet5k_socket.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ def __init__(
148148
family: int = AF_INET,
149149
type: int = SOCK_STREAM,
150150
proto: Any = 0,
151-
fileno: Optional[Any] = None,
152-
socknum: Optional[Any] = None,
151+
fileno: Optional[int] = None,
152+
socknum: Optional[int] = None,
153153
) -> None:
154154
"""
155155
:param int family: Socket address (and protocol) family, defaults to AF_INET.
@@ -315,7 +315,7 @@ def accept(
315315

316316
new_listen_socknum, addr = _the_interface.socket_accept(self.socknum)
317317
current_socknum = self.socknum
318-
# Create a new socket object and swap socket nums so we can continue listening
318+
# Create a new socket object and swap socket nums, so we can continue listening
319319
client_sock = socket()
320320
client_sock._socknum = current_socknum # pylint: disable=protected-access
321321
self._socknum = new_listen_socknum # pylint: disable=protected-access

adafruit_wiznet5k/adafruit_wiznet5k_wsgiserver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def _get_environ(self, client: socket.socket) -> Dict:
181181
The application callable will be given the resulting environ dictionary.
182182
It contains metadata about the incoming request and the request body ("wsgi.input")
183183
184-
:param socket.socket client: socket to read the request from
184+
:param socket.socket client: socket to read the request from.
185185
186186
:return Dict: Data for the application callable.
187187
"""

0 commit comments

Comments
 (0)