Skip to content

Commit

Permalink
Make sure smhi provider api only gets a maximimum of 6 digits coordin…
Browse files Browse the repository at this point in the history
…ates

Fixes MagicMirrorOrg#2955
  • Loading branch information
veeck committed Oct 21, 2022
1 parent 64ed5a5 commit 0903db5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Special thanks to: @rejas, @sdetweil
- Updated e2e tests (moved `done()` in helper functions) and use es6 syntax in all tests
- Updated da translation
- Rework weather module
- Make sure smhi provider api only gets a maximum of 6 digits coordinates (#2955)
- Use fetch instead of XMLHttpRequest in weatherprovider
- Use unix() method for parsing times, fix suntimes on the way

Expand Down
12 changes: 8 additions & 4 deletions modules/default/weather/providers/smhi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ WeatherProvider.register("smhi", {

// Set the default config properties that is specific to this provider
defaults: {
lat: 0,
lon: 0,
lat: 0, // Cant have more than 6 digits
lon: 0, // Cant have more than 6 digits
precipitationValue: "pmedian",
location: false
},
Expand Down Expand Up @@ -104,8 +104,12 @@ WeatherProvider.register("smhi", {
* @returns {string} the url for the specified coordinates
*/
getURL() {
let lon = this.config.lon;
let lat = this.config.lat;
const formatter = new Intl.NumberFormat("en-US", {
minimumFractionDigits: 2,
maximumFractionDigits: 2
});
const lon = formatter.format(this.config.lon);
const lat = formatter.format(this.config.lat);
return `https://opendata-download-metfcst.smhi.se/api/category/pmp3g/version/2/geotype/point/lon/${lon}/lat/${lat}/data.json`;
},

Expand Down

0 comments on commit 0903db5

Please sign in to comment.