Skip to content

Commit 97b924f

Browse files
authored
Merge pull request #46 from adafruit/patch-fix
Linted
2 parents 68bcd55 + 42e8a4c commit 97b924f

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

adafruit_wiznet5k/adafruit_wiznet5k_dhcp.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ def send_dhcp_message(self, state, time_elapsed, renew=False):
192192
# HW Type - ETH
193193
_BUFF[245] = 0x01
194194
# Client MAC Address
195-
for mac in range(0, len(self._mac_address)):
196-
_BUFF[246 + mac] = self._mac_address[mac]
195+
for mac, val in enumerate(self._mac_address):
196+
_BUFF[246 + mac] = val
197197

198198
# Option - Host Name
199199
_BUFF[252] = 12
@@ -471,23 +471,24 @@ def _dhcp_state_machine(self):
471471
print("* DHCP: Time to renew lease")
472472

473473
if (
474-
self._dhcp_state == STATE_DHCP_DISCOVER
475-
or self._dhcp_state == STATE_DHCP_REQUEST
476-
) and time.monotonic() > (self._start_time + self._response_timeout):
474+
self._dhcp_state
475+
in (
476+
STATE_DHCP_DISCOVER,
477+
STATE_DHCP_REQUEST,
478+
)
479+
and time.monotonic() > (self._start_time + self._response_timeout)
480+
):
477481
self._dhcp_state = STATE_DHCP_WAIT
478482
if self._sock is not None:
479483
self._sock.close()
480484
self._sock = None
481485

482486
def request_dhcp_lease(self):
483487
"""Request to renew or acquire a DHCP lease."""
484-
if self._dhcp_state == STATE_DHCP_LEASED or self._dhcp_state == STATE_DHCP_WAIT:
488+
if self._dhcp_state in (STATE_DHCP_LEASED, STATE_DHCP_WAIT):
485489
self._dhcp_state = STATE_DHCP_START
486490

487-
while (
488-
self._dhcp_state != STATE_DHCP_LEASED
489-
and self._dhcp_state != STATE_DHCP_WAIT
490-
):
491+
while self._dhcp_state not in (STATE_DHCP_LEASED, STATE_DHCP_WAIT):
491492
self._dhcp_state_machine()
492493

493494
return self._dhcp_state == STATE_DHCP_LEASED

examples/wiznet5k_wsgiserver_test.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,35 @@
2020
import busio
2121
import digitalio
2222
import neopixel
23-
import time
2423

2524
import adafruit_requests as requests
25+
from adafruit_wsgi.wsgi_app import WSGIApp
2626
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
2727
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket
2828
import adafruit_wiznet5k.adafruit_wiznet5k_wsgiserver as server
29-
from adafruit_wsgi.wsgi_app import WSGIApp
3029

3130

3231
print("Wiznet5k Web Server Test")
3332

3433

35-
def get_mac(i2c):
34+
def get_mac(i2c_obj):
3635
"Read MAC from 24AA02E48 chip and return it"
37-
mac = bytearray(6)
38-
while not i2c.try_lock():
36+
mac_addr = bytearray(6)
37+
while not i2c_obj.try_lock():
3938
pass
40-
i2c.writeto(0x50, bytearray((0xFA,)))
41-
i2c.readfrom_into(0x50, mac, start=0, end=6)
42-
i2c.unlock()
43-
return mac
39+
i2c_obj.writeto(0x50, bytearray((0xFA,)))
40+
i2c_obj.readfrom_into(0x50, mac_addr, start=0, end=6)
41+
i2c_obj.unlock()
42+
return mac_addr
4443

4544

4645
def get_static_file(filename):
4746
"Static file generator"
4847
with open(filename, "rb") as f:
49-
bytes = None
50-
while bytes is None or len(bytes) == 2048:
51-
bytes = f.read(2048)
52-
yield bytes
48+
b = None
49+
while b is None or len(b) == 2048:
50+
b = f.read(2048)
51+
yield b
5352

5453

5554
# Status LED
@@ -107,13 +106,13 @@ def large(request): # pylint: disable=unused-argument
107106

108107

109108
@web_app.route("/code")
110-
def large(request): # pylint: disable=unused-argument
109+
def code(request): # pylint: disable=unused-argument
111110
print("Static file code.py handler")
112111
return ("200 OK", [], get_static_file("code.py"))
113112

114113

115114
@web_app.route("/btc")
116-
def btc(request):
115+
def btc(request): # pylint: disable=unused-argument
117116
print("BTC handler")
118117
r = requests.get("http://api.coindesk.com/v1/bpi/currentprice/USD.json")
119118
result = r.text

0 commit comments

Comments
 (0)