diff --git a/src/components/widgets/openweathermap/weather.jsx b/src/components/widgets/openweathermap/weather.jsx
index 9f0a61ac..43edc091 100644
--- a/src/components/widgets/openweathermap/weather.jsx
+++ b/src/components/widgets/openweathermap/weather.jsx
@@ -5,7 +5,7 @@ import Icon from "./icon";
export default function OpenWeatherMap({ options }) {
const { data, error } = useSWR(
- `/api/widgets/openweathermap?lat=${options.latitude}&lon=${options.longitude}&apiKey=${options.apiKey}&duration=${options.cache}`
+ `/api/widgets/openweathermap?lat=${options.latitude}&lon=${options.longitude}&apiKey=${options.apiKey}&duration=${options.cache}&units=${options.units}`
);
if (error) {
@@ -27,17 +27,14 @@ export default function OpenWeatherMap({ options }) {
if (data.error) {
return
;
}
- // OpenWeatherMap returns temperature in Kelvins
- var temp_c = data.main.temp - 273.15;
- var temp_f = temp_c * 9 / 5 + 32;
return (
data.sys.sunrise) && (data.dt < data.sys.sundown) ? "day" : "night"} />
- {options.units === "metric" ? temp_c.toFixed(0) : temp_f.toFixed(0)}°
+ {data.main.temp.toFixed(1)}°
- {data.weather[0].description}
+ {data.weather[0].description.charAt(0).toUpperCase() + data.weather[0].description.slice(1)}
);
diff --git a/src/pages/api/widgets/openweathermap.js b/src/pages/api/widgets/openweathermap.js
index 471f69df..07dc9139 100644
--- a/src/pages/api/widgets/openweathermap.js
+++ b/src/pages/api/widgets/openweathermap.js
@@ -1,9 +1,9 @@
import cachedFetch from "utils/cached-fetch";
export default async function handler(req, res) {
- const { lat, lon, apiKey, duration } = req.query;
+ const { lat, lon, apiKey, duration, units } = req.query;
- const api_url = `https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${apiKey}`;
+ const api_url = `https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${apiKey}&units=${units}`;
res.send(await cachedFetch(api_url, duration));
}