@@ -1999,6 +1999,35 @@ class Button(Switch):
19991999Button .when_released = Button .when_deactivated
20002000
20012001
2002+ class MotionSensor (DigitalInputDevice ):
2003+ """
2004+ Represents a PIR (Passive Infrared) motion sensor (e.g. HC-SR501)
2005+
2006+ :param int pin:
2007+ The pin that the motion sensor is connected to.
2008+
2009+ :param bool pull_up:
2010+ If :data:`True` (the default), the device will be pulled up to
2011+ HIGH. If :data:`False`, the device will be pulled down to LOW.
2012+ Most PIR sensors work with pull_up=False.
2013+
2014+ :param float bounce_time:
2015+ The bounce time for the device. If set, the device will ignore
2016+ any motion events that happen within the bounce time after a
2017+ motion event. This is useful to prevent false triggers.
2018+ Defaults to 0.02 seconds.
2019+ """
2020+
2021+ def __init__ (self , pin , pull_up = False , bounce_time = 0.02 ):
2022+ super ().__init__ (pin = pin , pull_up = pull_up , bounce_time = bounce_time )
2023+
2024+
2025+ MotionSensor .motion_detected = MotionSensor .is_active
2026+ # Note: No alias for is_inactive - use 'not pir.motion_detected' for clarity
2027+ MotionSensor .when_motion = MotionSensor .when_activated
2028+ MotionSensor .when_no_motion = MotionSensor .when_deactivated
2029+
2030+
20022031class AnalogInputDevice (InputDevice , PinMixin ):
20032032 """
20042033 Represents a generic input device with analogue functionality, e.g.
@@ -2247,31 +2276,3 @@ def max_distance(self):
22472276 Returns the maximum distance that the sensor will measure in metres.
22482277 """
22492278 return self ._max_distance
2250-
2251-
2252- class MotionSensor (DigitalInputDevice ):
2253- """
2254- Represents a PIR (Passive Infrared) motion sensor (e.g. HC-SR501)
2255-
2256- :param int pin:
2257- The pin that the motion sensor is connected to.
2258-
2259- :param bool pull_up:
2260- If :data:`True` (the default), the device will be pulled up to
2261- HIGH. If :data:`False`, the device will be pulled down to LOW.
2262- Most PIR sensors work with pull_up=False.
2263-
2264- :param float bounce_time:
2265- The bounce time for the device. If set, the device will ignore
2266- any motion events that happen within the bounce time after a
2267- motion event. This is useful to prevent false triggers.
2268- Defaults to 0.02 seconds.
2269- """
2270-
2271- def __init__ (self , pin , pull_up = False , bounce_time = 0.02 ):
2272- super ().__init__ (pin = pin , pull_up = pull_up , bounce_time = bounce_time )
2273-
2274-
2275- MotionSensor .motion_detected = MotionSensor .is_active
2276- MotionSensor .when_motion = MotionSensor .when_activated
2277- MotionSensor .when_no_motion = MotionSensor .when_deactivated
0 commit comments