66from insteonplm .constants import (COMMAND_LIGHT_ON_0X11_NONE ,
77 COMMAND_LIGHT_OFF_0X13_0X00 ,
88 MESSAGE_FLAG_BROADCAST_0X80 ,
9+ MESSAGE_FLAG_DIRECT_MESSAGE_ACK_0X20 ,
910 COMMAND_ID_REQUEST_0X10_0X00 ,
1011 COMMAND_LIGHT_STATUS_REQUEST_0X19_0X00 ,
1112 MESSAGE_NAK ,
@@ -195,15 +196,34 @@ def async_light_on_level_callback(device_id, state, value):
195196 acknak = MESSAGE_ACK )
196197 plm .data_received (msg .bytes )
197198
199+ # Direct ACK of off message
200+ msg = StandardReceive (
201+ address = '4d5e6f' , target = '010b00' ,
202+ commandtuple = COMMAND_LIGHT_OFF_0X13_0X00 ,
203+ flags = MESSAGE_FLAG_DIRECT_MESSAGE_ACK_0X20 )
204+ plm .data_received (msg .bytes )
205+
198206 # Test that the second SET_LEVEL command is sent
199207 msg = StandardSend ('4d5e6f' , COMMAND_LIGHT_ON_0X11_NONE , cmd2 = 0xbb )
200208 cmd_sent = await wait_for_plm_command (plm , msg , loop )
201209 if not cmd_sent :
202210 assert False
203211
212+ # ACK the SET_LEVEL command and let the Direct ACK message expire
213+ msg = StandardSend ('4d5e6f' , COMMAND_LIGHT_ON_0X11_NONE , cmd2 = 0xbb ,
214+ acknak = MESSAGE_ACK )
215+ plm .data_received (msg .bytes )
216+
217+ msg = StandardReceive (
218+ address = '4d5e6f' , target = '010b00' ,
219+ commandtuple = COMMAND_LIGHT_ON_0X11_NONE ,
220+ cmd2 = 0xbb ,
221+ flags = MESSAGE_FLAG_DIRECT_MESSAGE_ACK_0X20 )
222+ plm .data_received (msg .bytes )
223+
204224 await plm .close ()
205225 _LOGGER .error ('PLM closed in test_plm' )
206- await asyncio .sleep (0 , loop = loop )
226+ await asyncio .sleep (.1 , loop = loop )
207227 open_tasks = asyncio .Task .all_tasks (loop = loop )
208228 for task in open_tasks :
209229 if hasattr (task , 'name' ):
@@ -215,6 +235,7 @@ def async_light_on_level_callback(device_id, state, value):
215235# pylint: disable=too-many-statements
216236async def do_plm_x10 (loop ):
217237 """Asyncio coroutine to test the PLM X10 message handling."""
238+ _LOGGER .setLevel (logging .DEBUG )
218239 _LOGGER .info ('Connecting to Insteon PLM' )
219240
220241 # pylint: disable=not-an-iterable
@@ -269,9 +290,12 @@ async def do_plm_x10(loop):
269290 await asyncio .sleep (.1 , loop = loop )
270291 assert cb .callbackvalue1 == 0x00
271292
293+ _LOGGER .info ('Close PLM' )
294+ _LOGGER .info ('_________' )
295+
272296 await plm .close ()
273297 _LOGGER .error ('PLM closed in test_x10' )
274- await asyncio .sleep (0 , loop = loop )
298+ await asyncio .sleep (.1 , loop = loop )
275299 open_tasks = asyncio .Task .all_tasks (loop = loop )
276300 for task in open_tasks :
277301 if hasattr (task , 'name' ):
@@ -310,3 +334,7 @@ def test_plm_x10():
310334 _LOGGER .error ('Task: %s' , task )
311335 if not task .done ():
312336 loop .run_until_complete (task )
337+
338+
339+ if __name__ == '__main__' :
340+ test_plm ()
0 commit comments