Skip to content

Commit eebf8f6

Browse files
committed
lib/hdc1080: fix a string format error when the I2C slave is not found
Signed-off-by: Ruben Moral <ruben.moral@digi.com>
1 parent 4bd0d4f commit eebf8f6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/sensor/hdc1080/hdc1080.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ def __init__(self, i2c, slave_addr=64):
2525
i2c -- The i2c object (driver) used to interact through device addresses.
2626
slave_addr -- The slave address of the sensor (default 64 or 0x40).
2727
"""
28+
# Perform a scan and make sure we find the slave device we want to talk to.
29+
devices = i2c.scan()
30+
assert slave_addr in devices, "Did not find slave %d in scan: %s" % (slave_addr, devices)
2831
self.i2c = i2c
29-
assert slave_addr in self.i2c.scan(), "Did not find slave %d in scan: %s" % slave_addr
3032
self.addr = slave_addr
3133
# received data from temperature and humidity registers is two unsigned characters
3234
self.fmt = '>2B'

0 commit comments

Comments
 (0)