@@ -271,91 +271,103 @@ def __init__(self, i2c: I2C, addr: int = _I2C_ADDRESS) -> None:
271
271
except Exception as error :
272
272
raise RuntimeError (f"Failed to initialize: { error } " ) from error
273
273
274
- def als_interrupt (self , enabled , white_channel ) :
274
+ def als_interrupt (self , enabled : bool , white_channel : bool ) -> bool :
275
275
"""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."""
277
279
try :
278
280
self ._als_int_en = enabled
279
281
self ._als_int_switch = white_channel
280
282
return True
281
283
except OSError :
282
284
return False
283
285
284
- def trigger_prox (self ):
286
+ def trigger_prox (self ) -> bool :
285
287
"""Triggers a single proximity measurement manually in active force mode.
286
288
Initiates a one-time proximity measurement in active force mode. This can be
287
289
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."""
289
293
try :
290
294
self ._prox_trigger = True
291
295
return True
292
296
except OSError :
293
297
return False
294
298
295
299
@property
296
- def prox_interrupt (self ):
300
+ def prox_interrupt (self ) -> str :
297
301
"""Interrupt mode for the proximity sensor
298
302
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
+ """
300
307
PS_INT_REVERSE = {value : key for key , value in PS_INT .items ()}
301
308
# Return the mode name if available, otherwise return "Unknown"
302
309
return PS_INT_REVERSE .get (self ._prox_interrupt , "Unknown" )
303
310
304
311
@prox_interrupt .setter
305
- def prox_interrupt (self , mode ) :
312
+ def prox_interrupt (self , mode : int ) -> None :
306
313
if mode not in PS_INT .values ():
307
314
raise ValueError ("Invalid interrupt mode" )
308
315
self ._prox_interrupt = mode
309
316
310
317
@property
311
- def prox_duty (self ):
318
+ def prox_duty (self ) -> str :
312
319
"""Proximity sensor duty cycle setting.
313
320
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."""
315
324
# Reverse lookup dictionary for PS_DUTY
316
325
PS_DUTY_REVERSE = {value : key for key , value in PS_DUTY .items ()}
317
326
return PS_DUTY_REVERSE .get (self ._prox_duty , "Unknown" )
318
327
319
328
@prox_duty .setter
320
- def prox_duty (self , setting ) :
329
+ def prox_duty (self , setting : int ) -> None :
321
330
if setting not in PS_DUTY .values ():
322
331
raise ValueError (f"Invalid proximity duty cycle setting: { setting } " )
323
332
self ._prox_duty = setting
324
333
325
334
@property
326
- def als_integration_time (self ):
335
+ def als_integration_time (self ) -> str :
327
336
"""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"""
329
340
# Reverse lookup dictionary for ALS_IT
330
341
ALS_IT_REVERSE = {value : key for key , value in ALS_IT .items ()}
331
342
# Map the result to the setting name, defaulting to "Unknown" if unmatched
332
343
return ALS_IT_REVERSE .get (self ._als_int_time , "Unknown" )
333
344
334
345
@als_integration_time .setter
335
- def als_integration_time (self , it ) :
346
+ def als_integration_time (self , it : int ) -> None :
336
347
if it not in ALS_IT .values ():
337
348
raise ValueError (f"Invalid ALS integration time setting: { it } " )
338
349
self ._als_int_time = it
339
350
340
351
@property
341
- def als_persistence (self ):
352
+ def als_persistence (self ) -> str :
342
353
"""ALS persistence setting. Configures the persistence level
343
354
of the ALS interrupt, which determines how many consecutive ALS threshold
344
355
triggers are required to activate the interrupt.
356
+
345
357
:return str: The current persistence setting
346
358
"""
347
359
# Reverse lookup dictionary for ALS_PERS
348
360
ALS_PERS_REVERSE = {value : key for key , value in ALS_PERS .items ()}
349
361
return ALS_PERS_REVERSE .get (self ._als_persistence , "Unknown" )
350
362
351
363
@als_persistence .setter
352
- def als_persistence (self , pers ) :
364
+ def als_persistence (self , pers : int ) -> None :
353
365
if pers not in ALS_PERS .values ():
354
366
raise ValueError (f"Invalid ALS persistence setting: { pers } " )
355
367
self ._als_persistence = pers
356
368
357
369
@property
358
- def prox_multi_pulse (self ):
370
+ def prox_multi_pulse (self ) -> str :
359
371
"""Configures the number of infrared pulses used by the proximity sensor in a
360
372
single measurement. Increasing the pulse count can improve accuracy,
361
373
especially in high ambient light conditions.
@@ -366,13 +378,13 @@ def prox_multi_pulse(self):
366
378
return PS_MP_REVERSE .get (self ._prox_multi_pulse , "Unknown" )
367
379
368
380
@prox_multi_pulse .setter
369
- def prox_multi_pulse (self , setting ) :
381
+ def prox_multi_pulse (self , setting : int ) -> None :
370
382
if setting not in PS_MPS .values ():
371
383
raise ValueError (f"Invalid PS_MPS setting: { setting } " )
372
384
self ._prox_multi_pulse = setting
373
385
374
386
@property
375
- def prox_integration_time (self ):
387
+ def prox_integration_time (self ) -> str :
376
388
"""Proximity sensor integration time. Configures the integration
377
389
time for the proximity sensor, which affects the duration for which the
378
390
sensor is sensitive to reflected light.
@@ -384,13 +396,13 @@ def prox_integration_time(self):
384
396
return PS_IT_REVERSE .get (self ._prox_integration_time , "Unknown" )
385
397
386
398
@prox_integration_time .setter
387
- def prox_integration_time (self , setting ) :
399
+ def prox_integration_time (self , setting : int ) -> None :
388
400
if setting not in PS_IT .values ():
389
401
raise ValueError (f"Invalid proximity integration time setting: { setting } " )
390
402
self ._prox_integration_time = setting
391
403
392
404
@property
393
- def prox_persistence (self ):
405
+ def prox_persistence (self ) -> str :
394
406
"""Proximity sensor persistence setting. Configures the persistence
395
407
level of the proximity sensor interrupt, defining how many consecutive
396
408
threshold triggers are required to activate the interrupt.
@@ -402,13 +414,13 @@ def prox_persistence(self):
402
414
return PS_PERS_REVERSE .get (self ._prox_persistence , "Unknown" )
403
415
404
416
@prox_persistence .setter
405
- def prox_persistence (self , setting ) :
417
+ def prox_persistence (self , setting : int ) -> None :
406
418
if setting not in PS_PERS .values ():
407
419
raise ValueError (f"Invalid proximity persistence setting: { setting } " )
408
420
self ._prox_persistence = setting
409
421
410
422
@property
411
- def prox_led_current (self ):
423
+ def prox_led_current (self ) -> str :
412
424
"""IR LED current setting. Configures the driving current for the
413
425
infrared LED used in proximity detection, which affects the range
414
426
and power consumption of the sensor.
@@ -419,13 +431,13 @@ def prox_led_current(self):
419
431
return LED_I_REVERSE .get (self ._prox_led_current , "Unknown" )
420
432
421
433
@prox_led_current .setter
422
- def prox_led_current (self , setting ) :
434
+ def prox_led_current (self , setting : int ) -> None :
423
435
if setting not in LED_I .values ():
424
436
raise ValueError (f"Invalid proximity IR LED current setting: { setting } " )
425
437
self ._prox_led_current = setting
426
438
427
439
@property
428
- def interrupt_flags (self ):
440
+ def interrupt_flags (self ) -> typing . Dict [ str , bool ] :
429
441
"""The current interrupt flags from the sensor. Retrieves the current
430
442
interrupt status flags, which indicate various sensor states, such as
431
443
threshold crossings or sunlight protection events.
0 commit comments