Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default for weatherEndpoint according to API 3.0 #3583

Merged
merged 8 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ _This release is scheduled to be released on 2025-01-01._

- [updatenotification] Fix pm2 using detection when pm2 script is in MagicMirror root folder (#3576)
- [core] Fix loading node_helper of modules: avoid black screen, display errors and continue loading with next module (#3578)
- [weather] changed default value for weatherEndpoint of provider openweathermap to "/onecall" (#3574)

## [2.29.0] - 2024-10-01

Expand Down
31 changes: 5 additions & 26 deletions modules/default/weather/providers/openweathermap.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ WeatherProvider.register("openweathermap", {
defaults: {
apiVersion: "3.0",
apiBase: "https://api.openweathermap.org/data/",
weatherEndpoint: "", // can be "onecall", "forecast" or "weather" (for current)
// weatherEndpoint is "/onecall" since API 3.0
// "/onecall", "/forecast" or "/weather" only for pro customers
weatherEndpoint: "/onecall",
locationID: false,
location: false,
lat: 0, // the onecall endpoint needs lat / lon values, it doesn't support the locationId
// the /onecall endpoint needs lat / lon values, it doesn't support the locationId
lat: 0,
lon: 0,
apiKey: ""
},
Expand Down Expand Up @@ -90,30 +93,6 @@ WeatherProvider.register("openweathermap", {
.finally(() => this.updateAvailable());
},

/**
* Overrides method for setting config to check if endpoint is correct for hourly
* @param {object} config The configuration object
*/
setConfig (config) {
this.config = config;
if (!this.config.weatherEndpoint) {
switch (this.config.type) {
case "hourly":
this.config.weatherEndpoint = "/onecall";
break;
case "daily":
case "forecast":
this.config.weatherEndpoint = "/forecast";
break;
case "current":
this.config.weatherEndpoint = "/weather";
break;
default:
Log.error("weatherEndpoint not configured and could not resolve it based on type");
}
}
},

/** OpenWeatherMap Specific Methods - These are not part of the default provider methods */
/*
* Gets the complete url for the request
Expand Down
2 changes: 2 additions & 0 deletions tests/configs/modules/weather/currentweather_compliments.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ let config = {
position: "bottom_bar",
config: {
location: "Munich",
weatherProvider: "openweathermap",
weatherEndpoint: "/weather",
mockData: '"#####WEATHERDATA#####"'
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/configs/modules/weather/currentweather_default.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ let config = {
config: {
location: "Munich",
showHumidity: "feelslike",
weatherProvider: "openweathermap",
weatherEndpoint: "/weather",
mockData: '"#####WEATHERDATA#####"'
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/configs/modules/weather/currentweather_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ let config = {
position: "bottom_bar",
config: {
location: "Munich",
weatherProvider: "openweathermap",
weatherEndpoint: "/weather",
mockData: '"#####WEATHERDATA#####"',
windUnits: "beaufort",
showWindDirectionAsArrow: true,
Expand Down
2 changes: 2 additions & 0 deletions tests/configs/modules/weather/currentweather_units.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ let config = {
position: "bottom_bar",
config: {
location: "Munich",
weatherProvider: "openweathermap",
weatherEndpoint: "/weather",
mockData: '"#####WEATHERDATA#####"',
decimalSymbol: ",",
showHumidity: "wind"
Expand Down
3 changes: 2 additions & 1 deletion tests/configs/modules/weather/forecastweather_absolute.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ let config = {
config: {
type: "forecast",
location: "Munich",
mockData: '"#####WEATHERDATA#####"',
weatherProvider: "openweathermap",
weatherEndpoint: "/forecast/daily",
mockData: '"#####WEATHERDATA#####"',
absoluteDates: true
}
}
Expand Down
5 changes: 3 additions & 2 deletions tests/configs/modules/weather/forecastweather_default.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ let config = {
config: {
type: "forecast",
location: "Munich",
mockData: '"#####WEATHERDATA#####"',
weatherEndpoint: "/forecast/daily"
weatherProvider: "openweathermap",
weatherEndpoint: "/forecast/daily",
mockData: '"#####WEATHERDATA#####"'
}
}
]
Expand Down
3 changes: 2 additions & 1 deletion tests/configs/modules/weather/forecastweather_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ let config = {
config: {
type: "forecast",
location: "Munich",
mockData: '"#####WEATHERDATA#####"',
weatherProvider: "openweathermap",
weatherEndpoint: "/forecast/daily",
mockData: '"#####WEATHERDATA#####"',
showPrecipitationAmount: true,
colored: true,
tableClass: "myTableClass"
Expand Down
3 changes: 2 additions & 1 deletion tests/configs/modules/weather/forecastweather_units.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ let config = {
config: {
type: "forecast",
location: "Munich",
mockData: '"#####WEATHERDATA#####"',
weatherProvider: "openweathermap",
weatherEndpoint: "/forecast/daily",
mockData: '"#####WEATHERDATA#####"',
decimalSymbol: "_",
showPrecipitationAmount: true
}
Expand Down
2 changes: 2 additions & 0 deletions tests/configs/modules/weather/hourlyweather_default.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ let config = {
config: {
type: "hourly",
location: "Berlin",
weatherProvider: "openweathermap",
weatherEndpoint: "/onecall",
mockData: '"#####WEATHERDATA#####"'
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/configs/modules/weather/hourlyweather_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ let config = {
config: {
type: "hourly",
location: "Berlin",
weatherProvider: "openweathermap",
weatherEndpoint: "/onecall",
mockData: '"#####WEATHERDATA#####"',
hourlyForecastIncrements: 2
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ let config = {
config: {
type: "hourly",
location: "Berlin",
weatherProvider: "openweathermap",
weatherEndpoint: "/onecall",
mockData: '"#####WEATHERDATA#####"',
showPrecipitationAmount: true,
showPrecipitationProbability: true
Expand Down