|
34 | 34 | from micropython import const
|
35 | 35 |
|
36 | 36 | try:
|
37 |
| - from typing import Tuple, Union # pylint: disable=unused-import |
| 37 | + from typing import Optional, Tuple |
38 | 38 | from busio import I2C
|
39 | 39 | except ImportError:
|
40 | 40 | pass
|
@@ -99,7 +99,7 @@ def enabled(self, enable: bool) -> None:
|
99 | 99 | self._disable()
|
100 | 100 |
|
101 | 101 | @property
|
102 |
| - def lux(self) -> Union[None, float]: |
| 102 | + def lux(self) -> Optional[float]: |
103 | 103 | """The computed lux value or None when value is not computable."""
|
104 | 104 | return self._compute_lux()
|
105 | 105 |
|
@@ -224,7 +224,7 @@ def clear_interrupt(self) -> None:
|
224 | 224 | with self.i2c_device as i2c:
|
225 | 225 | i2c.write(self.buf, end=1)
|
226 | 226 |
|
227 |
| - def _compute_lux(self) -> Union[None, float]: |
| 227 | + def _compute_lux(self) -> Optional[float]: |
228 | 228 | """Based on datasheet for FN package."""
|
229 | 229 | ch0, ch1 = self.luminosity
|
230 | 230 | if ch0 == 0:
|
@@ -259,19 +259,17 @@ def _enable(self) -> None:
|
259 | 259 | def _disable(self) -> None:
|
260 | 260 | self._write_control_register(_CONTROL_POWEROFF)
|
261 | 261 |
|
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") |
265 | 265 | self.buf[0] = _COMMAND_BIT | reg
|
266 | 266 | if count == 2:
|
267 | 267 | self.buf[0] |= _WORD_BIT
|
268 | 268 | with self.i2c_device as i2c:
|
269 | 269 | i2c.write_then_readinto(self.buf, self.buf, out_end=1, in_start=1)
|
270 | 270 | if count == 1:
|
271 | 271 | 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] |
275 | 273 |
|
276 | 274 | def _write_control_register(self, reg: int) -> None:
|
277 | 275 | self.buf[0] = _COMMAND_BIT | _REGISTER_CONTROL
|
|
0 commit comments