@@ -191,7 +191,10 @@ def __init__(
191191 raise
192192
193193 def _pin_changed (self , ticks , state ):
194- self ._fire_events (ticks , self ._state_to_value (state ))
194+ # XXX This is a bit of a hack; _fire_events takes *is_active* rather
195+ # than *value*. Here we're assuming no-one's overridden the default
196+ # implementation of *is_active*.
197+ self ._fire_events (ticks , bool (self ._state_to_value (state )))
195198
196199
197200class SmoothedInputDevice (EventsMixin , InputDevice ):
@@ -420,10 +423,6 @@ class Button(HoldMixin, DigitalInputDevice):
420423 :param pin_factory:
421424 See :doc:`api_pins` for more information (this is an advanced feature
422425 which most users can ignore).
423-
424- .. attribute:: value
425-
426- Returns 1 if the button is currently pressed, and 0 if it is not.
427426 """
428427 def __init__ (
429428 self , pin = None , pull_up = True , active_state = None , bounce_time = None ,
@@ -434,6 +433,13 @@ def __init__(
434433 self .hold_time = hold_time
435434 self .hold_repeat = hold_repeat
436435
436+ @property
437+ def value (self ):
438+ """
439+ Returns 1 if the button is currently pressed, and 0 if it is not.
440+ """
441+ return super (Button , self ).value
442+
437443Button .is_pressed = Button .is_active
438444Button .pressed_time = Button .active_time
439445Button .when_pressed = Button .when_activated
@@ -504,12 +510,6 @@ class LineSensor(SmoothedInputDevice):
504510 which most users can ignore).
505511
506512 .. _CamJam #3 EduKit: http://camjam.me/?page_id=1035
507-
508- .. attribute:: value
509-
510- Returns a value representing the average of the queued values. This
511- is nearer 0 for black under the sensor, and nearer 1 for white under
512- the sensor.
513513 """
514514 def __init__ (
515515 self , pin = None , pull_up = False , active_state = None , queue_len = 5 ,
@@ -525,6 +525,15 @@ def __init__(
525525 self .close ()
526526 raise
527527
528+ @property
529+ def value (self ):
530+ """
531+ Returns a value representing the average of the queued values. This
532+ is nearer 0 for black under the sensor, and nearer 1 for white under
533+ the sensor.
534+ """
535+ return super (LineSensor , self ).value
536+
528537 @property
529538 def line_detected (self ):
530539 return not self .is_active
@@ -594,13 +603,6 @@ class MotionSensor(SmoothedInputDevice):
594603 :param pin_factory:
595604 See :doc:`api_pins` for more information (this is an advanced feature
596605 which most users can ignore).
597-
598- .. attribute:: value
599-
600- With the default *queue_len* of 1, this is effectively boolean where 0
601- means no motion detected and 1 means motion detected. If you specify
602- a *queue_len* greater than 1, this will be an averaged value where
603- values closer to 1 imply motion detection.
604606 """
605607 def __init__ (
606608 self , pin = None , pull_up = False , active_state = None , queue_len = 1 ,
@@ -615,6 +617,16 @@ def __init__(
615617 self .close ()
616618 raise
617619
620+ @property
621+ def value (self ):
622+ """
623+ With the default *queue_len* of 1, this is effectively boolean where 0
624+ means no motion detected and 1 means motion detected. If you specify
625+ a *queue_len* greater than 1, this will be an averaged value where
626+ values closer to 1 imply motion detection.
627+ """
628+ return super (MotionSensor , self ).value
629+
618630MotionSensor .motion_detected = MotionSensor .is_active
619631MotionSensor .when_motion = MotionSensor .when_activated
620632MotionSensor .when_no_motion = MotionSensor .when_deactivated
@@ -675,10 +687,6 @@ class LightSensor(SmoothedInputDevice):
675687 which most users can ignore).
676688
677689 .. _CamJam #2 EduKit: http://camjam.me/?page_id=623
678-
679- .. attribute:: value
680-
681- Returns a value between 0 (dark) and 1 (light).
682690 """
683691 def __init__ (
684692 self , pin = None , queue_len = 5 , charge_time_limit = 0.01 ,
@@ -724,6 +732,13 @@ def _read(self):
724732 self .pin_factory .ticks_diff (self ._charge_time , start ) /
725733 self .charge_time_limit )
726734
735+ @property
736+ def value (self ):
737+ """
738+ Returns a value between 0 (dark) and 1 (light).
739+ """
740+ return super (LightSensor , self ).value
741+
727742LightSensor .light_detected = LightSensor .is_active
728743LightSensor .when_light = LightSensor .when_activated
729744LightSensor .when_dark = LightSensor .when_deactivated
@@ -827,13 +842,6 @@ class DistanceSensor(SmoothedInputDevice):
827842 which most users can ignore).
828843
829844 .. _CamJam #3 EduKit: http://camjam.me/?page_id=1035
830-
831- .. attribute:: value
832-
833- Returns a value between 0, indicating the reflector is either touching
834- the sensor or is sufficiently near that the sensor can't tell the
835- difference, and 1, indicating the reflector is at or beyond the
836- specified *max_distance*.
837845 """
838846 ECHO_LOCK = Lock ()
839847
@@ -916,6 +924,16 @@ def distance(self):
916924 """
917925 return self .value * self ._max_distance
918926
927+ @property
928+ def value (self ):
929+ """
930+ Returns a value between 0, indicating the reflector is either touching
931+ the sensor or is sufficiently near that the sensor can't tell the
932+ difference, and 1, indicating the reflector is at or beyond the
933+ specified *max_distance*.
934+ """
935+ return super (DistanceSensor , self ).value
936+
919937 @property
920938 def trigger (self ):
921939 """
0 commit comments