Skip to content

Commit

Permalink
Merge pull request #61 from fewieden/develop
Browse files Browse the repository at this point in the history
2.2.1
  • Loading branch information
fewieden authored Apr 8, 2021
2 parents dce2690 + e0b1712 commit 7263ddc
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# MMM-Fuel Changelog

## [2.2.1]

### Fixed

* Filtering of station ids lead to invalid price request for provider tankerkoenig

### Changed

* Log a warning if no fuel station detail could be fetched
* Updated provider integration documentation

## [2.2.0]

Thanks to @TheDuffman85 for his contribution to this release.
Expand Down
4 changes: 2 additions & 2 deletions apis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ The response has to have the following format:
```
{
types: ['diesel', 'e5', 'e10'], // Array | types supported by the API provider.
unit: 'km', // String | unit for the distance either in kilometres (km) or miles (ml).
currency: 'EUR', // String | curreny of the fuel prices either in EUR or USD.
unit: 'km', // String | unit for the distance either `kilometer` or `mile`.
currency: 'EUR', // String | 3 character representation of the currency for the fuel prices e.g. `EUR`, `USD` or `AUD`.
byPrice: stations, // Array | stations (see above) sorted by price.
byDistance: distance // Array | stations (see above) sorted by distance.
};
Expand Down
18 changes: 12 additions & 6 deletions apis/tankerkoenig.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,8 @@ async function getPricesByRadius() {
* @returns {void}
*/
async function setStationInfos(stationsByRadius) {

// Filter out possible duplicate stations which are included in the radius search.
for (const station of stationsByRadius) {
config.stationIds = config.stationIds.filter(e => e !== station.id);
config.stationIds = config.stationIds.filter(id => id !== station.id);
}

if (config.stationIds.length > 10) {
Expand All @@ -186,7 +184,8 @@ async function setStationInfos(stationsByRadius) {
const parsedResponse = await response.json();

if (!parsedResponse.ok) {
throw new Error('Error no fuel station detail');
console.warn(`MMM-Fuel: No fuel station detail. StationId: ${stationId} Error: ${parsedResponse.message}`);
continue;
}

const station = parsedResponse.station;
Expand Down Expand Up @@ -240,14 +239,21 @@ async function getPricesByStationList(stationsByRadius) {
await setStationInfos(stationsByRadius);
}

const response = await fetch(generateStationPricesUrl(Object.keys(stationInfos)));
const stationIds = Object.keys(stationInfos);
const stations = [];

if (!stationIds.length) {
console.warn('MMM-Fuel: Filtered stationIds list is empty');
return stations;
}

const response = await fetch(generateStationPricesUrl(stationIds));
const parsedResponse = await response.json();

if (!parsedResponse.ok) {
throw new Error('Error no fuel station prices');
}

const stations = [];
for (const [stationId, info] of Object.entries(parsedResponse.prices)) {
stations.push({
...stationInfos[stationId],
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mmm-fuel",
"version": "2.2.0",
"version": "2.2.1",
"description": "Gas Station price Module for MagicMirror2",
"scripts": {
"lint": "eslint . && stylelint **/*.css",
Expand Down

0 comments on commit 7263ddc

Please sign in to comment.