diff --git a/pkgs/default.nix b/pkgs/default.nix index 9ff7a753c..218471600 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -113,6 +113,7 @@ let # jackett doesn't allow customization of the bind address: this will probably always be here. jackett = callPackage ./patched/jackett { inherit (unpatched) jackett; }; + libgweather = callPackage ./patched/libgweather { inherit (unpatched) libgweather; }; # modemmanager = callPackage ./patched/modemmanager { inherit (unpatched) modemmanager; }; diff --git a/pkgs/patched/libgweather/default.nix b/pkgs/patched/libgweather/default.nix new file mode 100644 index 000000000..e2bcbdd39 --- /dev/null +++ b/pkgs/patched/libgweather/default.nix @@ -0,0 +1,13 @@ +{ lib +, libgweather +, ... +}@attrs: +(libgweather.override + (removeAttrs attrs [ "libgweather" ]) +).overrideAttrs (upstream: { + patches = lib.unique ( + (upstream.patches or []) ++ [ + ./nws-fix-null-string-comparison.patch + ] + ); +}) diff --git a/pkgs/patched/libgweather/nws-fix-null-string-comparison.patch b/pkgs/patched/libgweather/nws-fix-null-string-comparison.patch new file mode 100644 index 000000000..267cb5b04 --- /dev/null +++ b/pkgs/patched/libgweather/nws-fix-null-string-comparison.patch @@ -0,0 +1,49 @@ +commit 29b80763f81688f789c907f7ecba4c8063745ac2 (HEAD -> sane-dev) +Author: Colin +Date: 2023-08-24 08:03:47 +0000 + + nws: fix null string comparison for visibility forecast + + The API returns a json entry like `"unitCode": "wmoUnit:km"` for the + visibility property. All the other fields are observed to still be + "uom". + +diff --git a/libgweather/weather-nws.c b/libgweather/weather-nws.c +index 2a7238b9..501c3523 100644 +--- a/libgweather/weather-nws.c ++++ b/libgweather/weather-nws.c +@@ -381,6 +381,9 @@ read_interval_values (GSList *forecast_list, + uom = NULL; + if (json_object_has_member (prop, "uom")) { + uom = json_object_get_string_member (prop, "uom"); ++ } else if (json_object_has_member (prop, "unitCode")) { ++ // The "visibility" property in forecasts uses this unique key for the unit ++ uom = json_object_get_string_member (prop, "unitCode"); + } + + read_value = (*select_read_value) (uom); +@@ -776,6 +779,12 @@ read_visibility_m (GWeatherInfo *info, JsonNode *node) + info->visibility = json_node_get_double (node) / VISIBILITY_SM_TO_M (1.); + } + ++static void ++read_visibility_km (GWeatherInfo *info, JsonNode *node) ++{ ++ info->visibility = json_node_get_double (node) / VISIBILITY_SM_TO_KM (1.); ++} ++ + static void + read_visibility_sm (GWeatherInfo *info, JsonNode *node) + { +@@ -785,8 +794,10 @@ read_visibility_sm (GWeatherInfo *info, JsonNode *node) + static ValueReader + select_read_visibility (const gchar *uom) + { +- if (strcmp (uom, "wmoUnit:m") == 0) { ++ if (uom != NULL && strcmp (uom, "wmoUnit:m") == 0) { + return read_visibility_m; ++ } else if (uom != NULL && strcmp (uom, "wmoUnit:km") == 0) { ++ return read_visibility_km; + } + return read_visibility_sm; + }