Skip to content

Commit

Permalink
Merge pull request #1 from JHWelch/call-api
Browse files Browse the repository at this point in the history
Get Functional
  • Loading branch information
JHWelch authored Jan 21, 2024
2 parents fe7239e + 738722f commit 29feb61
Show file tree
Hide file tree
Showing 12 changed files with 650 additions and 163 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2
28 changes: 25 additions & 3 deletions MMM-CTA.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
Module.register('MMM-CTA', {
defaults: {
updateInterval: 60000,
trainApiKey: null,
busApiKey: null,
maxResultsTrain: 5,
maxResultsBus: 5,
stops: [],
},

requiresVersion: '2.2.0',
Expand All @@ -29,8 +34,11 @@ Module.register('MMM-CTA', {

getData() {
this.sendSocketNotification('MMM-CTA-FETCH', {
token: this.config.token,
city: this.config.city,
trainApiKey: this.config.trainApiKey,
busApiKey: this.config.busApiKey,
stops: this.config.stops,
maxResultsTrain: this.config.maxResultsTrain,
maxResultsBus: this.config.maxResultsBus,
});
},

Expand All @@ -41,6 +49,13 @@ Module.register('MMM-CTA', {
getTemplateData() {
return {
loading: this.loading,
stops: this.data.stops?.map((stop) => ({
...stop,
arrivals: stop.arrivals?.map((arrival) => ({
direction: arrival.direction,
arrival: arrival.arrival ?? this.getMinutesUntil(arrival.time),
})),
})),
};
},

Expand All @@ -67,8 +82,15 @@ Module.register('MMM-CTA', {
return;
}

this.data.aqi = payload.aqi;
this.data.stops = payload.stops;
this.loading = false;
this.updateDom(300);
},

getMinutesUntil(arrivalTime) {
const now = new Date();
const diffInMilliseconds = new Date(arrivalTime) - now;

return Math.floor(diffInMilliseconds / 1000 / 60);
},
});
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
> [!CAUTION]
> This module is still in development and is not ready for use.
# MMM-CTA

This is a module for the [MagicMirror²](https://github.com/MichMich/MagicMirror/).
Expand All @@ -17,7 +14,7 @@ git clone https://github.com/JHWelch/MMM-CTA.git
Install NPM dependencies
```sh
cd MMM-CTA
npm install
npm install --production
```

## Using the module
Expand Down Expand Up @@ -47,6 +44,12 @@ var config = {

## Development

### Installation

```sh
npm install
```

### Testing

There is a test suite using Jest.
Expand Down
134 changes: 0 additions & 134 deletions __tests__/MMM-AQI.spec.js

This file was deleted.

Loading

0 comments on commit 29feb61

Please sign in to comment.