Debian Codegraph @

scripts/generate_supported_devices.py

raw
1 #!/usr/bin/env python3
2 """Generate SUPPORTED_DEVICES.md from the device capability registry.
3
4 Run manually with `python scripts/generate_supported_devices.py`, or let the
5 `generate-supported-devices` pre-commit hook regenerate it automatically.
6 """
7
8 import sys
9 from pathlib import Path
10
11 REPO_ROOT = Path(__file__).resolve().parent.parent
12
13 sys.path.insert(0, str(REPO_ROOT / "src"))
14
15 from govee_local_api.light_capabilities import ( # noqa: E402
16 GOVEE_LIGHT_CAPABILITIES,
17 SCENE_CODES,
18 GoveeLightFeatures,
19 )
20
21 OUTPUT_FILE = REPO_ROOT / "SUPPORTED_DEVICES.md"
22
23 YES = "✅"
24 NO = "❌"
25
26
27 def _mark(features: GoveeLightFeatures, flag: GoveeLightFeatures) -> str:
28 return YES if features & flag else NO
29
30
31 def generate() -> str:
32 scene_names = ", ".join(SCENE_CODES)
33 lines = [
34 "# Supported Devices",
35 "",
36 "<!-- Auto-generated by scripts/generate_supported_devices.py — do not edit by hand. -->",
37 "<!-- Regenerate with: python scripts/generate_supported_devices.py -->",
38 "",
39 f"The library currently knows **{len(GOVEE_LIGHT_CAPABILITIES)}** device"
40 " models and the features each one supports. Models not listed here are"
41 " still discovered, but fall back to on/off control only. If your device"
42 " is missing or its capabilities are wrong, please"
43 " [open an issue](https://github.com/Galorhallen/govee-local-api/issues).",
44 "",
45 f"Devices with scene support share the same scene set: {scene_names}.",
46 "",
47 "| Model | RGB | Color Temperature | Brightness | Segments | Scenes |",
48 "| ----- | --- | ----------------- | ---------- | -------- | ------ |",
49 ]
50
51 for model, capabilities in sorted(GOVEE_LIGHT_CAPABILITIES.items()):
52 features = capabilities.features
53 segments = (
54 str(capabilities.segments_count) if capabilities.segments_count else "-"
55 )
56 lines.append(
57 f"| {model} "
58 f"| {_mark(features, GoveeLightFeatures.COLOR_RGB)} "
59 f"| {_mark(features, GoveeLightFeatures.COLOR_KELVIN_TEMPERATURE)} "
60 f"| {_mark(features, GoveeLightFeatures.BRIGHTNESS)} "
61 f"| {segments} "
62 f"| {_mark(features, GoveeLightFeatures.SCENES)} |"
63 )
64
65 return "\n".join(lines) + "\n"
66
67
68 if __name__ == "__main__":
69 OUTPUT_FILE.write_text(generate(), encoding="utf-8")