contact.py 551 B

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