1
0

lock.py 1.0 KB

12345678910111213141516171819202122232425262728293031
  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. if data:
  12. _LOGGER.debug("data: %s", data.hex())
  13. return {
  14. "battery": data[2] & 0b01111111 if data else None,
  15. "calibration": bool(mfr_data[7] & 0b10000000),
  16. "status": LockStatus((mfr_data[7] & 0b01110000) >> 4),
  17. "update_from_secondary_lock": bool(mfr_data[7] & 0b00001000),
  18. "door_open": bool(mfr_data[7] & 0b00000100),
  19. "double_lock_mode": bool(mfr_data[8] & 0b10000000),
  20. "unclosed_alarm": bool(mfr_data[8] & 0b00100000),
  21. "unlocked_alarm": bool(mfr_data[8] & 0b00010000),
  22. "auto_lock_paused": bool(mfr_data[8] & 0b00000010),
  23. "night_latch": bool(mfr_data[9] & 0b00000001) if len(mfr_data) > 9 else False,
  24. }