@@ -42,12 +42,13 @@ DAY_LABELS = [
4242def main (config ):
4343 # Config
4444 location = json .decode (config .get ("location" ) or DEFAULT_LOCATION )
45+ celsius = config .bool ("celsius" , False )
4546
46- response = http .get (WEATHER_URL + location ["lat" ] + "," + location ["lng" ], ttl_seconds = 300 )
47+ response = http .get (WEATHER_URL + location ["lat" ] + "," + location ["lng" ])
4748 if response .status_code != 200 :
4849 fail ("failed to fetch weather %d" , response .status_code )
4950
50- forecast = http .get (response .json ()["properties" ]["forecastHourly" ], ttl_seconds = 300 )
51+ forecast = http .get (response .json ()["properties" ]["forecastHourly" ])
5152 if forecast .status_code != 200 :
5253 fail ("failed to fetch forecast %d" , forecast .status_code )
5354
@@ -66,7 +67,7 @@ def main(config):
6667 prevDay = day
6768 days [len (days ) - 1 ].append (period )
6869
69- nowTemp = int (math .round (rightNow ["temperature" ]))
70+ nowTemp = to_celsius ( int (math .round (rightNow ["temperature" ])), celsius )
7071 cols = [render .Column (
7172 cross_align = "center" ,
7273 children = [
@@ -80,7 +81,7 @@ def main(config):
8081 if len (cols ) >= MAX_DAYS_TO_SHOW :
8182 break
8283 dayStart = time .parse_time (day [0 ]["startTime" ])
83- temps = [p ["temperature" ] for p in day ]
84+ temps = [to_celsius ( p ["temperature" ], celsius ) for p in day ]
8485 high = int (math .round (max (temps )))
8586 forecast = mode ([p ["shortForecast" ] for p in day ])
8687
@@ -151,9 +152,22 @@ def get_schema():
151152 desc = "Location for which to display weather data." ,
152153 icon = "locationDot" ,
153154 ),
155+ schema .Toggle (
156+ id = "celsius" ,
157+ name = "Celsius" ,
158+ desc = "Enable to show temperature in Celsius" ,
159+ icon = "temperatureHalf" ,
160+ default = False ,
161+ ),
154162 ],
155163 )
156164
165+ def to_celsius (val , is_celsius ):
166+ if is_celsius :
167+ return int (math .round ((val - 32 ) * 5 / 9 ))
168+ else :
169+ return val
170+
157171# Weather icons from https://www.flaticon.com/free-icons/weather
158172# (free with attribution)
159173SUNNY = base64 .decode ("""
0 commit comments