light_strip.py 910 B

1234567891011121314151617181920212223242526272829303132
  1. """Light strip adv parser."""
  2. from __future__ import annotations
  3. import struct
  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(data: bytes | None, mfr_data: bytes | None) -> dict[str, bool | int]:
  19. """Support for strip light 3 and floor lamp."""
  20. common_data = process_wostrip(data, mfr_data)
  21. if not common_data:
  22. return {}
  23. light_data = {"cw": struct.unpack(">H", mfr_data[16:18])[0]}
  24. return common_data | light_data