Skip to content

Commit 6635e40

Browse files
committed
Fixed NameErrors caused by moving probing logic into private method
1 parent e9459c7 commit 6635e40

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

adafruit_bus_device/i2c_device.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ class I2CDevice:
6060

6161
def __init__(self, i2c, device_address, probe=True):
6262

63-
if probe:
64-
self.__probe_for_device()
65-
6663
self.i2c = i2c
6764
self.device_address = device_address
6865

66+
if probe:
67+
self.__probe_for_device()
68+
6969
def readinto(self, buf, **kwargs):
7070
"""
7171
Read into ``buf`` from the device. The number of bytes read will be the
@@ -157,17 +157,17 @@ def __probe_for_device(self):
157157
if you get an OSError it means the device is not there
158158
or that the device does not support these means of probing
159159
"""
160-
while not i2c.try_lock():
160+
while not self.i2c.try_lock():
161161
pass
162162
try:
163-
i2c.writeto(device_address, b'')
163+
self.i2c.writeto(self.device_address, b'')
164164
except OSError:
165165
# some OS's dont like writing an empty bytesting...
166166
# Retry by reading a byte
167167
try:
168168
result = bytearray(1)
169-
i2c.readfrom_into(device_address, result)
169+
self.i2c.readfrom_into(self.device_address, result)
170170
except OSError:
171-
raise ValueError("No I2C device at address: %x" % device_address)
171+
raise ValueError("No I2C device at address: %x" % self.device_address)
172172
finally:
173-
i2c.unlock()
173+
self.i2c.unlock()

0 commit comments

Comments
 (0)