1
0

bulb.py 632 B

1234567891011121314151617181920
  1. """Bulb parser."""
  2. from __future__ import annotations
  3. def process_color_bulb(
  4. data: bytes | None, mfr_data: bytes | None
  5. ) -> dict[str, bool | int]:
  6. """Process WoBulb 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. }