Skip to content

Commit f8c07a0

Browse files
committed
Add missing type annotations
1 parent a03aee6 commit f8c07a0

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

adafruit_tsl2561.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from micropython import const
3535

3636
try:
37-
from typing import Tuple, Union # pylint: disable=unused-import
37+
from typing import Optional, Tuple
3838
from busio import I2C
3939
except ImportError:
4040
pass
@@ -99,7 +99,7 @@ def enabled(self, enable: bool) -> None:
9999
self._disable()
100100

101101
@property
102-
def lux(self) -> Union[None, float]:
102+
def lux(self) -> Optional[float]:
103103
"""The computed lux value or None when value is not computable."""
104104
return self._compute_lux()
105105

@@ -224,7 +224,7 @@ def clear_interrupt(self) -> None:
224224
with self.i2c_device as i2c:
225225
i2c.write(self.buf, end=1)
226226

227-
def _compute_lux(self) -> Union[None, float]:
227+
def _compute_lux(self) -> Optional[float]:
228228
"""Based on datasheet for FN package."""
229229
ch0, ch1 = self.luminosity
230230
if ch0 == 0:
@@ -259,19 +259,17 @@ def _enable(self) -> None:
259259
def _disable(self) -> None:
260260
self._write_control_register(_CONTROL_POWEROFF)
261261

262-
def _read_register(self, reg: int, count: int = 1) -> Union[int, Tuple[int, int]]:
263-
# pylint: disable=no-else-return
264-
# Disable should be removed when refactor can be tested
262+
def _read_register(self, reg: int, count: int = 1) -> Tuple[int, Tuple[int, int]]:
263+
if count not in (1, 2):
264+
raise RuntimeError("Can only read up to 2 consecutive registers")
265265
self.buf[0] = _COMMAND_BIT | reg
266266
if count == 2:
267267
self.buf[0] |= _WORD_BIT
268268
with self.i2c_device as i2c:
269269
i2c.write_then_readinto(self.buf, self.buf, out_end=1, in_start=1)
270270
if count == 1:
271271
return self.buf[1]
272-
elif count == 2:
273-
return self.buf[1], self.buf[2]
274-
return None
272+
return self.buf[1], self.buf[2]
275273

276274
def _write_control_register(self, reg: int) -> None:
277275
self.buf[0] = _COMMAND_BIT | _REGISTER_CONTROL

0 commit comments

Comments
 (0)