Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
options to switch between miles and km
Browse files Browse the repository at this point in the history
  • Loading branch information
hdurdle committed Aug 7, 2019
1 parent 960a529 commit b3bf144
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
23 changes: 17 additions & 6 deletions MMM-BMWConnected.js
Expand Up @@ -3,7 +3,9 @@ Module.register('MMM-BMWConnected', {
defaults: {
apiBase: "www.bmw-connecteddrive.co.uk",
refresh: 15,
vehicleAngle: 300
vehicleAngle: 300,
distance: "miles",
debug: false
},

getStyles: function () {
Expand Down Expand Up @@ -55,6 +57,12 @@ Module.register('MMM-BMWConnected', {
},

getDom: function () {

var distanceSuffix = "mi";
if (this.config.distance === "km") {
distanceSuffix = "km";
}

var wrapper = document.createElement("div");

if (this.config.email === "" || this.config.password === "") {
Expand All @@ -68,7 +76,6 @@ Module.register('MMM-BMWConnected', {
return wrapper;
}


var info = this.bmwInfo;

var carContainer = document.createElement("div");
Expand All @@ -86,7 +93,7 @@ Module.register('MMM-BMWConnected', {
var mileage = document.createElement("span");
mileage.classList.add("mileage");
mileage.appendChild(this.faIconFactory("fa-road"));
mileage.appendChild(document.createTextNode(info.mileage + " mi"));
mileage.appendChild(document.createTextNode(info.mileage + " " + distanceSuffix));
carContainer.appendChild(mileage);

wrapper.appendChild(carContainer);
Expand Down Expand Up @@ -138,13 +145,13 @@ Module.register('MMM-BMWConnected', {
var elecRange = document.createElement("span");
elecRange.classList.add("elecRange");
elecRange.appendChild(this.faIconFactory("fa-charging-station"));
elecRange.appendChild(document.createTextNode(info.electricRange + " mi"));
elecRange.appendChild(document.createTextNode(info.electricRange + " " + distanceSuffix));
carContainer.appendChild(elecRange);

var fuelRange = document.createElement("span");
fuelRange.classList.add("fuelRange");
fuelRange.appendChild(this.faIconFactory("fa-gas-pump"));
fuelRange.appendChild(document.createTextNode(info.fuelRange + " mi"));
fuelRange.appendChild(document.createTextNode(info.fuelRange + " " + distanceSuffix));
carContainer.appendChild(fuelRange);
wrapper.appendChild(carContainer);

Expand All @@ -155,7 +162,11 @@ Module.register('MMM-BMWConnected', {
var updated = document.createElement("span");
updated.classList.add("updated");
updated.appendChild(this.faIconFactory("fa-info"));
updated.appendChild(document.createTextNode("last updated " + moment(info.updateTime).fromNow()));
var lastUpdateText = "last updated " + moment(info.updateTime).fromNow();
if (this.config.debug) {
lastUpdateText += " [" + info.unitOfLength + "]";
}
updated.appendChild(document.createTextNode(lastUpdateText));
carContainer.appendChild(updated);
wrapper.appendChild(carContainer);

Expand Down
12 changes: 12 additions & 0 deletions README.md
Expand Up @@ -63,6 +63,10 @@ The module has a few configuration options:
<tr>
<td><code>vehicleAngle</code></td>
<td>The angle of rotation for the car image. <br /><br /><strong>Default: </strong><code>300</code><br/>Between 0 and 350 in increments of 10.</td>
</tr>
<tr>
<td><code>distance</code></td>
<td>The unit of distance used for mileage and range. <br /><br /><strong>Default: </strong><code>miles</code><br/>Can be: miles or km.</td>
</tr>
</tbody>
</table>
Expand All @@ -71,6 +75,14 @@ The module has a few configuration options:

If possible the module will pull an image of your car from BMW's API. I only have one BMW, so can't test the placement/graphics of other vehicles. I'd love to see what it looks like if you try it. Tweet images to me at https://twitter.com/hdurdle

## Help

If you have a moment, please set <code>debug</code> to <code>true</code> in the config and see what text appears in <code>[ ]</code> after the last updated time. I'm trying to see what the BMW API returns for countries that use KM instead of miles. I might be able to avoid making it a config option and pull it direct from the API. Tweet images and comments to me at https://twitter.com/hdurdle

![Debug Screenshot](debug.png "Debug Screenshot")

Also, if you can offer translations for the few bits of direct text ("last updated") for your language, let me know (along with where the placeholder should go in your language!).

## Thanks

Hat tip to [Nils Schneider](https://github.com/Lyve1981/BMW-ConnectedDrive-JSON-Wrapper) for the library code for performing the BMW authentication dance.
Binary file added debug.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion node_helper.js
Expand Up @@ -54,9 +54,16 @@ module.exports = NodeHelper.create({
connectorStatus: attributes.connectorStatus,
vin: vin,
chargingLevelHv: Number(attributes.chargingLevelHv).toFixed(),
imageUrl: null
imageUrl: null,
unitOfLength: attributes.unitOfLength
}

if (self.config.distance === "km") {
self.bmwInfo.electricRange = Number(attributes.beRemainingRangeElectricKm).toFixed();
self.bmwInfo.fuelRange = Number(attributes.beRemainingRangeFuelKm).toFixed();
}


var getImagesUri = '/api/vehicle/image/v1/' + vin + "?startAngle=0&stepAngle=10&width=640"
bmwrequest.call(self.config.apiBase, getImagesUri, '', token, tokenType, function (data) {
try {
Expand Down

0 comments on commit b3bf144

Please sign in to comment.