contact.py 586 B

123456789101112131415
  1. """Contact sensor parser."""
  2. from __future__ import annotations
  3. def process_wocontact(data: bytes, mfr_data: bytes | None) -> dict[str, bool | int]:
  4. """Process woContact Sensor services data."""
  5. return {
  6. "tested": bool(data[1] & 0b10000000),
  7. "motion_detected": bool(data[1] & 0b01000000),
  8. "battery": data[2] & 0b01111111,
  9. "contact_open": data[3] & 0b00000010 == 0b00000010,
  10. "contact_timeout": data[3] & 0b00000110 == 0b00000110,
  11. "is_light": bool(data[3] & 0b00000001),
  12. "button_count": (data[7] & 0b11110000) >> 4,
  13. }