forked from ikalchev/HAP-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMotionSensor.py
More file actions
28 lines (19 loc) · 714 Bytes
/
MotionSensor.py
File metadata and controls
28 lines (19 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# An Accessory for a MotionSensor
import random
import RPi.GPIO as GPIO
from pyhap.accessory import Accessory
from pyhap.const import CATEGORY_SENSOR
class MotionSensor(Accessory):
category = CATEGORY_SENSOR
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
serv_motion = self.add_preload_service('MotionSensor')
self.char_detected = serv_motion.configure_char('MotionDetected')
GPIO.setmode(GPIO.BCM)
GPIO.setup(7, GPIO.IN)
GPIO.add_event_detect(7, GPIO.RISING, callback=self._detected)
def _detected(self, _pin):
self.char_detected.set_value(True)
def stop(self):
super().stop()
GPIO.cleanup()