relay_switch.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. """Relay Switch adv parser."""
  2. from __future__ import annotations
  3. from typing import Any
  4. def process_relay_switch_common_data(data: bytes | None, mfr_data: bytes | None) -> dict[str, Any]:
  5. """Process relay switch 1 and 1PM common data."""
  6. if mfr_data is None:
  7. return {}
  8. return {
  9. "switchMode": True, # for compatibility, useless
  10. "sequence_number": mfr_data[6],
  11. "isOn": bool(mfr_data[7] & 0b10000000),
  12. }
  13. def process_garage_door_opener(data: bytes | None, mfr_data: bytes | None) -> dict[str, Any]:
  14. """Process garage door opener services data."""
  15. if mfr_data is None:
  16. return {}
  17. common_data = process_relay_switch_common_data(data, mfr_data)
  18. common_data["door_open"] = not bool(mfr_data[7] & 0b00100000)
  19. return common_data
  20. def process_relay_switch_2pm(data: bytes | None, mfr_data: bytes | None) -> dict[int, dict[str, Any]]:
  21. """Process Relay Switch 2PM services data."""
  22. if mfr_data is None:
  23. return {}
  24. return {
  25. 1: {
  26. **process_relay_switch_common_data(data, mfr_data),
  27. },
  28. 2: {
  29. "switchMode": True, # for compatibility, useless
  30. "sequence_number": mfr_data[6],
  31. "isOn": bool(mfr_data[7] & 0b01000000),
  32. },
  33. }