@@ -333,13 +333,69 @@ async def close(self):
333333 await self .pause_writing ()
334334 await asyncio .sleep (0 , loop = self ._loop )
335335
336+ def trigger_group_on (self , group ):
337+ """Trigger an All-Link Group on."""
338+ from .messages .standardSend import StandardSend
339+ from .constants import COMMAND_LIGHT_ON_0X11_NONE
340+ target = Address (bytearray ([0x00 , 0x00 , group ]))
341+ flags = 0xc0
342+ msg = StandardSend (target , COMMAND_LIGHT_ON_0X11_NONE ,
343+ cmd2 = 0xff , flags = flags )
344+ self .send_msg (msg )
345+ dev_list = self ._find_scene (group )
346+ _LOGGER .debug ('Scene %d turned on' , group )
347+ for addr in dev_list :
348+ device = self ._devices [addr .id ]
349+ if hasattr (device , 'async_refresh_state' ):
350+ _LOGGER .debug ('Checking status of device %s' , addr .human )
351+ device .async_refresh_state ()
352+
353+ def trigger_group_off (self , group ):
354+ """Trigger an All-Link Group off."""
355+ from .messages .standardSend import StandardSend
356+ from .constants import COMMAND_LIGHT_OFF_0X13_0X00
357+ target = Address (bytearray ([0x00 , 0x00 , group ]))
358+ flags = 0xc0
359+ msg = StandardSend (target , COMMAND_LIGHT_OFF_0X13_0X00 , flags = flags )
360+ self .send_msg (msg )
361+ dev_list = self ._find_scene (group )
362+ _LOGGER .debug ('Scene %d turned off' , group )
363+ for addr in dev_list :
364+ device = self ._devices [addr .id ]
365+ if hasattr (device , 'async_refresh_state' ):
366+ _LOGGER .debug ('Checking status of device %s' , addr .human )
367+ device .async_refresh_state ()
368+
369+ def _find_scene (self , group ):
370+ """Identify all devices that are part of a scene."""
371+ device_list = []
372+ for rec_num in self ._aldb :
373+ rec = self ._aldb [rec_num ]
374+ _LOGGER .debug ('Checking record for scene: %s' , rec )
375+ if (rec .control_flags .is_controller and rec .group == group ):
376+ if rec .address not in device_list :
377+ device_list .append (rec .address )
378+ for addr in self ._devices :
379+ device = self ._devices [addr ]
380+ aldb = device .aldb
381+ for mem_addr in aldb :
382+ rec = aldb [mem_addr ]
383+ _LOGGER .debug ('Checking record for scene: %s' , rec )
384+ if (rec .control_flags .is_in_use and
385+ rec .group == group and
386+ rec .address == self ._address ):
387+ if rec .address not in device_list :
388+ device_list .append (device .address )
389+ return device_list
390+
336391 async def _setup_devices (self ):
337392 await self .devices .load_saved_device_info ()
338393 _LOGGER .debug ('Found %d saved devices' ,
339394 len (self .devices .saved_devices ))
340395 self ._get_plm_info ()
341396 self .devices .add_known_devices (self )
342397
398+ # Comment out the following lines for testing
343399 if self ._load_aldb :
344400 self ._load_all_link_database ()
345401 else :
0 commit comments