@@ -33,8 +33,9 @@ def test_close(api):
3333def test_commands ():
3434 import string
3535 anum = string .ascii_letters + string .digits + '_'
36+ commands = {** xbee_api .COMMAND_REQUESTS , ** xbee_api .COMMAND_RESPONSES }
3637
37- for cmd_name , cmd_opts in xbee_api . COMMANDS .items ():
38+ for cmd_name , cmd_opts in commands .items ():
3839 assert isinstance (cmd_name , str ) is True
3940 assert all ([c in anum for c in cmd_name ]), cmd_name
4041 assert len (cmd_opts ) == 3
@@ -47,12 +48,12 @@ def test_commands():
4748@pytest .mark .asyncio
4849async def test_command (api ):
4950 def mock_api_frame (name , * args ):
50- c = xbee_api .COMMANDS [name ]
51+ c = xbee_api .COMMAND_REQUESTS [name ]
5152 return mock .sentinel .api_frame_data , c [2 ]
5253 api ._api_frame = mock .MagicMock (side_effect = mock_api_frame )
5354 api ._uart .send = mock .MagicMock ()
5455
55- for cmd_name , cmd_opts in xbee_api .COMMANDS .items ():
56+ for cmd_name , cmd_opts in xbee_api .COMMAND_REQUESTS .items ():
5657 cmd_id , schema , expect_reply = cmd_opts
5758 ret = api ._command (cmd_name , mock .sentinel .cmd_data )
5859 if expect_reply :
@@ -62,28 +63,30 @@ def mock_api_frame(name, *args):
6263 assert ret is None
6364 assert api ._api_frame .call_count == 1
6465 assert api ._api_frame .call_args [0 ][0 ] == cmd_name
65- assert api ._api_frame .call_args [0 ][1 ] == mock .sentinel .cmd_data
66+ assert api ._api_frame .call_args [0 ][1 ] == api ._seq - 1
67+ assert api ._api_frame .call_args [0 ][2 ] == mock .sentinel .cmd_data
6668 assert api ._uart .send .call_count == 1
6769 assert api ._uart .send .call_args [0 ][0 ] == mock .sentinel .api_frame_data
6870 api ._api_frame .reset_mock ()
6971 api ._uart .send .reset_mock ()
7072
71-
72- def test_seq_command (api ):
73- api ._command = mock .MagicMock ()
74- api ._seq = mock .sentinel .seq
75- api ._seq_command (mock .sentinel .cmd_name , mock .sentinel .args )
76- assert api ._command .call_count == 1
77- assert api ._command .call_args [0 ][0 ] == mock .sentinel .cmd_name
78- assert api ._command .call_args [0 ][1 ] == mock .sentinel .seq
79- assert api ._command .call_args [0 ][2 ] == mock .sentinel .args
73+ ret = api ._command (cmd_name , mock .sentinel .cmd_data , mask_frame_id = True )
74+ assert ret is None
75+ assert api ._api_frame .call_count == 1
76+ assert api ._api_frame .call_args [0 ][0 ] == cmd_name
77+ assert api ._api_frame .call_args [0 ][1 ] == 0
78+ assert api ._api_frame .call_args [0 ][2 ] == mock .sentinel .cmd_data
79+ assert api ._uart .send .call_count == 1
80+ assert api ._uart .send .call_args [0 ][0 ] == mock .sentinel .api_frame_data
81+ api ._api_frame .reset_mock ()
82+ api ._uart .send .reset_mock ()
8083
8184
8285async def _test_at_or_queued_at_command (api , cmd , monkeypatch , do_reply = True ):
8386 monkeypatch .setattr (t , 'serialize' , mock .MagicMock (return_value = mock .sentinel .serialize ))
8487
8588 def mock_command (name , * args ):
86- rsp = xbee_api .COMMANDS [name ][2 ]
89+ rsp = xbee_api .COMMAND_REQUESTS [name ][2 ]
8790 ret = None
8891 if rsp :
8992 ret = asyncio .Future ()
@@ -99,9 +102,8 @@ def mock_command(name, *args):
99102 assert t .serialize .call_count == 1
100103 assert api ._command .call_count == 1
101104 assert api ._command .call_args [0 ][0 ] in ('at' , 'queued_at' )
102- assert api ._command .call_args [0 ][1 ] == mock .sentinel .seq
103- assert api ._command .call_args [0 ][2 ] == at_cmd .encode ('ascii' )
104- assert api ._command .call_args [0 ][3 ] == mock .sentinel .serialize
105+ assert api ._command .call_args [0 ][1 ] == at_cmd .encode ('ascii' )
106+ assert api ._command .call_args [0 ][2 ] == mock .sentinel .serialize
105107 assert res == mock .sentinel .at_result
106108 t .serialize .reset_mock ()
107109 api ._command .reset_mock ()
@@ -129,7 +131,7 @@ async def _test_remote_at_command(api, monkeypatch, do_reply=True):
129131 monkeypatch .setattr (t , 'serialize' , mock .MagicMock (return_value = mock .sentinel .serialize ))
130132
131133 def mock_command (name , * args ):
132- rsp = xbee_api .COMMANDS [name ][2 ]
134+ rsp = xbee_api .COMMAND_REQUESTS [name ][2 ]
133135 ret = None
134136 if rsp :
135137 ret = asyncio .Future ()
@@ -147,12 +149,11 @@ def mock_command(name, *args):
147149 assert t .serialize .call_count == 1
148150 assert api ._command .call_count == 1
149151 assert api ._command .call_args [0 ][0 ] == 'remote_at'
150- assert api ._command .call_args [0 ][1 ] == mock .sentinel .seq
151- assert api ._command .call_args [0 ][2 ] == mock .sentinel .ieee
152- assert api ._command .call_args [0 ][3 ] == mock .sentinel .nwk
153- assert api ._command .call_args [0 ][4 ] == mock .sentinel .opts
154- assert api ._command .call_args [0 ][5 ] == at_cmd .encode ('ascii' )
155- assert api ._command .call_args [0 ][6 ] == mock .sentinel .serialize
152+ assert api ._command .call_args [0 ][1 ] == mock .sentinel .ieee
153+ assert api ._command .call_args [0 ][2 ] == mock .sentinel .nwk
154+ assert api ._command .call_args [0 ][3 ] == mock .sentinel .opts
155+ assert api ._command .call_args [0 ][4 ] == at_cmd .encode ('ascii' )
156+ assert api ._command .call_args [0 ][5 ] == mock .sentinel .serialize
156157 assert res == mock .sentinel .at_result
157158 t .serialize .reset_mock ()
158159 api ._command .reset_mock ()
@@ -172,7 +173,7 @@ async def test_remote_at_cmd_no_rsp(api, monkeypatch):
172173
173174def test_api_frame (api ):
174175 ieee = t .EUI64 ([t .uint8_t (a ) for a in range (0 , 8 )])
175- for cmd_name , cmd_opts in xbee_api .COMMANDS .items ():
176+ for cmd_name , cmd_opts in xbee_api .COMMAND_REQUESTS .items ():
176177 cmd_id , schema , repl = cmd_opts
177178 if schema :
178179 args = [ieee if isinstance (a (), t .EUI64 ) else a () for a in schema ]
@@ -186,7 +187,7 @@ def test_frame_received(api, monkeypatch):
186187 return_value = (mock .sentinel .deserialize_data , b'' )))
187188 my_handler = mock .MagicMock ()
188189
189- for cmd , cmd_opts in xbee_api .COMMANDS .items ():
190+ for cmd , cmd_opts in xbee_api .COMMAND_RESPONSES .items ():
190191 cmd_id = cmd_opts [0 ]
191192 payload = b'\x01 \x02 \x03 \x04 '
192193 data = cmd_id .to_bytes (1 , 'big' ) + payload
@@ -206,10 +207,10 @@ def test_frame_received_no_handler(api, monkeypatch):
206207 my_handler = mock .MagicMock ()
207208 cmd = 'no_handler'
208209 cmd_id = 0x00
209- xbee_api .COMMANDS [cmd ] = (cmd_id , (), None )
210+ xbee_api .COMMAND_RESPONSES [cmd ] = (cmd_id , (), None )
210211 api ._commands_by_id [cmd_id ] = cmd
211212
212- cmd_opts = xbee_api .COMMANDS [cmd ]
213+ cmd_opts = xbee_api .COMMAND_RESPONSES [cmd ]
213214 cmd_id = cmd_opts [0 ]
214215 payload = b'\x01 \x02 \x03 \x04 '
215216 data = cmd_id .to_bytes (1 , 'big' ) + payload
0 commit comments