Skip to content

Commit ea87f52

Browse files
committed
Code review notes
Improve persist documentation. Full description of accepted values. Code consistency: other contrained setters assert, persist now asserts Input arguments are called `val` throughout.
1 parent 82262a0 commit ea87f52

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

adafruit_tsl2591.py

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,9 @@ def threshold_low(self) -> int:
302302
return th_low
303303

304304
@threshold_low.setter
305-
def threshold_low(self, value: int) -> None:
306-
lower = value & 0xFF
307-
upper = (value >> 8) & 0xFF
305+
def threshold_low(self, val: int) -> None:
306+
lower = val & 0xFF
307+
upper = (val >> 8) & 0xFF
308308
self._write_u8(_TSL2591_AILTL, lower)
309309
self._write_u8(_TSL2591_AILTH, upper)
310310

@@ -317,9 +317,9 @@ def threshold_high(self) -> int:
317317
return th_high
318318

319319
@threshold_high.setter
320-
def threshold_high(self, value: int) -> None:
321-
lower = value & 0xFF
322-
upper = (value >> 8) & 0xFF
320+
def threshold_high(self, val: int) -> None:
321+
lower = val & 0xFF
322+
upper = (val >> 8) & 0xFF
323323
self._write_u8(_TSL2591_AIHTL, lower)
324324
self._write_u8(_TSL2591_AIHTH, upper)
325325

@@ -332,9 +332,9 @@ def nopersist_threshold_low(self) -> int:
332332
return np_th_low
333333

334334
@nopersist_threshold_low.setter
335-
def nopersist_threshold_low(self, value: int) -> None:
336-
lower = value & 0xFF
337-
upper = (value >> 8) & 0xFF
335+
def nopersist_threshold_low(self, val: int) -> None:
336+
lower = val & 0xFF
337+
upper = (val >> 8) & 0xFF
338338
self._write_u8(_TSL2591_NPAILTL, lower)
339339
self._write_u8(_TSL2591_NPAILTH, upper)
340340

@@ -347,22 +347,43 @@ def nopersist_threshold_high(self) -> int:
347347
return np_th_high
348348

349349
@nopersist_threshold_high.setter
350-
def nopersist_threshold_high(self, value: int) -> None:
351-
lower = value & 0xFF
352-
upper = (value >> 8) & 0xFF
350+
def nopersist_threshold_high(self, val: int) -> None:
351+
lower = val & 0xFF
352+
upper = (val >> 8) & 0xFF
353353
self._write_u8(_TSL2591_NPAIHTL, lower)
354354
self._write_u8(_TSL2591_NPAIHTH, upper)
355355

356356
@property
357357
def persist(self) -> int:
358358
"""Get and set the interrupt persist filter - the number of consecutive out-of-range
359-
ALS cycles necessary to generate an interrupt."""
359+
ALS cycles necessary to generate an interrupt. Valid persist values are 0 - 15 (inclusive),
360+
corresponding to a preset number of cycles. Only the 4 lower bits will be used to write
361+
to the device.
362+
Can be a value of:
363+
- ``0 (0000)`` - Every ALS cycle generates an interrupt.
364+
- ``1 (0001)`` - Any value outside of threshold range.
365+
- ``2 (0010)`` - 2 consecutive values out of range.
366+
- ``3 (0011)`` - 3 consecutive values out of range.
367+
- ``4 (0100)`` - 5 consecutive values out of range.
368+
- ``5 (0101)`` - 10 consecutive values out of range.
369+
- ``6 (0110)`` - 15 consecutive values out of range.
370+
- ``7 (0111)`` - 20 consecutive values out of range.
371+
- ``8 (1000)`` - 25 consecutive values out of range.
372+
- ``9 (1001)`` - 30 consecutive values out of range.
373+
- ``10 (1010)`` - 35 consecutive values out of range.
374+
- ``11 (1011)`` - 40 consecutive values out of range.
375+
- ``12 (1100)`` - 45 consecutive values out of range.
376+
- ``13 (1101)`` - 50 consecutive values out of range.
377+
- ``14 (1110)`` - 55 consecutive values out of range.
378+
- ``15 (1111)`` - 60 consecutive values out of range.
379+
"""
360380
persist = self._read_u8(_TSL2591_PERSIST_FILTER)
361381
return persist & 0x0F
362382

363383
@persist.setter
364-
def persist(self, value: int) -> None:
365-
persist = value & 0x0F
384+
def persist(self, val: int) -> None:
385+
assert 0 <= val <= 15
386+
persist = val & 0x0F
366387
self._write_u8(_TSL2591_PERSIST_FILTER, persist)
367388

368389
@property

0 commit comments

Comments
 (0)