Skip to content

Commit

Permalink
better error handling for abnormal AQI value
Browse files Browse the repository at this point in the history
  • Loading branch information
bekki committed Sep 13, 2020
1 parent 6cd51c3 commit c79e9bd
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions code.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@
'Unhealthy1' : 0xFFA500,
'Unhealthy2' : 0xFF0000,
'Unhealthy3' : 0xFF0000,
'Hazardous' : 0xFF00FF,
'Error' : 0xFF0000
'Hazardous' : 0xFF00FF
}

def pm25_to_air_quality(pm25_value):
Expand Down Expand Up @@ -223,8 +222,14 @@ def seconds_elapsed_since(checkpoint):
% (pm25_env, length, str(pm25_average)))

aqi = pm25_to_aqi(pm25_average)
aqi_text = ("AQI: %d" % (aqi))
aqi_color = AQI_COLORS[aqi_to_air_quality(aqi)]

if aqi == "Error":
aqi_text = "AQI: Error"
aqi_color = 0xFF0000
else:
aqi_text = "AQI: %d" % aqi
aqi_color = AQI_COLORS[aqi_to_air_quality(aqi)]

gc.collect()

text_area = label.Label(terminalio.FONT, text=aqi_text, color=aqi_color)
Expand Down

0 comments on commit c79e9bd

Please sign in to comment.