1
1
"""Embrava Blynclight Support"""
2
2
3
- from functools import cached_property
4
3
from typing import ClassVar
5
4
6
- from busylight_core . light import Light
5
+ from . embrava_base import EmbravaBase
7
6
8
- from ._blynclight import FlashSpeed , State
9
7
10
-
11
- class Blynclight (Light ):
8
+ class Blynclight (EmbravaBase ):
12
9
"""Embrava Blynclight status light controller.
13
10
14
11
The Blynclight is a USB-connected RGB LED device with additional features
@@ -19,102 +16,4 @@ class Blynclight(Light):
19
16
(0x2C0D , 0x0001 ): "Blynclight" ,
20
17
(0x2C0D , 0x000C ): "Blynclight" ,
21
18
(0x0E53 , 0x2516 ): "Blynclight" ,
22
- }
23
-
24
- @cached_property
25
- def state (self ) -> State :
26
- """The device state manager."""
27
- return State ()
28
-
29
- def __bytes__ (self ) -> bytes :
30
- if not self .is_lit :
31
- self .state .off = True
32
- self .state .flash = False
33
- self .state .dim = False
34
-
35
- return bytes ([0 , * bytes (self .state ), 0xFF , 0x22 ])
36
-
37
- def on (self , color : tuple [int , int , int ], led : int = 0 ) -> None :
38
- """Turn on the Blynclight with the specified color.
39
-
40
- :param value: RGB color tuple (red, green, blue)
41
- """
42
- with self .batch_update ():
43
- self .color = color
44
-
45
- @property
46
- def color (self ) -> tuple [int , int , int ]:
47
- """Tuple of RGB color values."""
48
- return (self .state .red , self .state .green , self .state .blue )
49
-
50
- @color .setter
51
- def color (self , value : tuple [int , int , int ]) -> None :
52
- self .state .red , self .state .green , self .state .blue = value
53
-
54
- def dim (self ) -> None :
55
- """Set the light to dim mode (reduced brightness)."""
56
- with self .batch_update ():
57
- self .state .dim = True
58
-
59
- def bright (self ) -> None :
60
- """Set the light to bright mode (full brightness)."""
61
- with self .batch_update ():
62
- self .state .dim = False
63
-
64
- def play_sound (
65
- self ,
66
- music : int = 0 ,
67
- volume : int = 1 ,
68
- repeat : bool = False ,
69
- ) -> None :
70
- """Play a sound on the Blynclight device.
71
-
72
- :param music: Music track number to play (0-7)
73
- :param volume: Volume level (0-3)
74
- :param repeat: Whether the music repeats
75
- """
76
- with self .batch_update ():
77
- self .state .repeat = repeat
78
- self .state .play = True
79
- self .state .music = music
80
- self .state .mute = False
81
- self .state .volume = volume
82
-
83
- def stop_sound (self ) -> None :
84
- """Stop playing any currently playing sound."""
85
- with self .batch_update ():
86
- self .state .play = False
87
-
88
- def mute (self ) -> None :
89
- """Mute the device sound output."""
90
- with self .batch_update ():
91
- self .state .mute = True
92
-
93
- def unmute (self ) -> None :
94
- """Unmute the device sound output."""
95
- with self .batch_update ():
96
- self .state .mute = False
97
-
98
- def flash (self , color : tuple [int , int , int ], speed : FlashSpeed = None ) -> None :
99
- """Flash the light with the specified color and speed.
100
-
101
- :param color: RGB color tuple to flash
102
- :param speed: Flashing speed (default is slow)
103
-
104
- """
105
- speed = speed or FlashSpeed .slow
106
-
107
- with self .batch_update ():
108
- self .color = color
109
- self .state .flash = True
110
- self .state .speed = speed .value
111
-
112
- def stop_flashing (self ) -> None :
113
- """Stop the flashing pattern and return to solid color."""
114
- with self .batch_update ():
115
- self .state .flash = False
116
-
117
- def reset (self ) -> None :
118
- """Reset the device to its default state (off, no sound)."""
119
- self .state .reset ()
120
- self .update ()
19
+ }
0 commit comments