1
0

motion.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. """Motion sensor parser."""
  2. from __future__ import annotations
  3. def process_wopresence(
  4. data: bytes | None, mfr_data: bytes | None
  5. ) -> dict[str, bool | int]:
  6. """Process WoPresence Sensor services data."""
  7. if data is None and mfr_data is None:
  8. return {}
  9. tested = None
  10. battery = None
  11. led = None
  12. iot = None
  13. sense_distance = None
  14. light_intensity = None
  15. is_light = None
  16. if data:
  17. tested = bool(data[1] & 0b10000000)
  18. motion_detected = bool(data[1] & 0b01000000)
  19. battery = data[2] & 0b01111111
  20. led = (data[5] & 0b00100000) >> 5
  21. iot = (data[5] & 0b00010000) >> 4
  22. sense_distance = (data[5] & 0b00001100) >> 2
  23. light_intensity = data[5] & 0b00000011
  24. is_light = bool(data[5] & 0b00000010)
  25. if mfr_data and len(mfr_data) >= 8:
  26. motion_detected = bool(mfr_data[7] & 0b01000000)
  27. is_light = bool(mfr_data[7] & 0b00100000)
  28. return {
  29. "tested": tested,
  30. "motion_detected": motion_detected,
  31. "battery": battery,
  32. "led": led,
  33. "iot": iot,
  34. "sense_distance": sense_distance,
  35. "light_intensity": light_intensity,
  36. "is_light": is_light,
  37. }