@@ -289,6 +289,7 @@ def __init__(self, device_config: Dict[str, Any]) -> None:
289289 self ._cmd_mode_future : Optional [asyncio .Future ] = None
290290 self ._reset : asyncio .Event = asyncio .Event ()
291291 self ._running : asyncio .Event = asyncio .Event ()
292+ self ._send_lock = asyncio .Lock ()
292293
293294 @property
294295 def reset_event (self ):
@@ -353,12 +354,13 @@ async def _remote_at_command(self, ieee, nwk, options, name, *args):
353354 LOGGER .debug ("Remote AT command: %s %s" , name , args )
354355 data = t .serialize (args , (AT_COMMANDS [name ],))
355356 try :
356- return await asyncio .wait_for (
357- self ._command (
358- "remote_at" , ieee , nwk , options , name .encode ("ascii" ), data
359- ),
360- timeout = REMOTE_AT_COMMAND_TIMEOUT ,
361- )
357+ async with self ._send_lock :
358+ return await asyncio .wait_for (
359+ self ._command (
360+ "remote_at" , ieee , nwk , options , name .encode ("ascii" ), data
361+ ),
362+ timeout = REMOTE_AT_COMMAND_TIMEOUT ,
363+ )
362364 except asyncio .TimeoutError :
363365 LOGGER .warning ("No response to %s command" , name )
364366 raise
@@ -367,10 +369,11 @@ async def _at_partial(self, cmd_type, name, *args):
367369 LOGGER .debug ("%s command: %s %s" , cmd_type , name , args )
368370 data = t .serialize (args , (AT_COMMANDS [name ],))
369371 try :
370- return await asyncio .wait_for (
371- self ._command (cmd_type , name .encode ("ascii" ), data ),
372- timeout = AT_COMMAND_TIMEOUT ,
373- )
372+ async with self ._send_lock :
373+ return await asyncio .wait_for (
374+ self ._command (cmd_type , name .encode ("ascii" ), data ),
375+ timeout = AT_COMMAND_TIMEOUT ,
376+ )
374377 except asyncio .TimeoutError :
375378 LOGGER .warning ("%s: No response to %s command" , cmd_type , name )
376379 raise
@@ -597,9 +600,3 @@ async def _probe(self) -> None:
597600 raise APIException ("Failed to configure XBee for API mode" )
598601 finally :
599602 self .close ()
600-
601- def __getattr__ (self , item ):
602- """Handle supported command requests."""
603- if item in COMMAND_REQUESTS :
604- return functools .partial (self ._command , item )
605- raise AttributeError (f"Unknown command { item } " )
0 commit comments