From f928211b9e82529661c91a7c3a2d229832d62c2f Mon Sep 17 00:00:00 2001 From: Andrey Goder Date: Sat, 25 Oct 2025 16:53:12 -0700 Subject: [PATCH 1/4] Support celsius option --- apps/nws_live_forecast/nws_live_forecast.star | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/apps/nws_live_forecast/nws_live_forecast.star b/apps/nws_live_forecast/nws_live_forecast.star index 7b7ee2685f..5a2470c52f 100644 --- a/apps/nws_live_forecast/nws_live_forecast.star +++ b/apps/nws_live_forecast/nws_live_forecast.star @@ -42,12 +42,13 @@ DAY_LABELS = [ def main(config): # Config location = json.decode(config.get("location") or DEFAULT_LOCATION) + celsius = config.bool("celsius", False) - response = http.get(WEATHER_URL + location["lat"] + "," + location["lng"], ttl_seconds = 300) + response = http.get(WEATHER_URL + location["lat"] + "," + location["lng"]) if response.status_code != 200: fail("failed to fetch weather %d", response.status_code) - forecast = http.get(response.json()["properties"]["forecastHourly"], ttl_seconds = 300) + forecast = http.get(response.json()["properties"]["forecastHourly"]) if forecast.status_code != 200: fail("failed to fetch forecast %d", forecast.status_code) @@ -66,7 +67,7 @@ def main(config): prevDay = day days[len(days) - 1].append(period) - nowTemp = int(math.round(rightNow["temperature"])) + nowTemp = to_celsius(int(math.round(rightNow["temperature"])), celsius) cols = [render.Column( cross_align = "center", children = [ @@ -80,7 +81,7 @@ def main(config): if len(cols) >= MAX_DAYS_TO_SHOW: break dayStart = time.parse_time(day[0]["startTime"]) - temps = [p["temperature"] for p in day] + temps = [to_celsius(p["temperature"], celsius) for p in day] high = int(math.round(max(temps))) forecast = mode([p["shortForecast"] for p in day]) @@ -151,9 +152,22 @@ def get_schema(): desc = "Location for which to display weather data.", icon = "locationDot", ), + schema.Toggle( + id = "celsius", + name = "Celsius", + desc = "Enable to show temperature in Celsius", + icon = "temperatureHalf", + default = False, + ), ], ) +def to_celsius(val, is_celsius): + if is_celsius: + return int(math.round((val - 32) * 5/9)) + else: + return val + # Weather icons from https://www.flaticon.com/free-icons/weather # (free with attribution) SUNNY = base64.decode(""" From 7dfac52f5ae8a670d9f4c065ea7802cb9ca537ac Mon Sep 17 00:00:00 2001 From: Andrey Goder Date: Sat, 25 Oct 2025 17:01:18 -0700 Subject: [PATCH 2/4] chore: trigger CI after fix From 2d0861d788a8b1be8711373ce55a68178fef1745 Mon Sep 17 00:00:00 2001 From: Andrey Goder Date: Sat, 25 Oct 2025 17:05:03 -0700 Subject: [PATCH 3/4] fix format --- apps/nws_live_forecast/nws_live_forecast.star | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/nws_live_forecast/nws_live_forecast.star b/apps/nws_live_forecast/nws_live_forecast.star index 5a2470c52f..03aa6a4775 100644 --- a/apps/nws_live_forecast/nws_live_forecast.star +++ b/apps/nws_live_forecast/nws_live_forecast.star @@ -163,10 +163,10 @@ def get_schema(): ) def to_celsius(val, is_celsius): - if is_celsius: - return int(math.round((val - 32) * 5/9)) - else: - return val + if is_celsius: + return int(math.round((val - 32) * 5 / 9)) + else: + return val # Weather icons from https://www.flaticon.com/free-icons/weather # (free with attribution) From 37585948ba5f58e20eaba25c1c6c8a18c438f8f4 Mon Sep 17 00:00:00 2001 From: Andrey Goder Date: Sat, 25 Oct 2025 17:06:08 -0700 Subject: [PATCH 4/4] restore ttl --- apps/nws_live_forecast/nws_live_forecast.star | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/nws_live_forecast/nws_live_forecast.star b/apps/nws_live_forecast/nws_live_forecast.star index 03aa6a4775..fb2cb60101 100644 --- a/apps/nws_live_forecast/nws_live_forecast.star +++ b/apps/nws_live_forecast/nws_live_forecast.star @@ -44,11 +44,11 @@ def main(config): location = json.decode(config.get("location") or DEFAULT_LOCATION) celsius = config.bool("celsius", False) - response = http.get(WEATHER_URL + location["lat"] + "," + location["lng"]) + response = http.get(WEATHER_URL + location["lat"] + "," + location["lng"], ttl_seconds = 300) if response.status_code != 200: fail("failed to fetch weather %d", response.status_code) - forecast = http.get(response.json()["properties"]["forecastHourly"]) + forecast = http.get(response.json()["properties"]["forecastHourly"], ttl_seconds = 300) if forecast.status_code != 200: fail("failed to fetch forecast %d", forecast.status_code)