light_strip.py 642 B

123456789101112131415161718192021
  1. """Light strip adv parser."""
  2. from __future__ import annotations
  3. def process_wostrip(
  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. "sequence_number": mfr_data[6],
  11. "isOn": bool(mfr_data[7] & 0b10000000),
  12. "brightness": mfr_data[7] & 0b01111111,
  13. "delay": bool(mfr_data[8] & 0b10000000),
  14. "preset": bool(mfr_data[8] & 0b00001000),
  15. "color_mode": mfr_data[8] & 0b00000111,
  16. "speed": mfr_data[9] & 0b01111111,
  17. "loop_index": mfr_data[10] & 0b11111110,
  18. }