From bd090a09d7b3ff4c4f1817884a36be603988f2ac Mon Sep 17 00:00:00 2001 From: Brikwerk Date: Tue, 15 Sep 2020 17:54:48 -0700 Subject: [PATCH] Added better error handling for macro input --- nxbt/cli.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/nxbt/cli.py b/nxbt/cli.py index e7075f5..4d36141 100644 --- a/nxbt/cli.py +++ b/nxbt/cli.py @@ -1,5 +1,6 @@ import argparse from random import randint +from time import sleep import os from .nxbt import Nxbt, PRO_CONTROLLER @@ -180,8 +181,16 @@ def macro(): print("Connected!") print("Running macro...") - nx.macro(index, macro) - print("Finished running macro. Exiting...") + macro_id = nx.macro(index, macro, block=False) + while (True): + if nx.state[index]["state"] == "crashed": + print("Controller crashed while running macro") + print(nx.state[index]["errors"]) + break + if macro_id in nx.state[index]["finished_macros"]: + print("Finished running macro. Exiting...") + break + sleep(1/30) def list_switch_addresses():