Skip to content

Commit 7e17bcb

Browse files
committed
typing, a few more docstrings
1 parent cb146bf commit 7e17bcb

File tree

1 file changed

+36
-24
lines changed

1 file changed

+36
-24
lines changed

adafruit_vcnl4200.py

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -271,91 +271,103 @@ def __init__(self, i2c: I2C, addr: int = _I2C_ADDRESS) -> None:
271271
except Exception as error:
272272
raise RuntimeError(f"Failed to initialize: {error}") from error
273273

274-
def als_interrupt(self, enabled, white_channel):
274+
def als_interrupt(self, enabled: bool, white_channel: bool) -> bool:
275275
"""Configure ALS interrupt settings, enabling or disabling
276-
the interrupt and selecting the interrupt channel."""
276+
the interrupt and selecting the interrupt channel.
277+
278+
:return bool: True if setting the values succeeded, False otherwise."""
277279
try:
278280
self._als_int_en = enabled
279281
self._als_int_switch = white_channel
280282
return True
281283
except OSError:
282284
return False
283285

284-
def trigger_prox(self):
286+
def trigger_prox(self) -> bool:
285287
"""Triggers a single proximity measurement manually in active force mode.
286288
Initiates a one-time proximity measurement in active force mode. This can be
287289
used when proximity measurements are not continuous and need to be triggered
288-
individually."""
290+
individually.
291+
292+
:return bool: True if triggering succeeded, False otherwise."""
289293
try:
290294
self._prox_trigger = True
291295
return True
292296
except OSError:
293297
return False
294298

295299
@property
296-
def prox_interrupt(self):
300+
def prox_interrupt(self) -> str:
297301
"""Interrupt mode for the proximity sensor
298302
Configures the interrupt condition for the proximity sensor, which determines
299-
when an interrupt will be triggered based on the detected proximity."""
303+
when an interrupt will be triggered based on the detected proximity.
304+
305+
:return str: The interrupt mode for the proximity sensor.
306+
"""
300307
PS_INT_REVERSE = {value: key for key, value in PS_INT.items()}
301308
# Return the mode name if available, otherwise return "Unknown"
302309
return PS_INT_REVERSE.get(self._prox_interrupt, "Unknown")
303310

304311
@prox_interrupt.setter
305-
def prox_interrupt(self, mode):
312+
def prox_interrupt(self, mode: int) -> None:
306313
if mode not in PS_INT.values():
307314
raise ValueError("Invalid interrupt mode")
308315
self._prox_interrupt = mode
309316

310317
@property
311-
def prox_duty(self):
318+
def prox_duty(self) -> str:
312319
"""Proximity sensor duty cycle setting.
313320
Configures the duty cycle of the infrared emitter for the proximity sensor,
314-
which affects power consumption and response time."""
321+
which affects power consumption and response time.
322+
323+
:return str: The duty cycle of the infrared emitter for the proximity sensor."""
315324
# Reverse lookup dictionary for PS_DUTY
316325
PS_DUTY_REVERSE = {value: key for key, value in PS_DUTY.items()}
317326
return PS_DUTY_REVERSE.get(self._prox_duty, "Unknown")
318327

319328
@prox_duty.setter
320-
def prox_duty(self, setting):
329+
def prox_duty(self, setting: int) -> None:
321330
if setting not in PS_DUTY.values():
322331
raise ValueError(f"Invalid proximity duty cycle setting: {setting}")
323332
self._prox_duty = setting
324333

325334
@property
326-
def als_integration_time(self):
335+
def als_integration_time(self) -> str:
327336
"""ALS integration time setting. Configures the integration time for
328-
the ambient light sensor to control sensitivity and range."""
337+
the ambient light sensor to control sensitivity and range.
338+
339+
:return str: The ALS integration time setting"""
329340
# Reverse lookup dictionary for ALS_IT
330341
ALS_IT_REVERSE = {value: key for key, value in ALS_IT.items()}
331342
# Map the result to the setting name, defaulting to "Unknown" if unmatched
332343
return ALS_IT_REVERSE.get(self._als_int_time, "Unknown")
333344

334345
@als_integration_time.setter
335-
def als_integration_time(self, it):
346+
def als_integration_time(self, it: int) -> None:
336347
if it not in ALS_IT.values():
337348
raise ValueError(f"Invalid ALS integration time setting: {it}")
338349
self._als_int_time = it
339350

340351
@property
341-
def als_persistence(self):
352+
def als_persistence(self) -> str:
342353
"""ALS persistence setting. Configures the persistence level
343354
of the ALS interrupt, which determines how many consecutive ALS threshold
344355
triggers are required to activate the interrupt.
356+
345357
:return str: The current persistence setting
346358
"""
347359
# Reverse lookup dictionary for ALS_PERS
348360
ALS_PERS_REVERSE = {value: key for key, value in ALS_PERS.items()}
349361
return ALS_PERS_REVERSE.get(self._als_persistence, "Unknown")
350362

351363
@als_persistence.setter
352-
def als_persistence(self, pers):
364+
def als_persistence(self, pers: int) -> None:
353365
if pers not in ALS_PERS.values():
354366
raise ValueError(f"Invalid ALS persistence setting: {pers}")
355367
self._als_persistence = pers
356368

357369
@property
358-
def prox_multi_pulse(self):
370+
def prox_multi_pulse(self) -> str:
359371
"""Configures the number of infrared pulses used by the proximity sensor in a
360372
single measurement. Increasing the pulse count can improve accuracy,
361373
especially in high ambient light conditions.
@@ -366,13 +378,13 @@ def prox_multi_pulse(self):
366378
return PS_MP_REVERSE.get(self._prox_multi_pulse, "Unknown")
367379

368380
@prox_multi_pulse.setter
369-
def prox_multi_pulse(self, setting):
381+
def prox_multi_pulse(self, setting: int) -> None:
370382
if setting not in PS_MPS.values():
371383
raise ValueError(f"Invalid PS_MPS setting: {setting}")
372384
self._prox_multi_pulse = setting
373385

374386
@property
375-
def prox_integration_time(self):
387+
def prox_integration_time(self) -> str:
376388
"""Proximity sensor integration time. Configures the integration
377389
time for the proximity sensor, which affects the duration for which the
378390
sensor is sensitive to reflected light.
@@ -384,13 +396,13 @@ def prox_integration_time(self):
384396
return PS_IT_REVERSE.get(self._prox_integration_time, "Unknown")
385397

386398
@prox_integration_time.setter
387-
def prox_integration_time(self, setting):
399+
def prox_integration_time(self, setting: int) -> None:
388400
if setting not in PS_IT.values():
389401
raise ValueError(f"Invalid proximity integration time setting: {setting}")
390402
self._prox_integration_time = setting
391403

392404
@property
393-
def prox_persistence(self):
405+
def prox_persistence(self) -> str:
394406
"""Proximity sensor persistence setting. Configures the persistence
395407
level of the proximity sensor interrupt, defining how many consecutive
396408
threshold triggers are required to activate the interrupt.
@@ -402,13 +414,13 @@ def prox_persistence(self):
402414
return PS_PERS_REVERSE.get(self._prox_persistence, "Unknown")
403415

404416
@prox_persistence.setter
405-
def prox_persistence(self, setting):
417+
def prox_persistence(self, setting: int) -> None:
406418
if setting not in PS_PERS.values():
407419
raise ValueError(f"Invalid proximity persistence setting: {setting}")
408420
self._prox_persistence = setting
409421

410422
@property
411-
def prox_led_current(self):
423+
def prox_led_current(self) -> str:
412424
"""IR LED current setting. Configures the driving current for the
413425
infrared LED used in proximity detection, which affects the range
414426
and power consumption of the sensor.
@@ -419,13 +431,13 @@ def prox_led_current(self):
419431
return LED_I_REVERSE.get(self._prox_led_current, "Unknown")
420432

421433
@prox_led_current.setter
422-
def prox_led_current(self, setting):
434+
def prox_led_current(self, setting: int) -> None:
423435
if setting not in LED_I.values():
424436
raise ValueError(f"Invalid proximity IR LED current setting: {setting}")
425437
self._prox_led_current = setting
426438

427439
@property
428-
def interrupt_flags(self):
440+
def interrupt_flags(self) -> typing.Dict[str, bool]:
429441
"""The current interrupt flags from the sensor. Retrieves the current
430442
interrupt status flags, which indicate various sensor states, such as
431443
threshold crossings or sunlight protection events.

0 commit comments

Comments
 (0)