motion.py 568 B

123456789101112131415
  1. """Motion sensor parser."""
  2. def process_wopresence(data: bytes, mfr_data: bytes | None) -> dict[str, bool | int]:
  3. """Process WoPresence Sensor services data."""
  4. return {
  5. "tested": bool(data[1] & 0b10000000),
  6. "motion_detected": bool(data[1] & 0b01000000),
  7. "battery": data[2] & 0b01111111,
  8. "led": (data[5] & 0b00100000) >> 5,
  9. "iot": (data[5] & 0b00010000) >> 4,
  10. "sense_distance": (data[5] & 0b00001100) >> 2,
  11. "light_intensity": data[5] & 0b00000011,
  12. "is_light": bool(data[5] & 0b00000010),
  13. }