From 9cda686d24a7968450051f36f8519891f044441a Mon Sep 17 00:00:00 2001 From: Felipe Martins Diel Date: Fri, 22 May 2020 14:55:44 -0300 Subject: [PATCH] Handle storage error --- cli/broadlink_cli | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/cli/broadlink_cli b/cli/broadlink_cli index 1abd2ad..ead3a60 100755 --- a/cli/broadlink_cli +++ b/cli/broadlink_cli @@ -6,7 +6,7 @@ import codecs import time import broadlink -from broadlink.exceptions import ReadError +from broadlink.exceptions import ReadError, StorageError TICK = 32.84 TIMEOUT = 30 @@ -131,10 +131,11 @@ if args.send: if args.learn or (args.learnfile and not args.rfscanlearn): dev.enter_learning() print("Learning...") - for second in range(TIMEOUT): + start = time.time() + while time.time() - start < TIMEOUT: try: data = dev.check_data() - except ReadError: + except (ReadError, StorageError): time.sleep(1) else: break @@ -198,7 +199,8 @@ if args.rfscanlearn: dev.sweep_frequency() print("Learning RF Frequency, press and hold the button to learn...") - for second in range(TIMEOUT): + start = time.time() + while time.time() - start < TIMEOUT: time.sleep(1) if dev.check_frequency(): break @@ -216,10 +218,11 @@ if args.rfscanlearn: dev.find_rf_packet() - for second in range(TIMEOUT): + start = time.time() + while time.time() - start < TIMEOUT: try: data = dev.check_data() - except ReadError: + except (ReadError, StorageError): time.sleep(1) else: break