1
0

relay_switch.py 888 B

12345678910111213141516171819202122232425262728293031
  1. """Relay Switch adv parser."""
  2. from __future__ import annotations
  3. def process_worelay_switch_1pm(
  4. data: bytes | None, mfr_data: bytes | None
  5. ) -> dict[str, bool | int]:
  6. """Process WoStrip services data."""
  7. if mfr_data is None:
  8. return {}
  9. return {
  10. "switchMode": True, # for compatibility, useless
  11. "sequence_number": mfr_data[6],
  12. "isOn": bool(mfr_data[7] & 0b10000000),
  13. "power": ((mfr_data[10] << 8) + mfr_data[11]) / 10,
  14. "voltage": 0,
  15. "current": 0,
  16. }
  17. def process_worelay_switch_1plus(
  18. data: bytes | None, mfr_data: bytes | None
  19. ) -> dict[str, bool | int]:
  20. """Process WoStrip services data."""
  21. if mfr_data is None:
  22. return {}
  23. return {
  24. "switchMode": True, # for compatibility, useless
  25. "sequence_number": mfr_data[6],
  26. "isOn": bool(mfr_data[7] & 0b10000000),
  27. }