1
0
mirror of https://github.com/mjg59/python-broadlink.git synced 2024-11-22 07:00:12 +01:00

Handle storage error

This commit is contained in:
Felipe Martins Diel 2020-05-22 14:55:44 -03:00
parent 1dfdb065d0
commit 9cda686d24

View File

@ -6,7 +6,7 @@ import codecs
import time import time
import broadlink import broadlink
from broadlink.exceptions import ReadError from broadlink.exceptions import ReadError, StorageError
TICK = 32.84 TICK = 32.84
TIMEOUT = 30 TIMEOUT = 30
@ -131,10 +131,11 @@ if args.send:
if args.learn or (args.learnfile and not args.rfscanlearn): if args.learn or (args.learnfile and not args.rfscanlearn):
dev.enter_learning() dev.enter_learning()
print("Learning...") print("Learning...")
for second in range(TIMEOUT): start = time.time()
while time.time() - start < TIMEOUT:
try: try:
data = dev.check_data() data = dev.check_data()
except ReadError: except (ReadError, StorageError):
time.sleep(1) time.sleep(1)
else: else:
break break
@ -198,7 +199,8 @@ if args.rfscanlearn:
dev.sweep_frequency() dev.sweep_frequency()
print("Learning RF Frequency, press and hold the button to learn...") 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) time.sleep(1)
if dev.check_frequency(): if dev.check_frequency():
break break
@ -216,10 +218,11 @@ if args.rfscanlearn:
dev.find_rf_packet() dev.find_rf_packet()
for second in range(TIMEOUT): start = time.time()
while time.time() - start < TIMEOUT:
try: try:
data = dev.check_data() data = dev.check_data()
except ReadError: except (ReadError, StorageError):
time.sleep(1) time.sleep(1)
else: else:
break break