Skip to content

Commit 8beade9

Browse files
Merge pull request #44 from smwa/add_linking
Add bulb linking and unlinking to v6 bridge
2 parents 70307c2 + 87cf4a7 commit 8beade9

File tree

3 files changed

+96
-5
lines changed

3 files changed

+96
-5
lines changed

limitlessled/group/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ def on(self, state):
8585
cmd = self.command_set.on()
8686
self.send(cmd)
8787

88+
def link(self):
89+
""" Link new lights. """
90+
cmd = self.command_set.link()
91+
self.send(cmd)
92+
93+
def unlink(self):
94+
""" Unlink linked lights. """
95+
cmd = self.command_set.unlink()
96+
self.send(cmd)
97+
8898
@property
8999
def bridge(self):
90100
""" Bridge property. """

limitlessled/group/commands/v6.py

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ class CommandV6(Command):
1717
PASSWORD_BYTE1 = 0x00
1818
PASSWORD_BYTE2 = 0x00
1919

20+
TYPE_CONTROL = 0x31
21+
TYPE_LINK = 0x3D
22+
TYPE_UNLINK = 0x3E
23+
2024
def __init__(self, cmd_1, cmd_2, remote_style, group_number,
21-
select=False, select_command=None):
25+
select=False, select_command=None, command_type=0x31):
2226
"""
2327
Initialize command.
2428
:param cmd_1: The first part of the command.
@@ -27,9 +31,11 @@ def __init__(self, cmd_1, cmd_2, remote_style, group_number,
2731
:param group_number: Group number (1-4).
2832
:param select: If command requires selection.
2933
:param select_command: Selection command bytes.
34+
:param command_type: Whether the command is for control, link, or unlink
3035
"""
3136
super().__init__(cmd_1, cmd_2, group_number, select, select_command)
3237
self._remote_style = remote_style
38+
self.type = command_type
3339

3440
def get_bytes(self, bridge):
3541
"""
@@ -44,7 +50,7 @@ def get_bytes(self, bridge):
4450
sn = bridge.sn
4551

4652
preamble = [0x80, 0x00, 0x00, 0x00, 0x11, wb1, wb2, 0x00, sn, 0x00]
47-
cmd = [0x31, self.PASSWORD_BYTE1, self.PASSWORD_BYTE2,
53+
cmd = [self.type, self.PASSWORD_BYTE1, self.PASSWORD_BYTE2,
4854
self._remote_style, self._cmd_1,
4955
self._cmd_2, self._cmd_2, self._cmd_2, self._cmd_2]
5056
zone_selector = [self._group_number, 0x00]
@@ -132,16 +138,17 @@ def convert_hue(self, hue, legacy_color_wheel=False):
132138
return hue % (self.MAX_HUE + 1)
133139

134140
def _build_command(self, cmd_1, cmd_2,
135-
select=False, select_command=None):
141+
select=False, select_command=None, command_type=0x31):
136142
"""
137143
Constructs the complete command.
138144
:param cmd_1: Light command 1.
139145
:param cmd_2: Light command 2.
146+
:param command_type: Whether the command is for control, link, or unlink
140147
:return: The complete command.
141148
"""
142149

143150
return CommandV6(cmd_1, cmd_2, self._remote_style, self._group_number,
144-
select, select_command)
151+
select, select_command, command_type)
145152

146153

147154
class CommandSetBridgeLightV6(CommandSetV6):
@@ -222,6 +229,20 @@ def off(self):
222229
"""
223230
return self._build_command(0x01, 0x08)
224231

232+
def link(self):
233+
"""
234+
Build command for linking new lights.
235+
:return: The command.
236+
"""
237+
return self._build_command(0x00, 0x00, command_type=CommandV6.TYPE_LINK)
238+
239+
def unlink(self):
240+
"""
241+
Build command for unlinking linked lights.
242+
:return: The command.
243+
"""
244+
return self._build_command(0x00, 0x00, command_type=CommandV6.TYPE_UNLINK)
245+
225246
def night_light(self):
226247
"""
227248
Build command for turning the led into night light mode.
@@ -284,6 +305,20 @@ def off(self):
284305
"""
285306
return self._build_command(0x04, 0x04)
286307

308+
def link(self):
309+
"""
310+
Build command for linking new lights.
311+
:return: The command.
312+
"""
313+
return self._build_command(0x00, 0x00, command_type=CommandV6.TYPE_LINK)
314+
315+
def unlink(self):
316+
"""
317+
Build command for unlinking linked lights.
318+
:return: The command.
319+
"""
320+
return self._build_command(0x00, 0x00, command_type=CommandV6.TYPE_UNLINK)
321+
287322
def night_light(self):
288323
"""
289324
Build command for turning the dimmer into night light mode.
@@ -326,6 +361,20 @@ def off(self):
326361
"""
327362
return self._build_command(0x03, 0x02)
328363

364+
def link(self):
365+
"""
366+
Build command for linking new lights.
367+
:return: The command.
368+
"""
369+
return self._build_command(0x00, 0x00, command_type=CommandV6.TYPE_LINK)
370+
371+
def unlink(self):
372+
"""
373+
Build command for unlinking linked lights.
374+
:return: The command.
375+
"""
376+
return self._build_command(0x00, 0x00, command_type=CommandV6.TYPE_UNLINK)
377+
329378
def night_light(self):
330379
"""
331380
Build command for turning the led into night light mode.
@@ -383,6 +432,20 @@ def off(self):
383432
"""
384433
return self._build_command(0x03, 0x02)
385434

435+
def link(self):
436+
"""
437+
Build command for linking new lights.
438+
:return: The command.
439+
"""
440+
return self._build_command(0x00, 0x00, command_type=CommandV6.TYPE_LINK)
441+
442+
def unlink(self):
443+
"""
444+
Build command for unlinking linked lights.
445+
:return: The command.
446+
"""
447+
return self._build_command(0x00, 0x00, command_type=CommandV6.TYPE_UNLINK)
448+
386449
def night_light(self):
387450
"""
388451
Build command for turning the led into night light mode.
@@ -496,6 +559,20 @@ def off(self):
496559
"""
497560
return self._build_command(0x04, 0x02)
498561

562+
def link(self):
563+
"""
564+
Build command for linking new lights.
565+
:return: The command.
566+
"""
567+
return self._build_command(0x00, 0x00, command_type=CommandV6.TYPE_LINK)
568+
569+
def unlink(self):
570+
"""
571+
Build command for unlinking linked lights.
572+
:return: The command.
573+
"""
574+
return self._build_command(0x00, 0x00, command_type=CommandV6.TYPE_UNLINK)
575+
499576
def night_light(self):
500577
"""
501578
Build command for turning the led into night light mode.

limitlessled/pipeline.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def __init__(self):
7979
'repeat', 'brightness', 'wait', 'temperature', 'white',
8080
'white_up', 'white_down', 'red_up', 'red_down',
8181
'green_up', 'green_down', 'blue_up', 'blue_down',
82-
'night_light']
82+
'night_light', 'link', 'unlink']
8383
for name in stages:
8484
self._add_stage(name)
8585

@@ -188,6 +188,10 @@ def _execute_stage(self, index, stage, stop):
188188
self._group.blue_down()
189189
elif stage.name == 'night_light':
190190
self._group.night_light()
191+
elif stage.name == 'link':
192+
self._group.link()
193+
elif stage.name == 'unlink':
194+
self._group.unlink()
191195
elif stage.name == 'flash':
192196
self._group.flash(**stage.kwargs)
193197
elif stage.name == 'repeat':

0 commit comments

Comments
 (0)