Skip to content

Commit 81f608d

Browse files
committed
Add ability to retrieve zone from decoded command
1 parent f570239 commit 81f608d

1 file changed

Lines changed: 20 additions & 20 deletions

File tree

eiscp/core.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -242,27 +242,27 @@ def command_to_iscp(command, arguments=None, zone=None):
242242
return '{}{}'.format(prefix, value)
243243

244244

245-
def iscp_to_command(iscp_message):
246-
for zone, zone_cmds in commands.COMMANDS.items():
247-
# For now, ISCP commands are always three characters, which
248-
# makes this easy.
249-
command, args = iscp_message[:3], iscp_message[3:]
250-
if command in zone_cmds:
251-
if args in zone_cmds[command]['values']:
252-
return zone_cmds[command]['name'], \
253-
zone_cmds[command]['values'][args]['name']
254-
else:
255-
match = re.match('[+-]?[0-9a-f]+$', args, re.IGNORECASE)
256-
if match:
257-
return zone_cmds[command]['name'], \
258-
int(args, 16)
245+
def iscp_to_command(iscp_message, with_zone=False):
246+
def __iscp_to_command(iscp_message):
247+
for zone, zone_cmds in commands.COMMANDS.items():
248+
# For now, ISCP commands are always three characters, which
249+
# makes this easy.
250+
command, args = iscp_message[:3], iscp_message[3:]
251+
if command in zone_cmds:
252+
if args in zone_cmds[command]['values']:
253+
return zone, zone_cmds[command]['name'], \
254+
zone_cmds[command]['values'][args]['name']
259255
else:
260-
return zone_cmds[command]['name'], args
261-
262-
else:
263-
raise ValueError(
264-
'Cannot convert ISCP message to command: {}'.format(iscp_message))
265-
256+
match = re.match('[+-]?[0-9a-f]+$', args, re.IGNORECASE)
257+
if match:
258+
return zone, zone_cmds[command]['name'], int(args, 16)
259+
else:
260+
return zone, zone_cmds[command]['name'], args
261+
else:
262+
raise ValueError(
263+
'Cannot convert ISCP message to command: {}'.format(iscp_message))
264+
zone, ret_cmd, args = __iscp_to_command(iscp_message)
265+
return zone, ret_cmd, args if with_zone else ret_cmd, args
266266

267267
def filter_for_message(getter_func, msg):
268268
"""Helper that calls ``getter_func`` until a matching message

0 commit comments

Comments
 (0)