light_strip.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. """Light strip adv parser."""
  2. from __future__ import annotations
  3. from ..helpers import _UNPACK_UINT16_BE
  4. def process_wostrip(
  5. data: bytes | None, mfr_data: bytes | None
  6. ) -> dict[str, bool | int]:
  7. """Process WoStrip services data."""
  8. if mfr_data is None:
  9. return {}
  10. return {
  11. "sequence_number": mfr_data[6],
  12. "isOn": bool(mfr_data[7] & 0b10000000),
  13. "brightness": mfr_data[7] & 0b01111111,
  14. "delay": bool(mfr_data[8] & 0b10000000),
  15. "network_state": (mfr_data[8] & 0b01110000) >> 4,
  16. "color_mode": mfr_data[8] & 0b00001111,
  17. }
  18. def process_light(
  19. data: bytes | None, mfr_data: bytes | None, cw_offset: int = 16
  20. ) -> dict[str, bool | int]:
  21. """Support for strip light 3 and floor lamp."""
  22. common_data = process_wostrip(data, mfr_data)
  23. if not common_data:
  24. return {}
  25. light_data = {"cw": _UNPACK_UINT16_BE(mfr_data, cw_offset)[0]}
  26. return common_data | light_data
  27. def process_rgbic_light(
  28. data: bytes | None, mfr_data: bytes | None
  29. ) -> dict[str, bool | int]:
  30. """Support for RGBIC lights."""
  31. return process_light(data, mfr_data, cw_offset=10)