@@ -244,27 +244,27 @@ def command_to_iscp(command, arguments=None, zone=None):
244244 return '{}{}' .format (prefix , value )
245245
246246
247- def iscp_to_command (iscp_message ):
248- for zone , zone_cmds in commands .COMMANDS .items ():
249- # For now, ISCP commands are always three characters, which
250- # makes this easy.
251- command , args = iscp_message [:3 ], iscp_message [3 :]
252- if command in zone_cmds :
253- if args in zone_cmds [command ]['values' ]:
254- return zone_cmds [command ]['name' ], \
255- zone_cmds [command ]['values' ][args ]['name' ]
256- else :
257- match = re .match ('[+-]?[0-9a-f]+$' , args , re .IGNORECASE )
258- if match :
259- return zone_cmds [command ]['name' ], \
260- int (args , 16 )
247+ def iscp_to_command (iscp_message , with_zone = False ):
248+ def __iscp_to_command (iscp_message ):
249+ for zone , zone_cmds in commands .COMMANDS .items ():
250+ # For now, ISCP commands are always three characters, which
251+ # makes this easy.
252+ command , args = iscp_message [:3 ], iscp_message [3 :]
253+ if command in zone_cmds :
254+ if args in zone_cmds [command ]['values' ]:
255+ return zone , zone_cmds [command ]['name' ], \
256+ zone_cmds [command ]['values' ][args ]['name' ]
261257 else :
262- return zone_cmds [command ]['name' ], args
263-
264- else :
265- raise ValueError (
266- 'Cannot convert ISCP message to command: {}' .format (iscp_message ))
267-
258+ match = re .match ('[+-]?[0-9a-f]+$' , args , re .IGNORECASE )
259+ if match :
260+ return zone , zone_cmds [command ]['name' ], int (args , 16 )
261+ else :
262+ return zone , zone_cmds [command ]['name' ], args
263+ else :
264+ raise ValueError (
265+ 'Cannot convert ISCP message to command: {}' .format (iscp_message ))
266+ zone , ret_cmd , args = __iscp_to_command (iscp_message )
267+ return (zone , ret_cmd , args ) if with_zone else (ret_cmd , args )
268268
269269def filter_for_message (getter_func , msg ):
270270 """Helper that calls ``getter_func`` until a matching message
0 commit comments