Skip to content

Commit 8df44bb

Browse files
added types for i2c class
also added import for the i2c type inside of a try except
1 parent 06c76fe commit 8df44bb

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

adafruit_bme680.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
import math
3434
from micropython import const
3535

36+
try:
37+
# Used only for type annotations.
38+
from busio import I2C
39+
except ImportError:
40+
pass
41+
3642
__version__ = "0.0.0-auto.0"
3743
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BME680.git"
3844

@@ -437,7 +443,14 @@ class Adafruit_BME680_I2C(Adafruit_BME680):
437443
438444
"""
439445

440-
def __init__(self, i2c, address=0x77, debug=False, *, refresh_rate=10):
446+
def __init__(
447+
self,
448+
i2c: I2C,
449+
address: int = 0x77,
450+
debug: bool = False,
451+
*,
452+
refresh_rate: int = 10
453+
) -> None:
441454
"""Initialize the I2C device at the 'address' given"""
442455
from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel
443456
i2c_device,
@@ -447,7 +460,7 @@ def __init__(self, i2c, address=0x77, debug=False, *, refresh_rate=10):
447460
self._debug = debug
448461
super().__init__(refresh_rate=refresh_rate)
449462

450-
def _read(self, register, length):
463+
def _read(self, register: int, length: int) -> bytearray:
451464
"""Returns an array of 'length' bytes from the 'register'"""
452465
with self._i2c as i2c:
453466
i2c.write(bytes([register & 0xFF]))
@@ -457,7 +470,7 @@ def _read(self, register, length):
457470
print("\t$%02X => %s" % (register, [hex(i) for i in result]))
458471
return result
459472

460-
def _write(self, register, values):
473+
def _write(self, register: int, values: int) -> None:
461474
"""Writes an array of 'length' bytes to the 'register'"""
462475
with self._i2c as i2c:
463476
buffer = bytearray(2 * len(values))

0 commit comments

Comments
 (0)