Debian Codegraph @

src/govee_local_api/light_capabilities.py

raw symbols SCIP
1 from enum import IntFlag
2
3
4 class GoveeLightFeatures(IntFlag):
5 """Govee Lights capabilities."""
6
7 COLOR_RGB = 0x01
8 COLOR_KELVIN_TEMPERATURE = 0x02
9 BRIGHTNESS = 0x04
10 SEGMENT_CONTROL = 0x08
11 SCENES = 0x10
12
13
14 COMMON_FEATURES: GoveeLightFeatures = (
15 GoveeLightFeatures.COLOR_RGB
16 | GoveeLightFeatures.COLOR_KELVIN_TEMPERATURE
17 | GoveeLightFeatures.BRIGHTNESS
18 )
19
20
21 class GoveeLightCapabilities:
22 def __init__(
23 self,
24 features: GoveeLightFeatures,
25 segments: list[bytes] | None = None,
26 scenes: dict[str, bytes] | None = None,
27 ) -> None:
28 self.features = features
29 # Copy the inputs: they are module-level shared tables
30 # (SEGMENT_CODES / SCENE_CODES), and capability objects are shared
31 # across devices — a consumer mutating one instance must not
32 # corrupt every other device's capabilities.
33 self.segments = (
34 list(segments)
35 if segments and features & GoveeLightFeatures.SEGMENT_CONTROL
36 else []
37 )
38 self.scenes = (
39 dict(scenes) if scenes and features & GoveeLightFeatures.SCENES else {}
40 )
41
42 @property
43 def segments_count(self) -> int:
44 return len(self.segments)
45
46 @property
47 def available_scenes(self) -> list[str]:
48 return list(self.scenes.keys())
49
50 def __repr__(self) -> str:
51 return f"GoveeLightCapabilities(features={self.features!r}, segments={self.segments!r}, scenes={self.scenes!r})"
52
53 def __str__(self) -> str:
54 return f"GoveeLightCapabilities(features={self.features!r}, segments={len(self.segments)}, scenes={len(self.scenes)})"
55
56
57 SEGMENT_CODES: list[bytes] = [
58 b"\x01\x00", # 1
59 b"\x02\x00", # 2
60 b"\x04\x00", # 3
61 b"\x08\x00", # 4
62 b"\x10\x00", # 5
63 b"\x20\x00", # 6
64 b"\x40\x00", # 7
65 b"\x80\x00", # 8
66 b"\x00\x01", # 9
67 b"\x00\x02", # 10
68 b"\x00\x04", # 11
69 b"\x00\x08", # 12
70 b"\x00\x10", # 13
71 b"\x00\x20", # 14
72 b"\x00\x40", # 15
73 ]
74
75 SCENE_CODES: dict[str, bytes] = {
76 "sunrise": b"\x00",
77 "sunset": b"\x01",
78 "movie": b"\x04",
79 "dating": b"\x05",
80 "romantic": b"\x07",
81 "twinkle": b"\x08",
82 "candlelight": b"\x09",
83 "snowflake": b"\x0f",
84 "energetic": b"\x10",
85 "breathe": b"\x0a",
86 "crossing": b"\x15",
87 }
88
89
90 def create_with_capabilities(
91 rgb: bool, temperature: bool, brightness: bool, segments: int, scenes: bool
92 ) -> GoveeLightCapabilities:
93 features: GoveeLightFeatures = GoveeLightFeatures(0)
94 segments_codes = []
95
96 if rgb:
97 features = features | GoveeLightFeatures.COLOR_RGB
98 if temperature:
99 features = features | GoveeLightFeatures.COLOR_KELVIN_TEMPERATURE
100 if brightness:
101 features = features | GoveeLightFeatures.BRIGHTNESS
102 if segments > 0:
103 features = features | GoveeLightFeatures.SEGMENT_CONTROL
104 segments_codes = SEGMENT_CODES[:segments]
105
106 if scenes:
107 features = features | GoveeLightFeatures.SCENES
108
109 return GoveeLightCapabilities(
110 features, segments_codes, SCENE_CODES if scenes else {}
111 )
112
113
114 BASIC_CAPABILITIES = create_with_capabilities(
115 rgb=True, temperature=True, brightness=True, segments=0, scenes=True
116 )
117
118 ON_OFF_CAPABILITIES = create_with_capabilities(
119 rgb=False, temperature=False, brightness=False, segments=0, scenes=False
120 )
121
122
123 GOVEE_LIGHT_CAPABILITIES: dict[str, GoveeLightCapabilities] = {
124 # Models with common features
125 "H1232": BASIC_CAPABILITIES,
126 "H1250": BASIC_CAPABILITIES,
127 "H1270": BASIC_CAPABILITIES,
128 "H1310": BASIC_CAPABILITIES,
129 "H1401": BASIC_CAPABILITIES,
130 "H14A1": BASIC_CAPABILITIES,
131 "H14C0": BASIC_CAPABILITIES,
132 "H14C1": BASIC_CAPABILITIES,
133 "H1630": BASIC_CAPABILITIES,
134 "H16B0": BASIC_CAPABILITIES,
135 "H16C0": BASIC_CAPABILITIES,
136 "H1A43": BASIC_CAPABILITIES,
137 "H1A45": BASIC_CAPABILITIES,
138 "H2A40": BASIC_CAPABILITIES,
139 "H2A41": BASIC_CAPABILITIES,
140 "H3200": BASIC_CAPABILITIES,
141 "H3500": BASIC_CAPABILITIES,
142 "H3501": BASIC_CAPABILITIES,
143 "H3510": BASIC_CAPABILITIES,
144 "H3511": BASIC_CAPABILITIES,
145 "H3751": BASIC_CAPABILITIES,
146 "H6004": BASIC_CAPABILITIES,
147 "H6006": BASIC_CAPABILITIES, # Issue #133 - temp confirmed via Cloud API (2000-9000K)
148 "H6008": BASIC_CAPABILITIES,
149 "H600A": BASIC_CAPABILITIES,
150 "H600D": BASIC_CAPABILITIES,
151 "H601A": BASIC_CAPABILITIES, # Issue #129
152 "H6020": create_with_capabilities(True, True, True, 0, True),
153 "H6022": BASIC_CAPABILITIES,
154 "H6038": BASIC_CAPABILITIES,
155 "H6039": create_with_capabilities(True, True, True, 12, True),
156 "H6042": create_with_capabilities(True, True, True, 5, True),
157 "H6043": create_with_capabilities(
158 True, False, True, 10, True
159 ), # Issue #254 - TV Light Bars 2, no temp
160 "H6046": create_with_capabilities(True, True, True, 10, True),
161 "H6047": create_with_capabilities(True, True, True, 10, True),
162 "H6048": create_with_capabilities(True, True, True, 24, True),
163 "H6051": BASIC_CAPABILITIES,
164 "H6052": BASIC_CAPABILITIES,
165 "H6056": BASIC_CAPABILITIES,
166 "H6059": BASIC_CAPABILITIES,
167 "H605D": BASIC_CAPABILITIES,
168 "H6061": BASIC_CAPABILITIES,
169 "H6062": BASIC_CAPABILITIES,
170 "H6063": create_with_capabilities(True, True, True, 0, False),
171 "H6065": BASIC_CAPABILITIES,
172 "H6066": BASIC_CAPABILITIES,
173 "H6069": create_with_capabilities(True, False, True, 20, True),
174 "H6067": BASIC_CAPABILITIES,
175 "H606A": BASIC_CAPABILITIES,
176 "H6072": create_with_capabilities(True, True, True, 8, True),
177 "H6073": BASIC_CAPABILITIES,
178 "H6076": create_with_capabilities(True, True, True, 7, True),
179 "H6076A": BASIC_CAPABILITIES,
180 "H6078": BASIC_CAPABILITIES,
181 "H6079": BASIC_CAPABILITIES,
182 "H607C": create_with_capabilities(True, True, True, 13, True),
183 "H6087": create_with_capabilities(True, True, True, 12, True),
184 "H6088": create_with_capabilities(True, True, True, 6, True),
185 "H608A": BASIC_CAPABILITIES,
186 "H608B": create_with_capabilities(True, True, True, 15, True),
187 "H608C": BASIC_CAPABILITIES,
188 "H608D": BASIC_CAPABILITIES,
189 "H6093": create_with_capabilities(False, True, True, 0, True),
190 "H6094": BASIC_CAPABILITIES,
191 "H6095": create_with_capabilities(True, True, True, 0, True),
192 "H609D": BASIC_CAPABILITIES,
193 "H60A0": BASIC_CAPABILITIES,
194 "H60A1": create_with_capabilities(True, True, True, 13, True),
195 "H60A4": create_with_capabilities(True, True, True, 11, False),
196 "H60A6": create_with_capabilities(True, True, True, 0, False),
197 "H60B0": BASIC_CAPABILITIES, # Issue #252 - segments TBD
198 "H60B1": create_with_capabilities(True, True, True, 3, True),
199 "H60B2": create_with_capabilities(True, True, True, 3, True),
200 "H60C1": create_with_capabilities(True, True, True, 3, True), # Issue #232
201 "H610A": BASIC_CAPABILITIES,
202 "H610B": BASIC_CAPABILITIES,
203 "H610E": create_with_capabilities(True, True, True, 7, False),
204 "H610F": create_with_capabilities(True, True, True, 7, False),
205 "H6110": BASIC_CAPABILITIES,
206 "H6117": BASIC_CAPABILITIES,
207 "H6141": BASIC_CAPABILITIES,
208 "H6143": BASIC_CAPABILITIES,
209 "H6144": BASIC_CAPABILITIES,
210 "H6159": BASIC_CAPABILITIES,
211 "H615A": create_with_capabilities(True, True, True, 0, True),
212 "H615B": create_with_capabilities(True, True, True, 0, True),
213 "H615C": create_with_capabilities(True, True, True, 0, True),
214 "H615D": create_with_capabilities(True, True, True, 0, True),
215 "H615E": create_with_capabilities(True, True, True, 0, True),
216 "H6163": BASIC_CAPABILITIES,
217 "H6167": create_with_capabilities(True, True, True, 12, True),
218 "H6168": BASIC_CAPABILITIES,
219 "H616C": BASIC_CAPABILITIES,
220 "H616D": create_with_capabilities(True, True, True, 15, True),
221 "H616E": BASIC_CAPABILITIES,
222 "H6172": BASIC_CAPABILITIES,
223 "H6173": BASIC_CAPABILITIES,
224 "H6175": BASIC_CAPABILITIES,
225 "H6176": BASIC_CAPABILITIES,
226 "H6182": BASIC_CAPABILITIES,
227 "H618A": create_with_capabilities(True, True, True, 15, True),
228 "H618C": create_with_capabilities(True, True, True, 15, True),
229 "H618E": create_with_capabilities(True, True, True, 15, True),
230 "H618F": create_with_capabilities(True, True, True, 15, True),
231 "H618G": BASIC_CAPABILITIES,
232 "H619A": create_with_capabilities(True, True, True, 10, True),
233 "H619B": create_with_capabilities(True, True, True, 10, True),
234 "H619C": create_with_capabilities(True, True, True, 10, True),
235 "H619D": create_with_capabilities(True, True, True, 10, True),
236 "H619E": create_with_capabilities(True, True, True, 10, True),
237 "H619Z": BASIC_CAPABILITIES,
238 "H61A0": BASIC_CAPABILITIES,
239 "H61A1": BASIC_CAPABILITIES,
240 "H61A2": BASIC_CAPABILITIES,
241 "H61A3": BASIC_CAPABILITIES,
242 "H61A5": BASIC_CAPABILITIES,
243 "H61A8": BASIC_CAPABILITIES,
244 "H61A9": BASIC_CAPABILITIES,
245 "H61B1": BASIC_CAPABILITIES,
246 "H61B2": BASIC_CAPABILITIES,
247 "H61B3": create_with_capabilities(True, True, True, 15, True),
248 "H61B6": create_with_capabilities(True, True, True, 0, True),
249 "H61B8": create_with_capabilities(True, True, True, 40, True),
250 "H61B9": create_with_capabilities(True, True, True, 0, True),
251 "H61BA": BASIC_CAPABILITIES,
252 "H61BC": BASIC_CAPABILITIES,
253 "H61BE": BASIC_CAPABILITIES,
254 "H61C2": BASIC_CAPABILITIES,
255 "H61C3": BASIC_CAPABILITIES,
256 "H61C5": BASIC_CAPABILITIES,
257 "H61D3": create_with_capabilities(True, True, True, 15, True),
258 "H61D5": BASIC_CAPABILITIES,
259 "H61D6": BASIC_CAPABILITIES,
260 "H61E0": BASIC_CAPABILITIES,
261 "H61E1": BASIC_CAPABILITIES,
262 "H61E5": create_with_capabilities(True, True, True, 12, True),
263 "H61E6": create_with_capabilities(True, True, True, 15, True),
264 "H61F2": create_with_capabilities(True, True, True, 4, True),
265 "H61F5": create_with_capabilities(True, True, True, 10, True),
266 "H61F6": create_with_capabilities(True, True, True, 20, True),
267 "H6609": create_with_capabilities(True, True, True, 18, True),
268 "H6630": BASIC_CAPABILITIES,
269 "H6631": BASIC_CAPABILITIES,
270 "H6640": create_with_capabilities(True, True, True, 14, True),
271 "H6641": create_with_capabilities(True, True, True, 14, True),
272 "H6671": BASIC_CAPABILITIES,
273 "H6672": BASIC_CAPABILITIES,
274 "H6800": BASIC_CAPABILITIES,
275 "H6810": create_with_capabilities(True, True, True, 0, False),
276 "H6811": BASIC_CAPABILITIES,
277 "H6840": BASIC_CAPABILITIES,
278 "H6841": BASIC_CAPABILITIES,
279 "H6860": BASIC_CAPABILITIES,
280 "H6861": BASIC_CAPABILITIES,
281 "H6870": BASIC_CAPABILITIES,
282 "H6871": create_with_capabilities(True, True, True, 0, True),
283 "H7012": create_with_capabilities(False, False, True, 0, False),
284 "H7013": create_with_capabilities(False, False, True, 0, False),
285 "H7020": BASIC_CAPABILITIES,
286 "H7021": BASIC_CAPABILITIES,
287 "H7025": create_with_capabilities(True, False, True, 15, True),
288 "H7026": create_with_capabilities(True, False, True, 30, True),
289 "H7027": BASIC_CAPABILITIES,
290 "H7028": BASIC_CAPABILITIES,
291 "H702A": create_with_capabilities(
292 True, True, True, 15, True
293 ), # Issue #245 - Outdoor S14 Bulb String Lights 2
294 "H702B": create_with_capabilities(True, True, True, 0, True),
295 "H702C": BASIC_CAPABILITIES, # Issue #262 - segments TBD
296 "H7030": BASIC_CAPABILITIES,
297 "H7033": BASIC_CAPABILITIES,
298 "H7037": BASIC_CAPABILITIES,
299 "H7038": BASIC_CAPABILITIES,
300 "H7039": create_with_capabilities(True, True, True, 45, True),
301 "H703A": BASIC_CAPABILITIES,
302 "H703B": BASIC_CAPABILITIES,
303 "H7041": BASIC_CAPABILITIES,
304 "H7042": BASIC_CAPABILITIES,
305 "H7045": BASIC_CAPABILITIES,
306 "H7046": BASIC_CAPABILITIES,
307 "H7050": BASIC_CAPABILITIES,
308 "H7051": BASIC_CAPABILITIES,
309 "H7052": create_with_capabilities(True, True, True, 15, True),
310 "H7053": create_with_capabilities(True, True, True, 0, True),
311 "H7055": BASIC_CAPABILITIES,
312 "H7056": BASIC_CAPABILITIES,
313 "H7057": create_with_capabilities(True, True, True, 0, True),
314 "H7058": create_with_capabilities(True, True, True, 0, True),
315 "H705A": BASIC_CAPABILITIES,
316 "H705B": BASIC_CAPABILITIES,
317 "H705C": BASIC_CAPABILITIES,
318 "H705D": create_with_capabilities(True, True, True, 9, True),
319 "H705E": create_with_capabilities(True, True, True, 18, True),
320 "H705F": create_with_capabilities(True, True, True, 27, True),
321 "H7060": BASIC_CAPABILITIES,
322 "H7061": BASIC_CAPABILITIES,
323 "H7062": BASIC_CAPABILITIES,
324 "H7063": BASIC_CAPABILITIES,
325 "H7065": BASIC_CAPABILITIES,
326 "H7066": BASIC_CAPABILITIES,
327 "H7067": create_with_capabilities(True, True, True, 0, True),
328 "H706A": BASIC_CAPABILITIES,
329 "H706B": BASIC_CAPABILITIES,
330 "H706C": BASIC_CAPABILITIES,
331 "H7070": BASIC_CAPABILITIES,
332 "H7071": BASIC_CAPABILITIES,
333 "H7072": BASIC_CAPABILITIES,
334 "H7073": BASIC_CAPABILITIES,
335 "H7075": BASIC_CAPABILITIES,
336 "H7076": create_with_capabilities(True, True, True, 15, True),
337 "H707A": BASIC_CAPABILITIES,
338 "H707B": BASIC_CAPABILITIES,
339 "H707C": BASIC_CAPABILITIES,
340 "H7086": create_with_capabilities(True, True, True, 0, True),
341 "H7087": BASIC_CAPABILITIES,
342 "H7093": create_with_capabilities(True, True, True, 2, True),
343 "H7094": BASIC_CAPABILITIES,
344 "H70A1": create_with_capabilities(True, True, True, 15, True),
345 "H70A2": create_with_capabilities(True, True, True, 20, True),
346 "H70A3": create_with_capabilities(True, True, True, 15, True),
347 "H70B1": BASIC_CAPABILITIES,
348 "H70B3": BASIC_CAPABILITIES,
349 "H70B5": create_with_capabilities(True, True, True, 3, True),
350 "H70B6": create_with_capabilities(True, True, True, 0, True),
351 "H70B8": BASIC_CAPABILITIES,
352 "H70BC": BASIC_CAPABILITIES,
353 "H70C1": BASIC_CAPABILITIES,
354 "H70C2": BASIC_CAPABILITIES,
355 "H70C4": create_with_capabilities(True, True, True, 10, True),
356 "H70C5": create_with_capabilities(True, True, True, 10, True),
357 "H70C7": create_with_capabilities(True, True, True, 10, True),
358 "H70C9": BASIC_CAPABILITIES,
359 "H70D1": create_with_capabilities(True, True, True, 10, True),
360 "H70D2": create_with_capabilities(True, True, True, 10, True),
361 "H70D3": BASIC_CAPABILITIES,
362 "H8015": BASIC_CAPABILITIES,
363 "H801A": BASIC_CAPABILITIES,
364 "H801B": BASIC_CAPABILITIES,
365 "H801D": BASIC_CAPABILITIES,
366 "H8022": BASIC_CAPABILITIES,
367 "H8025": BASIC_CAPABILITIES,
368 "H8026": BASIC_CAPABILITIES,
369 "H802A": BASIC_CAPABILITIES,
370 "H8048": BASIC_CAPABILITIES,
371 "H8057": BASIC_CAPABILITIES,
372 "H805A": create_with_capabilities(True, True, True, 0, True),
373 "H805B": BASIC_CAPABILITIES,
374 "H805C": create_with_capabilities(True, True, True, 9, True),
375 "H8066": BASIC_CAPABILITIES,
376 "H8069": BASIC_CAPABILITIES,
377 "H8072": create_with_capabilities(True, True, True, 8, True),
378 "H8076": BASIC_CAPABILITIES,
379 "H8076A": BASIC_CAPABILITIES,
380 "H807C": BASIC_CAPABILITIES,
381 "H808A": create_with_capabilities(True, True, True, 5, True),
382 "H80A1": create_with_capabilities(True, True, True, 14, True),
383 "H80A4": BASIC_CAPABILITIES,
384 "H80C4": BASIC_CAPABILITIES,
385 "H80C5": create_with_capabilities(True, True, True, 10, True),
386 "H80D1": BASIC_CAPABILITIES, # Issue #261 - Icicle lights
387 "H8630": BASIC_CAPABILITIES,
388 "H8811": BASIC_CAPABILITIES,
389 "H8840": BASIC_CAPABILITIES,
390 "H8841": BASIC_CAPABILITIES,
391 }