1
0

lock.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. }
  25. def process_wolock_pro(
  26. data: bytes | None, mfr_data: bytes | None
  27. ) -> dict[str, bool | int]:
  28. _LOGGER.debug("mfr_data: %s", mfr_data.hex())
  29. if data:
  30. _LOGGER.debug("data: %s", data.hex())
  31. res = {
  32. "battery": data[2] & 0b01111111 if data else None,
  33. "calibration": bool(mfr_data[7] & 0b10000000),
  34. "status": LockStatus((mfr_data[7] & 0b00111000) >> 3),
  35. "door_open": bool(mfr_data[8] & 0b01100000),
  36. # Double lock mode is not supported on Lock Pro
  37. "update_from_secondary_lock": False,
  38. "double_lock_mode": False,
  39. "unclosed_alarm": bool(mfr_data[11] & 0b10000000),
  40. "unlocked_alarm": bool(mfr_data[11] & 0b01000000),
  41. "auto_lock_paused": bool(mfr_data[8] & 0b100000),
  42. # Looks like night latch bit is not anymore in ADV
  43. "night_latch": False,
  44. }
  45. _LOGGER.debug(res)
  46. return res