File: bulb.py

package info (click to toggle)
pyswitchbot 0.72.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 876 kB
  • sloc: python: 12,717; makefile: 2
file content (21 lines) | stat: -rw-r--r-- 633 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""Bulb parser."""

from __future__ import annotations


def process_color_bulb(
    data: bytes | None, mfr_data: bytes | None
) -> dict[str, bool | int]:
    """Process WoBulb services data."""
    if mfr_data is None:
        return {}
    return {
        "sequence_number": mfr_data[6],
        "isOn": bool(mfr_data[7] & 0b10000000),
        "brightness": mfr_data[7] & 0b01111111,
        "delay": bool(mfr_data[8] & 0b10000000),
        "preset": bool(mfr_data[8] & 0b00001000),
        "color_mode": mfr_data[8] & 0b00000111,
        "speed": mfr_data[9] & 0b01111111,
        "loop_index": mfr_data[10] & 0b11111110,
    }