Skip to content

Commit

Permalink
Merge pull request #58 from fewieden/develop
Browse files Browse the repository at this point in the history
v2.2.0
  • Loading branch information
fewieden authored Apr 4, 2021
2 parents 82b2fa7 + 887bdc2 commit dce2690
Show file tree
Hide file tree
Showing 18 changed files with 304 additions and 51 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
github: fewieden
custom: ['https://paypal.me/fewieden']
Binary file removed .github/example.jpg
Binary file not shown.
Binary file removed .github/example2.jpg
Binary file not shown.
Binary file added .github/fuel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/global.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: build

on:
push:
branches: [ master, develop ]
pull_request:
branches: [ master, develop ]

jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 14.x ]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run lint
15 changes: 15 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: changelog

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: dangoslen/[email protected]
with:
changeLogPath: CHANGELOG.md
skipLabels: Skip Changelog
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ jspm_packages
.node_repl_history

docs/
debug.js
.vscode/launch.json
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# MMM-Fuel Changelog

## [2.2.0]

Thanks to @TheDuffman85 for his contribution to this release.

### Added

* Config option `stationIds` to check prices of specific gas stations (Tankerkönig only)
* Github actions

### Changed

* 3rd decimal is now superscripted
* Price and distance values are now localized based on global config option `locale`.

### Removed

* Travis-CI integration

## [2.1.2]

### Added
Expand Down
48 changes: 31 additions & 17 deletions MMM-Fuel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @see https://github.com/fewieden/MMM-Fuel
*/

/* global google */
/* global google Module Log config */

/**
* @external Module
Expand All @@ -33,18 +33,6 @@
* @requires external:google
*/
Module.register('MMM-Fuel', {
/** @member {Object} units - Is used to determine the unit symbol of the global config option units. */
units: {
imperial: 'ml',
metric: 'km'
},

/** @member {Object} currencies - Is used to convert currencies into symbols. */
currencies: {
AUD: '$',
EUR: '€'
},

/** @member {boolean} sortByPrice - Flag to switch between sorting (price and distance). */
sortByPrice: true,
/** @member {?Interval} interval - Toggles sortByPrice */
Expand Down Expand Up @@ -317,12 +305,12 @@ Module.register('MMM-Fuel', {
* @function initMap
* @description Initializes the map, markers and layers.
*
* @param {boolean} success - Only initialize the map if success is truthy.
* @param {Error} error - Only initialize if modal render callback doesn't contain error.
*
* @returns {void}
*/
initMap(success) {
if (!success || this.map) {
initMap(error) {
if (error || this.map) {
return;
}

Expand Down Expand Up @@ -410,7 +398,33 @@ Module.register('MMM-Fuel', {
return '-';
}

return `${this.config.toFixed ? price.toFixed(2) : price} ${this.currencies[this.priceList.currency]}`;
let prefix = '';
if (typeof price === 'string') {
prefix = price[0];
price = parseFloat(price.slice(1));
}

const fractionDigits = this.config.toFixed ? 2 : 3;

const priceParts = new Intl.NumberFormat(config.locale, {
style: 'currency',
currency: this.priceList.currency,
minimumFractionDigits: fractionDigits,
maximumFractionDigits: fractionDigits
}).formatToParts(price);

return prefix + priceParts.map(part => {
if (!this.config.toFixed && part.type === 'fraction') {
return part.value.slice(0, -1) + part.value.slice(-1).sup();
}

return part.value;
}).join('');
});
this.nunjucksEnvironment().addFilter('formatDistance', distance => new Intl.NumberFormat(config.locale, {
style: 'unit',
unit: this.priceList.unit,
maximumFractionDigits: 1
}).format(distance));
}
});
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://raw.githubusercontent.com/fewieden/MMM-Fuel/master/LICENSE) [![Build Status](https://travis-ci.org/fewieden/MMM-Fuel.svg?branch=master)](https://travis-ci.org/fewieden/MMM-Fuel) [![Code Climate](https://codeclimate.com/github/fewieden/MMM-Fuel/badges/gpa.svg?style=flat)](https://codeclimate.com/github/fewieden/MMM-Fuel) [![Known Vulnerabilities](https://snyk.io/test/github/fewieden/mmm-fuel/badge.svg)](https://snyk.io/test/github/fewieden/mmm-fuel)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://raw.githubusercontent.com/fewieden/MMM-Fuel/master/LICENSE) ![Build status](https://github.com/fewieden/MMM-Fuel/workflows/build/badge.svg) [![Code Climate](https://codeclimate.com/github/fewieden/MMM-Fuel/badges/gpa.svg?style=flat)](https://codeclimate.com/github/fewieden/MMM-Fuel) [![Known Vulnerabilities](https://snyk.io/test/github/fewieden/mmm-fuel/badge.svg)](https://snyk.io/test/github/fewieden/mmm-fuel)

# MMM-Fuel

Gas Station Price Module for MagicMirror<sup>2</sup>

## Examples

![](.github/example.jpg) ![](.github/example2.jpg) ![](.github/example3.png)
![](.github/fuel.png) ![](.github/example3.png)

## Dependencies

Expand Down Expand Up @@ -63,6 +63,16 @@ Gas Station Price Module for MagicMirror<sup>2</sup>
| `rotateInterval` | `60000` (1 min) | How fast the sorting should be switched between byPrice and byDistance. |
| `updateInterval` | `900000` (15 mins) | How often should the data be fetched. **If your value is to small, you risk to get banned from the API provider. I suggest a minimum of 15mins** |

## Global config

| **Option** | **Default** | **Description** |
| --- | --- | --- |
| `locale` | `undefined` | By default it is using your system settings. You can specify the locale in the global MagicMirror config. Possible values are for e.g.: `'en-US'` or `'de-DE'`. |

To set a global config you have to set the value in your config.js file inside the MagicMirror project.

![](.github/global.png)

### tankerkoenig (Germany only)

Read the [Terms of Use](https://creativecommons.tankerkoenig.de/#usage) carefully, especially the restrictions for smart mirrors,
Expand All @@ -72,7 +82,8 @@ or your API access will be suspended.
| --- | --- | --- |
| `api_key` | REQUIRED | Get an API key for free access to the data of [tankerkoenig.de](https://creativecommons.tankerkoenig.de/#register). |
| `types` | `["diesel"]` | Valid options are `diesel`, `e5` and `e10`. |
| `radius` | `5` | Valid range is 1-25. |
| `radius` | `5` | Valid range is 0-25. Set to 0 to disable. Not required if `stationIds` are provided. |
| `stationIds` | `[]` | Optional array of fuel station ids to fetch instead of the radius. You can only specify a maximum of 10 and you can find the ids [here](https://creativecommons.tankerkoenig.de/TankstellenFinder/index.html). Using radius and station ids in parallel will result in more API calls. If you run into issues increase the `updateInterval`. |

### spritpreisrechner (Austria only)

Expand Down
2 changes: 1 addition & 1 deletion apis/nsw.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async function getData() {

return {
types: ['diesel', 'e5'],
unit: 'km',
unit: 'kilometer',
currency: 'AUD',
byPrice: stations,
byDistance: distance
Expand Down
2 changes: 1 addition & 1 deletion apis/spritpreisrechner.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ async function getData() {

return {
types: ['diesel', 'e5', 'gas'],
unit: 'km',
unit: 'kilometer',
currency: 'EUR',
byPrice: stations,
byDistance: distance
Expand Down
Loading

0 comments on commit dce2690

Please sign in to comment.