Skip to content

Commit e6d2a19

Browse files
committed
agile_pricing_display.py: handling of 'secrets.py' related errors
1 parent 833659d commit e6d2a19

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

examples/agile_pricing_display.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,33 @@
5252

5353
MARGIN = 15
5454

55+
56+
def show_message(text):
57+
display.set_pen(ORANGE)
58+
display.clear()
59+
display.set_pen(ORANGE_2)
60+
display.text(f"{text}", 5, 10, WIDTH, 2)
61+
presto.update()
62+
63+
5564
# Connect to the network and get time.
56-
display.set_pen(ORANGE)
57-
display.clear()
58-
display.set_pen(ORANGE_2)
59-
display.text("Connecting...", 5, 10, WIDTH, 2)
60-
presto.update()
65+
show_message("Connecting...")
6166

62-
presto.connect()
67+
try:
68+
presto.connect()
69+
except ValueError as e:
70+
while True:
71+
show_message(e)
72+
except ImportError as e:
73+
while True:
74+
show_message(e)
6375

6476
# Set the correct time using the NTP service.
6577
try:
6678
ntptime.settime()
6779
except OSError:
6880
while True:
69-
display.set_pen(ORANGE)
70-
display.clear()
71-
display.set_pen(ORANGE_2)
72-
display.text("Unable to get time.\n\nCheck network settings in 'secrets.py' and try again.", 5, 10, WIDTH - 10, 2)
73-
presto.update()
81+
show_message("Unable to get time.\n\nCheck network settings in 'secrets.py' and try again.")
7482

7583
# Keep a record of the last time we updated.
7684
# We only want to be requesting new information every half an hour.

0 commit comments

Comments
 (0)