lock.py 964 B

1234567891011121314151617181920212223242526272829
  1. """Lock parser."""
  2. from __future__ import annotations
  3. import logging
  4. from ..const import LockStatus
  5. _LOGGER = logging.getLogger(__name__)
  6. def process_wolock(data: bytes | None, mfr_data: bytes | None) -> dict[str, bool | int]:
  7. """Process woLock services data."""
  8. if mfr_data is None:
  9. return {}
  10. _LOGGER.debug("mfr_data: %s", mfr_data.hex())
  11. _LOGGER.debug("data: %s", data.hex())
  12. return {
  13. "battery": data[2] & 0b01111111 if data else None,
  14. "calibration": bool(mfr_data[7] & 0b10000000),
  15. "status": LockStatus((mfr_data[7] & 0b01110000) >> 4),
  16. "update_from_secondary_lock": bool(mfr_data[7] & 0b00001000),
  17. "door_open": bool(mfr_data[7] & 0b00000100),
  18. "double_lock_mode": bool(mfr_data[8] & 0b10000000),
  19. "unclosed_alarm": bool(mfr_data[8] & 0b00100000),
  20. "unlocked_alarm": bool(mfr_data[8] & 0b00010000),
  21. "auto_lock_paused": bool(mfr_data[8] & 0b00000010),
  22. }