Files
Karsten Hassel d05ea751d9 Release 2.35.0 (#4072)
## Release Notes
Thanks to: @angeldeejay, @in-voker, @JHWelch, @khassel,
@KristjanESPERANTO, @rejas, @sdetweil
> ⚠️ This release needs nodejs version >=22.21.1 <23 || >=24 (no change
to previous release)

[Compare to previous Release
v2.34.0](https://github.com/MagicMirrorOrg/MagicMirror/compare/v2.34.0...v2.25.0)

> ⚠️ We introduced some internal changes with this release, please read
[this forum
post](https://forum.magicmirror.builders/topic/20138/upcoming-release-april-1-2026-breaking-changes-some-operational-changes)
before upgrading!

### [core]
- Prepare Release 2.35.0 (#4071)
- docs: add security policy and vulnerability reporting guidelines
(#4069)
- refactor: simplify internal `require()` calls (#4056)
- allow environment variables in cors urls (#4033)
- fix cors proxy getting binary data (e.g. png, webp) (#4030)
- fix: correct secret redaction and optimize loadConfig (#4031)
- change loading config.js, allow variables in config.js and try to
protect sensitive data (#4029)
- remove kioskmode (#4027)
- Add dark theme logo (#4026)
- move custom.css from css to config (#4020)
- move default modules from /modules/default to /defaultmodules (#4019)
- update node versions in workflows (#4018)
- [core] refactor: extract and centralize HTTP fetcher (#4016)
- fix systeminformation not displaying electron version (#4012)
- Update node-ical and support it's rrule-temporal changes (#4010)
- Change default start scripts from X11 to Wayland (#4011)
- refactor: unify favicon for index.html and Electron (#4006)
- [core] run systeminformation in subprocess so the info is always
displayed (#4002)
- set next release dev number (#4000)

### [dependencies]
- update dependencies (#4068)
- update dependencies incl. electron to v41 (#4058)
- chore: upgrade ESLint to v10 and fix newly surfaced issues (#4057)
- chore: update ESLint and plugins, simplify config, apply new rules
(#4052)
- chore: update dependencies + add exports, files, and sideEffects
fields to package.json (#4040)
- [core] refactor: enable ESLint rule require-await and handle detected
issues (#4038)
- Update node-ical and other deps (#4025)
- chore: update dependencies (#4021)
- chore(eslint): migrate from eslint-plugin-vitest to
@vitest/eslint-plugin and run rules only on test files (#4014)
- Update deps as requested by dependabot (#4008)
- update Collaboration.md and dependencies (#4001)

### [logging]
- refactor: further logger clean-up (#4050)
- Fix Node.js v25 logging prefix and modernize logger (#4049)

### [modules/calendar]
- fix(calendar): make showEnd behavior more consistent across time
formats (#4059)
- test(calendar): fix hardcoded date in event shape test (#4055)
- [calendar] refactor: delegate event expansion to node-ical's
expandRecurringEvent (#4047)
- calendar.js: remove useless hasCalendarURL function (#4028)
- fix(calendar): update to node-ical 0.23.1 and fix full-day recurrence
lookup (#4013)
- fix(calendar): correct day-of-week for full-day recurring events
across all timezones (#4004)

### [modules/newsfeed]
- fix(newsfeed): fix full article view and add framing check (#4039)
- [newsfeed] refactor: migrate to centralized HTTPFetcher (#4023)

### [modules/weather]
- fix(weather): fix openmeteo forecast stuck in the past (#4064)
- fix(weather): fix weathergov forecast day labels off by one (#4065)
- weather: fixes for templates (#4054)
- weather: add possibility to override njk's and css (#4051)
- Use getDateString in openmeteo (#4046)
- [weather] refactor: migrate to server-side providers with centralized
HTTPFetcher (#4032)
- [weather] feat: add Weather API Provider  (#4036)

### [testing]
- chore: remove obsolete Jest config and unit test global setup (#4044)
- replace template_spec test with config_variables test (#4034)
- refactor(clientonly): modernize code structure and add comprehensive
tests (#4022)
- Switch to undici Agent for HTTPS requests (#4015)
- chore: migrate CI workflows to ubuntu-slim for faster startup times
(#4007)

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com>
Co-authored-by: Bugsounet - Cédric <github@bugsounet.fr>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: sam detweiler <sdetweil@gmail.com>
Co-authored-by: Veeck <github@veeck.de>
Co-authored-by: veeck <gitkraken@veeck.de>
Co-authored-by: Magnus <34011212+MagMar94@users.noreply.github.com>
Co-authored-by: Ikko Eltociear Ashimine <eltociear@gmail.com>
Co-authored-by: DevIncomin <56730075+Developer-Incoming@users.noreply.github.com>
Co-authored-by: Nathan <n8nyoung@gmail.com>
Co-authored-by: mixasgr <mixasgr@users.noreply.github.com>
Co-authored-by: Savvas Adamtziloglou <savvas-gr@greeklug.gr>
Co-authored-by: Konstantinos <geraki@gmail.com>
Co-authored-by: OWL4C <124401812+OWL4C@users.noreply.github.com>
Co-authored-by: BugHaver <43462320+bughaver@users.noreply.github.com>
Co-authored-by: BugHaver <43462320+lsaadeh@users.noreply.github.com>
Co-authored-by: Koen Konst <koenspero@gmail.com>
Co-authored-by: Koen Konst <c.h.konst@avisi.nl>
Co-authored-by: dathbe <github@beffa.us>
Co-authored-by: Marcel <m-idler@users.noreply.github.com>
Co-authored-by: Kevin G. <crazylegstoo@gmail.com>
Co-authored-by: Jboucly <33218155+jboucly@users.noreply.github.com>
Co-authored-by: Jboucly <contact@jboucly.fr>
Co-authored-by: Jarno <54169345+jarnoml@users.noreply.github.com>
Co-authored-by: Jordan Welch <JordanHWelch@gmail.com>
Co-authored-by: Blackspirits <blackspirits@gmail.com>
Co-authored-by: Samed Ozdemir <samed@xsor.io>
Co-authored-by: in-voker <58696565+in-voker@users.noreply.github.com>
Co-authored-by: Andrés Vanegas Jiménez <142350+angeldeejay@users.noreply.github.com>
2026-04-01 12:35:16 +02:00

293 lines
7.2 KiB
JavaScript

const Log = require("logger");
const HTTPFetcher = require("#http_fetcher");
/**
* Weatherbit weather provider
* See: https://www.weatherbit.io/
*/
class WeatherbitProvider {
constructor (config) {
this.config = {
apiBase: "https://api.weatherbit.io/v2.0",
apiKey: "",
lat: 0,
lon: 0,
type: "current",
updateInterval: 10 * 60 * 1000,
...config
};
this.fetcher = null;
this.onDataCallback = null;
this.onErrorCallback = null;
}
setCallbacks (onDataCallback, onErrorCallback) {
this.onDataCallback = onDataCallback;
this.onErrorCallback = onErrorCallback;
}
initialize () {
if (!this.config.apiKey || this.config.apiKey === "YOUR_API_KEY_HERE") {
Log.error("[weatherbit] No API key configured");
if (this.onErrorCallback) {
this.onErrorCallback({
message: "Weatherbit API key required. Get one at https://www.weatherbit.io/",
translationKey: "MODULE_ERROR_UNSPECIFIED"
});
}
return;
}
this.#initializeFetcher();
}
#initializeFetcher () {
const url = this.#getUrl();
this.fetcher = new HTTPFetcher(url, {
reloadInterval: this.config.updateInterval,
headers: {
Accept: "application/json"
},
logContext: "weatherprovider.weatherbit"
});
this.fetcher.on("response", async (response) => {
try {
const data = await response.json();
this.#handleResponse(data);
} catch (error) {
Log.error("[weatherbit] Parse error:", error);
if (this.onErrorCallback) {
this.onErrorCallback({
message: "Failed to parse API response",
translationKey: "MODULE_ERROR_UNSPECIFIED"
});
}
}
});
this.fetcher.on("error", (errorInfo) => {
if (this.onErrorCallback) {
this.onErrorCallback(errorInfo);
}
});
}
#getUrl () {
const endpoint = this.#getWeatherEndpoint();
return `${this.config.apiBase}${endpoint}?lat=${this.config.lat}&lon=${this.config.lon}&units=M&key=${this.config.apiKey}`;
}
#getWeatherEndpoint () {
switch (this.config.type) {
case "hourly":
return "/forecast/hourly";
case "daily":
case "forecast":
return "/forecast/daily";
case "current":
default:
return "/current";
}
}
#handleResponse (data) {
if (!data || !data.data || data.data.length === 0) {
Log.error("[weatherbit] No usable data received");
if (this.onErrorCallback) {
this.onErrorCallback({
message: "No usable data in API response",
translationKey: "MODULE_ERROR_UNSPECIFIED"
});
}
return;
}
let weatherData = null;
switch (this.config.type) {
case "current":
weatherData = this.#generateCurrent(data);
break;
case "forecast":
case "daily":
weatherData = this.#generateDaily(data);
break;
case "hourly":
weatherData = this.#generateHourly(data);
break;
default:
Log.error(`[weatherbit] Unknown weather type: ${this.config.type}`);
break;
}
if (weatherData && this.onDataCallback) {
this.onDataCallback(weatherData);
}
}
#generateCurrent (data) {
if (!data.data[0] || typeof data.data[0].temp === "undefined") {
return null;
}
const current = data.data[0];
const weather = {
date: new Date(current.ts * 1000),
temperature: parseFloat(current.temp),
humidity: parseFloat(current.rh),
windSpeed: parseFloat(current.wind_spd),
windFromDirection: current.wind_dir || null,
weatherType: this.#convertWeatherType(current.weather.icon),
sunrise: null,
sunset: null
};
// Parse sunrise/sunset from HH:mm format (already in local time)
if (current.sunrise) {
const [hours, minutes] = current.sunrise.split(":");
const sunrise = new Date(current.ts * 1000);
sunrise.setHours(parseInt(hours), parseInt(minutes), 0, 0);
weather.sunrise = sunrise;
}
if (current.sunset) {
const [hours, minutes] = current.sunset.split(":");
const sunset = new Date(current.ts * 1000);
sunset.setHours(parseInt(hours), parseInt(minutes), 0, 0);
weather.sunset = sunset;
}
return weather;
}
#generateDaily (data) {
const days = [];
for (const forecast of data.data) {
days.push({
date: new Date(forecast.datetime),
minTemperature: forecast.min_temp !== undefined ? parseFloat(forecast.min_temp) : null,
maxTemperature: forecast.max_temp !== undefined ? parseFloat(forecast.max_temp) : null,
precipitationAmount: forecast.precip !== undefined ? parseFloat(forecast.precip) : 0,
precipitationProbability: forecast.pop !== undefined ? parseFloat(forecast.pop) : null,
weatherType: this.#convertWeatherType(forecast.weather.icon)
});
}
return days;
}
#generateHourly (data) {
const hours = [];
for (const forecast of data.data) {
hours.push({
date: new Date(forecast.timestamp_local),
temperature: forecast.temp !== undefined ? parseFloat(forecast.temp) : null,
precipitationAmount: forecast.precip !== undefined ? parseFloat(forecast.precip) : 0,
precipitationProbability: forecast.pop !== undefined ? parseFloat(forecast.pop) : null,
windSpeed: forecast.wind_spd !== undefined ? parseFloat(forecast.wind_spd) : null,
windFromDirection: forecast.wind_dir || null,
weatherType: this.#convertWeatherType(forecast.weather.icon)
});
}
return hours;
}
/**
* Convert Weatherbit icon codes to weathericons.css icons
* See: https://www.weatherbit.io/api/codes
* @param {string} weatherType - Weatherbit icon code
* @returns {string|null} Weathericons.css icon name or null
*/
#convertWeatherType (weatherType) {
const weatherTypes = {
t01d: "day-thunderstorm",
t01n: "night-alt-thunderstorm",
t02d: "day-thunderstorm",
t02n: "night-alt-thunderstorm",
t03d: "thunderstorm",
t03n: "thunderstorm",
t04d: "day-thunderstorm",
t04n: "night-alt-thunderstorm",
t05d: "day-sleet-storm",
t05n: "night-alt-sleet-storm",
d01d: "day-sprinkle",
d01n: "night-alt-sprinkle",
d02d: "day-sprinkle",
d02n: "night-alt-sprinkle",
d03d: "day-showers",
d03n: "night-alt-showers",
r01d: "day-showers",
r01n: "night-alt-showers",
r02d: "day-rain",
r02n: "night-alt-rain",
r03d: "day-rain",
r03n: "night-alt-rain",
r04d: "day-sprinkle",
r04n: "night-alt-sprinkle",
r05d: "day-showers",
r05n: "night-alt-showers",
r06d: "day-showers",
r06n: "night-alt-showers",
f01d: "day-sleet",
f01n: "night-alt-sleet",
s01d: "day-snow",
s01n: "night-alt-snow",
s02d: "day-snow-wind",
s02n: "night-alt-snow-wind",
s03d: "snowflake-cold",
s03n: "snowflake-cold",
s04d: "day-rain-mix",
s04n: "night-alt-rain-mix",
s05d: "day-sleet",
s05n: "night-alt-sleet",
s06d: "day-snow",
s06n: "night-alt-snow",
a01d: "day-haze",
a01n: "dust",
a02d: "smoke",
a02n: "smoke",
a03d: "day-haze",
a03n: "dust",
a04d: "dust",
a04n: "dust",
a05d: "day-fog",
a05n: "night-fog",
a06d: "fog",
a06n: "fog",
c01d: "day-sunny",
c01n: "night-clear",
c02d: "day-sunny-overcast",
c02n: "night-alt-partly-cloudy",
c03d: "day-cloudy",
c03n: "night-alt-cloudy",
c04d: "cloudy",
c04n: "cloudy",
u00d: "rain-mix",
u00n: "rain-mix"
};
return weatherTypes[weatherType] || null;
}
start () {
if (this.fetcher) {
this.fetcher.startPeriodicFetch();
}
}
stop () {
if (this.fetcher) {
this.fetcher.clearTimer();
}
}
}
module.exports = WeatherbitProvider;