mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 12:55:22 +00:00
Compare commits
127 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
0300ce05d5 | ||
|
9e0293047f | ||
|
298e585361 | ||
|
21a6d1bcea | ||
|
bbe17b9b01 | ||
|
4381fc6695 | ||
|
818fd7b490 | ||
|
4c6c6f9ed3 | ||
|
2338a90191 | ||
|
6cad0e191b | ||
|
f23e604ed4 | ||
|
0c1abad9df | ||
|
fb96cc3c72 | ||
|
e917f40542 | ||
|
29d467715f | ||
|
b791a3761f | ||
|
02201d9f15 | ||
|
b8dbf95497 | ||
|
65022f3ce1 | ||
|
44854d6a4f | ||
|
203014c654 | ||
|
d3e53586fd | ||
|
9dd343054e | ||
|
11d17dd2c0 | ||
|
4cc3e481cc | ||
|
174da38cc8 | ||
|
0a35505e8d | ||
|
032f7ac299 | ||
|
ca906c4b36 | ||
|
50f72f09ac | ||
|
02cf9b37e2 | ||
|
6f273d76b3 | ||
|
0a1067ec7d | ||
|
48756e8774 | ||
|
4915ad8fc7 | ||
|
ba128cbae9 | ||
|
2a6e51493e | ||
|
ef678f9f8a | ||
|
e997ee7071 | ||
|
1273390af3 | ||
|
0f6eb4a244 | ||
|
2c0c62c89b | ||
|
ec13c952d9 | ||
|
6fc71cf6f8 | ||
|
bd3137a3dc | ||
|
b26da4f97f | ||
|
cde0adc28e | ||
|
2813f101b8 | ||
|
4d8fb8c176 | ||
|
9ae62d60f7 | ||
|
17c14e137e | ||
|
bc239f6608 | ||
|
6493fad8a4 | ||
|
d539f459ca | ||
|
2cca6a2f39 | ||
|
80e07bae0d | ||
|
d4c4f6e1a5 | ||
|
d24fe4e983 | ||
|
aaa9042810 | ||
|
a4bb1cefb9 | ||
|
c3339b47bb | ||
|
0c1e5ea881 | ||
|
3fbd9006ad | ||
|
be9761146c | ||
|
5aa9e7e0f6 | ||
|
65e87aea52 | ||
|
66fffc932c | ||
|
1e934e16af | ||
|
82fbb7e32d | ||
|
8bf9b9bef9 | ||
|
2d15e4f976 | ||
|
055ce56a57 | ||
|
f1f2a61dc8 | ||
|
39c1b37726 | ||
|
5b1b25fa86 | ||
|
54ab0b1bf0 | ||
|
5507e9ffe9 | ||
|
30d5bfe59e | ||
|
b716ec33d9 | ||
|
e25209d9f9 | ||
|
1f4ac82495 | ||
|
0baf58f3fd | ||
|
9a769203e3 | ||
|
1435efaea7 | ||
|
c411ac821e | ||
|
da0489fc0c | ||
|
c82de1e314 | ||
|
604a555e14 | ||
|
87e011ff96 | ||
|
9b2051827c | ||
|
47aefb0c82 | ||
|
70da1d6f5c | ||
|
c0743ce9de | ||
|
fe7b4044e0 | ||
|
701ce8ad47 | ||
|
591f907134 | ||
|
4f1db749c0 | ||
|
ae72ed8c67 | ||
|
ab7934fa98 | ||
|
a4c77f0c9e | ||
|
0023c64d59 | ||
|
b55b3bd63b | ||
|
cbda20f67e | ||
|
e598dbb206 | ||
|
094881fc5c | ||
|
b13414cab8 | ||
|
3e65ac653b | ||
|
05621c9876 | ||
|
938619ce0c | ||
|
8e5267d44f | ||
|
3b55886c45 | ||
|
ed3aceb427 | ||
|
c3b2aaec69 | ||
|
bb1d3431cc | ||
|
fe83fe338a | ||
|
6504b5e818 | ||
|
8578900bfb | ||
|
d730dd04bf | ||
|
1d90c5e1fe | ||
|
0f39b7733c | ||
|
038b6765e7 | ||
|
58569a648c | ||
|
df0f048ecc | ||
|
288a008e72 | ||
|
439690b981 | ||
|
b4e75f6844 | ||
|
3f6a5a7772 |
@@ -16,7 +16,7 @@
|
||||
},
|
||||
"parserOptions": {
|
||||
"sourceType": "module",
|
||||
"ecmaVersion": 2018,
|
||||
"ecmaVersion": 2020,
|
||||
"ecmaFeatures": {
|
||||
"globalReturn": true
|
||||
}
|
||||
|
4
.github/ISSUE_TEMPLATE.md
vendored
4
.github/ISSUE_TEMPLATE.md
vendored
@@ -20,9 +20,7 @@ If you are facing an issue or found a bug while trying to install MagicMirror²
|
||||
## I found a bug in the MagicMirror² Docker image
|
||||
|
||||
If you are facing an issue or found a bug while running MagicMirror² inside a Docker container please create an issue in the corresponding repository:
|
||||
|
||||
- karsten13/magicmirror: [https://gitlab.com/khassel/magicmirror](https://gitlab.com/khassel/magicmirror)
|
||||
- (deprecated) bastilimbach/docker-magicmirror: [https://github.com/bastilimbach/docker-MagicMirror](https://github.com/bastilimbach/docker-MagicMirror)
|
||||
[https://gitlab.com/khassel/magicmirror](https://gitlab.com/khassel/magicmirror)
|
||||
|
||||
---
|
||||
|
||||
|
6
.github/dependabot.yaml
vendored
Normal file
6
.github/dependabot.yaml
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
0
.github/stale.yml → .github/stale.yaml
vendored
0
.github/stale.yml → .github/stale.yaml
vendored
@@ -9,18 +9,21 @@ on:
|
||||
pull_request:
|
||||
branches: [master, develop]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [14.x, 16.x, 17.x]
|
||||
node-version: [14.x, 16.x, 18.x]
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v2
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
cache: "npm"
|
||||
@@ -28,7 +31,7 @@ jobs:
|
||||
run: |
|
||||
Xvfb :99 -screen 0 1024x768x16 &
|
||||
export DISPLAY=:99
|
||||
npm install
|
||||
npm run install-mm:dev
|
||||
touch css/custom.css
|
||||
npm run test:prettier
|
||||
npm run test:js
|
@@ -1,4 +1,5 @@
|
||||
# This workflow runs the automated test and uploads the coverage results to codecov.io
|
||||
# For more information see: https://github.com/codecov/codecov-action
|
||||
|
||||
name: "Run Codecov Tests"
|
||||
|
||||
@@ -8,13 +9,16 @@ on:
|
||||
pull_request:
|
||||
branches: [master, develop]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
run-and-upload-coverage-report:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: Install dependencies and run coverage
|
||||
run: |
|
||||
Xvfb :99 -screen 0 1024x768x16 &
|
||||
@@ -23,7 +27,7 @@ jobs:
|
||||
touch css/custom.css
|
||||
npm run test:coverage
|
||||
- name: Upload coverage results to codecov
|
||||
uses: codecov/codecov-action@v2
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
files: ./coverage/lcov.info
|
||||
fail_ci_if_error: true
|
14
.github/workflows/depsreview.yaml
vendored
Normal file
14
.github/workflows/depsreview.yaml
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
name: "Dependency Review"
|
||||
on: [pull_request]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
dependency-review:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: "Checkout Repository"
|
||||
uses: actions/checkout@v3
|
||||
- name: "Dependency Review"
|
||||
uses: actions/dependency-review-action@v2
|
@@ -1,4 +1,5 @@
|
||||
# This workflow enforces the update of a changelog file on every pull request
|
||||
# For more information see: https://github.com/dangoslen/changelog-enforcer
|
||||
|
||||
name: "Enforce Changelog"
|
||||
|
||||
@@ -11,10 +12,8 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
- name: Enforce changelog️
|
||||
uses: dangoslen/changelog-enforcer@v2
|
||||
uses: dangoslen/changelog-enforcer@v3
|
||||
with:
|
||||
changeLogPath: "CHANGELOG.md"
|
||||
skipLabels: "Skip Changelog"
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -16,7 +16,6 @@ vendor/node_modules/**/*
|
||||
jspm_modules
|
||||
.npm
|
||||
.node_repl_history
|
||||
.nyc_output/
|
||||
|
||||
# Visual Studio Code ignoramuses.
|
||||
.vscode/
|
||||
|
@@ -1,4 +1,3 @@
|
||||
/config
|
||||
/coverage
|
||||
.nyc_output
|
||||
package-lock.json
|
||||
|
173
CHANGELOG.md
173
CHANGELOG.md
@@ -5,6 +5,112 @@ This project adheres to [Semantic Versioning](https://semver.org/).
|
||||
|
||||
❤️ **Donate:** Enjoying MagicMirror²? [Please consider a donation!](https://magicmirror.builders/donate) With your help we can continue to improve the MagicMirror².
|
||||
|
||||
## [2.22.0] - 2023-01-01
|
||||
|
||||
Thanks to: @angeldeejay, @buxxi, @dariom, @dWoolridge, @KristjanESPERANTO, @MagMar94, @naveensrinivasan, @retroflex, @SkySails and @Tom.
|
||||
|
||||
Special thanks to @khassel, @rejas and @sdetweil for taking over most (if not all) of the work on this release as project collaborators. This version would not be there without their effort. Thank you!
|
||||
|
||||
### Added
|
||||
|
||||
- Added test for remoteFile option in compliments module
|
||||
- Added hourlyWeather functionality to Weather.gov weather provider
|
||||
- Removed weatherEndpoint definition from weathergov.js (not used)
|
||||
- Added css class names "today" and "tomorrow" for default calendar
|
||||
- Added Collaboration.md
|
||||
- Added new github action for dependency review (#2862)
|
||||
- Added a WeatherProvider for Open-Meteo
|
||||
- Added Yr as a weather provider
|
||||
- Added config options "ignoreXOriginHeader" and "ignoreContentSecurityPolicy"
|
||||
|
||||
### Removed
|
||||
|
||||
- Removed usage of internal fetch function of node until it is more stable
|
||||
|
||||
### Updated
|
||||
|
||||
- Cleaned up test directory (#2937) and jest config (#2959)
|
||||
- Wait for all modules to start before declaring the system ready (#2487)
|
||||
- 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 (#2935)
|
||||
- Reworked how weatherproviders handle units (#2849)
|
||||
- Use unix() method for parsing times, fix suntimes on the way (#2950)
|
||||
- Refactor conversion functions into utils class (#2958)
|
||||
- The `cors`-method in `server.js` now supports sending and recieving HTTP headers
|
||||
- Replace `…` by `…`
|
||||
- Cleanup compliments module
|
||||
- Updated dependencies including electron to v22 (#2903)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Correctly show apparent temperature in SMHI weather provider
|
||||
- Ensure updatenotification module isn't shown when local is _ahead_ of remote
|
||||
- Handle node_helper errors during startup (#2944)
|
||||
- Possibility to change FontAwesome class in calendar, so icons like `fab fa-facebook-square` works.
|
||||
- Fix cors problems with newsfeed articles (as far as possible), allow disabling cors per feed with option `useCorsProxy: false` (#2840)
|
||||
- Tests not waiting for the application to start and stop before starting the next test
|
||||
- Fix electron tests failing sometimes in github workflow
|
||||
- Fixed gap in clock module when displayed on the left side with displayType=digital
|
||||
- Fixed playwright issue by upgrading to v1.29.1 (#2969)
|
||||
|
||||
## [2.21.0] - 2022-10-01
|
||||
|
||||
Special thanks to: @BKeyport, @buxxi, @davide125, @khassel, @kolbyjack, @krukle, @MikeBishop, @rejas, @sdetweil, @SkySails and @veeck
|
||||
|
||||
### Added
|
||||
|
||||
- Added possibility to fetch calendars through socket notifications.
|
||||
- New scripts `install-mm` (and `install-mm:dev`) for simplifying mm installation (now: `npm run install-mm`) and adding params `--no-audit --no-fund --no-update-notifier` for less noise.
|
||||
- New `showTimeToday` option in calendar module shows time for current-day events even if `timeFormat` is `"relative"`.
|
||||
- Added hourly forecasts, apparent temperature & custom location name to SMHI weather provider.
|
||||
- Added new electron tests for calendar and moved some compliments tests from `e2e` to `electron` because of date mocking, removed mock stuff from compliments module.
|
||||
|
||||
### Removed
|
||||
|
||||
- Removed old and deprecated weather modules `currentweather` and `weatherforecast`.
|
||||
- Removed `DAYAFTERTOMORROW` from English.
|
||||
|
||||
### Updated
|
||||
|
||||
- Updated dependencies.
|
||||
- Updated jsdoc.
|
||||
- Updated font tree to use variables consistently.
|
||||
- Removed deprecated Docker Repository from issue template.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Broadcast all calendar events while still honoring global and per-calendar maximumEntries.
|
||||
- Respect rss ttl provided by newsfeed (#2883).
|
||||
- Fix multi day calendar events always presented as "(1/X)" instead of the amount of days the event has progressed.
|
||||
- Fix weatherbit provider to use type config value instead of endpoint.
|
||||
- Fix calendar events which DO NOT specify rrule byday adjusted incorrectly (#2885).
|
||||
- Fix e2e tests not failing on errors (#2911).
|
||||
|
||||
## [2.20.0] - 2022-07-02
|
||||
|
||||
Special thanks to the following contributors: @eouia, @khassel, @kolbyjack, @KristjanESPERANTO, @nathannaveen, @naveensrinivasan, @rejas, @rohitdharavath and @sdetweil.
|
||||
|
||||
### Added
|
||||
|
||||
- Added a new config option `httpHeaders` used by helmet (see https://helmetjs.github.io/). You can now set own httpHeaders which will override the defaults in `js/defauls.js` which is useful e.g. if you want to embed MagicMirror into annother website (solves #2847).
|
||||
- Show endDate for calendar events when dateHeader is enabled and showEnd is set to true (#2192).
|
||||
- Added the notification emitting from the weather module on information updated.
|
||||
- Use recommended file extension for YAML files (#2864).
|
||||
|
||||
### Updated
|
||||
|
||||
- Use latest node 18 when running tests on github actions.
|
||||
- Updated `electron` to v19 and other dependencies.
|
||||
- Use internal fetch function of node instead external `node-fetch` library if used node version >= `v18`.
|
||||
- Include duplicate events in broadcasts.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix problems with non latin fonds caused by updating to fontsource (fixes #2835).
|
||||
|
||||
## [2.19.0] - 2022-04-01
|
||||
|
||||
Special thanks to the following contributors: @10bias, @CFenner, @JHWelch, @k1rd3rf, @khassel, @kolbyjack, @krekos, @KristjanESPERANTO, @Nerfzooka, @oraclesean, @oscarb, @philnagel, @rejas, @sdetweil, @shin10, @SiderealArt and @Tom-Hirschberger.
|
||||
@@ -12,9 +118,9 @@ Special thanks to the following contributors: @10bias, @CFenner, @JHWelch, @k1rd
|
||||
### Added
|
||||
|
||||
- Added a config option under the weather module, `absoluteDates`, providing an option to format weather forecast date output with either absolute or relative dates.
|
||||
- Added test for new weather forecast `absoluteDates` porperty.
|
||||
- Added test for new weather forecast `absoluteDates` property.
|
||||
- The modules get a class hidden added/removed if they get hidden/shown which will also toggle pointer-events.
|
||||
- Added new config option `showTitleAsUrl` to newsfeed module. If set, the diplayed title is a link to the article which is useful when running in a browser and you want to read this article.
|
||||
- Added new config option `showTitleAsUrl` to newsfeed module. If set, the displayed title is a link to the article which is useful when running in a browser and you want to read this article.
|
||||
- Added internal cors proxy to get weather providers working without public proxies (fixes #2714). The new url `http(s)://address:port/cors?url=https://whatever-to-proxy` can be used in other modules too.
|
||||
- Added a WeatherProvider for Weatherflow.
|
||||
- Added new env var `ELECTRON_DISABLE_GPU` which disable gpu under electron if set (fixes #2831).
|
||||
@@ -23,12 +129,12 @@ Special thanks to the following contributors: @10bias, @CFenner, @JHWelch, @k1rd
|
||||
### Updated
|
||||
|
||||
- Deprecated roboto fonts package `roboto-fontface-bower` replaced with `fontsource`.
|
||||
- Update `electron` to v17, `helmet` to v5 (use defaults of v4) and other dependencies
|
||||
- Updates Font Awesome css class to new default style (fixes #2768)
|
||||
- Updated `electron` to v17, `helmet` to v5 (use defaults of v4) and other dependencies
|
||||
- Updated Font Awesome css class to new default style (fixes #2768)
|
||||
- Replaced deprecated modules `currentweather` and `weatherforecast` with dummy modules only displaying that they have to be replaced.
|
||||
- Include all calendar events from the configured date range when broadcasting.
|
||||
- Update Danish and German translation.
|
||||
- Update `node-ical` to v0.15 and added `luxon` as dependency for not breaking the "no-optional" install (see #2718 and #2824).
|
||||
- Updated Danish and German translation.
|
||||
- Updated `node-ical` to v0.15 and added `luxon` as dependency for not breaking the "no-optional" install (see #2718 and #2824).
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -39,6 +145,7 @@ Special thanks to the following contributors: @10bias, @CFenner, @JHWelch, @k1rd
|
||||
- Don't adjust startDate for full day events if endDate is in the past.
|
||||
- Fix windspeed conversion error in openweathermap provider. (#2812)
|
||||
- Fix conflicting parms turning off showEnd for full day events. (#2629)
|
||||
- Fix regression, calendar.maximumEntries not used to filter calendar level entries (#2868)
|
||||
|
||||
## [2.18.0] - 2022-01-01
|
||||
|
||||
@@ -53,8 +160,8 @@ Special thanks to the following contributors: @AmpioRosso, @eouia, @fewieden, @j
|
||||
- ESLint version supports now ECMAScript 2018.
|
||||
- Cleaned up `updatenotification` module and switched to nunjuck template.
|
||||
- Moved calendar tests from category `electron` to `e2e`.
|
||||
- Update missed translations for Korean language (ko.json).
|
||||
- Update missed translations for Dutch language (nl.json).
|
||||
- Updated missed translations for Korean language (ko.json).
|
||||
- Updated missed translations for Dutch language (nl.json).
|
||||
- Cleaned up `alert` module and switched to nunjuck template.
|
||||
- Moved weather tests from category `electron` to `e2e`.
|
||||
- Updated github actions.
|
||||
@@ -105,14 +212,14 @@ Special thanks to the following contributors: @apiontek, @eouia, @jupadin, @khas
|
||||
- Refactor test configs, use default test config for all tests.
|
||||
- Updated github templates.
|
||||
- Actually test all js and css files when lint script is run.
|
||||
- Update jsdocs and print warnings during testing too.
|
||||
- Update weathergov provider to try fetching not just current, but also foreacst, when API URLs available.
|
||||
- Updated jsdocs and print warnings during testing too.
|
||||
- Updated weathergov provider to try fetching not just current, but also foreacst, when API URLs available.
|
||||
- Refactored clock layout.
|
||||
- Refactored methods from weatherproviders into weatherobject (isDaytime, updateSunTime).
|
||||
- Use of `logger.js` in jest tests.
|
||||
- Run prettier over all relevant files.
|
||||
- Move tests needing electron in new category `electron`, use `server only` mode in `e2e` tests.
|
||||
- Update dependencies in package.json.
|
||||
- Updated dependencies in package.json.
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -146,13 +253,13 @@ Special thanks to the following contributors: @210954, @B1gG, @codac, @Crazylegs
|
||||
- Refactor code into es6 where possible (e.g. var -> let/const).
|
||||
- Use node v16 in github workflow (replacing node v10).
|
||||
- Moved some files into better suited directories.
|
||||
- Update dependencies in package.json, require node >= v12, remove `rrule-alt` and `rrule`.
|
||||
- Update dependencies in package.json and migrate husky to v6, fix husky setup in prod environment.
|
||||
- Updated dependencies in package.json, require node >= v12, remove `rrule-alt` and `rrule`.
|
||||
- Updated dependencies in package.json and migrate husky to v6, fix husky setup in prod environment.
|
||||
- Cleaned up error handling in newsfeed and calendar modules for real.
|
||||
- Updated default WEATHER module such that a provider can optionally set a custom unit-of-measure for precipitation (`weatherObject.precipitationUnits`).
|
||||
- Update documentation.
|
||||
- Update jest tests: Reset changes on js/logger.js, mock logger.js in global_vars tests.
|
||||
- Update dependencies in package.json.
|
||||
- Updated documentation.
|
||||
- Updated jest tests: Reset changes on js/logger.js, mock logger.js in global_vars tests.
|
||||
- Updated dependencies in package.json.
|
||||
|
||||
### Removed
|
||||
|
||||
@@ -264,10 +371,10 @@ Special thanks to the following contributors: @Alvinger, @AndyPoms, @ashishtank,
|
||||
|
||||
- Merging .gitignore in the config-folder with the .gitignore in the root-folder.
|
||||
- Weather module - forecast now show TODAY and TOMORROW instead of weekday, to make it easier to understand.
|
||||
- Update dependencies to latest versions.
|
||||
- Update dependencies eslint, feedme, simple-git and socket.io to latest versions.
|
||||
- Update lithuanian translation.
|
||||
- Update config sample.
|
||||
- Updated dependencies to latest versions.
|
||||
- Updated dependencies eslint, feedme, simple-git and socket.io to latest versions.
|
||||
- Updated lithuanian translation.
|
||||
- Updated config sample.
|
||||
- Highlight required version mismatch.
|
||||
- No select Text for TouchScreen use.
|
||||
- Corrected logic for timeFormat "relative" and "absolute".
|
||||
@@ -295,12 +402,12 @@ Special thanks to the following contributors: @Alvinger, @AndyPoms, @ashishtank,
|
||||
- Catch errors when parsing calendar data with ical. (#2022)
|
||||
- Fix Default Alert Module does not hide black overlay when alert is dismissed manually. (#2228)
|
||||
- Weather module - Always displays night icons when local is other than English. (#2221)
|
||||
- Update node-ical 0.12.4, fix invalid RRULE format in cal entries
|
||||
- Updated node-ical 0.12.4, fix invalid RRULE format in cal entries
|
||||
- Fix package.json for optional electron dependency (2378)
|
||||
- Update node-ical version again, 0.12.5, change RRULE fix (#2371, #2379)
|
||||
- Updated node-ical version again, 0.12.5, change RRULE fix (#2371, #2379)
|
||||
- Remove undefined objects from modules array (#2382)
|
||||
- Update node-ical version again, 0.12.7, change RRULE fix (#2371, #2379), node-ical now throws error (which we catch)
|
||||
- Update simple-git version to 2.31 unhandled promise rejection (#2383)
|
||||
- Updated node-ical version again, 0.12.7, change RRULE fix (#2371, #2379), node-ical now throws error (which we catch)
|
||||
- Updated simple-git version to 2.31 unhandled promise rejection (#2383)
|
||||
|
||||
## [2.13.0] - 2020-10-01
|
||||
|
||||
@@ -525,10 +632,10 @@ Special thanks to @sdetweil for all his great contributions!
|
||||
|
||||
- English translation for "Feels" to "Feels like"
|
||||
- Fixed the example calendar url in `config.js.sample`
|
||||
- Update `ical.js` to solve various calendar issues.
|
||||
- Update weather city list url [#1676](https://github.com/MichMich/MagicMirror/issues/1676)
|
||||
- Updated `ical.js` to solve various calendar issues.
|
||||
- Updated weather city list url [#1676](https://github.com/MichMich/MagicMirror/issues/1676)
|
||||
- Only update clock once per minute when seconds aren't shown
|
||||
- Update weatherprovider documentation.
|
||||
- Updated weatherprovider documentation.
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -548,7 +655,7 @@ Special thanks to @sdetweil for all his great contributions!
|
||||
- use current username vs hardcoded 'pi' to support non-pi install
|
||||
- check for npm installed. node install doesn't do npm anymore
|
||||
- check for mac as part of PM2 install, add install option string
|
||||
- update pm2 config with current username instead of hard coded 'pi'
|
||||
- Updated pm2 config with current username instead of hard coded 'pi'
|
||||
- check for screen saver config, "/etc/xdg/lxsession", bypass if not setup
|
||||
|
||||
## [2.7.1] - 2019-04-02
|
||||
@@ -756,7 +863,7 @@ A huge, huge, huge thanks to user @fewieden for all his hard work on the new `we
|
||||
- Add types for module.
|
||||
- Implement Danger.js to notify contributors when CHANGELOG.md is missing in PR.
|
||||
- Allow scrolling in full page article view of default newsfeed module with gesture events from [MMM-Gestures](https://github.com/thobach/MMM-Gestures)
|
||||
- Changed 'compliments.js' - update DOM if remote compliments are loaded instead of waiting one updateInterval to show custom compliments
|
||||
- Changed 'compliments.js' - Updated DOM if remote compliments are loaded instead of waiting one updateInterval to show custom compliments
|
||||
- Automated unit tests utils, deprecated, translator, cloneObject(lockstrings)
|
||||
- Automated integration tests translations
|
||||
- Add advanced filtering to the excludedEvents configuration of the default calendar module
|
||||
@@ -768,7 +875,7 @@ A huge, huge, huge thanks to user @fewieden for all his hard work on the new `we
|
||||
|
||||
- Add link to GitHub repository which contains the respective Dockerfile.
|
||||
- Optimized automated unit tests cloneObject, cmpVersions
|
||||
- Update notifications use now translation templates instead of normal strings.
|
||||
- Updated notifications use now translation templates instead of normal strings.
|
||||
- Yarn can be used now as an installation tool
|
||||
- Changed Electron dependency to v1.7.13.
|
||||
|
||||
@@ -975,7 +1082,7 @@ A huge, huge, huge thanks to user @fewieden for all his hard work on the new `we
|
||||
|
||||
### Fixed
|
||||
|
||||
- Update .gitignore to not ignore default modules folder.
|
||||
- Updated .gitignore to not ignore default modules folder.
|
||||
- Remove white flash on boot up.
|
||||
- Added `update` in Raspberry Pi installation script.
|
||||
- Fix an issue where the analog clock looked scrambled. ([#611](https://github.com/MichMich/MagicMirror/issues/611))
|
||||
@@ -1060,8 +1167,8 @@ A huge, huge, huge thanks to user @fewieden for all his hard work on the new `we
|
||||
### Updated
|
||||
|
||||
- Force fullscreen when kioskmode is active.
|
||||
- Update the .github templates and information with more modern information.
|
||||
- Update the Gruntfile with a more functional StyleLint implementation.
|
||||
- Updated the .github templates and information with more modern information.
|
||||
- Updated the Gruntfile with a more functional StyleLint implementation.
|
||||
|
||||
## [2.0.4] - 2016-08-07
|
||||
|
||||
|
12
Collaboration.md
Normal file
12
Collaboration.md
Normal file
@@ -0,0 +1,12 @@
|
||||
This document describes how collaborators of this repository should work together.
|
||||
|
||||
## Pull Requests
|
||||
|
||||
- never merge your own PR's
|
||||
- never merge without someone having approved (approving and merging from same person is allowed)
|
||||
- wait for all approvals requested (or the author decides something different in the comments)
|
||||
|
||||
## Issues
|
||||
|
||||
- "real" Issues are closed if the problem is solved and the fix is released
|
||||
- unrelated Issues (e.g. related to a foreign module) are closed immediately with a comment to open an issue in the module repository or to discuss this further in the forum or discord
|
@@ -1,6 +1,6 @@
|
||||
# The MIT License (MIT)
|
||||
|
||||
Copyright © 2016-2021 Michael Teeuw
|
||||
Copyright © 2016-2022 Michael Teeuw
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
|
18
css/main.css
18
css/main.css
@@ -8,7 +8,11 @@
|
||||
--font-secondary: "Roboto";
|
||||
|
||||
--font-size: 20px;
|
||||
--font-size-small: 0.75rem;
|
||||
--font-size-xsmall: 0.75rem;
|
||||
--font-size-small: 1rem;
|
||||
--font-size-medium: 1.5rem;
|
||||
--font-size-large: 3.25rem;
|
||||
--font-size-xlarge: 3.75rem;
|
||||
|
||||
--gap-body-top: 60px;
|
||||
--gap-body-right: 60px;
|
||||
@@ -60,27 +64,27 @@ body {
|
||||
}
|
||||
|
||||
.xsmall {
|
||||
font-size: var(--font-size-small);
|
||||
font-size: var(--font-size-xsmall);
|
||||
line-height: 1.275;
|
||||
}
|
||||
|
||||
.small {
|
||||
font-size: 1rem;
|
||||
font-size: var(--font-size-small);
|
||||
line-height: 1.25;
|
||||
}
|
||||
|
||||
.medium {
|
||||
font-size: 1.5rem;
|
||||
font-size: var(--font-size-medium);
|
||||
line-height: 1.225;
|
||||
}
|
||||
|
||||
.large {
|
||||
font-size: 3.25rem;
|
||||
font-size: var(--font-size-large);
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.xlarge {
|
||||
font-size: 3.75rem;
|
||||
font-size: var(--font-size-xlarge);
|
||||
line-height: 1;
|
||||
letter-spacing: -3px;
|
||||
}
|
||||
@@ -115,7 +119,7 @@ body {
|
||||
|
||||
header {
|
||||
text-transform: uppercase;
|
||||
font-size: var(--font-size-small);
|
||||
font-size: var(--font-size-xsmall);
|
||||
font-family: var(--font-primary), Arial, Helvetica, sans-serif;
|
||||
font-weight: 400;
|
||||
border-bottom: 1px solid var(--color-text-dimmed);
|
||||
|
28
fonts/package-lock.json
generated
28
fonts/package-lock.json
generated
@@ -7,31 +7,31 @@
|
||||
"name": "magicmirror-fonts",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@fontsource/roboto": "^4.5.5",
|
||||
"@fontsource/roboto-condensed": "^4.5.6"
|
||||
"@fontsource/roboto": "^4.5.8",
|
||||
"@fontsource/roboto-condensed": "^4.5.9"
|
||||
}
|
||||
},
|
||||
"node_modules/@fontsource/roboto": {
|
||||
"version": "4.5.5",
|
||||
"resolved": "https://registry.npmjs.org/@fontsource/roboto/-/roboto-4.5.5.tgz",
|
||||
"integrity": "sha512-Pe1p+gAO6K0aLxBXlLoJRHVx352tVc/v/7DOnvM3t+FYXb+KUga9aCD1NpnDfd0kKnWXqrZyAXguyyFWDDuphw=="
|
||||
"version": "4.5.8",
|
||||
"resolved": "https://registry.npmjs.org/@fontsource/roboto/-/roboto-4.5.8.tgz",
|
||||
"integrity": "sha512-CnD7zLItIzt86q4Sj3kZUiLcBk1dSk81qcqgMGaZe7SQ1P8hFNxhMl5AZthK1zrDM5m74VVhaOpuMGIL4gagaA=="
|
||||
},
|
||||
"node_modules/@fontsource/roboto-condensed": {
|
||||
"version": "4.5.6",
|
||||
"resolved": "https://registry.npmjs.org/@fontsource/roboto-condensed/-/roboto-condensed-4.5.6.tgz",
|
||||
"integrity": "sha512-WDN0RlwXa3ADUDJxrB9HEIhrwYdJFLTNw4YemEYSeIPURU5DAHSx2VFXFv69PbM7kV8At5yMTp8bQkL5TBUP3w=="
|
||||
"version": "4.5.9",
|
||||
"resolved": "https://registry.npmjs.org/@fontsource/roboto-condensed/-/roboto-condensed-4.5.9.tgz",
|
||||
"integrity": "sha512-ql4sQq+h8puBVildZ5ssjYf8DWDONYDe3PD3Bu/p1ZW9GnRETRNPPcCTs/q62HIl3QimwwkiKWynn6wZhQaetg=="
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@fontsource/roboto": {
|
||||
"version": "4.5.5",
|
||||
"resolved": "https://registry.npmjs.org/@fontsource/roboto/-/roboto-4.5.5.tgz",
|
||||
"integrity": "sha512-Pe1p+gAO6K0aLxBXlLoJRHVx352tVc/v/7DOnvM3t+FYXb+KUga9aCD1NpnDfd0kKnWXqrZyAXguyyFWDDuphw=="
|
||||
"version": "4.5.8",
|
||||
"resolved": "https://registry.npmjs.org/@fontsource/roboto/-/roboto-4.5.8.tgz",
|
||||
"integrity": "sha512-CnD7zLItIzt86q4Sj3kZUiLcBk1dSk81qcqgMGaZe7SQ1P8hFNxhMl5AZthK1zrDM5m74VVhaOpuMGIL4gagaA=="
|
||||
},
|
||||
"@fontsource/roboto-condensed": {
|
||||
"version": "4.5.6",
|
||||
"resolved": "https://registry.npmjs.org/@fontsource/roboto-condensed/-/roboto-condensed-4.5.6.tgz",
|
||||
"integrity": "sha512-WDN0RlwXa3ADUDJxrB9HEIhrwYdJFLTNw4YemEYSeIPURU5DAHSx2VFXFv69PbM7kV8At5yMTp8bQkL5TBUP3w=="
|
||||
"version": "4.5.9",
|
||||
"resolved": "https://registry.npmjs.org/@fontsource/roboto-condensed/-/roboto-condensed-4.5.9.tgz",
|
||||
"integrity": "sha512-ql4sQq+h8puBVildZ5ssjYf8DWDONYDe3PD3Bu/p1ZW9GnRETRNPPcCTs/q62HIl3QimwwkiKWynn6wZhQaetg=="
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@
|
||||
"url": "https://github.com/MichMich/MagicMirror/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fontsource/roboto": "^4.5.5",
|
||||
"@fontsource/roboto-condensed": "^4.5.6"
|
||||
"@fontsource/roboto": "^4.5.8",
|
||||
"@fontsource/roboto-condensed": "^4.5.9"
|
||||
}
|
||||
}
|
||||
|
@@ -2,57 +2,54 @@
|
||||
font-family: Roboto;
|
||||
font-style: normal;
|
||||
font-weight: 100;
|
||||
src: local("Roboto Thin"), local("Roboto-Thin"), url("node_modules/@fontsource/roboto/files/roboto-latin-100-normal.woff2") format("woff2"), url("node_modules/@fontsource/roboto/files/roboto-latin-100-normal.woff") format("woff");
|
||||
src: local("Roboto Thin"), local("Roboto-Thin"), url("node_modules/@fontsource/roboto/files/roboto-all-100-normal.woff") format("woff");
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "Roboto Condensed";
|
||||
font-style: normal;
|
||||
font-weight: 300;
|
||||
src: local("Roboto Condensed Light"), local("RobotoCondensed-Light"), url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-latin-300-normal.woff2") format("woff2"),
|
||||
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-latin-300-normal.woff") format("woff");
|
||||
src: local("Roboto Condensed Light"), local("RobotoCondensed-Light"), url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-all-300-normal.woff") format("woff");
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "Roboto Condensed";
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local("Roboto Condensed"), local("RobotoCondensed-Regular"), url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-latin-400-normal.woff2") format("woff2"),
|
||||
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-latin-400-normal.woff") format("woff");
|
||||
src: local("Roboto Condensed"), local("RobotoCondensed-Regular"), url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-all-400-normal.woff") format("woff");
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "Roboto Condensed";
|
||||
font-style: normal;
|
||||
font-weight: 700;
|
||||
src: local("Roboto Condensed Bold"), local("RobotoCondensed-Bold"), url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-latin-700-normal.woff2") format("woff2"),
|
||||
url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-latin-700-normal.woff") format("woff");
|
||||
src: local("Roboto Condensed Bold"), local("RobotoCondensed-Bold"), url("node_modules/@fontsource/roboto-condensed/files/roboto-condensed-all-700-normal.woff") format("woff");
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: Roboto;
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local("Roboto"), local("Roboto-Regular"), url("node_modules/@fontsource/roboto/files/roboto-latin-400-normal.woff2") format("woff2"), url("node_modules/@fontsource/roboto/files/roboto-latin-400-normal.woff") format("woff");
|
||||
src: local("Roboto"), local("Roboto-Regular"), url("node_modules/@fontsource/roboto/files/roboto-all-400-normal.woff") format("woff");
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: Roboto;
|
||||
font-style: normal;
|
||||
font-weight: 500;
|
||||
src: local("Roboto Medium"), local("Roboto-Medium"), url("node_modules/@fontsource/roboto/files/roboto-latin-500-normal.woff2") format("woff2"), url("node_modules/@fontsource/roboto/files/roboto-latin-500-normal.woff") format("woff");
|
||||
src: local("Roboto Medium"), local("Roboto-Medium"), url("node_modules/@fontsource/roboto/files/roboto-all-500-normal.woff") format("woff");
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: Roboto;
|
||||
font-style: normal;
|
||||
font-weight: 700;
|
||||
src: local("Roboto Bold"), local("Roboto-Bold"), url("node_modules/@fontsource/roboto/files/roboto-latin-700-normal.woff2") format("woff2"), url("node_modules/@fontsource/roboto/files/roboto-latin-700-normal.woff") format("woff");
|
||||
src: local("Roboto Bold"), local("Roboto-Bold"), url("node_modules/@fontsource/roboto/files/roboto-all-700-normal.woff") format("woff");
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: Roboto;
|
||||
font-style: normal;
|
||||
font-weight: 300;
|
||||
src: local("Roboto Light"), local("Roboto-Light"), url("node_modules/@fontsource/roboto/files/roboto-latin-300-normal.woff2") format("woff2"), url("node_modules/@fontsource/roboto/files/roboto-latin-300-normal.woff") format("woff");
|
||||
src: local("Roboto Light"), local("Roboto-Light"), url("node_modules/@fontsource/roboto/files/roboto-all-300-normal.woff") format("woff");
|
||||
}
|
||||
|
32
jest.config.js
Normal file
32
jest.config.js
Normal file
@@ -0,0 +1,32 @@
|
||||
module.exports = async () => {
|
||||
return {
|
||||
verbose: true,
|
||||
testTimeout: 20000,
|
||||
testSequencer: "<rootDir>/tests/configs/test_sequencer.js",
|
||||
projects: [
|
||||
{
|
||||
displayName: "unit",
|
||||
moduleNameMapper: {
|
||||
logger: "<rootDir>/js/logger.js"
|
||||
},
|
||||
testMatch: ["**/tests/unit/**/*.[jt]s?(x)"],
|
||||
testPathIgnorePatterns: ["<rootDir>/tests/unit/mocks"]
|
||||
},
|
||||
{
|
||||
displayName: "electron",
|
||||
testMatch: ["**/tests/electron/**/*.[jt]s?(x)"],
|
||||
testPathIgnorePatterns: ["<rootDir>/tests/electron/helpers/"]
|
||||
},
|
||||
{
|
||||
displayName: "e2e",
|
||||
setupFilesAfterEnv: ["<rootDir>/tests/e2e/helpers/mock-console.js"],
|
||||
testMatch: ["**/tests/e2e/**/*.[jt]s?(x)"],
|
||||
modulePaths: ["<rootDir>/js/"],
|
||||
testPathIgnorePatterns: ["<rootDir>/tests/e2e/helpers/", "<rootDir>/tests/e2e/mocks"]
|
||||
}
|
||||
],
|
||||
collectCoverageFrom: ["./clientonly/**/*.js", "./js/**/*.js", "./modules/**/*.js", "./serveronly/**/*.js"],
|
||||
coverageReporters: ["lcov", "text"],
|
||||
coverageProvider: "v8"
|
||||
};
|
||||
};
|
37
js/app.js
37
js/app.js
@@ -222,18 +222,33 @@ function App() {
|
||||
}
|
||||
}
|
||||
|
||||
loadModules(modules, function () {
|
||||
httpServer = new Server(config, function (app, io) {
|
||||
Log.log("Server started ...");
|
||||
loadModules(modules, async function () {
|
||||
httpServer = new Server(config);
|
||||
const { app, io } = await httpServer.open();
|
||||
Log.log("Server started ...");
|
||||
|
||||
for (let nodeHelper of nodeHelpers) {
|
||||
nodeHelper.setExpressApp(app);
|
||||
nodeHelper.setSocketIO(io);
|
||||
nodeHelper.start();
|
||||
const nodePromises = [];
|
||||
for (let nodeHelper of nodeHelpers) {
|
||||
nodeHelper.setExpressApp(app);
|
||||
nodeHelper.setSocketIO(io);
|
||||
|
||||
try {
|
||||
nodePromises.push(nodeHelper.start());
|
||||
} catch (error) {
|
||||
Log.error(`Error when starting node_helper for module ${nodeHelper.name}:`);
|
||||
Log.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
Promise.allSettled(nodePromises).then((results) => {
|
||||
// Log errors that happened during async node_helper startup
|
||||
results.forEach((result) => {
|
||||
if (result.status === "rejected") {
|
||||
Log.error(result.reason);
|
||||
}
|
||||
});
|
||||
|
||||
Log.log("Sockets connected & modules started ...");
|
||||
|
||||
if (typeof callback === "function") {
|
||||
callback(config);
|
||||
}
|
||||
@@ -247,14 +262,16 @@ function App() {
|
||||
* exists.
|
||||
*
|
||||
* Added to fix #1056
|
||||
*
|
||||
* @param {Function} callback Function to be called after the app has stopped
|
||||
*/
|
||||
this.stop = function () {
|
||||
this.stop = function (callback) {
|
||||
for (const nodeHelper of nodeHelpers) {
|
||||
if (typeof nodeHelper.stop === "function") {
|
||||
nodeHelper.stop();
|
||||
}
|
||||
}
|
||||
httpServer.close();
|
||||
httpServer.close().then(callback);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@@ -25,6 +25,9 @@ const defaults = {
|
||||
units: "metric",
|
||||
zoom: 1,
|
||||
customCss: "css/custom.css",
|
||||
// httpHeaders used by helmet, see https://helmetjs.github.io/. You can add other/more object values by overriding this in config.js,
|
||||
// e.g. you need to add `frameguard: false` for embedding MagicMirror in another website, see https://github.com/MichMich/MagicMirror/issues/2847
|
||||
httpHeaders: { contentSecurityPolicy: false, crossOriginOpenerPolicy: false, crossOriginEmbedderPolicy: false, crossOriginResourcePolicy: false, originAgentCluster: false },
|
||||
|
||||
modules: [
|
||||
{
|
||||
|
@@ -8,7 +8,7 @@ const Log = require("logger");
|
||||
let config = process.env.config ? JSON.parse(process.env.config) : {};
|
||||
// Module to control application life.
|
||||
const app = electron.app;
|
||||
// If ELECTRON_DISABLE_GPU is set electron is startet with --disable-gpu flag.
|
||||
// If ELECTRON_DISABLE_GPU is set electron is started with --disable-gpu flag.
|
||||
// See https://www.electronjs.org/docs/latest/tutorial/offscreen-rendering for more info.
|
||||
if (process.env.ELECTRON_DISABLE_GPU !== undefined) {
|
||||
app.disableHardwareAcceleration();
|
||||
@@ -103,6 +103,20 @@ function createWindow() {
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
|
||||
//remove response headers that prevent sites of being embedded into iframes if configured
|
||||
mainWindow.webContents.session.webRequest.onHeadersReceived((details, callback) => {
|
||||
let curHeaders = details.responseHeaders;
|
||||
if (config["ignoreXOriginHeader"] || false) {
|
||||
curHeaders = Object.fromEntries(Object.entries(curHeaders).filter((header) => !/x-frame-options/i.test(header[0])));
|
||||
}
|
||||
|
||||
if (config["ignoreContentSecurityPolicy"] || false) {
|
||||
curHeaders = Object.fromEntries(Object.entries(curHeaders).filter((header) => !/content-security-policy/i.test(header[0])));
|
||||
}
|
||||
|
||||
callback({ responseHeaders: curHeaders });
|
||||
});
|
||||
}
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
|
28
js/fetch.js
Normal file
28
js/fetch.js
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Helper class to provide either third party fetch library or (if node >= 18)
|
||||
* return internal node fetch implementation.
|
||||
*
|
||||
* Attention: After some discussion we always return the third party
|
||||
* implementation until the node implementation is stable and more tested
|
||||
*
|
||||
* @see https://github.com/MichMich/MagicMirror/pull/2952
|
||||
* @see https://github.com/MichMich/MagicMirror/issues/2649
|
||||
* @param {string} url to be fetched
|
||||
* @param {object} options object e.g. for headers
|
||||
* @class
|
||||
*/
|
||||
async function fetch(url, options = {}) {
|
||||
// const nodeVersion = process.version.match(/^v(\d+)\.*/)[1];
|
||||
// if (nodeVersion >= 18) {
|
||||
// // node version >= 18
|
||||
// return global.fetch(url, options);
|
||||
// } else {
|
||||
// // node version < 18
|
||||
// const nodefetch = require("node-fetch");
|
||||
// return nodefetch(url, options);
|
||||
// }
|
||||
const nodefetch = require("node-fetch");
|
||||
return nodefetch(url, options);
|
||||
}
|
||||
|
||||
module.exports = fetch;
|
@@ -70,7 +70,7 @@ const MM = (function () {
|
||||
* Select the wrapper dom object for a specific position.
|
||||
*
|
||||
* @param {string} position The name of the position.
|
||||
* @returns {HTMLElement} the wrapper element
|
||||
* @returns {HTMLElement | void} the wrapper element
|
||||
*/
|
||||
const selectWrapper = function (position) {
|
||||
const classes = position.replace("_", " ");
|
||||
|
@@ -22,39 +22,38 @@ const NodeHelper = Class.extend({
|
||||
Log.log(`Starting module helper: ${this.name}`);
|
||||
},
|
||||
|
||||
/* stop()
|
||||
/**
|
||||
* Called when the MagicMirror² server receives a `SIGINT`
|
||||
* Close any open connections, stop any sub-processes and
|
||||
* gracefully exit the module.
|
||||
*
|
||||
*/
|
||||
stop() {
|
||||
Log.log(`Stopping module helper: ${this.name}`);
|
||||
},
|
||||
|
||||
/* socketNotificationReceived(notification, payload)
|
||||
/**
|
||||
* This method is called when a socket notification arrives.
|
||||
*
|
||||
* argument notification string - The identifier of the notification.
|
||||
* argument payload mixed - The payload of the notification.
|
||||
* @param {string} notification The identifier of the notification.
|
||||
* @param {*} payload The payload of the notification.
|
||||
*/
|
||||
socketNotificationReceived(notification, payload) {
|
||||
Log.log(`${this.name} received a socket notification: ${notification} - Payload: ${payload}`);
|
||||
},
|
||||
|
||||
/* setName(name)
|
||||
/**
|
||||
* Set the module name.
|
||||
*
|
||||
* argument name string - Module name.
|
||||
* @param {string} name Module name.
|
||||
*/
|
||||
setName(name) {
|
||||
this.name = name;
|
||||
},
|
||||
|
||||
/* setPath(path)
|
||||
/**
|
||||
* Set the module path.
|
||||
*
|
||||
* argument path string - Module path.
|
||||
* @param {string} path Module path.
|
||||
*/
|
||||
setPath(path) {
|
||||
this.path = path;
|
||||
|
182
js/server.js
182
js/server.js
@@ -5,136 +5,114 @@
|
||||
* MIT Licensed.
|
||||
*/
|
||||
const express = require("express");
|
||||
const app = require("express")();
|
||||
const path = require("path");
|
||||
const ipfilter = require("express-ipfilter").IpFilter;
|
||||
const fs = require("fs");
|
||||
const helmet = require("helmet");
|
||||
const fetch = require("node-fetch");
|
||||
|
||||
const Log = require("logger");
|
||||
const Utils = require("./utils.js");
|
||||
const { cors, getConfig, getHtml, getVersion } = require("./server_functions.js");
|
||||
|
||||
/**
|
||||
* Server
|
||||
*
|
||||
* @param {object} config The MM config
|
||||
* @param {Function} callback Function called when done.
|
||||
* @class
|
||||
*/
|
||||
function Server(config, callback) {
|
||||
function Server(config) {
|
||||
const app = express();
|
||||
const port = process.env.MM_PORT || config.port;
|
||||
const serverSockets = new Set();
|
||||
|
||||
let server = null;
|
||||
if (config.useHttps) {
|
||||
const options = {
|
||||
key: fs.readFileSync(config.httpsPrivateKey),
|
||||
cert: fs.readFileSync(config.httpsCertificate)
|
||||
};
|
||||
server = require("https").Server(options, app);
|
||||
} else {
|
||||
server = require("http").Server(app);
|
||||
}
|
||||
const io = require("socket.io")(server, {
|
||||
cors: {
|
||||
origin: /.*$/,
|
||||
credentials: true
|
||||
},
|
||||
allowEIO3: true
|
||||
});
|
||||
|
||||
server.on("connection", (socket) => {
|
||||
serverSockets.add(socket);
|
||||
socket.on("close", () => {
|
||||
serverSockets.delete(socket);
|
||||
});
|
||||
});
|
||||
|
||||
Log.log(`Starting server on port ${port} ... `);
|
||||
|
||||
server.listen(port, config.address || "localhost");
|
||||
|
||||
if (config.ipWhitelist instanceof Array && config.ipWhitelist.length === 0) {
|
||||
Log.warn(Utils.colors.warn("You're using a full whitelist configuration to allow for all IPs"));
|
||||
}
|
||||
|
||||
app.use(function (req, res, next) {
|
||||
ipfilter(config.ipWhitelist, { mode: config.ipWhitelist.length === 0 ? "deny" : "allow", log: false })(req, res, function (err) {
|
||||
if (err === undefined) {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
return next();
|
||||
}
|
||||
Log.log(err.message);
|
||||
res.status(403).send("This device is not allowed to access your mirror. <br> Please check your config.js or config.js.sample to change this.");
|
||||
});
|
||||
});
|
||||
app.use(helmet({ contentSecurityPolicy: false, crossOriginOpenerPolicy: false, crossOriginEmbedderPolicy: false, crossOriginResourcePolicy: false, originAgentCluster: false }));
|
||||
|
||||
app.use("/js", express.static(__dirname));
|
||||
|
||||
const directories = ["/config", "/css", "/fonts", "/modules", "/vendor", "/translations", "/tests/configs"];
|
||||
for (const directory of directories) {
|
||||
app.use(directory, express.static(path.resolve(global.root_path + directory)));
|
||||
}
|
||||
|
||||
app.get("/cors", async function (req, res) {
|
||||
// example: http://localhost:8080/cors?url=https://google.de
|
||||
|
||||
try {
|
||||
const reg = "^/cors.+url=(.*)";
|
||||
let url = "";
|
||||
|
||||
let match = new RegExp(reg, "g").exec(req.url);
|
||||
if (!match) {
|
||||
url = "invalid url: " + req.url;
|
||||
Log.error(url);
|
||||
res.send(url);
|
||||
/**
|
||||
* Opens the server for incoming connections
|
||||
*
|
||||
* @returns {Promise} A promise that is resolved when the server listens to connections
|
||||
*/
|
||||
this.open = function () {
|
||||
return new Promise((resolve) => {
|
||||
if (config.useHttps) {
|
||||
const options = {
|
||||
key: fs.readFileSync(config.httpsPrivateKey),
|
||||
cert: fs.readFileSync(config.httpsCertificate)
|
||||
};
|
||||
server = require("https").Server(options, app);
|
||||
} else {
|
||||
url = match[1];
|
||||
Log.log("cors url: " + url);
|
||||
const response = await fetch(url, { headers: { "User-Agent": "Mozilla/5.0 MagicMirror/" + global.version } });
|
||||
const header = response.headers.get("Content-Type");
|
||||
const data = await response.text();
|
||||
if (header) res.set("Content-Type", header);
|
||||
res.send(data);
|
||||
server = require("http").Server(app);
|
||||
}
|
||||
} catch (error) {
|
||||
Log.error(error);
|
||||
res.send(error);
|
||||
}
|
||||
});
|
||||
const io = require("socket.io")(server, {
|
||||
cors: {
|
||||
origin: /.*$/,
|
||||
credentials: true
|
||||
},
|
||||
allowEIO3: true
|
||||
});
|
||||
|
||||
app.get("/version", function (req, res) {
|
||||
res.send(global.version);
|
||||
});
|
||||
server.on("connection", (socket) => {
|
||||
serverSockets.add(socket);
|
||||
socket.on("close", () => {
|
||||
serverSockets.delete(socket);
|
||||
});
|
||||
});
|
||||
|
||||
app.get("/config", function (req, res) {
|
||||
res.send(config);
|
||||
});
|
||||
Log.log(`Starting server on port ${port} ... `);
|
||||
server.listen(port, config.address || "localhost");
|
||||
|
||||
app.get("/", function (req, res) {
|
||||
let html = fs.readFileSync(path.resolve(`${global.root_path}/index.html`), { encoding: "utf8" });
|
||||
html = html.replace("#VERSION#", global.version);
|
||||
if (config.ipWhitelist instanceof Array && config.ipWhitelist.length === 0) {
|
||||
Log.warn(Utils.colors.warn("You're using a full whitelist configuration to allow for all IPs"));
|
||||
}
|
||||
|
||||
let configFile = "config/config.js";
|
||||
if (typeof global.configuration_file !== "undefined") {
|
||||
configFile = global.configuration_file;
|
||||
}
|
||||
html = html.replace("#CONFIG_FILE#", configFile);
|
||||
app.use(function (req, res, next) {
|
||||
ipfilter(config.ipWhitelist, { mode: config.ipWhitelist.length === 0 ? "deny" : "allow", log: false })(req, res, function (err) {
|
||||
if (err === undefined) {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
return next();
|
||||
}
|
||||
Log.log(err.message);
|
||||
res.status(403).send("This device is not allowed to access your mirror. <br> Please check your config.js or config.js.sample to change this.");
|
||||
});
|
||||
});
|
||||
|
||||
res.send(html);
|
||||
});
|
||||
app.use(helmet(config.httpHeaders));
|
||||
app.use("/js", express.static(__dirname));
|
||||
|
||||
if (typeof callback === "function") {
|
||||
callback(app, io);
|
||||
}
|
||||
// TODO add tests directory only when running tests?
|
||||
const directories = ["/config", "/css", "/fonts", "/modules", "/vendor", "/translations", "/tests/configs", "/tests/mocks"];
|
||||
for (const directory of directories) {
|
||||
app.use(directory, express.static(path.resolve(global.root_path + directory)));
|
||||
}
|
||||
|
||||
app.get("/cors", async (req, res) => await cors(req, res));
|
||||
|
||||
app.get("/version", (req, res) => getVersion(req, res));
|
||||
|
||||
app.get("/config", (req, res) => getConfig(req, res));
|
||||
|
||||
app.get("/", (req, res) => getHtml(req, res));
|
||||
|
||||
server.on("listening", () => {
|
||||
resolve({
|
||||
app,
|
||||
io
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Closes the server and destroys all lingering connections to it.
|
||||
*
|
||||
* @returns {Promise} A promise that resolves when server has successfully shut down
|
||||
*/
|
||||
this.close = function () {
|
||||
for (const socket of serverSockets.values()) {
|
||||
socket.destroy();
|
||||
}
|
||||
server.close();
|
||||
return new Promise((resolve) => {
|
||||
for (const socket of serverSockets.values()) {
|
||||
socket.destroy();
|
||||
}
|
||||
server.close(resolve);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
127
js/server_functions.js
Normal file
127
js/server_functions.js
Normal file
@@ -0,0 +1,127 @@
|
||||
const fetch = require("./fetch");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const Log = require("logger");
|
||||
|
||||
/**
|
||||
* Gets the config.
|
||||
*
|
||||
* @param {Request} req - the request
|
||||
* @param {Response} res - the result
|
||||
*/
|
||||
function getConfig(req, res) {
|
||||
res.send(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* A method that forewards HTTP Get-methods to the internet to avoid CORS-errors.
|
||||
*
|
||||
* Example input request url: /cors?sendheaders=header1:value1,header2:value2&expectedheaders=header1,header2&url=http://www.test.com/path?param1=value1
|
||||
*
|
||||
* Only the url-param of the input request url is required. It must be the last parameter.
|
||||
*
|
||||
* @param {Request} req - the request
|
||||
* @param {Response} res - the result
|
||||
*/
|
||||
async function cors(req, res) {
|
||||
try {
|
||||
const urlRegEx = "url=(.+?)$";
|
||||
let url = "";
|
||||
|
||||
const match = new RegExp(urlRegEx, "g").exec(req.url);
|
||||
if (!match) {
|
||||
url = "invalid url: " + req.url;
|
||||
Log.error(url);
|
||||
res.send(url);
|
||||
} else {
|
||||
url = match[1];
|
||||
|
||||
const headersToSend = getHeadersToSend(req.url);
|
||||
const expectedRecievedHeaders = geExpectedRecievedHeaders(req.url);
|
||||
|
||||
Log.log("cors url: " + url);
|
||||
const response = await fetch(url, { headers: headersToSend });
|
||||
|
||||
for (const header of expectedRecievedHeaders) {
|
||||
const headerValue = response.headers.get(header);
|
||||
if (header) res.set(header, headerValue);
|
||||
}
|
||||
const data = await response.text();
|
||||
res.send(data);
|
||||
}
|
||||
} catch (error) {
|
||||
Log.error(error);
|
||||
res.send(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets headers and values to attatch to the web request.
|
||||
*
|
||||
* @param {string} url - The url containing the headers and values to send.
|
||||
* @returns {object} An object specifying name and value of the headers.
|
||||
*/
|
||||
function getHeadersToSend(url) {
|
||||
const headersToSend = { "User-Agent": "Mozilla/5.0 MagicMirror/" + global.version };
|
||||
const headersToSendMatch = new RegExp("sendheaders=(.+?)(&|$)", "g").exec(url);
|
||||
if (headersToSendMatch) {
|
||||
const headers = headersToSendMatch[1].split(",");
|
||||
for (const header of headers) {
|
||||
const keyValue = header.split(":");
|
||||
if (keyValue.length !== 2) {
|
||||
throw new Error(`Invalid format for header ${header}`);
|
||||
}
|
||||
headersToSend[keyValue[0]] = decodeURIComponent(keyValue[1]);
|
||||
}
|
||||
}
|
||||
return headersToSend;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the headers expected from the response.
|
||||
*
|
||||
* @param {string} url - The url containing the expected headers from the response.
|
||||
* @returns {string[]} headers - The name of the expected headers.
|
||||
*/
|
||||
function geExpectedRecievedHeaders(url) {
|
||||
const expectedRecievedHeaders = ["Content-Type"];
|
||||
const expectedRecievedHeadersMatch = new RegExp("expectedheaders=(.+?)(&|$)", "g").exec(url);
|
||||
if (expectedRecievedHeadersMatch) {
|
||||
const headers = expectedRecievedHeadersMatch[1].split(",");
|
||||
for (const header of headers) {
|
||||
expectedRecievedHeaders.push(header);
|
||||
}
|
||||
}
|
||||
return expectedRecievedHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTML to display the magic mirror.
|
||||
*
|
||||
* @param {Request} req - the request
|
||||
* @param {Response} res - the result
|
||||
*/
|
||||
function getHtml(req, res) {
|
||||
let html = fs.readFileSync(path.resolve(`${global.root_path}/index.html`), { encoding: "utf8" });
|
||||
html = html.replace("#VERSION#", global.version);
|
||||
|
||||
let configFile = "config/config.js";
|
||||
if (typeof global.configuration_file !== "undefined") {
|
||||
configFile = global.configuration_file;
|
||||
}
|
||||
html = html.replace("#CONFIG_FILE#", configFile);
|
||||
|
||||
res.send(html);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the MagicMirror version.
|
||||
*
|
||||
* @param {Request} req - the request
|
||||
* @param {Response} res - the result
|
||||
*/
|
||||
function getVersion(req, res) {
|
||||
res.send(global.version);
|
||||
}
|
||||
|
||||
module.exports = { cors, getConfig, getHtml, getVersion };
|
0
modules/default/calendar/README.md
Executable file → Normal file
0
modules/default/calendar/README.md
Executable file → Normal file
105
modules/default/calendar/calendar.js
Executable file → Normal file
105
modules/default/calendar/calendar.js
Executable file → Normal file
@@ -14,6 +14,7 @@ Module.register("calendar", {
|
||||
limitDays: 0, // Limit the number of days shown, 0 = no limit
|
||||
displaySymbol: true,
|
||||
defaultSymbol: "calendar-alt", // Fontawesome Symbol see https://fontawesome.com/cheatsheet?from=io
|
||||
defaultSymbolClassName: "fas fa-fw fa-",
|
||||
showLocation: false,
|
||||
displayRepeatingCountTitle: false,
|
||||
defaultRepeatingCountTitle: "",
|
||||
@@ -37,6 +38,7 @@ Module.register("calendar", {
|
||||
hidePrivate: false,
|
||||
hideOngoing: false,
|
||||
hideTime: false,
|
||||
showTimeToday: false,
|
||||
colored: false,
|
||||
coloredSymbolOnly: false,
|
||||
customEvents: [], // Array of {keyword: "", symbol: "", color: ""} where Keyword is a regexp and symbol/color are to be applied for matched
|
||||
@@ -133,6 +135,10 @@ Module.register("calendar", {
|
||||
|
||||
// Override socket notification handler.
|
||||
socketNotificationReceived: function (notification, payload) {
|
||||
if (notification === "FETCH_CALENDAR") {
|
||||
this.sendSocketNotification(notification, { url: payload.url, id: this.identifier });
|
||||
}
|
||||
|
||||
if (this.identifier !== payload.id) {
|
||||
return;
|
||||
}
|
||||
@@ -158,11 +164,10 @@ Module.register("calendar", {
|
||||
|
||||
// Override dom generator.
|
||||
getDom: function () {
|
||||
// Define second, minute, hour, and day constants
|
||||
const oneSecond = 1000; // 1,000 milliseconds
|
||||
const oneMinute = oneSecond * 60;
|
||||
const oneHour = oneMinute * 60;
|
||||
const oneDay = oneHour * 24;
|
||||
const ONE_SECOND = 1000; // 1,000 milliseconds
|
||||
const ONE_MINUTE = ONE_SECOND * 60;
|
||||
const ONE_HOUR = ONE_MINUTE * 60;
|
||||
const ONE_DAY = ONE_HOUR * 24;
|
||||
|
||||
const events = this.createEventList(true);
|
||||
const wrapper = document.createElement("table");
|
||||
@@ -200,6 +205,8 @@ Module.register("calendar", {
|
||||
if (lastSeenDate !== dateAsString) {
|
||||
const dateRow = document.createElement("tr");
|
||||
dateRow.className = "normal";
|
||||
if (event.today) dateRow.className += " today";
|
||||
else if (event.tomorrow) dateRow.className += " tomorrow";
|
||||
|
||||
const dateCell = document.createElement("td");
|
||||
dateCell.colSpan = "3";
|
||||
@@ -225,6 +232,8 @@ Module.register("calendar", {
|
||||
}
|
||||
|
||||
eventWrapper.className = "normal event";
|
||||
if (event.today) eventWrapper.className += " today";
|
||||
else if (event.tomorrow) eventWrapper.className += " tomorrow";
|
||||
|
||||
const symbolWrapper = document.createElement("td");
|
||||
|
||||
@@ -239,7 +248,7 @@ Module.register("calendar", {
|
||||
const symbols = this.symbolsForEvent(event);
|
||||
symbols.forEach((s, index) => {
|
||||
const symbol = document.createElement("span");
|
||||
symbol.className = "fas fa-fw fa-" + s;
|
||||
symbol.className = s;
|
||||
if (index > 0) {
|
||||
symbol.style.paddingLeft = "5px";
|
||||
}
|
||||
@@ -305,6 +314,12 @@ Module.register("calendar", {
|
||||
timeWrapper.className = "time light align-left " + this.timeClassForUrl(event.url);
|
||||
timeWrapper.style.paddingLeft = "2px";
|
||||
timeWrapper.innerHTML = moment(event.startDate, "x").format("LT");
|
||||
|
||||
// Add endDate to dataheaders if showEnd is enabled
|
||||
if (this.config.showEnd) {
|
||||
timeWrapper.innerHTML += " - " + moment(event.endDate, "x").format("LT");
|
||||
}
|
||||
|
||||
eventWrapper.appendChild(timeWrapper);
|
||||
titleWrapper.classList.add("align-right");
|
||||
}
|
||||
@@ -327,7 +342,7 @@ Module.register("calendar", {
|
||||
// For full day events we use the fullDayEventDateFormat
|
||||
if (event.fullDayEvent) {
|
||||
//subtract one second so that fullDayEvents end at 23:59:59, and not at 0:00:00 one the next day
|
||||
event.endDate -= oneSecond;
|
||||
event.endDate -= ONE_SECOND;
|
||||
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").format(this.config.fullDayEventDateFormat));
|
||||
} else if (this.config.getRelative > 0 && event.startDate < now) {
|
||||
// Ongoing and getRelative is set
|
||||
@@ -337,7 +352,7 @@ Module.register("calendar", {
|
||||
timeUntilEnd: moment(event.endDate, "x").fromNow(true)
|
||||
})
|
||||
);
|
||||
} else if (this.config.urgency > 0 && event.startDate - now < this.config.urgency * oneDay) {
|
||||
} else if (this.config.urgency > 0 && event.startDate - now < this.config.urgency * ONE_DAY) {
|
||||
// Within urgency days
|
||||
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow());
|
||||
}
|
||||
@@ -345,9 +360,9 @@ Module.register("calendar", {
|
||||
// Full days events within the next two days
|
||||
if (event.today) {
|
||||
timeWrapper.innerHTML = this.capFirst(this.translate("TODAY"));
|
||||
} else if (event.startDate - now < oneDay && event.startDate - now > 0) {
|
||||
} else if (event.startDate - now < ONE_DAY && event.startDate - now > 0) {
|
||||
timeWrapper.innerHTML = this.capFirst(this.translate("TOMORROW"));
|
||||
} else if (event.startDate - now < 2 * oneDay && event.startDate - now > 0) {
|
||||
} else if (event.startDate - now < 2 * ONE_DAY && event.startDate - now > 0) {
|
||||
if (this.translate("DAYAFTERTOMORROW") !== "DAYAFTERTOMORROW") {
|
||||
timeWrapper.innerHTML = this.capFirst(this.translate("DAYAFTERTOMORROW"));
|
||||
}
|
||||
@@ -356,13 +371,13 @@ Module.register("calendar", {
|
||||
} else {
|
||||
// Show relative times
|
||||
if (event.startDate >= now || (event.fullDayEvent && event.today)) {
|
||||
// Use relative time
|
||||
// Use relative time
|
||||
if (!this.config.hideTime && !event.fullDayEvent) {
|
||||
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").calendar(null, { sameElse: this.config.dateFormat }));
|
||||
} else {
|
||||
timeWrapper.innerHTML = this.capFirst(
|
||||
moment(event.startDate, "x").calendar(null, {
|
||||
sameDay: "[" + this.translate("TODAY") + "]",
|
||||
sameDay: this.config.showTimeToday ? "LT" : "[" + this.translate("TODAY") + "]",
|
||||
nextDay: "[" + this.translate("TOMORROW") + "]",
|
||||
nextWeek: "dddd",
|
||||
sameElse: event.fullDayEvent ? this.config.fullDayEventDateFormat : this.config.dateFormat
|
||||
@@ -373,15 +388,15 @@ Module.register("calendar", {
|
||||
// Full days events within the next two days
|
||||
if (event.today) {
|
||||
timeWrapper.innerHTML = this.capFirst(this.translate("TODAY"));
|
||||
} else if (event.startDate - now < oneDay && event.startDate - now > 0) {
|
||||
} else if (event.startDate - now < ONE_DAY && event.startDate - now > 0) {
|
||||
timeWrapper.innerHTML = this.capFirst(this.translate("TOMORROW"));
|
||||
} else if (event.startDate - now < 2 * oneDay && event.startDate - now > 0) {
|
||||
} else if (event.startDate - now < 2 * ONE_DAY && event.startDate - now > 0) {
|
||||
if (this.translate("DAYAFTERTOMORROW") !== "DAYAFTERTOMORROW") {
|
||||
timeWrapper.innerHTML = this.capFirst(this.translate("DAYAFTERTOMORROW"));
|
||||
}
|
||||
}
|
||||
} else if (event.startDate - now < this.config.getRelative * oneHour) {
|
||||
// If event is within getRelative hours, display 'in xxx' time format or moment.fromNow()
|
||||
} else if (event.startDate - now < this.config.getRelative * ONE_HOUR) {
|
||||
// If event is within getRelative hours, display 'in xxx' time format or moment.fromNow()
|
||||
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow());
|
||||
}
|
||||
} else {
|
||||
@@ -410,6 +425,8 @@ Module.register("calendar", {
|
||||
if (event.location !== false) {
|
||||
const locationRow = document.createElement("tr");
|
||||
locationRow.className = "normal xsmall light";
|
||||
if (event.today) locationRow.className += " today";
|
||||
else if (event.tomorrow) locationRow.className += " tomorrow";
|
||||
|
||||
if (this.config.displaySymbol) {
|
||||
const symbolCell = document.createElement("td");
|
||||
@@ -480,6 +497,11 @@ Module.register("calendar", {
|
||||
* @returns {object[]} Array with events.
|
||||
*/
|
||||
createEventList: function (limitNumberOfEntries) {
|
||||
const ONE_SECOND = 1000; // 1,000 milliseconds
|
||||
const ONE_MINUTE = ONE_SECOND * 60;
|
||||
const ONE_HOUR = ONE_MINUTE * 60;
|
||||
const ONE_DAY = ONE_HOUR * 24;
|
||||
|
||||
const now = new Date();
|
||||
const today = moment().startOf("day");
|
||||
const future = moment().startOf("day").add(this.config.maximumNumberOfDays, "days").toDate();
|
||||
@@ -487,40 +509,44 @@ Module.register("calendar", {
|
||||
|
||||
for (const calendarUrl in this.calendarData) {
|
||||
const calendar = this.calendarData[calendarUrl];
|
||||
let remainingEntries = this.maximumEntriesForUrl(calendarUrl);
|
||||
for (const e in calendar) {
|
||||
const event = JSON.parse(JSON.stringify(calendar[e])); // clone object
|
||||
|
||||
if (event.endDate < now && limitNumberOfEntries) {
|
||||
if (this.config.hidePrivate && event.class === "PRIVATE") {
|
||||
// do not add the current event, skip it
|
||||
continue;
|
||||
}
|
||||
if (this.config.hidePrivate) {
|
||||
if (event.class === "PRIVATE") {
|
||||
// do not add the current event, skip it
|
||||
if (limitNumberOfEntries) {
|
||||
if (event.endDate < now) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (this.config.hideOngoing && limitNumberOfEntries) {
|
||||
if (event.startDate < now) {
|
||||
if (this.config.hideOngoing && event.startDate < now) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (this.listContainsEvent(events, event)) {
|
||||
continue;
|
||||
if (this.listContainsEvent(events, event)) {
|
||||
continue;
|
||||
}
|
||||
if (--remainingEntries < 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
event.url = calendarUrl;
|
||||
event.today = event.startDate >= today && event.startDate < today + 24 * 60 * 60 * 1000;
|
||||
event.today = event.startDate >= today && event.startDate < today + ONE_DAY;
|
||||
event.tomorrow = !event.today && event.startDate >= today + ONE_DAY && event.startDate < today + 2 * ONE_DAY;
|
||||
|
||||
/* if sliceMultiDayEvents is set to true, multiday events (events exceeding at least one midnight) are sliced into days,
|
||||
* otherwise, esp. in dateheaders mode it is not clear how long these events are.
|
||||
*/
|
||||
const maxCount = Math.ceil((event.endDate - 1 - moment(event.startDate, "x").endOf("day").format("x")) / (1000 * 60 * 60 * 24)) + 1;
|
||||
const maxCount = Math.ceil((event.endDate - 1 - moment(event.startDate, "x").endOf("day").format("x")) / ONE_DAY) + 1;
|
||||
if (this.config.sliceMultiDayEvents && maxCount > 1) {
|
||||
const splitEvents = [];
|
||||
let midnight = moment(event.startDate, "x").clone().startOf("day").add(1, "day").format("x");
|
||||
let count = 1;
|
||||
while (event.endDate > midnight) {
|
||||
const thisEvent = JSON.parse(JSON.stringify(event)); // clone object
|
||||
thisEvent.today = thisEvent.startDate >= today && thisEvent.startDate < today + 24 * 60 * 60 * 1000;
|
||||
thisEvent.today = thisEvent.startDate >= today && thisEvent.startDate < today + ONE_DAY;
|
||||
thisEvent.tomorrow = !thisEvent.today && thisEvent.startDate >= today + ONE_DAY && thisEvent.startDate < today + 2 * ONE_DAY;
|
||||
thisEvent.endDate = midnight;
|
||||
thisEvent.title += " (" + count + "/" + maxCount + ")";
|
||||
splitEvents.push(thisEvent);
|
||||
@@ -531,6 +557,8 @@ Module.register("calendar", {
|
||||
}
|
||||
// Last day
|
||||
event.title += " (" + count + "/" + maxCount + ")";
|
||||
event.today += event.startDate >= today && event.startDate < today + ONE_DAY;
|
||||
event.tomorrow = !event.today && event.startDate >= today + ONE_DAY && event.startDate < today + 2 * ONE_DAY;
|
||||
splitEvents.push(event);
|
||||
|
||||
for (let splitEvent of splitEvents) {
|
||||
@@ -714,6 +742,16 @@ Module.register("calendar", {
|
||||
return this.getCalendarProperty(url, "repeatingCountTitle", this.config.defaultRepeatingCountTitle);
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieves the maximum entry count for a specific calendar url.
|
||||
*
|
||||
* @param {string} url The calendar url
|
||||
* @returns {number} The maximum entry count
|
||||
*/
|
||||
maximumEntriesForUrl: function (url) {
|
||||
return this.getCalendarProperty(url, "maximumEntries", this.config.maximumEntries);
|
||||
},
|
||||
|
||||
/**
|
||||
* Helper method to retrieve the property for a specific calendar url.
|
||||
*
|
||||
@@ -734,6 +772,11 @@ Module.register("calendar", {
|
||||
|
||||
getCalendarPropertyAsArray: function (url, property, defaultValue) {
|
||||
let p = this.getCalendarProperty(url, property, defaultValue);
|
||||
if (property === "symbol" || property === "recurringSymbol" || property === "fullDaySymbol") {
|
||||
const className = this.getCalendarProperty(url, "symbolClassName", this.config.defaultSymbolClassName);
|
||||
p = className + p;
|
||||
}
|
||||
|
||||
if (!(p instanceof Array)) p = [p];
|
||||
return p;
|
||||
},
|
||||
@@ -771,7 +814,7 @@ Module.register("calendar", {
|
||||
line++;
|
||||
if (line > maxTitleLines - 1) {
|
||||
if (i < words.length) {
|
||||
currentLine += "…";
|
||||
currentLine += "…";
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -788,7 +831,7 @@ Module.register("calendar", {
|
||||
return (temp + currentLine).trim();
|
||||
} else {
|
||||
if (maxLength && typeof maxLength === "number" && string.length > maxLength) {
|
||||
return string.trim().slice(0, maxLength) + "…";
|
||||
return string.trim().slice(0, maxLength) + "…";
|
||||
} else {
|
||||
return string.trim();
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ const CalendarUtils = require("./calendarutils");
|
||||
const Log = require("logger");
|
||||
const NodeHelper = require("node_helper");
|
||||
const ical = require("node-ical");
|
||||
const fetch = require("node-fetch");
|
||||
const fetch = require("fetch");
|
||||
const digest = require("digest-fetch");
|
||||
const https = require("https");
|
||||
|
||||
|
@@ -333,9 +333,12 @@ const CalendarUtils = {
|
||||
// If the offset is negative (east of GMT), where the problem is
|
||||
if (dateoffset < 0) {
|
||||
if (dh < Math.abs(dateoffset / 60)) {
|
||||
// if the rrule byweekday WAS explicitly set , correct it
|
||||
// reduce the time by the offset
|
||||
// Apply the correction to the date/time to get it UTC relative
|
||||
date = new Date(date.getTime() - Math.abs(24 * 60) * 60000);
|
||||
if (curEvent.rrule.origOptions.byweekday !== undefined) {
|
||||
// Apply the correction to the date/time to get it UTC relative
|
||||
date = new Date(date.getTime() - Math.abs(24 * 60) * 60000);
|
||||
}
|
||||
// the duration was calculated way back at the top before we could correct the start time..
|
||||
// fix it for this event entry
|
||||
//duration = 24 * 60 * 60 * 1000;
|
||||
@@ -346,8 +349,11 @@ const CalendarUtils = {
|
||||
//if (event.start.tz === moment.tz.guess()) {
|
||||
// if the date hour is less than the offset
|
||||
if (24 - dh <= Math.abs(dateoffset / 60)) {
|
||||
// apply the correction to the date/time back to right day
|
||||
date = new Date(date.getTime() + Math.abs(24 * 60) * 60000);
|
||||
// if the rrule byweekday WAS explicitly set , correct it
|
||||
if (curEvent.rrule.origOptions.byweekday !== undefined) {
|
||||
// apply the correction to the date/time back to right day
|
||||
date = new Date(date.getTime() + Math.abs(24 * 60) * 60000);
|
||||
}
|
||||
// the duration was calculated way back at the top before we could correct the start time..
|
||||
// fix it for this event entry
|
||||
//duration = 24 * 60 * 60 * 1000;
|
||||
@@ -361,9 +367,12 @@ const CalendarUtils = {
|
||||
if (dateoffset < 0) {
|
||||
// if the date hour is less than the offset
|
||||
if (dh <= Math.abs(dateoffset / 60)) {
|
||||
// Reduce the time by the offset:
|
||||
// Apply the correction to the date/time to get it UTC relative
|
||||
date = new Date(date.getTime() - Math.abs(24 * 60) * 60000);
|
||||
// if the rrule byweekday WAS explicitly set , correct it
|
||||
if (curEvent.rrule.origOptions.byweekday !== undefined) {
|
||||
// Reduce the time by t:
|
||||
// Apply the correction to the date/time to get it UTC relative
|
||||
date = new Date(date.getTime() - Math.abs(24 * 60) * 60000);
|
||||
}
|
||||
// the duration was calculated way back at the top before we could correct the start time..
|
||||
// fix it for this event entry
|
||||
//duration = 24 * 60 * 60 * 1000;
|
||||
@@ -374,8 +383,11 @@ const CalendarUtils = {
|
||||
//if (event.start.tz === moment.tz.guess()) {
|
||||
// if the date hour is less than the offset
|
||||
if (24 - dh <= Math.abs(dateoffset / 60)) {
|
||||
// apply the correction to the date/time back to right day
|
||||
date = new Date(date.getTime() + Math.abs(24 * 60) * 60000);
|
||||
// if the rrule byweekday WAS explicitly set , correct it
|
||||
if (curEvent.rrule.origOptions.byweekday !== undefined) {
|
||||
// apply the correction to the date/time back to right day
|
||||
date = new Date(date.getTime() + Math.abs(24 * 60) * 60000);
|
||||
}
|
||||
// the duration was calculated way back at the top before we could correct the start time..
|
||||
// fix it for this event entry
|
||||
//duration = 24 * 60 * 60 * 1000;
|
||||
@@ -469,10 +481,6 @@ const CalendarUtils = {
|
||||
return;
|
||||
}
|
||||
|
||||
// Adjust start date so multiple day events will be displayed as happening today even though they started some days ago already
|
||||
if (fullDayEvent && startDate <= today && endDate > today) {
|
||||
startDate = moment(today);
|
||||
}
|
||||
// if the start and end are the same, then make end the 'end of day' value (start is at 00:00:00)
|
||||
if (fullDayEvent && startDate.format("x") === endDate.format("x")) {
|
||||
endDate = endDate.endOf("day");
|
||||
|
@@ -19,6 +19,14 @@ module.exports = NodeHelper.create({
|
||||
socketNotificationReceived: function (notification, payload) {
|
||||
if (notification === "ADD_CALENDAR") {
|
||||
this.createFetcher(payload.url, payload.fetchInterval, payload.excludedEvents, payload.maximumEntries, payload.maximumNumberOfDays, payload.auth, payload.broadcastPastEvents, payload.selfSignedCert, payload.id);
|
||||
} else if (notification === "FETCH_CALENDAR") {
|
||||
const key = payload.id + payload.url;
|
||||
if (typeof this.fetchers[key] === "undefined") {
|
||||
Log.error("Calendar Error. No fetcher exists with key: ", key);
|
||||
this.sendSocketNotification("CALENDAR_ERROR", { error_type: "MODULE_ERROR_UNSPECIFIED" });
|
||||
return;
|
||||
}
|
||||
this.fetchers[key].startFetch();
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -303,7 +303,7 @@ Module.register("clock", {
|
||||
}
|
||||
|
||||
/*******************************************
|
||||
* Update placement, respect old analogShowDate even if its not needed anymore
|
||||
* Update placement, respect old analogShowDate even if it's not needed anymore
|
||||
*/
|
||||
if (this.config.displayType === "analog") {
|
||||
// Display only an analog clock
|
||||
@@ -311,16 +311,16 @@ Module.register("clock", {
|
||||
wrapper.classList.add("clockGrid--bottom");
|
||||
} else if (this.config.analogShowDate === "bottom") {
|
||||
wrapper.classList.add("clockGrid--top");
|
||||
} else {
|
||||
//analogWrapper.style.gridArea = "center";
|
||||
}
|
||||
wrapper.appendChild(analogWrapper);
|
||||
} else if (this.config.displayType === "digital") {
|
||||
wrapper.appendChild(digitalWrapper);
|
||||
} else if (this.config.displayType === "both") {
|
||||
wrapper.classList.add("clockGrid--" + this.config.analogPlacement);
|
||||
wrapper.appendChild(analogWrapper);
|
||||
wrapper.appendChild(digitalWrapper);
|
||||
}
|
||||
|
||||
wrapper.appendChild(analogWrapper);
|
||||
wrapper.appendChild(digitalWrapper);
|
||||
|
||||
// Return the wrapper to the dom.
|
||||
return wrapper;
|
||||
}
|
||||
|
@@ -21,8 +21,7 @@ Module.register("compliments", {
|
||||
morningEndTime: 12,
|
||||
afternoonStartTime: 12,
|
||||
afternoonEndTime: 17,
|
||||
random: true,
|
||||
mockDate: null
|
||||
random: true
|
||||
},
|
||||
lastIndexUsed: -1,
|
||||
// Set currentweather from module
|
||||
@@ -40,7 +39,7 @@ Module.register("compliments", {
|
||||
this.lastComplimentIndex = -1;
|
||||
|
||||
if (this.config.remoteFile !== null) {
|
||||
this.complimentFile((response) => {
|
||||
this.loadComplimentFile().then((response) => {
|
||||
this.config.compliments = JSON.parse(response);
|
||||
this.updateDom();
|
||||
});
|
||||
@@ -85,30 +84,30 @@ Module.register("compliments", {
|
||||
*/
|
||||
complimentArray: function () {
|
||||
const hour = moment().hour();
|
||||
const date = this.config.mockDate ? this.config.mockDate : moment().format("YYYY-MM-DD");
|
||||
let compliments;
|
||||
const date = moment().format("YYYY-MM-DD");
|
||||
let compliments = [];
|
||||
|
||||
// Add time of day compliments
|
||||
if (hour >= this.config.morningStartTime && hour < this.config.morningEndTime && this.config.compliments.hasOwnProperty("morning")) {
|
||||
compliments = this.config.compliments.morning.slice(0);
|
||||
compliments = [...this.config.compliments.morning];
|
||||
} else if (hour >= this.config.afternoonStartTime && hour < this.config.afternoonEndTime && this.config.compliments.hasOwnProperty("afternoon")) {
|
||||
compliments = this.config.compliments.afternoon.slice(0);
|
||||
compliments = [...this.config.compliments.afternoon];
|
||||
} else if (this.config.compliments.hasOwnProperty("evening")) {
|
||||
compliments = this.config.compliments.evening.slice(0);
|
||||
}
|
||||
|
||||
if (typeof compliments === "undefined") {
|
||||
compliments = [];
|
||||
compliments = [...this.config.compliments.evening];
|
||||
}
|
||||
|
||||
// Add compliments based on weather
|
||||
if (this.currentWeatherType in this.config.compliments) {
|
||||
compliments.push.apply(compliments, this.config.compliments[this.currentWeatherType]);
|
||||
Array.prototype.push.apply(compliments, this.config.compliments[this.currentWeatherType]);
|
||||
}
|
||||
|
||||
compliments.push.apply(compliments, this.config.compliments.anytime);
|
||||
// Add compliments for anytime
|
||||
Array.prototype.push.apply(compliments, this.config.compliments.anytime);
|
||||
|
||||
// Add compliments for special days
|
||||
for (let entry in this.config.compliments) {
|
||||
if (new RegExp(entry).test(date)) {
|
||||
compliments.push.apply(compliments, this.config.compliments[entry]);
|
||||
Array.prototype.push.apply(compliments, this.config.compliments[entry]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,20 +117,13 @@ Module.register("compliments", {
|
||||
/**
|
||||
* Retrieve a file from the local filesystem
|
||||
*
|
||||
* @param {Function} callback Called when the file is retrieved.
|
||||
* @returns {Promise} Resolved when the file is loaded
|
||||
*/
|
||||
complimentFile: function (callback) {
|
||||
const xobj = new XMLHttpRequest(),
|
||||
isRemote = this.config.remoteFile.indexOf("http://") === 0 || this.config.remoteFile.indexOf("https://") === 0,
|
||||
path = isRemote ? this.config.remoteFile : this.file(this.config.remoteFile);
|
||||
xobj.overrideMimeType("application/json");
|
||||
xobj.open("GET", path, true);
|
||||
xobj.onreadystatechange = function () {
|
||||
if (xobj.readyState === 4 && xobj.status === 200) {
|
||||
callback(xobj.responseText);
|
||||
}
|
||||
};
|
||||
xobj.send(null);
|
||||
loadComplimentFile: async function () {
|
||||
const isRemote = this.config.remoteFile.indexOf("http://") === 0 || this.config.remoteFile.indexOf("https://") === 0,
|
||||
url = isRemote ? this.config.remoteFile : this.file(this.config.remoteFile);
|
||||
const response = await fetch(url);
|
||||
return await response.text();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -139,7 +131,7 @@ Module.register("compliments", {
|
||||
*
|
||||
* @returns {string} a compliment
|
||||
*/
|
||||
randomCompliment: function () {
|
||||
getRandomCompliment: function () {
|
||||
// get the current time of day compliments list
|
||||
const compliments = this.complimentArray();
|
||||
// variable for index to next message to display
|
||||
@@ -162,34 +154,33 @@ Module.register("compliments", {
|
||||
const wrapper = document.createElement("div");
|
||||
wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright pre-line";
|
||||
// get the compliment text
|
||||
const complimentText = this.randomCompliment();
|
||||
const complimentText = this.getRandomCompliment();
|
||||
// split it into parts on newline text
|
||||
const parts = complimentText.split("\n");
|
||||
// create a span to hold it all
|
||||
// create a span to hold the compliment
|
||||
const compliment = document.createElement("span");
|
||||
// process all the parts of the compliment text
|
||||
for (const part of parts) {
|
||||
// create a text element for each part
|
||||
compliment.appendChild(document.createTextNode(part));
|
||||
// add a break `
|
||||
compliment.appendChild(document.createElement("BR"));
|
||||
if (part !== "") {
|
||||
// create a text element for each part
|
||||
compliment.appendChild(document.createTextNode(part));
|
||||
// add a break
|
||||
compliment.appendChild(document.createElement("BR"));
|
||||
}
|
||||
}
|
||||
// only add compliment to wrapper if there is actual text in there
|
||||
if (compliment.children.length > 0) {
|
||||
// remove the last break
|
||||
compliment.lastElementChild.remove();
|
||||
wrapper.appendChild(compliment);
|
||||
}
|
||||
// remove the last break
|
||||
compliment.lastElementChild.remove();
|
||||
wrapper.appendChild(compliment);
|
||||
|
||||
return wrapper;
|
||||
},
|
||||
|
||||
// From data currentweather set weather type
|
||||
setCurrentWeatherType: function (type) {
|
||||
this.currentWeatherType = type;
|
||||
},
|
||||
|
||||
// Override notification handler.
|
||||
notificationReceived: function (notification, payload, sender) {
|
||||
if (notification === "CURRENTWEATHER_TYPE") {
|
||||
this.setCurrentWeatherType(payload.type);
|
||||
this.currentWeatherType = payload.type;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@@ -1,33 +0,0 @@
|
||||
/* eslint-disable */
|
||||
|
||||
/* MagicMirror²
|
||||
* Module: CurrentWeather
|
||||
*
|
||||
* By Michael Teeuw https://michaelteeuw.nl
|
||||
* MIT Licensed.
|
||||
*
|
||||
* This module is deprecated. Any additional feature will no longer be merged.
|
||||
*/
|
||||
Module.register("currentweather", {
|
||||
// Define start sequence.
|
||||
start: function () {
|
||||
Log.info("Starting module: " + this.name);
|
||||
},
|
||||
|
||||
// Override dom generator.
|
||||
getDom: function () {
|
||||
var wrapper = document.createElement("div");
|
||||
wrapper.className = this.config.tableClass;
|
||||
wrapper.innerHTML =
|
||||
"<style>text-decoration: none</style>" +
|
||||
"This module is deprecated since release v2.15 and removed with v2.19." +
|
||||
'<br>Please use the `weather` module as replacement, more info in the <a href="https://docs.magicmirror.builders/modules/weather.html" style="color: #ffffff">documentation</a>.';
|
||||
wrapper.className = "dimmed light small";
|
||||
return wrapper;
|
||||
},
|
||||
|
||||
// Override getHeader method.
|
||||
getHeader: function () {
|
||||
return "deprecated currentweather";
|
||||
}
|
||||
});
|
@@ -4,7 +4,7 @@
|
||||
* By Michael Teeuw https://michaelteeuw.nl
|
||||
* MIT Licensed.
|
||||
*/
|
||||
const defaultModules = ["alert", "calendar", "clock", "compliments", "currentweather", "helloworld", "newsfeed", "weatherforecast", "updatenotification", "weather"];
|
||||
const defaultModules = ["alert", "calendar", "clock", "compliments", "helloworld", "newsfeed", "updatenotification", "weather"];
|
||||
|
||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||
if (typeof module !== "undefined") {
|
||||
|
@@ -42,6 +42,14 @@ Module.register("newsfeed", {
|
||||
dangerouslyDisableAutoEscaping: false
|
||||
},
|
||||
|
||||
getUrlPrefix: function (item) {
|
||||
if (item.useCorsProxy) {
|
||||
return location.protocol + "//" + location.host + "/cors?url=";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
},
|
||||
|
||||
// Define required scripts.
|
||||
getScripts: function () {
|
||||
return ["moment.js"];
|
||||
@@ -142,14 +150,19 @@ Module.register("newsfeed", {
|
||||
sourceTitle: item.sourceTitle,
|
||||
publishDate: moment(new Date(item.pubdate)).fromNow(),
|
||||
title: item.title,
|
||||
url: item.url,
|
||||
url: this.getUrlPrefix(item) + item.url,
|
||||
description: item.description,
|
||||
items: items
|
||||
};
|
||||
},
|
||||
|
||||
getActiveItemURL: function () {
|
||||
return typeof this.newsItems[this.activeItem].url === "string" ? this.newsItems[this.activeItem].url : this.newsItems[this.activeItem].url.href;
|
||||
const item = this.newsItems[this.activeItem];
|
||||
if (item) {
|
||||
return typeof item.url === "string" ? this.getUrlPrefix(item) + item.url : this.getUrlPrefix(item) + item.url.href;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
@@ -7,8 +7,9 @@
|
||||
const Log = require("logger");
|
||||
const FeedMe = require("feedme");
|
||||
const NodeHelper = require("node_helper");
|
||||
const fetch = require("node-fetch");
|
||||
const fetch = require("fetch");
|
||||
const iconv = require("iconv-lite");
|
||||
const stream = require("stream");
|
||||
|
||||
/**
|
||||
* Responsible for requesting an update on the set interval and broadcasting the data.
|
||||
@@ -17,9 +18,10 @@ const iconv = require("iconv-lite");
|
||||
* @param {number} reloadInterval Reload interval in milliseconds.
|
||||
* @param {string} encoding Encoding of the feed.
|
||||
* @param {boolean} logFeedWarnings If true log warnings when there is an error parsing a news article.
|
||||
* @param {boolean} useCorsProxy If true cors proxy is used for article url's.
|
||||
* @class
|
||||
*/
|
||||
const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings) {
|
||||
const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings, useCorsProxy) {
|
||||
let reloadTimer = null;
|
||||
let items = [];
|
||||
|
||||
@@ -56,7 +58,8 @@ const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings
|
||||
title: title,
|
||||
description: description,
|
||||
pubdate: pubdate,
|
||||
url: url
|
||||
url: url,
|
||||
useCorsProxy: useCorsProxy
|
||||
});
|
||||
} else if (logFeedWarnings) {
|
||||
Log.warn("Can't parse feed item:");
|
||||
@@ -77,6 +80,19 @@ const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings
|
||||
scheduleTimer();
|
||||
});
|
||||
|
||||
parser.on("ttl", (minutes) => {
|
||||
try {
|
||||
// 86400000 = 24 hours is mentioned in the docs as maximum value:
|
||||
const ttlms = Math.min(minutes * 60 * 1000, 86400000);
|
||||
if (ttlms > reloadInterval) {
|
||||
reloadInterval = ttlms;
|
||||
Log.info("Newsfeed-Fetcher: reloadInterval set to ttl=" + reloadInterval + " for url " + url);
|
||||
}
|
||||
} catch (error) {
|
||||
Log.warn("Newsfeed-Fetcher: feed ttl is no valid integer=" + minutes + " for url " + url);
|
||||
}
|
||||
});
|
||||
|
||||
const nodeVersion = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
|
||||
const headers = {
|
||||
"User-Agent": "Mozilla/5.0 (Node.js " + nodeVersion + ") MagicMirror/" + global.version,
|
||||
@@ -87,7 +103,13 @@ const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings
|
||||
fetch(url, { headers: headers })
|
||||
.then(NodeHelper.checkFetchStatus)
|
||||
.then((response) => {
|
||||
response.body.pipe(iconv.decodeStream(encoding)).pipe(parser);
|
||||
let nodeStream;
|
||||
if (response.body instanceof stream.Readable) {
|
||||
nodeStream = response.body;
|
||||
} else {
|
||||
nodeStream = stream.Readable.fromWeb(response.body);
|
||||
}
|
||||
nodeStream.pipe(iconv.decodeStream(encoding)).pipe(parser);
|
||||
})
|
||||
.catch((error) => {
|
||||
fetchFailedCallback(this, error);
|
||||
|
@@ -34,6 +34,8 @@ module.exports = NodeHelper.create({
|
||||
const url = feed.url || "";
|
||||
const encoding = feed.encoding || "UTF-8";
|
||||
const reloadInterval = feed.reloadInterval || config.reloadInterval || 5 * 60 * 1000;
|
||||
let useCorsProxy = feed.useCorsProxy;
|
||||
if (useCorsProxy === undefined) useCorsProxy = true;
|
||||
|
||||
try {
|
||||
new URL(url);
|
||||
@@ -46,7 +48,7 @@ module.exports = NodeHelper.create({
|
||||
let fetcher;
|
||||
if (typeof this.fetchers[url] === "undefined") {
|
||||
Log.log("Create new newsfetcher for url: " + url + " - Interval: " + reloadInterval);
|
||||
fetcher = new NewsfeedFetcher(url, reloadInterval, encoding, config.logFeedWarnings);
|
||||
fetcher = new NewsfeedFetcher(url, reloadInterval, encoding, config.logFeedWarnings, useCorsProxy);
|
||||
|
||||
fetcher.onReceive(() => {
|
||||
this.broadcastFeeds();
|
||||
|
@@ -92,20 +92,18 @@ class GitHelper {
|
||||
// examples for status:
|
||||
// ## develop...origin/develop
|
||||
// ## master...origin/master [behind 8]
|
||||
status = status.match(/(?![.#])([^.]*)/g);
|
||||
// ## master...origin/master [ahead 8, behind 1]
|
||||
status = status.match(/## (.*)\.\.\.([^ ]*)(?: .*behind (\d+))?/);
|
||||
// examples for status:
|
||||
// [ ' develop', 'origin/develop', '' ]
|
||||
// [ ' master', 'origin/master [behind 8]', '' ]
|
||||
gitInfo.current = status[0].trim();
|
||||
status = status[1].split(" ");
|
||||
// examples for status:
|
||||
// [ 'origin/develop' ]
|
||||
// [ 'origin/master', '[behind', '8]' ]
|
||||
gitInfo.tracking = status[0].trim();
|
||||
// [ '## develop...origin/develop', 'develop', 'origin/develop' ]
|
||||
// [ '## master...origin/master [behind 8]', 'master', 'origin/master', '8' ]
|
||||
// [ '## master...origin/master [ahead 8, behind 1]', 'master', 'origin/master', '1' ]
|
||||
gitInfo.current = status[1];
|
||||
gitInfo.tracking = status[2];
|
||||
|
||||
if (status[2]) {
|
||||
if (status[3]) {
|
||||
// git fetch was already called before so `git status -sb` delivers already the behind number
|
||||
gitInfo.behind = parseInt(status[2].substring(0, status[2].length - 1));
|
||||
gitInfo.behind = parseInt(status[3]);
|
||||
gitInfo.isBehindInStatus = true;
|
||||
}
|
||||
|
||||
|
147
modules/default/utils.js
Normal file
147
modules/default/utils.js
Normal file
@@ -0,0 +1,147 @@
|
||||
/**
|
||||
* A function to make HTTP requests via the server to avoid CORS-errors.
|
||||
*
|
||||
* @param {string} url the url to fetch from
|
||||
* @param {string} type what contenttype to expect in the response, can be "json" or "xml"
|
||||
* @param {boolean} useCorsProxy A flag to indicate
|
||||
* @param {Array.<{name: string, value:string}>} requestHeaders the HTTP headers to send
|
||||
* @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to recieve
|
||||
* @returns {Promise} resolved when the fetch is done. The response headers is placed in a headers-property (provided the response does not allready contain a headers-property).
|
||||
*/
|
||||
async function performWebRequest(url, type = "json", useCorsProxy = false, requestHeaders = undefined, expectedResponseHeaders = undefined) {
|
||||
const request = {};
|
||||
if (useCorsProxy) {
|
||||
url = getCorsUrl(url, requestHeaders, expectedResponseHeaders);
|
||||
} else {
|
||||
request.headers = getHeadersToSend(requestHeaders);
|
||||
}
|
||||
const response = await fetch(url, request);
|
||||
const data = await response.text();
|
||||
|
||||
if (type === "xml") {
|
||||
return new DOMParser().parseFromString(data, "text/html");
|
||||
} else {
|
||||
if (!data || !data.length > 0) return undefined;
|
||||
|
||||
const dataResponse = JSON.parse(data);
|
||||
if (!dataResponse.headers) {
|
||||
dataResponse.headers = getHeadersFromResponse(expectedResponseHeaders, response);
|
||||
}
|
||||
return dataResponse;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a URL that will be used when calling the CORS-method on the server.
|
||||
*
|
||||
* @param {string} url the url to fetch from
|
||||
* @param {Array.<{name: string, value:string}>} requestHeaders the HTTP headers to send
|
||||
* @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to recieve
|
||||
* @returns {string} to be used as URL when calling CORS-method on server.
|
||||
*/
|
||||
const getCorsUrl = function (url, requestHeaders, expectedResponseHeaders) {
|
||||
if (!url || url.length < 1) {
|
||||
throw new Error(`Invalid URL: ${url}`);
|
||||
} else {
|
||||
let corsUrl = `${location.protocol}//${location.host}/cors?`;
|
||||
|
||||
const requestHeaderString = getRequestHeaderString(requestHeaders);
|
||||
if (requestHeaderString) corsUrl = `${corsUrl}sendheaders=${requestHeaderString}`;
|
||||
|
||||
const expectedResponseHeadersString = getExpectedResponseHeadersString(expectedResponseHeaders);
|
||||
if (requestHeaderString && expectedResponseHeadersString) {
|
||||
corsUrl = `${corsUrl}&expectedheaders=${expectedResponseHeadersString}`;
|
||||
} else if (expectedResponseHeadersString) {
|
||||
corsUrl = `${corsUrl}expectedheaders=${expectedResponseHeadersString}`;
|
||||
}
|
||||
|
||||
if (requestHeaderString || expectedResponseHeadersString) {
|
||||
return `${corsUrl}&url=${url}`;
|
||||
}
|
||||
return `${corsUrl}url=${url}`;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the part of the CORS URL that represents the HTTP headers to send.
|
||||
*
|
||||
* @param {Array.<{name: string, value:string}>} requestHeaders the HTTP headers to send
|
||||
* @returns {string} to be used as request-headers component in CORS URL.
|
||||
*/
|
||||
const getRequestHeaderString = function (requestHeaders) {
|
||||
let requestHeaderString = "";
|
||||
if (requestHeaders) {
|
||||
for (const header of requestHeaders) {
|
||||
if (requestHeaderString.length === 0) {
|
||||
requestHeaderString = `${header.name}:${encodeURIComponent(header.value)}`;
|
||||
} else {
|
||||
requestHeaderString = `${requestHeaderString},${header.name}:${encodeURIComponent(header.value)}`;
|
||||
}
|
||||
}
|
||||
return requestHeaderString;
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets headers and values to attatch to the web request.
|
||||
*
|
||||
* @param {Array.<{name: string, value:string}>} requestHeaders the HTTP headers to send
|
||||
* @returns {object} An object specifying name and value of the headers.
|
||||
*/
|
||||
const getHeadersToSend = (requestHeaders) => {
|
||||
const headersToSend = {};
|
||||
if (requestHeaders) {
|
||||
for (const header of requestHeaders) {
|
||||
headersToSend[header.name] = header.value;
|
||||
}
|
||||
}
|
||||
|
||||
return headersToSend;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the part of the CORS URL that represents the expected HTTP headers to recieve.
|
||||
*
|
||||
* @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to recieve
|
||||
* @returns {string} to be used as the expected HTTP-headers component in CORS URL.
|
||||
*/
|
||||
const getExpectedResponseHeadersString = function (expectedResponseHeaders) {
|
||||
let expectedResponseHeadersString = "";
|
||||
if (expectedResponseHeaders) {
|
||||
for (const header of expectedResponseHeaders) {
|
||||
if (expectedResponseHeadersString.length === 0) {
|
||||
expectedResponseHeadersString = `${header}`;
|
||||
} else {
|
||||
expectedResponseHeadersString = `${expectedResponseHeadersString},${header}`;
|
||||
}
|
||||
}
|
||||
return expectedResponseHeaders;
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the values for the expected headers from the response.
|
||||
*
|
||||
* @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to recieve
|
||||
* @param {Response} response the HTTP response
|
||||
* @returns {string} to be used as the expected HTTP-headers component in CORS URL.
|
||||
*/
|
||||
const getHeadersFromResponse = (expectedResponseHeaders, response) => {
|
||||
const responseHeaders = [];
|
||||
|
||||
if (expectedResponseHeaders) {
|
||||
for (const header of expectedResponseHeaders) {
|
||||
const headerValue = response.headers.get(header);
|
||||
responseHeaders.push({ name: header, value: headerValue });
|
||||
}
|
||||
}
|
||||
|
||||
return responseHeaders;
|
||||
};
|
||||
|
||||
if (typeof module !== "undefined")
|
||||
module.exports = {
|
||||
performWebRequest
|
||||
};
|
2
modules/default/weather/README.md
Executable file → Normal file
2
modules/default/weather/README.md
Executable file → Normal file
@@ -1,5 +1,5 @@
|
||||
# Weather Module
|
||||
|
||||
This module aims to be the replacement for the current `currentweather` and `weatherforcast` modules. The module will be configurable to be used as a current weather view, or to show the forecast. This way the module can be used twice to fulfill both purposes.
|
||||
This module will be configurable to be used as a current weather view, or to show the forecast. This way the module can be used twice to fulfill both purposes.
|
||||
|
||||
For configuration options, please check the [MagicMirror² documentation](https://docs.magicmirror.builders/modules/weather.html).
|
||||
|
10
modules/default/weather/current.njk
Executable file → Normal file
10
modules/default/weather/current.njk
Executable file → Normal file
@@ -3,15 +3,7 @@
|
||||
<div class="normal medium">
|
||||
<span class="wi wi-strong-wind dimmed"></span>
|
||||
<span>
|
||||
{% if config.useBeaufort %}
|
||||
{{ current.beaufortWindSpeed() | round }}
|
||||
{% else %}
|
||||
{% if config.useKmh %}
|
||||
{{ current.kmhWindSpeed() | round }}
|
||||
{% else %}
|
||||
{{ current.windSpeed | round }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{{ current.windSpeed | unit("wind") | round }}
|
||||
{% if config.showWindDirection %}
|
||||
<sup>
|
||||
{% if config.showWindDirectionAsArrow %}
|
||||
|
0
modules/default/weather/providers/README.md
Executable file → Normal file
0
modules/default/weather/providers/README.md
Executable file → Normal file
18
modules/default/weather/providers/darksky.js
Executable file → Normal file
18
modules/default/weather/providers/darksky.js
Executable file → Normal file
@@ -26,11 +26,6 @@ WeatherProvider.register("darksky", {
|
||||
lon: 0
|
||||
},
|
||||
|
||||
units: {
|
||||
imperial: "us",
|
||||
metric: "si"
|
||||
},
|
||||
|
||||
fetchCurrentWeather() {
|
||||
this.fetchData(this.getUrl())
|
||||
.then((data) => {
|
||||
@@ -67,13 +62,12 @@ WeatherProvider.register("darksky", {
|
||||
|
||||
// Create a URL from the config and base URL.
|
||||
getUrl() {
|
||||
const units = this.units[this.config.units] || "auto";
|
||||
return `${this.config.apiBase}${this.config.weatherEndpoint}/${this.config.apiKey}/${this.config.lat},${this.config.lon}?units=${units}&lang=${this.config.lang}`;
|
||||
return `${this.config.apiBase}${this.config.weatherEndpoint}/${this.config.apiKey}/${this.config.lat},${this.config.lon}?units=si&lang=${this.config.lang}`;
|
||||
},
|
||||
|
||||
// Implement WeatherDay generator.
|
||||
generateWeatherDayFromCurrentWeather(currentWeatherData) {
|
||||
const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
|
||||
const currentWeather = new WeatherObject();
|
||||
|
||||
currentWeather.date = moment();
|
||||
currentWeather.humidity = parseFloat(currentWeatherData.currently.humidity);
|
||||
@@ -81,8 +75,8 @@ WeatherProvider.register("darksky", {
|
||||
currentWeather.windSpeed = parseFloat(currentWeatherData.currently.windSpeed);
|
||||
currentWeather.windDirection = currentWeatherData.currently.windBearing;
|
||||
currentWeather.weatherType = this.convertWeatherType(currentWeatherData.currently.icon);
|
||||
currentWeather.sunrise = moment(currentWeatherData.daily.data[0].sunriseTime, "X");
|
||||
currentWeather.sunset = moment(currentWeatherData.daily.data[0].sunsetTime, "X");
|
||||
currentWeather.sunrise = moment.unix(currentWeatherData.daily.data[0].sunriseTime);
|
||||
currentWeather.sunset = moment.unix(currentWeatherData.daily.data[0].sunsetTime);
|
||||
|
||||
return currentWeather;
|
||||
},
|
||||
@@ -91,9 +85,9 @@ WeatherProvider.register("darksky", {
|
||||
const days = [];
|
||||
|
||||
for (const forecast of forecasts) {
|
||||
const weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
|
||||
const weather = new WeatherObject();
|
||||
|
||||
weather.date = moment(forecast.time, "X");
|
||||
weather.date = moment.unix(forecast.time);
|
||||
weather.minTemperature = forecast.temperatureMin;
|
||||
weather.maxTemperature = forecast.temperatureMax;
|
||||
weather.weatherType = this.convertWeatherType(forecast.icon);
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* global WeatherProvider, WeatherObject */
|
||||
/* global WeatherProvider, WeatherObject, WeatherUtils */
|
||||
|
||||
/* MagicMirror²
|
||||
* Module: Weather
|
||||
@@ -11,13 +11,13 @@
|
||||
* https://dd.weather.gc.ca/citypage_weather/schema/
|
||||
* https://eccc-msc.github.io/open-data/msc-datamart/readme_en/
|
||||
*
|
||||
* This module supports Canadian locations only and requires 2 additional config parms:
|
||||
* This module supports Canadian locations only and requires 2 additional config parameters:
|
||||
*
|
||||
* siteCode - the city/town unique identifier for which weather is to be displayed. Format is 's0000000'.
|
||||
*
|
||||
* provCode - the 2-character province code for the selected city/town.
|
||||
*
|
||||
* Example: for Toronto, Ontario, the following parms would be used
|
||||
* Example: for Toronto, Ontario, the following parameters would be used
|
||||
*
|
||||
* siteCode: 's0000458',
|
||||
* provCode: 'ON'
|
||||
@@ -64,17 +64,13 @@ WeatherProvider.register("envcanada", {
|
||||
start: function () {
|
||||
Log.info(`Weather provider: ${this.providerName} started.`);
|
||||
this.setFetchedLocation(this.config.location);
|
||||
|
||||
// Ensure kmH are ignored since these are custom-handled by this Provider
|
||||
|
||||
this.config.useKmh = false;
|
||||
},
|
||||
|
||||
//
|
||||
// Override the fetchCurrentWeather method to query EC and construct a Current weather object
|
||||
//
|
||||
fetchCurrentWeather() {
|
||||
this.fetchData(this.getUrl(), "GET", "xml")
|
||||
this.fetchData(this.getUrl(), "xml")
|
||||
.then((data) => {
|
||||
if (!data) {
|
||||
// Did not receive usable new data.
|
||||
@@ -94,7 +90,7 @@ WeatherProvider.register("envcanada", {
|
||||
// Override the fetchWeatherForecast method to query EC and construct Forecast weather objects
|
||||
//
|
||||
fetchWeatherForecast() {
|
||||
this.fetchData(this.getUrl(), "GET", "xml")
|
||||
this.fetchData(this.getUrl(), "xml")
|
||||
.then((data) => {
|
||||
if (!data) {
|
||||
// Did not receive usable new data.
|
||||
@@ -114,7 +110,7 @@ WeatherProvider.register("envcanada", {
|
||||
// Override the fetchWeatherHourly method to query EC and construct Forecast weather objects
|
||||
//
|
||||
fetchWeatherHourly() {
|
||||
this.fetchData(this.getUrl(), "GET", "xml")
|
||||
this.fetchData(this.getUrl(), "xml")
|
||||
.then((data) => {
|
||||
if (!data) {
|
||||
// Did not receive usable new data.
|
||||
@@ -137,8 +133,8 @@ WeatherProvider.register("envcanada", {
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
// Build the EC URL based on the Site Code and Province Code specified in the config parms. Note that the
|
||||
// URL defaults to the Englsih version simply because there is no language dependancy in the data
|
||||
// Build the EC URL based on the Site Code and Province Code specified in the config params. Note that the
|
||||
// URL defaults to the English version simply because there is no language dependency in the data
|
||||
// being accessed. This is only pertinent when using the EC data elements that contain a textual forecast.
|
||||
//
|
||||
getUrl() {
|
||||
@@ -150,7 +146,7 @@ WeatherProvider.register("envcanada", {
|
||||
//
|
||||
|
||||
generateWeatherObjectFromCurrentWeather(ECdoc) {
|
||||
const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||
const currentWeather = new WeatherObject();
|
||||
|
||||
// There are instances where EC will update weather data and current temperature will not be
|
||||
// provided. While this is a defect in the EC systems, we need to accommodate to avoid a current temp
|
||||
@@ -161,13 +157,13 @@ WeatherProvider.register("envcanada", {
|
||||
// EC finds no current temp. In this scenario, MM will end up displaying a current temp of null;
|
||||
|
||||
if (ECdoc.querySelector("siteData currentConditions temperature").textContent) {
|
||||
currentWeather.temperature = this.convertTemp(ECdoc.querySelector("siteData currentConditions temperature").textContent);
|
||||
currentWeather.temperature = ECdoc.querySelector("siteData currentConditions temperature").textContent;
|
||||
this.cacheCurrentTemp = currentWeather.temperature;
|
||||
} else {
|
||||
currentWeather.temperature = this.cacheCurrentTemp;
|
||||
}
|
||||
|
||||
currentWeather.windSpeed = this.convertWind(ECdoc.querySelector("siteData currentConditions wind speed").textContent);
|
||||
currentWeather.windSpeed = WeatherUtils.convertWindToMs(ECdoc.querySelector("siteData currentConditions wind speed").textContent);
|
||||
|
||||
currentWeather.windDirection = ECdoc.querySelector("siteData currentConditions wind bearing").textContent;
|
||||
|
||||
@@ -190,11 +186,11 @@ WeatherProvider.register("envcanada", {
|
||||
currentWeather.feelsLikeTemp = currentWeather.temperature;
|
||||
|
||||
if (ECdoc.querySelector("siteData currentConditions windChill")) {
|
||||
currentWeather.feelsLikeTemp = this.convertTemp(ECdoc.querySelector("siteData currentConditions windChill").textContent);
|
||||
currentWeather.feelsLikeTemp = ECdoc.querySelector("siteData currentConditions windChill").textContent;
|
||||
}
|
||||
|
||||
if (ECdoc.querySelector("siteData currentConditions humidex")) {
|
||||
currentWeather.feelsLikeTemp = this.convertTemp(ECdoc.querySelector("siteData currentConditions humidex").textContent);
|
||||
currentWeather.feelsLikeTemp = ECdoc.querySelector("siteData currentConditions humidex").textContent;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,7 +221,7 @@ WeatherProvider.register("envcanada", {
|
||||
|
||||
const days = [];
|
||||
|
||||
const weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||
const weather = new WeatherObject();
|
||||
|
||||
const foreBaseDates = ECdoc.querySelectorAll("siteData forecastGroup dateTime");
|
||||
const baseDate = foreBaseDates[1].querySelector("timeStamp").textContent;
|
||||
@@ -326,7 +322,7 @@ WeatherProvider.register("envcanada", {
|
||||
days.push(weather);
|
||||
|
||||
//
|
||||
// Now do the the rest of the forecast starting at nextDay. We will process each day using 2 EC
|
||||
// Now do the rest of the forecast starting at nextDay. We will process each day using 2 EC
|
||||
// forecast Elements. This will address the fact that the EC forecast always includes Today and
|
||||
// Tonight for each day. This is why we iterate through the forecast by a a count of 2, with each
|
||||
// iteration looking at the current Element and the next Element.
|
||||
@@ -335,12 +331,12 @@ WeatherProvider.register("envcanada", {
|
||||
let lastDate = moment(baseDate, "YYYYMMDDhhmmss");
|
||||
|
||||
for (let stepDay = nextDay; stepDay < lastDay; stepDay += 2) {
|
||||
let weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||
let weather = new WeatherObject();
|
||||
|
||||
// Add 1 to the date to reflect the current forecast day we are building
|
||||
|
||||
lastDate = lastDate.add(1, "day");
|
||||
weather.date = moment(lastDate, "X");
|
||||
weather.date = moment.unix(lastDate);
|
||||
|
||||
// Capture the temperatures for the current Element and the next Element in order to set
|
||||
// the Min and Max temperatures for the forecast
|
||||
@@ -389,17 +385,17 @@ WeatherProvider.register("envcanada", {
|
||||
const hourGroup = ECdoc.querySelectorAll("siteData hourlyForecastGroup hourlyForecast");
|
||||
|
||||
for (let stepHour = 0; stepHour < 24; stepHour += 1) {
|
||||
const weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||
const weather = new WeatherObject();
|
||||
|
||||
// Determine local time by applying UTC offset to the forecast timestamp
|
||||
|
||||
const foreTime = moment(hourGroup[stepHour].getAttribute("dateTimeUTC"), "YYYYMMDDhhmmss");
|
||||
const currTime = foreTime.add(hourOffset, "hours");
|
||||
weather.date = moment(currTime, "X");
|
||||
weather.date = moment.unix(currTime);
|
||||
|
||||
// Capture the temperature
|
||||
|
||||
weather.temperature = this.convertTemp(hourGroup[stepHour].querySelector("temperature").textContent);
|
||||
weather.temperature = hourGroup[stepHour].querySelector("temperature").textContent;
|
||||
|
||||
// Capture Likelihood of Precipitation (LOP) and unit-of-measure values
|
||||
|
||||
@@ -450,7 +446,7 @@ WeatherProvider.register("envcanada", {
|
||||
weather.minTemperature = this.todayTempCacheMin;
|
||||
weather.maxTemperature = this.todayTempCacheMax;
|
||||
} else {
|
||||
weather.minTemperature = this.convertTemp(currentTemp);
|
||||
weather.minTemperature = currentTemp;
|
||||
weather.maxTemperature = weather.minTemperature;
|
||||
}
|
||||
}
|
||||
@@ -463,14 +459,14 @@ WeatherProvider.register("envcanada", {
|
||||
//
|
||||
|
||||
if (todayClass === "low") {
|
||||
weather.minTemperature = this.convertTemp(todayTemp);
|
||||
weather.minTemperature = todayTemp;
|
||||
if (today === 0 && fullDay === true) {
|
||||
this.todayTempCacheMin = weather.minTemperature;
|
||||
}
|
||||
}
|
||||
|
||||
if (todayClass === "high") {
|
||||
weather.maxTemperature = this.convertTemp(todayTemp);
|
||||
weather.maxTemperature = todayTemp;
|
||||
if (today === 0 && fullDay === true) {
|
||||
this.todayTempCacheMax = weather.maxTemperature;
|
||||
}
|
||||
@@ -482,11 +478,11 @@ WeatherProvider.register("envcanada", {
|
||||
|
||||
if (fullDay === true) {
|
||||
if (nextClass === "low") {
|
||||
weather.minTemperature = this.convertTemp(nextTemp);
|
||||
weather.minTemperature = nextTemp;
|
||||
}
|
||||
|
||||
if (nextClass === "high") {
|
||||
weather.maxTemperature = this.convertTemp(nextTemp);
|
||||
weather.maxTemperature = nextTemp;
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -536,31 +532,6 @@ WeatherProvider.register("envcanada", {
|
||||
}
|
||||
},
|
||||
|
||||
//
|
||||
// Unit conversions
|
||||
//
|
||||
//
|
||||
// Convert C to F temps
|
||||
//
|
||||
convertTemp(temp) {
|
||||
if (this.config.tempUnits === "imperial") {
|
||||
return 1.8 * temp + 32;
|
||||
} else {
|
||||
return temp;
|
||||
}
|
||||
},
|
||||
|
||||
//
|
||||
// Convert km/h to mph
|
||||
//
|
||||
convertWind(kilo) {
|
||||
if (this.config.windUnits === "imperial") {
|
||||
return kilo / 1.609344;
|
||||
} else {
|
||||
return kilo;
|
||||
}
|
||||
},
|
||||
|
||||
//
|
||||
// Convert the icons to a more usable name.
|
||||
//
|
||||
|
537
modules/default/weather/providers/openmeteo.js
Normal file
537
modules/default/weather/providers/openmeteo.js
Normal file
@@ -0,0 +1,537 @@
|
||||
/* global WeatherProvider, WeatherObject */
|
||||
|
||||
/* MagicMirror²
|
||||
* Module: Weather
|
||||
* Provider: Open-Meteo
|
||||
*
|
||||
* By Andrés Vanegas
|
||||
* MIT Licensed
|
||||
*
|
||||
* This class is a provider for Open-Meteo, based on Andrew Pometti's class
|
||||
* for Weatherbit.
|
||||
*/
|
||||
// https://www.bigdatacloud.com/docs/api/free-reverse-geocode-to-city-api
|
||||
const GEOCODE_BASE = "https://api.bigdatacloud.net/data/reverse-geocode-client";
|
||||
const OPEN_METEO_BASE = "https://api.open-meteo.com/v1";
|
||||
|
||||
WeatherProvider.register("openmeteo", {
|
||||
// Set the name of the provider.
|
||||
// Not strictly required, but helps for debugging.
|
||||
providerName: "Open-Meteo",
|
||||
|
||||
// Set the default config properties that is specific to this provider
|
||||
defaults: {
|
||||
apiBase: OPEN_METEO_BASE,
|
||||
lat: 0,
|
||||
lon: 0,
|
||||
past_days: 0,
|
||||
type: "current"
|
||||
},
|
||||
|
||||
// https://open-meteo.com/en/docs
|
||||
hourlyParams: [
|
||||
// Air temperature at 2 meters above ground
|
||||
"temperature_2m",
|
||||
// Relative humidity at 2 meters above ground
|
||||
"relativehumidity_2m",
|
||||
// Dew point temperature at 2 meters above ground
|
||||
"dewpoint_2m",
|
||||
// Apparent temperature is the perceived feels-like temperature combining wind chill factor, relative humidity and solar radiation
|
||||
"apparent_temperature",
|
||||
// Atmospheric air pressure reduced to mean sea level (msl) or pressure at surface. Typically pressure on mean sea level is used in meteorology. Surface pressure gets lower with increasing elevation.
|
||||
"pressure_msl",
|
||||
"surface_pressure",
|
||||
// Total cloud cover as an area fraction
|
||||
"cloudcover",
|
||||
// Low level clouds and fog up to 3 km altitude
|
||||
"cloudcover_low",
|
||||
// Mid level clouds from 3 to 8 km altitude
|
||||
"cloudcover_mid",
|
||||
// High level clouds from 8 km altitude
|
||||
"cloudcover_high",
|
||||
// Wind speed at 10, 80, 120 or 180 meters above ground. Wind speed on 10 meters is the standard level.
|
||||
"windspeed_10m",
|
||||
"windspeed_80m",
|
||||
"windspeed_120m",
|
||||
"windspeed_180m",
|
||||
// Wind direction at 10, 80, 120 or 180 meters above ground
|
||||
"winddirection_10m",
|
||||
"winddirection_80m",
|
||||
"winddirection_120m",
|
||||
"winddirection_180m",
|
||||
// Gusts at 10 meters above ground as a maximum of the preceding hour
|
||||
"windgusts_10m",
|
||||
// Shortwave solar radiation as average of the preceding hour. This is equal to the total global horizontal irradiation
|
||||
"shortwave_radiation",
|
||||
// Direct solar radiation as average of the preceding hour on the horizontal plane and the normal plane (perpendicular to the sun)
|
||||
"direct_radiation",
|
||||
"direct_normal_irradiance",
|
||||
// Diffuse solar radiation as average of the preceding hour
|
||||
"diffuse_radiation",
|
||||
// Vapor Pressure Deificit (VPD) in kilopascal (kPa). For high VPD (>1.6), water transpiration of plants increases. For low VPD (<0.4), transpiration decreases
|
||||
"vapor_pressure_deficit",
|
||||
// Evapotranspration from land surface and plants that weather models assumes for this location. Available soil water is considered. 1 mm evapotranspiration per hour equals 1 liter of water per spare meter.
|
||||
"evapotranspiration",
|
||||
// ET₀ Reference Evapotranspiration of a well watered grass field. Based on FAO-56 Penman-Monteith equations ET₀ is calculated from temperature, wind speed, humidity and solar radiation. Unlimited soil water is assumed. ET₀ is commonly used to estimate the required irrigation for plants.
|
||||
"et0_fao_evapotranspiration",
|
||||
// Total precipitation (rain, showers, snow) sum of the preceding hour
|
||||
"precipitation",
|
||||
// Snowfall amount of the preceding hour in centimeters. For the water equivalent in millimeter, divide by 7. E.g. 7 cm snow = 10 mm precipitation water equivalent
|
||||
"snowfall",
|
||||
// Rain from large scale weather systems of the preceding hour in millimeter
|
||||
"rain",
|
||||
// Showers from convective precipitation in millimeters from the preceding hour
|
||||
"showers",
|
||||
// Weather condition as a numeric code. Follow WMO weather interpretation codes.
|
||||
"weathercode",
|
||||
// Snow depth on the ground
|
||||
"snow_depth",
|
||||
// Altitude above sea level of the 0°C level
|
||||
"freezinglevel_height",
|
||||
// Temperature in the soil at 0, 6, 18 and 54 cm depths. 0 cm is the surface temperature on land or water surface temperature on water.
|
||||
"soil_temperature_0cm",
|
||||
"soil_temperature_6cm",
|
||||
"soil_temperature_18cm",
|
||||
"soil_temperature_54cm",
|
||||
// Average soil water content as volumetric mixing ratio at 0-1, 1-3, 3-9, 9-27 and 27-81 cm depths.
|
||||
"soil_moisture_0_1cm",
|
||||
"soil_moisture_1_3cm",
|
||||
"soil_moisture_3_9cm",
|
||||
"soil_moisture_9_27cm",
|
||||
"soil_moisture_27_81cm"
|
||||
],
|
||||
|
||||
dailyParams: [
|
||||
// Maximum and minimum daily air temperature at 2 meters above ground
|
||||
"temperature_2m_max",
|
||||
"temperature_2m_min",
|
||||
// Maximum and minimum daily apparent temperature
|
||||
"apparent_temperature_min",
|
||||
"apparent_temperature_max",
|
||||
// Sum of daily precipitation (including rain, showers and snowfall)
|
||||
"precipitation_sum",
|
||||
// Sum of daily rain
|
||||
"rain_sum",
|
||||
// Sum of daily showers
|
||||
"showers_sum",
|
||||
// Sum of daily snowfall
|
||||
"snowfall_sum",
|
||||
// The number of hours with rain
|
||||
"precipitation_hours",
|
||||
// The most severe weather condition on a given day
|
||||
"weathercode",
|
||||
// Sun rise and set times
|
||||
"sunrise",
|
||||
"sunset",
|
||||
// Maximum wind speed and gusts on a day
|
||||
"windspeed_10m_max",
|
||||
"windgusts_10m_max",
|
||||
// Dominant wind direction
|
||||
"winddirection_10m_dominant",
|
||||
// The sum of solar radiation on a given day in Megajoules
|
||||
"shortwave_radiation_sum",
|
||||
// Daily sum of ET₀ Reference Evapotranspiration of a well watered grass field
|
||||
"et0_fao_evapotranspiration"
|
||||
],
|
||||
|
||||
fetchedLocation: function () {
|
||||
return this.fetchedLocationName || "";
|
||||
},
|
||||
|
||||
fetchCurrentWeather() {
|
||||
this.fetchData(this.getUrl())
|
||||
.then((data) => this.parseWeatherApiResponse(data))
|
||||
.then((parsedData) => {
|
||||
if (!parsedData) {
|
||||
// No usable data?
|
||||
return;
|
||||
}
|
||||
|
||||
const currentWeather = this.generateWeatherDayFromCurrentWeather(parsedData);
|
||||
this.setCurrentWeather(currentWeather);
|
||||
})
|
||||
.catch(function (request) {
|
||||
Log.error("Could not load data ... ", request);
|
||||
})
|
||||
.finally(() => this.updateAvailable());
|
||||
},
|
||||
|
||||
fetchWeatherForecast() {
|
||||
this.fetchData(this.getUrl())
|
||||
.then((data) => this.parseWeatherApiResponse(data))
|
||||
.then((parsedData) => {
|
||||
if (!parsedData) {
|
||||
// No usable data?
|
||||
return;
|
||||
}
|
||||
|
||||
const dailyForecast = this.generateWeatherObjectsFromForecast(parsedData);
|
||||
this.setWeatherForecast(dailyForecast);
|
||||
})
|
||||
.catch(function (request) {
|
||||
Log.error("Could not load data ... ", request);
|
||||
})
|
||||
.finally(() => this.updateAvailable());
|
||||
},
|
||||
|
||||
fetchWeatherHourly() {
|
||||
this.fetchData(this.getUrl())
|
||||
.then((data) => this.parseWeatherApiResponse(data))
|
||||
.then((parsedData) => {
|
||||
if (!parsedData) {
|
||||
// No usable data?
|
||||
return;
|
||||
}
|
||||
|
||||
const hourlyForecast = this.generateWeatherObjectsFromHourly(parsedData);
|
||||
this.setWeatherHourly(hourlyForecast);
|
||||
})
|
||||
.catch(function (request) {
|
||||
Log.error("Could not load data ... ", request);
|
||||
})
|
||||
.finally(() => this.updateAvailable());
|
||||
},
|
||||
|
||||
/**
|
||||
* Overrides method for setting config to check if endpoint is correct for hourly
|
||||
*
|
||||
* @param {object} config The configuration object
|
||||
*/
|
||||
setConfig(config) {
|
||||
this.config = {
|
||||
lang: config.lang ?? "en",
|
||||
...this.defaults,
|
||||
...config
|
||||
};
|
||||
|
||||
// Set properly maxNumberOfDays and max Entries properties according to config and value ranges allowed in the documentation
|
||||
const maxEntriesLimit = ["daily", "forecast"].includes(this.config.type) ? 7 : this.config.type === "hourly" ? 48 : 0;
|
||||
if (this.config.hasOwnProperty("maxNumberOfDays") && !isNaN(parseFloat(this.config.maxNumberOfDays))) {
|
||||
const daysFactor = ["daily", "forecast"].includes(this.config.type) ? 1 : this.config.type === "hourly" ? 24 : 0;
|
||||
this.config.maxEntries = Math.max(1, Math.min(Math.round(parseFloat(this.config.maxNumberOfDays)) * daysFactor, maxEntriesLimit));
|
||||
this.config.maxNumberOfDays = Math.ceil(this.config.maxEntries / Math.max(1, daysFactor));
|
||||
}
|
||||
this.config.maxEntries = Math.max(1, Math.min(this.config.maxEntries, maxEntriesLimit));
|
||||
|
||||
if (!this.config.type) {
|
||||
Log.error("type not configured and could not resolve it");
|
||||
}
|
||||
|
||||
this.fetchLocation();
|
||||
},
|
||||
|
||||
// Generate valid query params to perform the request
|
||||
getQueryParameters() {
|
||||
let params = {
|
||||
latitude: this.config.lat,
|
||||
longitude: this.config.lon,
|
||||
timeformat: "unixtime",
|
||||
timezone: "auto",
|
||||
past_days: this.config.past_days ?? 0,
|
||||
daily: this.dailyParams,
|
||||
hourly: this.hourlyParams,
|
||||
// Fixed units as metric
|
||||
temperature_unit: "celsius",
|
||||
windspeed_unit: "kmh",
|
||||
precipitation_unit: "mm"
|
||||
};
|
||||
|
||||
const startDate = moment().startOf("day");
|
||||
const endDate = moment(startDate)
|
||||
.add(Math.max(0, Math.min(7, this.config.maxNumberOfDays)), "days")
|
||||
.endOf("day");
|
||||
|
||||
params["start_date"] = startDate.format("YYYY-MM-DD");
|
||||
|
||||
switch (this.config.type) {
|
||||
case "hourly":
|
||||
case "daily":
|
||||
case "forecast":
|
||||
params["end_date"] = endDate.format("YYYY-MM-DD");
|
||||
break;
|
||||
case "current":
|
||||
params["current_weather"] = true;
|
||||
params["end_date"] = params["start_date"];
|
||||
break;
|
||||
default:
|
||||
// Failsafe
|
||||
return "";
|
||||
}
|
||||
|
||||
return Object.keys(params)
|
||||
.filter((key) => (params[key] ? true : false))
|
||||
.map((key) => {
|
||||
switch (key) {
|
||||
case "hourly":
|
||||
case "daily":
|
||||
return encodeURIComponent(key) + "=" + params[key].join(",");
|
||||
default:
|
||||
return encodeURIComponent(key) + "=" + encodeURIComponent(params[key]);
|
||||
}
|
||||
})
|
||||
.join("&");
|
||||
},
|
||||
|
||||
// Create a URL from the config and base URL.
|
||||
getUrl() {
|
||||
return `${this.config.apiBase}/forecast?${this.getQueryParameters()}`;
|
||||
},
|
||||
|
||||
// Transpose hourly and daily data matrices
|
||||
transposeDataMatrix(data) {
|
||||
return data.time.map((_, index) =>
|
||||
Object.keys(data).reduce((row, key) => {
|
||||
return {
|
||||
...row,
|
||||
// Parse time values as momentjs instances
|
||||
[key]: ["time", "sunrise", "sunset"].includes(key) ? moment.unix(data[key][index]) : data[key][index]
|
||||
};
|
||||
}, {})
|
||||
);
|
||||
},
|
||||
|
||||
// Sanitize and validate API response
|
||||
parseWeatherApiResponse(data) {
|
||||
const validByType = {
|
||||
current: data.current_weather && data.current_weather.time,
|
||||
hourly: data.hourly && data.hourly.time && Array.isArray(data.hourly.time) && data.hourly.time.length > 0,
|
||||
daily: data.daily && data.daily.time && Array.isArray(data.daily.time) && data.daily.time.length > 0
|
||||
};
|
||||
// backwards compatibility
|
||||
const type = ["daily", "forecast"].includes(this.config.type) ? "daily" : this.config.type;
|
||||
|
||||
if (!validByType[type]) return;
|
||||
|
||||
switch (type) {
|
||||
case "current":
|
||||
if (!validByType.daily && !validByType.hourly) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "hourly":
|
||||
case "daily":
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
for (const key of ["hourly", "daily"]) {
|
||||
if (typeof data[key] === "object") {
|
||||
data[key] = this.transposeDataMatrix(data[key]);
|
||||
}
|
||||
}
|
||||
|
||||
if (data.current_weather) {
|
||||
data.current_weather.time = moment.unix(data.current_weather.time);
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
// Reverse geocoding from latitude and longitude provided
|
||||
fetchLocation() {
|
||||
this.fetchData(`${GEOCODE_BASE}?latitude=${this.config.lat}&longitude=${this.config.lon}&localityLanguage=${this.config.lang}`)
|
||||
.then((data) => {
|
||||
if (!data || !data.city) {
|
||||
// No usable data?
|
||||
return;
|
||||
}
|
||||
this.fetchedLocationName = `${data.city}, ${data.principalSubdivisionCode}`;
|
||||
})
|
||||
.catch((request) => {
|
||||
Log.error("Could not load data ... ", request);
|
||||
});
|
||||
},
|
||||
|
||||
// Implement WeatherDay generator.
|
||||
generateWeatherDayFromCurrentWeather(weather) {
|
||||
/**
|
||||
* Since some units comes from API response "splitted" into daily, hourly and current_weather
|
||||
* every time you request it, you have to ensure to get the data from the right place every time.
|
||||
* For the current weather case, the response have the following structure (after transposing):
|
||||
* ```
|
||||
* {
|
||||
* current_weather: { ...<some current weather here> },
|
||||
* hourly: [
|
||||
* 0: {...<data for hour zero here> },
|
||||
* 1: {...<data for hour one here> },
|
||||
* ...
|
||||
* ],
|
||||
* daily: [
|
||||
* {...<summary data for current day here> },
|
||||
* ]
|
||||
* }
|
||||
* ```
|
||||
* Some data should be returned from `hourly` array data when the index matches the current hour,
|
||||
* some data from the first and only one object received in `daily` array and some from the
|
||||
* `current_weather` object.
|
||||
*/
|
||||
const h = moment().hour();
|
||||
const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||
|
||||
currentWeather.date = weather.current_weather.time;
|
||||
currentWeather.windSpeed = weather.current_weather.windspeed;
|
||||
currentWeather.windDirection = weather.current_weather.winddirection;
|
||||
currentWeather.sunrise = weather.daily[0].sunrise;
|
||||
currentWeather.sunset = weather.daily[0].sunset;
|
||||
currentWeather.temperature = parseFloat(weather.current_weather.temperature);
|
||||
currentWeather.minTemperature = parseFloat(weather.daily[0].temperature_2m_min);
|
||||
currentWeather.maxTemperature = parseFloat(weather.daily[0].temperature_2m_max);
|
||||
currentWeather.weatherType = this.convertWeatherType(weather.current_weather.weathercode, currentWeather.isDayTime());
|
||||
currentWeather.humidity = parseFloat(weather.hourly[h].relativehumidity_2m);
|
||||
currentWeather.rain = parseFloat(weather.hourly[h].rain);
|
||||
currentWeather.snow = parseFloat(weather.hourly[h].snowfall * 10);
|
||||
currentWeather.precipitation = parseFloat(weather.hourly[h].precipitation);
|
||||
|
||||
return currentWeather;
|
||||
},
|
||||
|
||||
// Implement WeatherForecast generator.
|
||||
generateWeatherObjectsFromForecast(weathers) {
|
||||
const days = [];
|
||||
|
||||
weathers.daily.forEach((weather, i) => {
|
||||
const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||
|
||||
currentWeather.date = weather.time;
|
||||
currentWeather.windSpeed = weather.windspeed_10m_max;
|
||||
currentWeather.windDirection = weather.winddirection_10m_dominant;
|
||||
currentWeather.sunrise = weather.sunrise;
|
||||
currentWeather.sunset = weather.sunset;
|
||||
currentWeather.temperature = parseFloat((weather.apparent_temperature_max + weather.apparent_temperature_min) / 2);
|
||||
currentWeather.minTemperature = parseFloat(weather.apparent_temperature_min);
|
||||
currentWeather.maxTemperature = parseFloat(weather.apparent_temperature_max);
|
||||
currentWeather.weatherType = this.convertWeatherType(weather.weathercode, currentWeather.isDayTime());
|
||||
currentWeather.rain = parseFloat(weather.rain_sum);
|
||||
currentWeather.snow = parseFloat(weather.snowfall_sum * 10);
|
||||
currentWeather.precipitation = parseFloat(weather.precipitation_sum);
|
||||
|
||||
days.push(currentWeather);
|
||||
});
|
||||
|
||||
return days;
|
||||
},
|
||||
|
||||
// Implement WeatherHourly generator.
|
||||
generateWeatherObjectsFromHourly(weathers) {
|
||||
const hours = [];
|
||||
const now = moment();
|
||||
|
||||
weathers.hourly.forEach((weather, i) => {
|
||||
if ((hours.length === 0 && weather.time.hour() <= now.hour()) || hours.length >= this.config.maxEntries) {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||
const h = Math.ceil((i + 1) / 24) - 1;
|
||||
|
||||
currentWeather.date = weather.time;
|
||||
currentWeather.windSpeed = weather.windspeed_10m;
|
||||
currentWeather.windDirection = weather.winddirection_10m;
|
||||
currentWeather.sunrise = weathers.daily[h].sunrise;
|
||||
currentWeather.sunset = weathers.daily[h].sunset;
|
||||
currentWeather.temperature = parseFloat(weather.apparent_temperature);
|
||||
currentWeather.minTemperature = parseFloat(weathers.daily[h].apparent_temperature_min);
|
||||
currentWeather.maxTemperature = parseFloat(weathers.daily[h].apparent_temperature_max);
|
||||
currentWeather.weatherType = this.convertWeatherType(weather.weathercode, currentWeather.isDayTime());
|
||||
currentWeather.humidity = parseFloat(weather.relativehumidity_2m);
|
||||
currentWeather.rain = parseFloat(weather.rain);
|
||||
currentWeather.snow = parseFloat(weather.snowfall * 10);
|
||||
currentWeather.precipitation = parseFloat(weather.precipitation);
|
||||
|
||||
hours.push(currentWeather);
|
||||
});
|
||||
|
||||
return hours;
|
||||
},
|
||||
|
||||
// Map icons from Dark Sky to our icons.
|
||||
convertWeatherType(weathercode, isDayTime) {
|
||||
const weatherConditions = {
|
||||
0: "clear",
|
||||
1: "mainly-clear",
|
||||
2: "partly-cloudy",
|
||||
3: "overcast",
|
||||
45: "fog",
|
||||
48: "depositing-rime-fog",
|
||||
51: "drizzle-light-intensity",
|
||||
53: "drizzle-moderate-intensity",
|
||||
55: "drizzle-dense-intensity",
|
||||
56: "freezing-drizzle-light-intensity",
|
||||
57: "freezing-drizzle-dense-intensity",
|
||||
61: "rain-slight-intensity",
|
||||
63: "rain-moderate-intensity",
|
||||
65: "rain-heavy-intensity",
|
||||
66: "freezing-rain-light-heavy-intensity",
|
||||
67: "freezing-rain-heavy-intensity",
|
||||
71: "snow-fall-slight-intensity",
|
||||
73: "snow-fall-moderate-intensity",
|
||||
75: "snow-fall-heavy-intensity",
|
||||
77: "snow-grains",
|
||||
80: "rain-showers-slight",
|
||||
81: "rain-showers-moderate",
|
||||
82: "rain-showers-violent",
|
||||
85: "snow-showers-slight",
|
||||
86: "snow-showers-heavy",
|
||||
95: "thunderstorm",
|
||||
96: "thunderstorm-slight-hail",
|
||||
99: "thunderstorm-heavy-hail"
|
||||
};
|
||||
|
||||
if (!Object.keys(weatherConditions).includes(`${weathercode}`)) return null;
|
||||
|
||||
switch (weatherConditions[`${weathercode}`]) {
|
||||
case "clear":
|
||||
return isDayTime ? "day-sunny" : "night-clear";
|
||||
case "mainly-clear":
|
||||
case "partly-cloudy":
|
||||
return isDayTime ? "day-cloudy" : "night-alt-cloudy";
|
||||
case "overcast":
|
||||
return isDayTime ? "day-sunny-overcast" : "night-alt-partly-cloudy";
|
||||
case "fog":
|
||||
case "depositing-rime-fog":
|
||||
return isDayTime ? "day-fog" : "night-fog";
|
||||
case "drizzle-light-intensity":
|
||||
case "rain-slight-intensity":
|
||||
case "rain-showers-slight":
|
||||
return isDayTime ? "day-sprinkle" : "night-sprinkle";
|
||||
case "drizzle-moderate-intensity":
|
||||
case "rain-moderate-intensity":
|
||||
case "rain-showers-moderate":
|
||||
return isDayTime ? "day-showers" : "night-showers";
|
||||
case "drizzle-dense-intensity":
|
||||
case "rain-heavy-intensity":
|
||||
case "rain-showers-violent":
|
||||
return isDayTime ? "day-thunderstorm" : "night-thunderstorm";
|
||||
case "freezing-rain-light-intensity":
|
||||
return isDayTime ? "day-rain-mix" : "night-rain-mix";
|
||||
case "freezing-drizzle-light-intensity":
|
||||
case "freezing-drizzle-dense-intensity":
|
||||
return "snowflake-cold";
|
||||
case "snow-grains":
|
||||
return isDayTime ? "day-sleet" : "night-sleet";
|
||||
case "snow-fall-slight-intensity":
|
||||
case "snow-fall-moderate-intensity":
|
||||
return isDayTime ? "day-snow-wind" : "night-snow-wind";
|
||||
case "snow-fall-heavy-intensity":
|
||||
case "freezing-rain-heavy-intensity":
|
||||
return isDayTime ? "day-snow-thunderstorm" : "night-snow-thunderstorm";
|
||||
case "snow-showers-slight":
|
||||
case "snow-showers-heavy":
|
||||
return isDayTime ? "day-rain-mix" : "night-rain-mix";
|
||||
case "thunderstorm":
|
||||
return isDayTime ? "day-thunderstorm" : "night-thunderstorm";
|
||||
case "thunderstorm-slight-hail":
|
||||
return isDayTime ? "day-sleet" : "night-sleet";
|
||||
case "thunderstorm-heavy-hail":
|
||||
return isDayTime ? "day-sleet-storm" : "night-sleet-storm";
|
||||
default:
|
||||
return "na";
|
||||
}
|
||||
},
|
||||
|
||||
// Define required scripts.
|
||||
getScripts: function () {
|
||||
return ["moment.js"];
|
||||
}
|
||||
});
|
78
modules/default/weather/providers/openweathermap.js
Executable file → Normal file
78
modules/default/weather/providers/openweathermap.js
Executable file → Normal file
@@ -21,7 +21,7 @@ WeatherProvider.register("openweathermap", {
|
||||
weatherEndpoint: "", // can be "onecall", "forecast" or "weather" (for current)
|
||||
locationID: false,
|
||||
location: false,
|
||||
lat: 0, // the onecall endpoint needs lat / lon values, it doesn'T support the locationId
|
||||
lat: 0, // the onecall endpoint needs lat / lon values, it doesn't support the locationId
|
||||
lon: 0,
|
||||
apiKey: ""
|
||||
},
|
||||
@@ -30,14 +30,14 @@ WeatherProvider.register("openweathermap", {
|
||||
fetchCurrentWeather() {
|
||||
this.fetchData(this.getUrl())
|
||||
.then((data) => {
|
||||
let currentWeather;
|
||||
if (this.config.weatherEndpoint === "/onecall") {
|
||||
const weatherData = this.generateWeatherObjectsFromOnecall(data);
|
||||
this.setCurrentWeather(weatherData.current);
|
||||
currentWeather = this.generateWeatherObjectsFromOnecall(data).current;
|
||||
this.setFetchedLocation(`${data.timezone}`);
|
||||
} else {
|
||||
const currentWeather = this.generateWeatherObjectFromCurrentWeather(data);
|
||||
this.setCurrentWeather(currentWeather);
|
||||
currentWeather = this.generateWeatherObjectFromCurrentWeather(data);
|
||||
}
|
||||
this.setCurrentWeather(currentWeather);
|
||||
})
|
||||
.catch(function (request) {
|
||||
Log.error("Could not load data ... ", request);
|
||||
@@ -49,15 +49,17 @@ WeatherProvider.register("openweathermap", {
|
||||
fetchWeatherForecast() {
|
||||
this.fetchData(this.getUrl())
|
||||
.then((data) => {
|
||||
let forecast;
|
||||
let location;
|
||||
if (this.config.weatherEndpoint === "/onecall") {
|
||||
const weatherData = this.generateWeatherObjectsFromOnecall(data);
|
||||
this.setWeatherForecast(weatherData.days);
|
||||
this.setFetchedLocation(`${data.timezone}`);
|
||||
forecast = this.generateWeatherObjectsFromOnecall(data).days;
|
||||
location = `${data.timezone}`;
|
||||
} else {
|
||||
const forecast = this.generateWeatherObjectsFromForecast(data.list);
|
||||
this.setWeatherForecast(forecast);
|
||||
this.setFetchedLocation(`${data.city.name}, ${data.city.country}`);
|
||||
forecast = this.generateWeatherObjectsFromForecast(data.list);
|
||||
location = `${data.city.name}, ${data.city.country}`;
|
||||
}
|
||||
this.setWeatherForecast(forecast);
|
||||
this.setFetchedLocation(location);
|
||||
})
|
||||
.catch(function (request) {
|
||||
Log.error("Could not load data ... ", request);
|
||||
@@ -123,16 +125,17 @@ WeatherProvider.register("openweathermap", {
|
||||
* Generate a WeatherObject based on currentWeatherInformation
|
||||
*/
|
||||
generateWeatherObjectFromCurrentWeather(currentWeatherData) {
|
||||
const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
|
||||
const currentWeather = new WeatherObject();
|
||||
|
||||
currentWeather.date = moment.unix(currentWeatherData.dt);
|
||||
currentWeather.humidity = currentWeatherData.main.humidity;
|
||||
currentWeather.temperature = currentWeatherData.main.temp;
|
||||
currentWeather.feelsLikeTemp = currentWeatherData.main.feels_like;
|
||||
currentWeather.windSpeed = currentWeatherData.wind.speed;
|
||||
currentWeather.windDirection = currentWeatherData.wind.deg;
|
||||
currentWeather.weatherType = this.convertWeatherType(currentWeatherData.weather[0].icon);
|
||||
currentWeather.sunrise = moment(currentWeatherData.sys.sunrise, "X");
|
||||
currentWeather.sunset = moment(currentWeatherData.sys.sunset, "X");
|
||||
currentWeather.sunrise = moment.unix(currentWeatherData.sys.sunrise);
|
||||
currentWeather.sunset = moment.unix(currentWeatherData.sys.sunset);
|
||||
|
||||
return currentWeather;
|
||||
},
|
||||
@@ -147,8 +150,7 @@ WeatherProvider.register("openweathermap", {
|
||||
return this.fetchForecastDaily(forecasts);
|
||||
}
|
||||
// if weatherEndpoint does not match forecast or forecast/daily, what should be returned?
|
||||
const days = [new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh)];
|
||||
return days;
|
||||
return [new WeatherObject()];
|
||||
},
|
||||
|
||||
/*
|
||||
@@ -159,8 +161,7 @@ WeatherProvider.register("openweathermap", {
|
||||
return this.fetchOnecall(data);
|
||||
}
|
||||
// if weatherEndpoint does not match onecall, what should be returned?
|
||||
const weatherData = { current: new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh), hours: [], days: [] };
|
||||
return weatherData;
|
||||
return { current: new WeatherObject(), hours: [], days: [] };
|
||||
},
|
||||
|
||||
/*
|
||||
@@ -176,10 +177,10 @@ WeatherProvider.register("openweathermap", {
|
||||
let snow = 0;
|
||||
// variable for date
|
||||
let date = "";
|
||||
let weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
|
||||
let weather = new WeatherObject();
|
||||
|
||||
for (const forecast of forecasts) {
|
||||
if (date !== moment(forecast.dt, "X").format("YYYY-MM-DD")) {
|
||||
if (date !== moment.unix(forecast.dt).format("YYYY-MM-DD")) {
|
||||
// calculate minimum/maximum temperature, specify rain amount
|
||||
weather.minTemperature = Math.min.apply(null, minTemp);
|
||||
weather.maxTemperature = Math.max.apply(null, maxTemp);
|
||||
@@ -189,7 +190,7 @@ WeatherProvider.register("openweathermap", {
|
||||
// push weather information to days array
|
||||
days.push(weather);
|
||||
// create new weather-object
|
||||
weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
|
||||
weather = new WeatherObject();
|
||||
|
||||
minTemp = [];
|
||||
maxTemp = [];
|
||||
@@ -197,16 +198,16 @@ WeatherProvider.register("openweathermap", {
|
||||
snow = 0;
|
||||
|
||||
// set new date
|
||||
date = moment(forecast.dt, "X").format("YYYY-MM-DD");
|
||||
date = moment.unix(forecast.dt).format("YYYY-MM-DD");
|
||||
|
||||
// specify date
|
||||
weather.date = moment(forecast.dt, "X");
|
||||
weather.date = moment.unix(forecast.dt);
|
||||
|
||||
// If the first value of today is later than 17:00, we have an icon at least!
|
||||
weather.weatherType = this.convertWeatherType(forecast.weather[0].icon);
|
||||
}
|
||||
|
||||
if (moment(forecast.dt, "X").format("H") >= 8 && moment(forecast.dt, "X").format("H") <= 17) {
|
||||
if (moment.unix(forecast.dt).format("H") >= 8 && moment.unix(forecast.dt).format("H") <= 17) {
|
||||
weather.weatherType = this.convertWeatherType(forecast.weather[0].icon);
|
||||
}
|
||||
|
||||
@@ -252,9 +253,9 @@ WeatherProvider.register("openweathermap", {
|
||||
const days = [];
|
||||
|
||||
for (const forecast of forecasts) {
|
||||
const weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
|
||||
const weather = new WeatherObject();
|
||||
|
||||
weather.date = moment(forecast.dt, "X");
|
||||
weather.date = moment.unix(forecast.dt);
|
||||
weather.minTemperature = forecast.temp.min;
|
||||
weather.maxTemperature = forecast.temp.max;
|
||||
weather.weatherType = this.convertWeatherType(forecast.weather[0].icon);
|
||||
@@ -298,13 +299,13 @@ WeatherProvider.register("openweathermap", {
|
||||
let precip = false;
|
||||
|
||||
// get current weather, if requested
|
||||
const current = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
|
||||
const current = new WeatherObject();
|
||||
if (data.hasOwnProperty("current")) {
|
||||
current.date = moment(data.current.dt, "X").utcOffset(data.timezone_offset / 60);
|
||||
current.date = moment.unix(data.current.dt).utcOffset(data.timezone_offset / 60);
|
||||
current.windSpeed = data.current.wind_speed;
|
||||
current.windDirection = data.current.wind_deg;
|
||||
current.sunrise = moment(data.current.sunrise, "X").utcOffset(data.timezone_offset / 60);
|
||||
current.sunset = moment(data.current.sunset, "X").utcOffset(data.timezone_offset / 60);
|
||||
current.sunrise = moment.unix(data.current.sunrise).utcOffset(data.timezone_offset / 60);
|
||||
current.sunset = moment.unix(data.current.sunset).utcOffset(data.timezone_offset / 60);
|
||||
current.temperature = data.current.temp;
|
||||
current.weatherType = this.convertWeatherType(data.current.weather[0].icon);
|
||||
current.humidity = data.current.humidity;
|
||||
@@ -330,14 +331,13 @@ WeatherProvider.register("openweathermap", {
|
||||
current.feelsLikeTemp = data.current.feels_like;
|
||||
}
|
||||
|
||||
let weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
|
||||
let weather = new WeatherObject();
|
||||
|
||||
// get hourly weather, if requested
|
||||
const hours = [];
|
||||
if (data.hasOwnProperty("hourly")) {
|
||||
for (const hour of data.hourly) {
|
||||
weather.date = moment(hour.dt, "X").utcOffset(data.timezone_offset / 60);
|
||||
// weather.date = moment(hour.dt, "X").utcOffset(data.timezone_offset/60).format(onecallDailyFormat+","+onecallHourlyFormat);
|
||||
weather.date = moment.unix(hour.dt).utcOffset(data.timezone_offset / 60);
|
||||
weather.temperature = hour.temp;
|
||||
weather.feelsLikeTemp = hour.feels_like;
|
||||
weather.humidity = hour.humidity;
|
||||
@@ -366,7 +366,7 @@ WeatherProvider.register("openweathermap", {
|
||||
}
|
||||
|
||||
hours.push(weather);
|
||||
weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
|
||||
weather = new WeatherObject();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,9 +374,9 @@ WeatherProvider.register("openweathermap", {
|
||||
const days = [];
|
||||
if (data.hasOwnProperty("daily")) {
|
||||
for (const day of data.daily) {
|
||||
weather.date = moment(day.dt, "X").utcOffset(data.timezone_offset / 60);
|
||||
weather.sunrise = moment(day.sunrise, "X").utcOffset(data.timezone_offset / 60);
|
||||
weather.sunset = moment(day.sunset, "X").utcOffset(data.timezone_offset / 60);
|
||||
weather.date = moment.unix(day.dt).utcOffset(data.timezone_offset / 60);
|
||||
weather.sunrise = moment.unix(day.sunrise).utcOffset(data.timezone_offset / 60);
|
||||
weather.sunset = moment.unix(day.sunset).utcOffset(data.timezone_offset / 60);
|
||||
weather.minTemperature = day.temp.min;
|
||||
weather.maxTemperature = day.temp.max;
|
||||
weather.humidity = day.humidity;
|
||||
@@ -405,7 +405,7 @@ WeatherProvider.register("openweathermap", {
|
||||
}
|
||||
|
||||
days.push(weather);
|
||||
weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
|
||||
weather = new WeatherObject();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -474,7 +474,7 @@ WeatherProvider.register("openweathermap", {
|
||||
return;
|
||||
}
|
||||
|
||||
params += "&units=" + this.config.units;
|
||||
params += "&units=metric"; // WeatherProviders should use metric internally and use the units only for when displaying data
|
||||
params += "&lang=" + this.config.lang;
|
||||
params += "&APPID=" + this.config.apiKey;
|
||||
|
||||
|
@@ -15,21 +15,22 @@ WeatherProvider.register("smhi", {
|
||||
|
||||
// Set the default config properties that is specific to this provider
|
||||
defaults: {
|
||||
lat: 0,
|
||||
lon: 0,
|
||||
precipitationValue: "pmedian"
|
||||
lat: 0, // Cant have more than 6 digits
|
||||
lon: 0, // Cant have more than 6 digits
|
||||
precipitationValue: "pmedian",
|
||||
location: false
|
||||
},
|
||||
|
||||
/**
|
||||
* Implements method in interface for fetching current weather
|
||||
* Implements method in interface for fetching current weather.
|
||||
*/
|
||||
fetchCurrentWeather() {
|
||||
this.fetchData(this.getURL())
|
||||
.then((data) => {
|
||||
let closest = this.getClosestToCurrentTime(data.timeSeries);
|
||||
let coordinates = this.resolveCoordinates(data);
|
||||
let weatherObject = this.convertWeatherDataToObject(closest, coordinates);
|
||||
this.setFetchedLocation(`(${coordinates.lat},${coordinates.lon})`);
|
||||
const closest = this.getClosestToCurrentTime(data.timeSeries);
|
||||
const coordinates = this.resolveCoordinates(data);
|
||||
const weatherObject = this.convertWeatherDataToObject(closest, coordinates);
|
||||
this.setFetchedLocation(this.config.location || `(${coordinates.lat},${coordinates.lon})`);
|
||||
this.setCurrentWeather(weatherObject);
|
||||
})
|
||||
.catch((error) => Log.error("Could not load data: " + error.message))
|
||||
@@ -37,21 +38,35 @@ WeatherProvider.register("smhi", {
|
||||
},
|
||||
|
||||
/**
|
||||
* Implements method in interface for fetching a forecast.
|
||||
* Handling hourly forecast would be easy as not grouping by day but it seems really specific for one weather provider for now.
|
||||
* Implements method in interface for fetching a multi-day forecast.
|
||||
*/
|
||||
fetchWeatherForecast() {
|
||||
this.fetchData(this.getURL())
|
||||
.then((data) => {
|
||||
let coordinates = this.resolveCoordinates(data);
|
||||
let weatherObjects = this.convertWeatherDataGroupedByDay(data.timeSeries, coordinates);
|
||||
this.setFetchedLocation(`(${coordinates.lat},${coordinates.lon})`);
|
||||
const coordinates = this.resolveCoordinates(data);
|
||||
const weatherObjects = this.convertWeatherDataGroupedBy(data.timeSeries, coordinates);
|
||||
this.setFetchedLocation(this.config.location || `(${coordinates.lat},${coordinates.lon})`);
|
||||
this.setWeatherForecast(weatherObjects);
|
||||
})
|
||||
.catch((error) => Log.error("Could not load data: " + error.message))
|
||||
.finally(() => this.updateAvailable());
|
||||
},
|
||||
|
||||
/**
|
||||
* Implements method in interface for fetching hourly forecasts.
|
||||
*/
|
||||
fetchWeatherHourly() {
|
||||
this.fetchData(this.getURL())
|
||||
.then((data) => {
|
||||
const coordinates = this.resolveCoordinates(data);
|
||||
const weatherObjects = this.convertWeatherDataGroupedBy(data.timeSeries, coordinates, "hour");
|
||||
this.setFetchedLocation(this.config.location || `(${coordinates.lat},${coordinates.lon})`);
|
||||
this.setWeatherHourly(weatherObjects);
|
||||
})
|
||||
.catch((error) => Log.error("Could not load data: " + error.message))
|
||||
.finally(() => this.updateAvailable());
|
||||
},
|
||||
|
||||
/**
|
||||
* Overrides method for setting config with checks for the precipitationValue being unset or invalid
|
||||
*
|
||||
@@ -60,7 +75,7 @@ WeatherProvider.register("smhi", {
|
||||
setConfig(config) {
|
||||
this.config = config;
|
||||
if (!config.precipitationValue || ["pmin", "pmean", "pmedian", "pmax"].indexOf(config.precipitationValue) === -1) {
|
||||
console.log("invalid or not set: " + config.precipitationValue);
|
||||
Log.log("invalid or not set: " + config.precipitationValue);
|
||||
config.precipitationValue = this.defaults.precipitationValue;
|
||||
}
|
||||
},
|
||||
@@ -89,11 +104,30 @@ 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: 6,
|
||||
maximumFractionDigits: 6
|
||||
});
|
||||
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`;
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculates the apparent temperature based on known atmospheric data.
|
||||
*
|
||||
* @param {object} weatherData Weatherdata to use for the calculation
|
||||
* @returns {number} The apparent temperature
|
||||
*/
|
||||
calculateApparentTemperature(weatherData) {
|
||||
const Ta = this.paramValue(weatherData, "t");
|
||||
const rh = this.paramValue(weatherData, "r");
|
||||
const ws = this.paramValue(weatherData, "ws");
|
||||
const p = (rh / 100) * 6.105 * Math.E * ((17.27 * Ta) / (237.7 + Ta));
|
||||
|
||||
return Ta + 0.33 * p - 0.7 * ws - 4;
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts the returned data into a WeatherObject with required properties set for both current weather and forecast.
|
||||
* The returned units is always in metric system.
|
||||
@@ -104,8 +138,7 @@ WeatherProvider.register("smhi", {
|
||||
* @returns {WeatherObject} The converted weatherdata at the specified location
|
||||
*/
|
||||
convertWeatherDataToObject(weatherData, coordinates) {
|
||||
// Weather data is only for Sweden and nobody in Sweden would use imperial
|
||||
let currentWeather = new WeatherObject("metric", "metric", "metric");
|
||||
let currentWeather = new WeatherObject();
|
||||
|
||||
currentWeather.date = moment(weatherData.validTime);
|
||||
currentWeather.updateSunTime(coordinates.lat, coordinates.lon);
|
||||
@@ -114,6 +147,7 @@ WeatherProvider.register("smhi", {
|
||||
currentWeather.windSpeed = this.paramValue(weatherData, "ws");
|
||||
currentWeather.windDirection = this.paramValue(weatherData, "wd");
|
||||
currentWeather.weatherType = this.convertWeatherType(this.paramValue(weatherData, "Wsymb2"), currentWeather.isDayTime());
|
||||
currentWeather.feelsLikeTemp = this.calculateApparentTemperature(weatherData);
|
||||
|
||||
// Determine the precipitation amount and category and update the
|
||||
// weatherObject with it, the valuetype to use can be configured or uses
|
||||
@@ -143,13 +177,14 @@ WeatherProvider.register("smhi", {
|
||||
},
|
||||
|
||||
/**
|
||||
* Takes all of the data points and converts it to one WeatherObject per day.
|
||||
* Takes all the data points and converts it to one WeatherObject per day.
|
||||
*
|
||||
* @param {object[]} allWeatherData Array of weatherdata
|
||||
* @param {object} coordinates Coordinates of the locations of the weather
|
||||
* @param {string} groupBy The interval to use for grouping the data (day, hour)
|
||||
* @returns {WeatherObject[]} Array of weatherobjects
|
||||
*/
|
||||
convertWeatherDataGroupedByDay(allWeatherData, coordinates) {
|
||||
convertWeatherDataGroupedBy(allWeatherData, coordinates, groupBy = "day") {
|
||||
let currentWeather;
|
||||
let result = [];
|
||||
|
||||
@@ -157,10 +192,11 @@ WeatherProvider.register("smhi", {
|
||||
let dayWeatherTypes = [];
|
||||
|
||||
for (const weatherObject of allWeatherObjects) {
|
||||
//If its the first object or if a day change we need to reset the summary object
|
||||
if (!currentWeather || !currentWeather.date.isSame(weatherObject.date, "day")) {
|
||||
currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||
//If its the first object or if a day/hour change we need to reset the summary object
|
||||
if (!currentWeather || !currentWeather.date.isSame(weatherObject.date, groupBy)) {
|
||||
currentWeather = new WeatherObject();
|
||||
dayWeatherTypes = [];
|
||||
currentWeather.temperature = weatherObject.temperature;
|
||||
currentWeather.date = weatherObject.date;
|
||||
currentWeather.minTemperature = Infinity;
|
||||
currentWeather.maxTemperature = -Infinity;
|
||||
@@ -170,7 +206,7 @@ WeatherProvider.register("smhi", {
|
||||
result.push(currentWeather);
|
||||
}
|
||||
|
||||
//Keep track of what icons has been used for each hour of daytime and use the middle one for the forecast
|
||||
//Keep track of what icons have been used for each hour of daytime and use the middle one for the forecast
|
||||
if (weatherObject.isDayTime()) {
|
||||
dayWeatherTypes.push(weatherObject.weatherType);
|
||||
}
|
||||
@@ -238,7 +274,7 @@ WeatherProvider.register("smhi", {
|
||||
|
||||
/**
|
||||
* Map the icon value from SMHI to an icon that MagicMirror² understands.
|
||||
* Uses different icons depending if its daytime or nighttime.
|
||||
* Uses different icons depending on if its daytime or nighttime.
|
||||
* SMHI's description of what the numeric value means is the comment after the case.
|
||||
*
|
||||
* @param {number} input The SMHI icon value
|
||||
|
63
modules/default/weather/providers/ukmetoffice.js
Executable file → Normal file
63
modules/default/weather/providers/ukmetoffice.js
Executable file → Normal file
@@ -1,4 +1,4 @@
|
||||
/* global WeatherProvider, WeatherObject */
|
||||
/* global WeatherProvider, WeatherObject, WeatherUtils */
|
||||
|
||||
/* MagicMirror²
|
||||
* Module: Weather
|
||||
@@ -21,11 +21,6 @@ WeatherProvider.register("ukmetoffice", {
|
||||
apiKey: ""
|
||||
},
|
||||
|
||||
units: {
|
||||
imperial: "us",
|
||||
metric: "si"
|
||||
},
|
||||
|
||||
// Overwrite the fetchCurrentWeather method.
|
||||
fetchCurrentWeather() {
|
||||
this.fetchData(this.getUrl("3hourly"))
|
||||
@@ -80,7 +75,7 @@ WeatherProvider.register("ukmetoffice", {
|
||||
* Generate a WeatherObject based on currentWeatherInformation
|
||||
*/
|
||||
generateWeatherObjectFromCurrentWeather(currentWeatherData) {
|
||||
const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
|
||||
const currentWeather = new WeatherObject();
|
||||
const location = currentWeatherData.SiteRep.DV.Location;
|
||||
|
||||
// data times are always UTC
|
||||
@@ -103,11 +98,11 @@ WeatherProvider.register("ukmetoffice", {
|
||||
if (timeInMins >= p && timeInMins - 180 < p) {
|
||||
// finally got the one we want, so populate weather object
|
||||
currentWeather.humidity = rep.H;
|
||||
currentWeather.temperature = this.convertTemp(rep.T);
|
||||
currentWeather.feelsLikeTemp = this.convertTemp(rep.F);
|
||||
currentWeather.temperature = rep.T;
|
||||
currentWeather.feelsLikeTemp = rep.F;
|
||||
currentWeather.precipitation = parseInt(rep.Pp);
|
||||
currentWeather.windSpeed = this.convertWindSpeed(rep.S);
|
||||
currentWeather.windDirection = this.convertWindDirection(rep.D);
|
||||
currentWeather.windSpeed = WeatherUtils.convertWindToMetric(rep.S);
|
||||
currentWeather.windDirection = WeatherUtils.convertWindDirection(rep.D);
|
||||
currentWeather.weatherType = this.convertWeatherType(rep.W);
|
||||
}
|
||||
}
|
||||
@@ -130,7 +125,7 @@ WeatherProvider.register("ukmetoffice", {
|
||||
// loop round the (5) periods getting the data
|
||||
// for each period array, Day is [0], Night is [1]
|
||||
for (const period of forecasts.SiteRep.DV.Location.Period) {
|
||||
const weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
|
||||
const weather = new WeatherObject();
|
||||
|
||||
// data times are always UTC
|
||||
const dateStr = period.value;
|
||||
@@ -140,8 +135,8 @@ WeatherProvider.register("ukmetoffice", {
|
||||
if (periodDate.isSameOrAfter(moment.utc().startOf("day"))) {
|
||||
// populate the weather object
|
||||
weather.date = moment.utc(dateStr.substr(0, 10), "YYYY-MM-DD");
|
||||
weather.minTemperature = this.convertTemp(period.Rep[1].Nm);
|
||||
weather.maxTemperature = this.convertTemp(period.Rep[0].Dm);
|
||||
weather.minTemperature = period.Rep[1].Nm;
|
||||
weather.maxTemperature = period.Rep[0].Dm;
|
||||
weather.weatherType = this.convertWeatherType(period.Rep[0].W);
|
||||
weather.precipitation = parseInt(period.Rep[0].PPd);
|
||||
|
||||
@@ -192,46 +187,6 @@ WeatherProvider.register("ukmetoffice", {
|
||||
return weatherTypes.hasOwnProperty(weatherType) ? weatherTypes[weatherType] : null;
|
||||
},
|
||||
|
||||
/*
|
||||
* Convert temp (from degrees C) if required
|
||||
*/
|
||||
convertTemp(tempInC) {
|
||||
return this.tempUnits === "imperial" ? (tempInC * 9) / 5 + 32 : tempInC;
|
||||
},
|
||||
|
||||
/*
|
||||
* Convert wind speed (from mph to m/s or km/h) if required
|
||||
*/
|
||||
convertWindSpeed(windInMph) {
|
||||
return this.windUnits === "metric" ? (this.useKmh ? windInMph * 1.60934 : windInMph / 2.23694) : windInMph;
|
||||
},
|
||||
|
||||
/*
|
||||
* Convert the wind direction cardinal to value
|
||||
*/
|
||||
convertWindDirection(windDirection) {
|
||||
const windCardinals = {
|
||||
N: 0,
|
||||
NNE: 22,
|
||||
NE: 45,
|
||||
ENE: 67,
|
||||
E: 90,
|
||||
ESE: 112,
|
||||
SE: 135,
|
||||
SSE: 157,
|
||||
S: 180,
|
||||
SSW: 202,
|
||||
SW: 225,
|
||||
WSW: 247,
|
||||
W: 270,
|
||||
WNW: 292,
|
||||
NW: 315,
|
||||
NNW: 337
|
||||
};
|
||||
|
||||
return windCardinals.hasOwnProperty(windDirection) ? windCardinals[windDirection] : null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Generates an url with api parameters based on the config.
|
||||
*
|
||||
|
@@ -20,11 +20,9 @@
|
||||
* weatherProvider: "ukmetofficedatahub",
|
||||
* apiBase: "https://api-metoffice.apiconnect.ibmcloud.com/metoffice/production/v0/forecasts/point/",
|
||||
* apiKey: "[YOUR API KEY]",
|
||||
* apiSecret: "[YOUR API SECRET]]",
|
||||
* apiSecret: "[YOUR API SECRET]",
|
||||
* lat: [LATITUDE (DECIMAL)],
|
||||
* lon: [LONGITUDE (DECIMAL)],
|
||||
* windUnits: "mps" | "kph" | "mph" (default)
|
||||
* tempUnits: "imperial" | "metric" (default)
|
||||
* lon: [LONGITUDE (DECIMAL)]
|
||||
*
|
||||
* At time of writing, free accounts are limited to 360 requests a day per service (hourly, 3hourly, daily); take this in mind when
|
||||
* setting your update intervals. For reference, 360 requests per day is once every 4 minutes.
|
||||
@@ -51,8 +49,7 @@ WeatherProvider.register("ukmetofficedatahub", {
|
||||
apiKey: "",
|
||||
apiSecret: "",
|
||||
lat: 0,
|
||||
lon: 0,
|
||||
windUnits: "mph"
|
||||
lon: 0
|
||||
},
|
||||
|
||||
// Build URL with query strings according to DataHub API (https://metoffice.apiconnect.ibmcloud.com/metoffice/production/api)
|
||||
@@ -89,7 +86,7 @@ WeatherProvider.register("ukmetofficedatahub", {
|
||||
fetchCurrentWeather() {
|
||||
this.fetchWeather(this.getUrl("hourly"), this.getHeaders())
|
||||
.then((data) => {
|
||||
// Check data is useable
|
||||
// Check data is usable
|
||||
if (!data || !data.features || !data.features[0].properties || !data.features[0].properties.timeSeries || data.features[0].properties.timeSeries.length === 0) {
|
||||
// Did not receive usable new data.
|
||||
// Maybe this needs a better check?
|
||||
@@ -109,13 +106,13 @@ WeatherProvider.register("ukmetofficedatahub", {
|
||||
// Catch any error(s)
|
||||
.catch((error) => Log.error("Could not load data: " + error.message))
|
||||
|
||||
// Let the module know there're new data available
|
||||
// Let the module know there is data available
|
||||
.finally(() => this.updateAvailable());
|
||||
},
|
||||
|
||||
// Create a WeatherObject using current weather data (data for the current hour)
|
||||
generateWeatherObjectFromCurrentWeather(currentWeatherData) {
|
||||
const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
|
||||
const currentWeather = new WeatherObject();
|
||||
|
||||
// Extract the actual forecasts
|
||||
let forecastDataHours = currentWeatherData.features[0].properties.timeSeries;
|
||||
@@ -128,19 +125,19 @@ WeatherProvider.register("ukmetofficedatahub", {
|
||||
let forecastTime = moment.utc(forecastDataHours[hour].time);
|
||||
if (nowUtc.isSameOrAfter(forecastTime) && nowUtc.isBefore(moment(forecastTime.add(1, "h")))) {
|
||||
currentWeather.date = forecastTime;
|
||||
currentWeather.windSpeed = this.convertWindSpeed(forecastDataHours[hour].windSpeed10m);
|
||||
currentWeather.windSpeed = forecastDataHours[hour].windSpeed10m;
|
||||
currentWeather.windDirection = forecastDataHours[hour].windDirectionFrom10m;
|
||||
currentWeather.temperature = this.convertTemp(forecastDataHours[hour].screenTemperature);
|
||||
currentWeather.minTemperature = this.convertTemp(forecastDataHours[hour].minScreenAirTemp);
|
||||
currentWeather.maxTemperature = this.convertTemp(forecastDataHours[hour].maxScreenAirTemp);
|
||||
currentWeather.temperature = forecastDataHours[hour].screenTemperature;
|
||||
currentWeather.minTemperature = forecastDataHours[hour].minScreenAirTemp;
|
||||
currentWeather.maxTemperature = forecastDataHours[hour].maxScreenAirTemp;
|
||||
currentWeather.weatherType = this.convertWeatherType(forecastDataHours[hour].significantWeatherCode);
|
||||
currentWeather.humidity = forecastDataHours[hour].screenRelativeHumidity;
|
||||
currentWeather.rain = forecastDataHours[hour].totalPrecipAmount;
|
||||
currentWeather.snow = forecastDataHours[hour].totalSnowAmount;
|
||||
currentWeather.precipitation = forecastDataHours[hour].probOfPrecipitation;
|
||||
currentWeather.feelsLikeTemp = this.convertTemp(forecastDataHours[hour].feelsLikeTemperature);
|
||||
currentWeather.feelsLikeTemp = forecastDataHours[hour].feelsLikeTemperature;
|
||||
|
||||
// Pass on full details so they can be used in custom templates
|
||||
// Pass on full details, so they can be used in custom templates
|
||||
// Note the units of the supplied data when using this (see top of file)
|
||||
currentWeather.rawData = forecastDataHours[hour];
|
||||
}
|
||||
@@ -148,7 +145,7 @@ WeatherProvider.register("ukmetofficedatahub", {
|
||||
|
||||
// Determine the sunrise/sunset times - (still) not supplied in UK Met Office data
|
||||
// Passes {longitude, latitude} to SunCalc, could pass height to, but
|
||||
// SunCalc.getTimes doesnt take that into account
|
||||
// SunCalc.getTimes doesn't take that into account
|
||||
currentWeather.updateSunTime(this.config.lat, this.config.lon);
|
||||
|
||||
return currentWeather;
|
||||
@@ -158,7 +155,7 @@ WeatherProvider.register("ukmetofficedatahub", {
|
||||
fetchWeatherForecast() {
|
||||
this.fetchWeather(this.getUrl("daily"), this.getHeaders())
|
||||
.then((data) => {
|
||||
// Check data is useable
|
||||
// Check data is usable
|
||||
if (!data || !data.features || !data.features[0].properties || !data.features[0].properties.timeSeries || data.features[0].properties.timeSeries.length === 0) {
|
||||
// Did not receive usable new data.
|
||||
// Maybe this needs a better check?
|
||||
@@ -178,7 +175,7 @@ WeatherProvider.register("ukmetofficedatahub", {
|
||||
// Catch any error(s)
|
||||
.catch((error) => Log.error("Could not load data: " + error.message))
|
||||
|
||||
// Let the module know there're new data available
|
||||
// Let the module know there is new data available
|
||||
.finally(() => this.updateAvailable());
|
||||
},
|
||||
|
||||
@@ -194,7 +191,7 @@ WeatherProvider.register("ukmetofficedatahub", {
|
||||
|
||||
// Go through each day in the forecasts
|
||||
for (let day in forecastDataDays) {
|
||||
const forecastWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
|
||||
const forecastWeather = new WeatherObject();
|
||||
|
||||
// Get date of forecast
|
||||
let forecastDate = moment.utc(forecastDataDays[day].time);
|
||||
@@ -202,11 +199,11 @@ WeatherProvider.register("ukmetofficedatahub", {
|
||||
// Check if forecast is for today or in the future (i.e., ignore yesterday's forecast)
|
||||
if (forecastDate.isSameOrAfter(today)) {
|
||||
forecastWeather.date = forecastDate;
|
||||
forecastWeather.minTemperature = this.convertTemp(forecastDataDays[day].nightMinScreenTemperature);
|
||||
forecastWeather.maxTemperature = this.convertTemp(forecastDataDays[day].dayMaxScreenTemperature);
|
||||
forecastWeather.minTemperature = forecastDataDays[day].nightMinScreenTemperature;
|
||||
forecastWeather.maxTemperature = forecastDataDays[day].dayMaxScreenTemperature;
|
||||
|
||||
// Using daytime forecast values
|
||||
forecastWeather.windSpeed = this.convertWindSpeed(forecastDataDays[day].midday10MWindSpeed);
|
||||
forecastWeather.windSpeed = forecastDataDays[day].midday10MWindSpeed;
|
||||
forecastWeather.windDirection = forecastDataDays[day].midday10MWindDirection;
|
||||
forecastWeather.weatherType = this.convertWeatherType(forecastDataDays[day].daySignificantWeatherCode);
|
||||
forecastWeather.precipitation = forecastDataDays[day].dayProbabilityOfPrecipitation;
|
||||
@@ -214,9 +211,9 @@ WeatherProvider.register("ukmetofficedatahub", {
|
||||
forecastWeather.humidity = forecastDataDays[day].middayRelativeHumidity;
|
||||
forecastWeather.rain = forecastDataDays[day].dayProbabilityOfRain;
|
||||
forecastWeather.snow = forecastDataDays[day].dayProbabilityOfSnow;
|
||||
forecastWeather.feelsLikeTemp = this.convertTemp(forecastDataDays[day].dayMaxFeelsLikeTemp);
|
||||
forecastWeather.feelsLikeTemp = forecastDataDays[day].dayMaxFeelsLikeTemp;
|
||||
|
||||
// Pass on full details so they can be used in custom templates
|
||||
// Pass on full details, so they can be used in custom templates
|
||||
// Note the units of the supplied data when using this (see top of file)
|
||||
forecastWeather.rawData = forecastDataDays[day];
|
||||
|
||||
@@ -232,27 +229,6 @@ WeatherProvider.register("ukmetofficedatahub", {
|
||||
this.fetchedLocationName = name;
|
||||
},
|
||||
|
||||
// Convert temperatures to Fahrenheit (from degrees C), if required
|
||||
convertTemp(tempInC) {
|
||||
return this.config.tempUnits === "imperial" ? (tempInC * 9) / 5 + 32 : tempInC;
|
||||
},
|
||||
|
||||
// Convert wind speed from metres per second
|
||||
// To keep the supplied metres per second units, use "mps"
|
||||
// To use kilometres per hour, use "kph"
|
||||
// Else assumed imperial and the value is returned in miles per hour (a Met Office user is likely to be UK-based)
|
||||
convertWindSpeed(windInMpS) {
|
||||
if (this.config.windUnits === "mps") {
|
||||
return windInMpS;
|
||||
}
|
||||
|
||||
if (this.config.windUnits === "kph" || this.config.windUnits === "metric" || this.config.useKmh) {
|
||||
return windInMpS * 3.6;
|
||||
}
|
||||
|
||||
return windInMpS * 2.23694;
|
||||
},
|
||||
|
||||
// Match the Met Office "significant weather code" to a weathericons.css icon
|
||||
// Use: https://metoffice.apiconnect.ibmcloud.com/metoffice/production/node/264
|
||||
// and: https://erikflowers.github.io/weather-icons/
|
||||
|
@@ -18,17 +18,11 @@ WeatherProvider.register("weatherbit", {
|
||||
// Set the default config properties that is specific to this provider
|
||||
defaults: {
|
||||
apiBase: "https://api.weatherbit.io/v2.0",
|
||||
weatherEndpoint: "/current",
|
||||
apiKey: "",
|
||||
lat: 0,
|
||||
lon: 0
|
||||
},
|
||||
|
||||
units: {
|
||||
imperial: "I",
|
||||
metric: "M"
|
||||
},
|
||||
|
||||
fetchedLocation: function () {
|
||||
return this.fetchedLocationName || "";
|
||||
},
|
||||
@@ -69,10 +63,34 @@ WeatherProvider.register("weatherbit", {
|
||||
.finally(() => this.updateAvailable());
|
||||
},
|
||||
|
||||
/**
|
||||
* Overrides method for setting config to check if endpoint is correct for hourly
|
||||
*
|
||||
* @param {object} config The configuration object
|
||||
*/
|
||||
setConfig(config) {
|
||||
this.config = config;
|
||||
if (!this.config.weatherEndpoint) {
|
||||
switch (this.config.type) {
|
||||
case "hourly":
|
||||
this.config.weatherEndpoint = "/forecast/hourly";
|
||||
break;
|
||||
case "daily":
|
||||
case "forecast":
|
||||
this.config.weatherEndpoint = "/forecast/daily";
|
||||
break;
|
||||
case "current":
|
||||
this.config.weatherEndpoint = "/current";
|
||||
break;
|
||||
default:
|
||||
Log.error("weatherEndpoint not configured and could not resolve it based on type");
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Create a URL from the config and base URL.
|
||||
getUrl() {
|
||||
const units = this.units[this.config.units] || "auto";
|
||||
return `${this.config.apiBase}${this.config.weatherEndpoint}?lat=${this.config.lat}&lon=${this.config.lon}&units=${units}&key=${this.config.apiKey}`;
|
||||
return `${this.config.apiBase}${this.config.weatherEndpoint}?lat=${this.config.lat}&lon=${this.config.lon}&units=M&key=${this.config.apiKey}`;
|
||||
},
|
||||
|
||||
// Implement WeatherDay generator.
|
||||
@@ -82,9 +100,9 @@ WeatherProvider.register("weatherbit", {
|
||||
let tzOffset = d.getTimezoneOffset();
|
||||
tzOffset = tzOffset * -1;
|
||||
|
||||
const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||
const currentWeather = new WeatherObject();
|
||||
|
||||
currentWeather.date = moment(currentWeatherData.data[0].ts, "X");
|
||||
currentWeather.date = moment.unix(currentWeatherData.data[0].ts);
|
||||
currentWeather.humidity = parseFloat(currentWeatherData.data[0].rh);
|
||||
currentWeather.temperature = parseFloat(currentWeatherData.data[0].temp);
|
||||
currentWeather.windSpeed = parseFloat(currentWeatherData.data[0].wind_spd);
|
||||
@@ -102,7 +120,7 @@ WeatherProvider.register("weatherbit", {
|
||||
const days = [];
|
||||
|
||||
for (const forecast of forecasts) {
|
||||
const weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||
const weather = new WeatherObject();
|
||||
|
||||
weather.date = moment(forecast.datetime, "YYYY-MM-DD");
|
||||
weather.minTemperature = forecast.min_temp;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* global WeatherProvider, WeatherObject */
|
||||
/* global WeatherProvider, WeatherObject, WeatherUtils */
|
||||
|
||||
/* MagicMirror²
|
||||
* Module: Weather
|
||||
@@ -23,36 +23,19 @@ WeatherProvider.register("weatherflow", {
|
||||
stationid: ""
|
||||
},
|
||||
|
||||
units: {
|
||||
imperial: {
|
||||
temp: "f",
|
||||
wind: "mph",
|
||||
pressure: "hpa",
|
||||
precip: "in",
|
||||
distance: "mi"
|
||||
},
|
||||
metric: {
|
||||
temp: "c",
|
||||
wind: "kph",
|
||||
pressure: "mb",
|
||||
precip: "mm",
|
||||
distance: "km"
|
||||
}
|
||||
},
|
||||
|
||||
fetchCurrentWeather() {
|
||||
this.fetchData(this.getUrl())
|
||||
.then((data) => {
|
||||
const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
|
||||
const currentWeather = new WeatherObject();
|
||||
currentWeather.date = moment();
|
||||
|
||||
currentWeather.humidity = data.current_conditions.relative_humidity;
|
||||
currentWeather.temperature = data.current_conditions.air_temperature;
|
||||
currentWeather.windSpeed = data.current_conditions.wind_avg;
|
||||
currentWeather.windSpeed = WeatherUtils.convertWindToMs(data.current_conditions.wind_avg);
|
||||
currentWeather.windDirection = data.current_conditions.wind_direction;
|
||||
currentWeather.weatherType = data.forecast.daily[0].icon;
|
||||
currentWeather.sunrise = moment(data.forecast.daily[0].sunrise, "X");
|
||||
currentWeather.sunset = moment(data.forecast.daily[0].sunset, "X");
|
||||
currentWeather.sunrise = moment.unix(data.forecast.daily[0].sunrise);
|
||||
currentWeather.sunset = moment.unix(data.forecast.daily[0].sunset);
|
||||
this.setCurrentWeather(currentWeather);
|
||||
})
|
||||
.catch(function (request) {
|
||||
@@ -67,9 +50,9 @@ WeatherProvider.register("weatherflow", {
|
||||
const days = [];
|
||||
|
||||
for (const forecast of data.forecast.daily) {
|
||||
const weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
|
||||
const weather = new WeatherObject();
|
||||
|
||||
weather.date = moment(forecast.day_start_local, "X");
|
||||
weather.date = moment.unix(forecast.day_start_local);
|
||||
weather.minTemperature = forecast.air_temp_low;
|
||||
weather.maxTemperature = forecast.air_temp_high;
|
||||
weather.weatherType = forecast.icon;
|
||||
@@ -88,22 +71,6 @@ WeatherProvider.register("weatherflow", {
|
||||
|
||||
// Create a URL from the config and base URL.
|
||||
getUrl() {
|
||||
return (
|
||||
this.config.apiBase +
|
||||
"better_forecast?station_id=" +
|
||||
this.config.stationid +
|
||||
"&units_temp=" +
|
||||
this.units[this.config.units].temp +
|
||||
"&units_wind=" +
|
||||
this.units[this.config.units].wind +
|
||||
"&units_pressure=" +
|
||||
this.units[this.config.units].pressure +
|
||||
"&units_precip=" +
|
||||
this.units[this.config.units].precip +
|
||||
"&units_distance=" +
|
||||
this.units[this.config.units].distance +
|
||||
"&token=" +
|
||||
this.config.token
|
||||
);
|
||||
return `${this.config.apiBase}better_forecast?station_id=${this.config.stationid}&units_temp=c&units_wind=kph&units_pressure=mb&units_precip=mm&units_distance=km&token=${this.config.token}`;
|
||||
}
|
||||
});
|
||||
|
134
modules/default/weather/providers/weathergov.js
Executable file → Normal file
134
modules/default/weather/providers/weathergov.js
Executable file → Normal file
@@ -1,4 +1,4 @@
|
||||
/* global WeatherProvider, WeatherObject */
|
||||
/* global WeatherProvider, WeatherObject, WeatherUtils */
|
||||
|
||||
/* MagicMirror²
|
||||
* Module: Weather
|
||||
@@ -22,7 +22,6 @@ WeatherProvider.register("weathergov", {
|
||||
// Set the default config properties that is specific to this provider
|
||||
defaults: {
|
||||
apiBase: "https://api.weather.gov/points/",
|
||||
weatherEndpoint: "/forecast",
|
||||
lat: 0,
|
||||
lon: 0
|
||||
},
|
||||
@@ -57,7 +56,7 @@ WeatherProvider.register("weathergov", {
|
||||
// Overwrite the fetchCurrentWeather method.
|
||||
fetchCurrentWeather() {
|
||||
if (!this.configURLs) {
|
||||
Log.info("fetch wx waiting on config URLs");
|
||||
Log.info("fetchCurrentWeather: fetch wx waiting on config URLs");
|
||||
return;
|
||||
}
|
||||
this.fetchData(this.stationObsURL)
|
||||
@@ -78,7 +77,7 @@ WeatherProvider.register("weathergov", {
|
||||
// Overwrite the fetchWeatherForecast method.
|
||||
fetchWeatherForecast() {
|
||||
if (!this.configURLs) {
|
||||
Log.info("fetch wx waiting on config URLs");
|
||||
Log.info("fetchWeatherForecast: fetch wx waiting on config URLs");
|
||||
return;
|
||||
}
|
||||
this.fetchData(this.forecastURL)
|
||||
@@ -96,6 +95,28 @@ WeatherProvider.register("weathergov", {
|
||||
.finally(() => this.updateAvailable());
|
||||
},
|
||||
|
||||
// Overwrite the fetchWeatherHourly method.
|
||||
fetchWeatherHourly() {
|
||||
if (!this.configURLs) {
|
||||
Log.info("fetchWeatherHourly: fetch wx waiting on config URLs");
|
||||
return;
|
||||
}
|
||||
this.fetchData(this.forecastHourlyURL)
|
||||
.then((data) => {
|
||||
if (!data) {
|
||||
// Did not receive usable new data.
|
||||
// Maybe this needs a better check?
|
||||
return;
|
||||
}
|
||||
const hourly = this.generateWeatherObjectsFromHourly(data.properties.periods);
|
||||
this.setWeatherHourly(hourly);
|
||||
})
|
||||
.catch(function (request) {
|
||||
Log.error("Could not load data ... ", request);
|
||||
})
|
||||
.finally(() => this.updateAvailable());
|
||||
},
|
||||
|
||||
/** Weather.gov Specific Methods - These are not part of the default provider methods */
|
||||
|
||||
/*
|
||||
@@ -110,8 +131,8 @@ WeatherProvider.register("weathergov", {
|
||||
}
|
||||
this.fetchedLocationName = data.properties.relativeLocation.properties.city + ", " + data.properties.relativeLocation.properties.state;
|
||||
Log.log("Forecast location is " + this.fetchedLocationName);
|
||||
this.forecastURL = data.properties.forecast;
|
||||
this.forecastHourlyURL = data.properties.forecastHourly;
|
||||
this.forecastURL = data.properties.forecast + "?units=si";
|
||||
this.forecastHourlyURL = data.properties.forecastHourly + "?units=si";
|
||||
this.forecastGridDataURL = data.properties.forecastGridData;
|
||||
this.observationStationsURL = data.properties.observationStations;
|
||||
// with this URL, we chain another promise for the station obs URL
|
||||
@@ -130,14 +151,49 @@ WeatherProvider.register("weathergov", {
|
||||
.finally(() => {
|
||||
// excellent, let's fetch some actual wx data
|
||||
this.configURLs = true;
|
||||
|
||||
// handle 'forecast' config, fall back to 'current'
|
||||
if (config.type === "forecast") {
|
||||
this.fetchWeatherForecast();
|
||||
} else if (config.type === "hourly") {
|
||||
this.fetchWeatherHourly();
|
||||
} else {
|
||||
this.fetchCurrentWeather();
|
||||
}
|
||||
});
|
||||
},
|
||||
/*
|
||||
* Generate a WeatherObject based on hourlyWeatherInformation
|
||||
* Weather.gov API uses specific units; API does not include choice of units
|
||||
* ... object needs data in units based on config!
|
||||
*/
|
||||
generateWeatherObjectsFromHourly(forecasts) {
|
||||
const days = [];
|
||||
|
||||
// variable for date
|
||||
let weather = new WeatherObject();
|
||||
for (const forecast of forecasts) {
|
||||
weather.date = moment(forecast.startTime.slice(0, 19));
|
||||
if (forecast.windSpeed.search(" ") < 0) {
|
||||
weather.windSpeed = forecast.windSpeed;
|
||||
} else {
|
||||
weather.windSpeed = forecast.windSpeed.slice(0, forecast.windSpeed.search(" "));
|
||||
}
|
||||
weather.windDirection = this.convertWindDirection(forecast.windDirection);
|
||||
weather.temperature = forecast.temperature;
|
||||
weather.tempUnits = forecast.temperatureUnit;
|
||||
// use the forecast isDayTime attribute to help build the weatherType label
|
||||
weather.weatherType = this.convertWeatherType(forecast.shortForecast, forecast.isDaytime);
|
||||
|
||||
days.push(weather);
|
||||
|
||||
weather = new WeatherObject();
|
||||
}
|
||||
|
||||
// push weather information to days array
|
||||
days.push(weather);
|
||||
return days;
|
||||
},
|
||||
|
||||
/*
|
||||
* Generate a WeatherObject based on currentWeatherInformation
|
||||
@@ -145,24 +201,24 @@ WeatherProvider.register("weathergov", {
|
||||
* ... object needs data in units based on config!
|
||||
*/
|
||||
generateWeatherObjectFromCurrentWeather(currentWeatherData) {
|
||||
const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
|
||||
const currentWeather = new WeatherObject();
|
||||
|
||||
currentWeather.date = moment(currentWeatherData.timestamp);
|
||||
currentWeather.temperature = this.convertTemp(currentWeatherData.temperature.value);
|
||||
currentWeather.windSpeed = this.convertSpeed(currentWeatherData.windSpeed.value);
|
||||
currentWeather.temperature = currentWeatherData.temperature.value;
|
||||
currentWeather.windSpeed = WeatherUtils.convertWindToMs(currentWeatherData.windSpeed.value);
|
||||
currentWeather.windDirection = currentWeatherData.windDirection.value;
|
||||
currentWeather.minTemperature = this.convertTemp(currentWeatherData.minTemperatureLast24Hours.value);
|
||||
currentWeather.maxTemperature = this.convertTemp(currentWeatherData.maxTemperatureLast24Hours.value);
|
||||
currentWeather.minTemperature = currentWeatherData.minTemperatureLast24Hours.value;
|
||||
currentWeather.maxTemperature = currentWeatherData.maxTemperatureLast24Hours.value;
|
||||
currentWeather.humidity = Math.round(currentWeatherData.relativeHumidity.value);
|
||||
currentWeather.rain = null;
|
||||
currentWeather.snow = null;
|
||||
currentWeather.precipitation = this.convertLength(currentWeatherData.precipitationLastHour.value);
|
||||
if (currentWeatherData.heatIndex.value !== null) {
|
||||
currentWeather.feelsLikeTemp = this.convertTemp(currentWeatherData.heatIndex.value);
|
||||
currentWeather.feelsLikeTemp = currentWeatherData.heatIndex.value;
|
||||
} else if (currentWeatherData.windChill.value !== null) {
|
||||
currentWeather.feelsLikeTemp = this.convertTemp(currentWeatherData.windChill.value);
|
||||
currentWeather.feelsLikeTemp = currentWeatherData.windChill.value;
|
||||
} else {
|
||||
currentWeather.feelsLikeTemp = this.convertTemp(currentWeatherData.temperature.value);
|
||||
currentWeather.feelsLikeTemp = currentWeatherData.temperature.value;
|
||||
}
|
||||
// determine the sunrise/sunset times - not supplied in weather.gov data
|
||||
currentWeather.updateSunTime(this.config.lat, this.config.lon);
|
||||
@@ -191,7 +247,7 @@ WeatherProvider.register("weathergov", {
|
||||
let maxTemp = [];
|
||||
// variable for date
|
||||
let date = "";
|
||||
let weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
|
||||
let weather = new WeatherObject();
|
||||
weather.precipitation = 0;
|
||||
|
||||
for (const forecast of forecasts) {
|
||||
@@ -203,7 +259,7 @@ WeatherProvider.register("weathergov", {
|
||||
// push weather information to days array
|
||||
days.push(weather);
|
||||
// create new weather-object
|
||||
weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
|
||||
weather = new WeatherObject();
|
||||
|
||||
minTemp = [];
|
||||
maxTemp = [];
|
||||
@@ -242,26 +298,6 @@ WeatherProvider.register("weathergov", {
|
||||
/*
|
||||
* Unit conversions
|
||||
*/
|
||||
// conversion to fahrenheit
|
||||
convertTemp(temp) {
|
||||
if (this.config.tempUnits === "imperial") {
|
||||
return (9 / 5) * temp + 32;
|
||||
} else {
|
||||
return temp;
|
||||
}
|
||||
},
|
||||
// conversion to mph or kmh
|
||||
convertSpeed(metSec) {
|
||||
if (this.config.windUnits === "imperial") {
|
||||
return metSec * 2.23694;
|
||||
} else {
|
||||
if (this.config.useKmh) {
|
||||
return metSec * 3.6;
|
||||
} else {
|
||||
return metSec;
|
||||
}
|
||||
}
|
||||
},
|
||||
// conversion to inches
|
||||
convertLength(meters) {
|
||||
if (this.config.units === "imperial") {
|
||||
@@ -339,31 +375,5 @@ WeatherProvider.register("weathergov", {
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
/*
|
||||
Convert the direction into Degrees
|
||||
*/
|
||||
convertWindDirection(windDirection) {
|
||||
const windCardinals = {
|
||||
N: 0,
|
||||
NNE: 22,
|
||||
NE: 45,
|
||||
ENE: 67,
|
||||
E: 90,
|
||||
ESE: 112,
|
||||
SE: 135,
|
||||
SSE: 157,
|
||||
S: 180,
|
||||
SSW: 202,
|
||||
SW: 225,
|
||||
WSW: 247,
|
||||
W: 270,
|
||||
WNW: 292,
|
||||
NW: 315,
|
||||
NNW: 337
|
||||
};
|
||||
|
||||
return windCardinals.hasOwnProperty(windDirection) ? windCardinals[windDirection] : null;
|
||||
}
|
||||
});
|
||||
|
626
modules/default/weather/providers/yr.js
Normal file
626
modules/default/weather/providers/yr.js
Normal file
@@ -0,0 +1,626 @@
|
||||
/* global WeatherProvider, WeatherObject */
|
||||
|
||||
/* MagicMirror²
|
||||
* Module: Weather
|
||||
* Provider: Yr.no
|
||||
*
|
||||
* By Magnus Marthinsen
|
||||
* MIT Licensed
|
||||
*
|
||||
* This class is a provider for Yr.no, a norwegian sweather service.
|
||||
*
|
||||
* Terms of service: https://developer.yr.no/doc/TermsOfService/
|
||||
*/
|
||||
WeatherProvider.register("yr", {
|
||||
providerName: "Yr",
|
||||
|
||||
// Set the default config properties that is specific to this provider
|
||||
defaults: {
|
||||
useCorsProxy: true,
|
||||
apiBase: "https://api.met.no/weatherapi",
|
||||
altitude: 0,
|
||||
currentForecastHours: 1 //1, 6 or 12
|
||||
},
|
||||
|
||||
start() {
|
||||
if (typeof Storage === "undefined") {
|
||||
//local storage unavailable
|
||||
Log.error("The Yr weather provider requires local storage.");
|
||||
throw new Error("Local storage not available");
|
||||
}
|
||||
Log.info(`Weather provider: ${this.providerName} started.`);
|
||||
},
|
||||
|
||||
fetchCurrentWeather() {
|
||||
this.getCurrentWeather()
|
||||
.then((currentWeather) => {
|
||||
this.setCurrentWeather(currentWeather);
|
||||
this.updateAvailable();
|
||||
})
|
||||
.catch((error) => {
|
||||
Log.error(error);
|
||||
throw new Error(error);
|
||||
});
|
||||
},
|
||||
|
||||
async getCurrentWeather() {
|
||||
const getRequests = [this.getWeatherData(), this.getStellarData()];
|
||||
const [weatherData, stellarData] = await Promise.all(getRequests);
|
||||
if (!stellarData) {
|
||||
Log.warn("No stelar data available.");
|
||||
}
|
||||
if (!weatherData.properties.timeseries || !weatherData.properties.timeseries[0]) {
|
||||
Log.error("No weather data available.");
|
||||
return;
|
||||
}
|
||||
const currentTime = moment();
|
||||
let forecast = weatherData.properties.timeseries[0];
|
||||
let closestTimeInPast = currentTime.diff(moment(forecast.time));
|
||||
for (const forecastTime of weatherData.properties.timeseries) {
|
||||
const comparison = currentTime.diff(moment(forecastTime.time));
|
||||
if (0 < comparison && comparison < closestTimeInPast) {
|
||||
closestTimeInPast = comparison;
|
||||
forecast = forecastTime;
|
||||
}
|
||||
}
|
||||
const forecastXHours = this.getForecastForXHoursFrom(forecast.data);
|
||||
forecast.weatherType = this.convertWeatherType(forecastXHours.summary.symbol_code, forecast.time);
|
||||
forecast.precipitation = forecastXHours.details?.precipitation_amount;
|
||||
forecast.minTemperature = forecastXHours.details?.air_temperature_min;
|
||||
forecast.maxTemperature = forecastXHours.details?.air_temperature_max;
|
||||
return this.getWeatherDataFrom(forecast, stellarData, weatherData.properties.meta.units);
|
||||
},
|
||||
|
||||
getWeatherData() {
|
||||
return new Promise((resolve, reject) => {
|
||||
// If a user has several Yr-modules, for instance one current and one forecast, the API calls must be synchronized across classes.
|
||||
// This is to avoid multiple similar calls to the API.
|
||||
let shouldWait = localStorage.getItem("yrIsFetchingWeatherData");
|
||||
if (shouldWait) {
|
||||
const checkForGo = setInterval(function () {
|
||||
shouldWait = localStorage.getItem("yrIsFetchingWeatherData");
|
||||
}, 100);
|
||||
setTimeout(function () {
|
||||
clearInterval(checkForGo);
|
||||
shouldWait = false;
|
||||
}, 5000); //Assume other fetch finished but failed to remove lock
|
||||
const attemptFetchWeather = setInterval(() => {
|
||||
if (!shouldWait) {
|
||||
clearInterval(checkForGo);
|
||||
clearInterval(attemptFetchWeather);
|
||||
this.getWeatherDataFromYrOrCache(resolve, reject);
|
||||
}
|
||||
}, 100);
|
||||
} else {
|
||||
this.getWeatherDataFromYrOrCache(resolve, reject);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
getWeatherDataFromYrOrCache(resolve, reject) {
|
||||
localStorage.setItem("yrIsFetchingWeatherData", "true");
|
||||
|
||||
let weatherData = this.getWeatherDataFromCache();
|
||||
if (this.weatherDataIsValid(weatherData)) {
|
||||
localStorage.removeItem("yrIsFetchingWeatherData");
|
||||
Log.debug("Weather data found in cache.");
|
||||
resolve(weatherData);
|
||||
} else {
|
||||
this.getWeatherDataFromYr(weatherData?.downloadedAt)
|
||||
.then((weatherData) => {
|
||||
Log.debug("Got weather data from yr.");
|
||||
if (weatherData) {
|
||||
this.cacheWeatherData(weatherData);
|
||||
} else {
|
||||
//Undefined if unchanged
|
||||
weatherData = this.getWeatherDataFromCache();
|
||||
}
|
||||
resolve(weatherData);
|
||||
})
|
||||
.catch((err) => {
|
||||
Log.error(err);
|
||||
reject("Unable to get weather data from Yr.");
|
||||
})
|
||||
.finally(() => {
|
||||
localStorage.removeItem("yrIsFetchingWeatherData");
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
weatherDataIsValid(weatherData) {
|
||||
return (
|
||||
weatherData &&
|
||||
weatherData.timeout &&
|
||||
0 < moment(weatherData.timeout).diff(moment()) &&
|
||||
(!weatherData.geometry || !weatherData.geometry.coordinates || !weatherData.geometry.coordinates.length < 2 || (weatherData.geometry.coordinates[0] === this.config.lat && weatherData.geometry.coordinates[1] === this.config.lon))
|
||||
);
|
||||
},
|
||||
|
||||
getWeatherDataFromCache() {
|
||||
const weatherData = localStorage.getItem("weatherData");
|
||||
if (weatherData) {
|
||||
return JSON.parse(weatherData);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
},
|
||||
|
||||
getWeatherDataFromYr(currentDataFetchedAt) {
|
||||
const requestHeaders = [{ name: "Accept", value: "application/json" }];
|
||||
if (currentDataFetchedAt) {
|
||||
requestHeaders.push({ name: "If-Modified-Since", value: currentDataFetchedAt });
|
||||
}
|
||||
|
||||
const expectedResponseHeaders = ["expires", "date"];
|
||||
|
||||
return this.fetchData(this.getForecastUrl(), "json", requestHeaders, expectedResponseHeaders)
|
||||
.then((data) => {
|
||||
if (!data || !data.headers) return data;
|
||||
data.timeout = data.headers.find((header) => header.name === "expires").value;
|
||||
data.downloadedAt = data.headers.find((header) => header.name === "date").value;
|
||||
data.headers = undefined;
|
||||
return data;
|
||||
})
|
||||
.catch((err) => {
|
||||
Log.error("Could not load weather data.", err);
|
||||
throw new Error(err);
|
||||
});
|
||||
},
|
||||
|
||||
getForecastUrl() {
|
||||
if (!this.config.lat) {
|
||||
Log.error("Latitude not provided.");
|
||||
throw new Error("Latitude not provided.");
|
||||
}
|
||||
if (!this.config.lon) {
|
||||
Log.error("Longitude not provided.");
|
||||
throw new Error("Longitude not provided.");
|
||||
}
|
||||
|
||||
let lat = this.config.lat.toString();
|
||||
let lon = this.config.lon.toString();
|
||||
const altitude = this.config.altitude ?? 0;
|
||||
|
||||
if (lat.includes(".") && lat.split(".")[1].length > 4) {
|
||||
Log.warn("Latitude is too specific for weather data. Do not use more than four decimals. Trimming to maximum length.");
|
||||
const latParts = lat.split(".");
|
||||
lat = `${latParts[0]}.${latParts[1].substring(0, 4)}`;
|
||||
}
|
||||
if (lon.includes(".") && lon.split(".")[1].length > 4) {
|
||||
Log.warn("Longitude is too specific for weather data. Do not use more than four decimals. Trimming to maximum length.");
|
||||
const lonParts = lon.split(".");
|
||||
lon = `${lonParts[0]}.${lonParts[1].substring(0, 4)}`;
|
||||
}
|
||||
|
||||
return `${this.config.apiBase}/locationforecast/2.0/complete?&altitude=${altitude}&lat=${lat}&lon=${lon}`;
|
||||
},
|
||||
|
||||
cacheWeatherData(weatherData) {
|
||||
localStorage.setItem("weatherData", JSON.stringify(weatherData));
|
||||
},
|
||||
|
||||
getAuthenticationString() {
|
||||
if (!this.config.authenticationEmail) throw new Error("Authentication email not provided.");
|
||||
return `${this.config.applicaitionName} ${this.config.authenticationEmail}`;
|
||||
},
|
||||
|
||||
getStellarData() {
|
||||
// If a user has several Yr-modules, for instance one current and one forecast, the API calls must be synchronized across classes.
|
||||
// This is to avoid multiple similar calls to the API.
|
||||
return new Promise((resolve, reject) => {
|
||||
let shouldWait = localStorage.getItem("yrIsFetchingStellarData");
|
||||
if (shouldWait) {
|
||||
const checkForGo = setInterval(function () {
|
||||
shouldWait = localStorage.getItem("yrIsFetchingStellarData");
|
||||
}, 100);
|
||||
setTimeout(function () {
|
||||
clearInterval(checkForGo);
|
||||
shouldWait = false;
|
||||
}, 5000); //Assume other fetch finished but failed to remove lock
|
||||
const attemptFetchWeather = setInterval(() => {
|
||||
if (!shouldWait) {
|
||||
clearInterval(checkForGo);
|
||||
clearInterval(attemptFetchWeather);
|
||||
this.getStellarDataFromYrOrCache(resolve, reject);
|
||||
}
|
||||
}, 100);
|
||||
} else {
|
||||
this.getStellarDataFromYrOrCache(resolve, reject);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
getStellarDataFromYrOrCache(resolve, reject) {
|
||||
localStorage.setItem("yrIsFetchingStellarData", "true");
|
||||
|
||||
let stellarData = this.getStellarDataFromCache();
|
||||
const today = moment().format("YYYY-MM-DD");
|
||||
const tomorrow = moment().add(1, "days").format("YYYY-MM-DD");
|
||||
if (stellarData && stellarData.today && stellarData.today.date === today && stellarData.tomorrow && stellarData.tomorrow.date === tomorrow) {
|
||||
Log.debug("Stellar data found in cache.");
|
||||
localStorage.removeItem("yrIsFetchingStellarData");
|
||||
resolve(stellarData);
|
||||
} else if (stellarData && stellarData.tomorrow && stellarData.tomorrow.date === today) {
|
||||
Log.debug("stellar data for today found in cache, but not for tomorrow.");
|
||||
stellarData.today = stellarData.tomorrow;
|
||||
this.getStellarDataFromYr(tomorrow)
|
||||
.then((data) => {
|
||||
if (data) {
|
||||
data.date = tomorrow;
|
||||
stellarData.tomorrow = data;
|
||||
this.cacheStellarData(stellarData);
|
||||
resolve(stellarData);
|
||||
} else {
|
||||
reject("No stellar data returned from Yr for " + tomorrow);
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
Log.error(err);
|
||||
reject("Unable to get stellar data from Yr for " + tomorrow);
|
||||
})
|
||||
.finally(() => {
|
||||
localStorage.removeItem("yrIsFetchingStellarData");
|
||||
});
|
||||
} else {
|
||||
this.getStellarDataFromYr(today, 2)
|
||||
.then((stellarData) => {
|
||||
if (stellarData) {
|
||||
stellarData = {
|
||||
today: stellarData
|
||||
};
|
||||
stellarData.tomorrow = Object.assign({}, stellarData.today);
|
||||
stellarData.today.date = today;
|
||||
stellarData.tomorrow.date = tomorrow;
|
||||
this.cacheStellarData(stellarData);
|
||||
resolve(stellarData);
|
||||
} else {
|
||||
Log.error("Something went wrong when fetching stellar data. Responses: " + stellarData);
|
||||
reject(stellarData);
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
Log.error(err);
|
||||
reject("Unable to get stellar data from Yr.");
|
||||
})
|
||||
.finally(() => {
|
||||
localStorage.removeItem("yrIsFetchingStellarData");
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
getStellarDataFromCache() {
|
||||
const stellarData = localStorage.getItem("stellarData");
|
||||
if (stellarData) {
|
||||
return JSON.parse(stellarData);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
},
|
||||
|
||||
getStellarDataFromYr(date, days = 1) {
|
||||
const requestHeaders = [{ name: "Accept", value: "application/json" }];
|
||||
return this.fetchData(this.getStellarDatatUrl(date, days), "json", requestHeaders)
|
||||
.then((data) => {
|
||||
Log.debug("Got stellar data from yr.");
|
||||
return data;
|
||||
})
|
||||
.catch((err) => {
|
||||
Log.error("Could not load weather data.", err);
|
||||
throw new Error(err);
|
||||
});
|
||||
},
|
||||
|
||||
getStellarDatatUrl(date, days) {
|
||||
if (!this.config.lat) {
|
||||
Log.error("Latitude not provided.");
|
||||
throw new Error("Latitude not provided.");
|
||||
}
|
||||
if (!this.config.lon) {
|
||||
Log.error("Longitude not provided.");
|
||||
throw new Error("Longitude not provided.");
|
||||
}
|
||||
|
||||
let lat = this.config.lat.toString();
|
||||
let lon = this.config.lon.toString();
|
||||
const altitude = this.config.altitude ?? 0;
|
||||
|
||||
if (lat.includes(".") && lat.split(".")[1].length > 4) {
|
||||
Log.warn("Latitude is too specific for stellar data. Do not use more than four decimals. Trimming to maximum length.");
|
||||
const latParts = lat.split(".");
|
||||
lat = `${latParts[0]}.${latParts[1].substring(0, 4)}`;
|
||||
}
|
||||
if (lon.includes(".") && lon.split(".")[1].length > 4) {
|
||||
Log.warn("Longitude is too specific for stellar data. Do not use more than four decimals. Trimming to maximum length.");
|
||||
const lonParts = lon.split(".");
|
||||
lon = `${lonParts[0]}.${lonParts[1].substring(0, 4)}`;
|
||||
}
|
||||
|
||||
let utcOffset = moment().utcOffset() / 60;
|
||||
let utcOffsetPrefix = "%2B";
|
||||
if (utcOffset < 0) {
|
||||
utcOffsetPrefix = "-";
|
||||
}
|
||||
utcOffset = Math.abs(utcOffset);
|
||||
let minutes = "00";
|
||||
if (utcOffset % 1 !== 0) {
|
||||
minutes = "30";
|
||||
}
|
||||
let hours = Math.floor(utcOffset).toString();
|
||||
if (hours.length < 2) {
|
||||
hours = `0${hours}`;
|
||||
}
|
||||
|
||||
return `${this.config.apiBase}/sunrise/2.0/.json?date=${date}&days=${days}&height=${altitude}&lat=${lat}&lon=${lon}&offset=${utcOffsetPrefix}${hours}%3A${minutes}`;
|
||||
},
|
||||
|
||||
cacheStellarData(data) {
|
||||
localStorage.setItem("stellarData", JSON.stringify(data));
|
||||
},
|
||||
|
||||
getWeatherDataFrom(forecast, stellarData, units) {
|
||||
const weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
|
||||
const stellarTimesToday = stellarData?.today ? this.getStellarTimesFrom(stellarData.today, moment().format("YYYY-MM-DD")) : undefined;
|
||||
const stellarTimesTomorrow = stellarData?.tomorrow ? this.getStellarTimesFrom(stellarData.tomorrow, moment().add(1, "days").format("YYYY-MM-DD")) : undefined;
|
||||
|
||||
weather.date = moment(forecast.time);
|
||||
weather.windSpeed = forecast.data.instant.details.wind_speed;
|
||||
weather.windDirection = (forecast.data.instant.details.wind_from_direction + 180) % 360;
|
||||
weather.temperature = forecast.data.instant.details.air_temperature;
|
||||
weather.minTemperature = forecast.minTemperature;
|
||||
weather.maxTemperature = forecast.maxTemperature;
|
||||
weather.weatherType = forecast.weatherType;
|
||||
weather.humidity = forecast.data.instant.details.relative_humidity;
|
||||
weather.precipitation = forecast.precipitation;
|
||||
weather.precipitationUnits = units.precipitation_amount;
|
||||
|
||||
if (stellarTimesToday) {
|
||||
weather.sunset = moment(stellarTimesToday.sunset.time);
|
||||
weather.sunrise = weather.sunset < moment() && stellarTimesTomorrow ? moment(stellarTimesTomorrow.sunrise.time) : moment(stellarTimesToday.sunrise.time);
|
||||
}
|
||||
|
||||
return weather;
|
||||
},
|
||||
|
||||
convertWeatherType(weatherType, weatherTime) {
|
||||
const weatherHour = moment(weatherTime).format("HH");
|
||||
|
||||
const weatherTypes = {
|
||||
clearsky_day: "day-sunny",
|
||||
clearsky_night: "night-clear",
|
||||
clearsky_polartwilight: weatherHour < 14 ? "sunrise" : "sunset",
|
||||
cloudy: "cloudy",
|
||||
fair_day: "day-sunny-overcast",
|
||||
fair_night: "night-alt-partly-cloudy",
|
||||
fair_polartwilight: "day-sunny-overcast",
|
||||
fog: "fog",
|
||||
heavyrain: "rain", // Possibly raindrops or raindrop
|
||||
heavyrainandthunder: "thunderstorm",
|
||||
heavyrainshowers_day: "day-rain",
|
||||
heavyrainshowers_night: "night-alt-rain",
|
||||
heavyrainshowers_polartwilight: "day-rain",
|
||||
heavyrainshowersandthunder_day: "day-thunderstorm",
|
||||
heavyrainshowersandthunder_night: "night-alt-thunderstorm",
|
||||
heavyrainshowersandthunder_polartwilight: "day-thunderstorm",
|
||||
heavysleet: "sleet",
|
||||
heavysleetandthunder: "day-sleet-storm",
|
||||
heavysleetshowers_day: "day-sleet",
|
||||
heavysleetshowers_night: "night-alt-sleet",
|
||||
heavysleetshowers_polartwilight: "day-sleet",
|
||||
heavysleetshowersandthunder_day: "day-sleet-storm",
|
||||
heavysleetshowersandthunder_night: "night-alt-sleet-storm",
|
||||
heavysleetshowersandthunder_polartwilight: "day-sleet-storm",
|
||||
heavysnow: "snow-wind",
|
||||
heavysnowandthunder: "day-snow-thunderstorm",
|
||||
heavysnowshowers_day: "day-snow-wind",
|
||||
heavysnowshowers_night: "night-alt-snow-wind",
|
||||
heavysnowshowers_polartwilight: "day-snow-wind",
|
||||
heavysnowshowersandthunder_day: "day-snow-thunderstorm",
|
||||
heavysnowshowersandthunder_night: "night-alt-snow-thunderstorm",
|
||||
heavysnowshowersandthunder_polartwilight: "day-snow-thunderstorm",
|
||||
lightrain: "rain-mix",
|
||||
lightrainandthunder: "thunderstorm",
|
||||
lightrainshowers_day: "day-rain-mix",
|
||||
lightrainshowers_night: "night-alt-rain-mix",
|
||||
lightrainshowers_polartwilight: "day-rain-mix",
|
||||
lightrainshowersandthunder_day: "thunderstorm",
|
||||
lightrainshowersandthunder_night: "thunderstorm",
|
||||
lightrainshowersandthunder_polartwilight: "thunderstorm",
|
||||
lightsleet: "day-sleet",
|
||||
lightsleetandthunder: "day-sleet-storm",
|
||||
lightsleetshowers_day: "day-sleet",
|
||||
lightsleetshowers_night: "night-alt-sleet",
|
||||
lightsleetshowers_polartwilight: "day-sleet",
|
||||
lightsnow: "snowflake-cold",
|
||||
lightsnowandthunder: "day-snow-thunderstorm",
|
||||
lightsnowshowers_day: "day-snow-wind",
|
||||
lightsnowshowers_night: "night-alt-snow-wind",
|
||||
lightsnowshowers_polartwilight: "day-snow-wind",
|
||||
lightssleetshowersandthunder_day: "day-sleet-storm",
|
||||
lightssleetshowersandthunder_night: "night-alt-sleet-storm",
|
||||
lightssleetshowersandthunder_polartwilight: "day-sleet-storm",
|
||||
lightssnowshowersandthunder_day: "day-snow-thunderstorm",
|
||||
lightssnowshowersandthunder_night: "night-alt-snow-thunderstorm",
|
||||
lightssnowshowersandthunder_polartwilight: "day-snow-thunderstorm",
|
||||
partlycloudy_day: "day-cloudy",
|
||||
partlycloudy_night: "night-alt-cloudy",
|
||||
partlycloudy_polartwilight: "day-cloudy",
|
||||
rain: "rain",
|
||||
rainandthunder: "thunderstorm",
|
||||
rainshowers_day: "day-rain",
|
||||
rainshowers_night: "night-alt-rain",
|
||||
rainshowers_polartwilight: "day-rain",
|
||||
rainshowersandthunder_day: "thunderstorm",
|
||||
rainshowersandthunder_night: "lightning",
|
||||
rainshowersandthunder_polartwilight: "thunderstorm",
|
||||
sleet: "sleet",
|
||||
sleetandthunder: "day-sleet-storm",
|
||||
sleetshowers_day: "day-sleet",
|
||||
sleetshowers_night: "night-alt-sleet",
|
||||
sleetshowers_polartwilight: "day-sleet",
|
||||
sleetshowersandthunder_day: "day-sleet-storm",
|
||||
sleetshowersandthunder_night: "night-alt-sleet-storm",
|
||||
sleetshowersandthunder_polartwilight: "day-sleet-storm",
|
||||
snow: "snowflake-cold",
|
||||
snowandthunder: "lightning",
|
||||
snowshowers_day: "day-snow-wind",
|
||||
snowshowers_night: "night-alt-snow-wind",
|
||||
snowshowers_polartwilight: "day-snow-wind",
|
||||
snowshowersandthunder_day: "day-snow-thunderstorm",
|
||||
snowshowersandthunder_night: "night-alt-snow-thunderstorm",
|
||||
snowshowersandthunder_polartwilight: "day-snow-thunderstorm"
|
||||
};
|
||||
|
||||
return weatherTypes.hasOwnProperty(weatherType) ? weatherTypes[weatherType] : null;
|
||||
},
|
||||
|
||||
getStellarTimesFrom(stellarData, date) {
|
||||
for (const time of stellarData.location.time) {
|
||||
if (time.date === date) {
|
||||
return time;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
|
||||
getForecastForXHoursFrom(weather) {
|
||||
if (this.config.currentForecastHours === 1) {
|
||||
if (weather.next_1_hours) {
|
||||
return weather.next_1_hours;
|
||||
} else if (weather.next_6_hours) {
|
||||
return weather.next_6_hours;
|
||||
} else {
|
||||
return weather.next_12_hours;
|
||||
}
|
||||
} else if (this.config.currentForecastHours === 6) {
|
||||
if (weather.next_6_hours) {
|
||||
return weather.next_6_hours;
|
||||
} else if (weather.next_12_hours) {
|
||||
return weather.next_12_hours;
|
||||
} else {
|
||||
return weather.next_1_hours;
|
||||
}
|
||||
} else {
|
||||
if (weather.next_12_hours) {
|
||||
return weather.next_12_hours;
|
||||
} else if (weather.next_6_hours) {
|
||||
return weather.next_6_hours;
|
||||
} else {
|
||||
return weather.next_1_hours;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
fetchWeatherHourly() {
|
||||
this.getWeatherForecast("hourly")
|
||||
.then((forecast) => {
|
||||
this.setWeatherHourly(forecast);
|
||||
this.updateAvailable();
|
||||
})
|
||||
.catch((error) => {
|
||||
Log.error(error);
|
||||
throw new Error(error);
|
||||
});
|
||||
},
|
||||
|
||||
async getWeatherForecast(type) {
|
||||
const getRequests = [this.getWeatherData(), this.getStellarData()];
|
||||
const [weatherData, stellarData] = await Promise.all(getRequests);
|
||||
if (!weatherData.properties.timeseries || !weatherData.properties.timeseries[0]) {
|
||||
Log.error("No weather data available.");
|
||||
return;
|
||||
}
|
||||
if (!stellarData) {
|
||||
Log.warn("No stelar data available.");
|
||||
}
|
||||
let forecasts;
|
||||
switch (type) {
|
||||
case "hourly":
|
||||
forecasts = this.getHourlyForecastFrom(weatherData);
|
||||
break;
|
||||
case "daily":
|
||||
default:
|
||||
forecasts = this.getDailyForecastFrom(weatherData);
|
||||
break;
|
||||
}
|
||||
const series = [];
|
||||
for (const forecast of forecasts) {
|
||||
series.push(this.getWeatherDataFrom(forecast, stellarData, weatherData.properties.meta.units));
|
||||
}
|
||||
return series;
|
||||
},
|
||||
|
||||
getHourlyForecastFrom(weatherData) {
|
||||
const series = [];
|
||||
|
||||
for (const forecast of weatherData.properties.timeseries) {
|
||||
forecast.symbol = forecast.data.next_1_hours?.summary?.symbol_code;
|
||||
forecast.precipitation = forecast.data.next_1_hours?.details?.precipitation_amount;
|
||||
forecast.minTemperature = forecast.data.next_1_hours?.details?.air_temperature_min;
|
||||
forecast.maxTemperature = forecast.data.next_1_hours?.details?.air_temperature_max;
|
||||
forecast.weatherType = this.convertWeatherType(forecast.symbol, forecast.time);
|
||||
series.push(forecast);
|
||||
}
|
||||
return series;
|
||||
},
|
||||
|
||||
getDailyForecastFrom(weatherData) {
|
||||
const series = [];
|
||||
|
||||
const days = weatherData.properties.timeseries.reduce(function (days, forecast) {
|
||||
const date = moment(forecast.time).format("YYYY-MM-DD");
|
||||
days[date] = days[date] || [];
|
||||
days[date].push(forecast);
|
||||
return days;
|
||||
}, Object.create(null));
|
||||
|
||||
Object.keys(days).forEach(function (time, index) {
|
||||
let minTemperature = undefined;
|
||||
let maxTemperature = undefined;
|
||||
|
||||
//Default to first entry
|
||||
let forecast = days[time][0];
|
||||
forecast.symbol = forecast.data.next_12_hours?.summary?.symbol_code;
|
||||
forecast.precipitation = forecast.data.next_12_hours?.details?.precipitation_amount;
|
||||
|
||||
//Coming days
|
||||
let forecastDiffToEight = undefined;
|
||||
for (const timeseries of days[time]) {
|
||||
if (!timeseries.data.next_6_hours) continue; //next_6_hours has the most data
|
||||
|
||||
if (!minTemperature || timeseries.data.next_6_hours.details.air_temperature_min < minTemperature) minTemperature = timeseries.data.next_6_hours.details.air_temperature_min;
|
||||
if (!maxTemperature || maxTemperature < timeseries.data.next_6_hours.details.air_temperature_max) maxTemperature = timeseries.data.next_6_hours.details.air_temperature_max;
|
||||
|
||||
let closestTime = Math.abs(moment(timeseries.time).local().set({ hour: 8, minute: 0, second: 0, millisecond: 0 }).diff(moment(timeseries.time).local()));
|
||||
if ((forecastDiffToEight === undefined || closestTime < forecastDiffToEight) && timeseries.data.next_12_hours) {
|
||||
forecastDiffToEight = closestTime;
|
||||
forecast = timeseries;
|
||||
}
|
||||
}
|
||||
const forecastXHours = forecast.data.next_12_hours ?? forecast.data.next_6_hours ?? forecast.data.next_1_hours;
|
||||
if (forecastXHours) {
|
||||
forecast.symbol = forecastXHours.summary?.symbol_code;
|
||||
forecast.precipitation = forecastXHours.details?.precipitation_amount;
|
||||
forecast.minTemperature = minTemperature;
|
||||
forecast.maxTemperature = maxTemperature;
|
||||
|
||||
series.push(forecast);
|
||||
}
|
||||
});
|
||||
for (const forecast of series) {
|
||||
forecast.weatherType = this.convertWeatherType(forecast.symbol, forecast.time);
|
||||
}
|
||||
return series;
|
||||
},
|
||||
|
||||
fetchWeatherForecast() {
|
||||
this.getWeatherForecast("daily")
|
||||
.then((forecast) => {
|
||||
this.setWeatherForecast(forecast);
|
||||
this.updateAvailable();
|
||||
})
|
||||
.catch((error) => {
|
||||
Log.error(error);
|
||||
throw new Error(error);
|
||||
});
|
||||
}
|
||||
});
|
@@ -1,4 +1,4 @@
|
||||
/* global WeatherProvider */
|
||||
/* global WeatherProvider, WeatherUtils */
|
||||
|
||||
/* MagicMirror²
|
||||
* Module: Weather
|
||||
@@ -13,7 +13,6 @@ Module.register("weather", {
|
||||
roundTemp: false,
|
||||
type: "current", // current, forecast, daily (equivalent to forecast), hourly (only with OpenWeatherMap /onecall endpoint)
|
||||
units: config.units,
|
||||
useKmh: false,
|
||||
tempUnits: config.units,
|
||||
windUnits: config.units,
|
||||
updateInterval: 10 * 60 * 1000, // every 10 minutes
|
||||
@@ -23,7 +22,6 @@ Module.register("weather", {
|
||||
showPeriodUpper: false,
|
||||
showWindDirection: true,
|
||||
showWindDirectionAsArrow: false,
|
||||
useBeaufort: true,
|
||||
lang: config.language,
|
||||
showHumidity: false,
|
||||
showSun: true,
|
||||
@@ -60,7 +58,7 @@ Module.register("weather", {
|
||||
|
||||
// Return the scripts that are necessary for the weather module.
|
||||
getScripts: function () {
|
||||
return ["moment.js", "weatherprovider.js", "weatherobject.js", "suncalc.js", this.file("providers/" + this.config.weatherProvider.toLowerCase() + ".js")];
|
||||
return ["moment.js", this.file("../utils.js"), "weatherutils.js", "weatherprovider.js", "weatherobject.js", "suncalc.js", this.file("providers/" + this.config.weatherProvider.toLowerCase() + ".js")];
|
||||
},
|
||||
|
||||
// Override getHeader method.
|
||||
@@ -77,6 +75,14 @@ Module.register("weather", {
|
||||
start: function () {
|
||||
moment.locale(this.config.lang);
|
||||
|
||||
if (this.config.useKmh) {
|
||||
Log.warn("Your are using the deprecated config values 'useKmh'. Please switch to windUnits!");
|
||||
this.windUnits = "kmh";
|
||||
} else if (this.config.useBeaufort) {
|
||||
Log.warn("Your are using the deprecated config values 'useBeaufort'. Please switch to windUnits!");
|
||||
this.windUnits = "beaufort";
|
||||
}
|
||||
|
||||
// Initialize the weather provider.
|
||||
this.weatherProvider = WeatherProvider.initialize(this.config.weatherProvider, this);
|
||||
|
||||
@@ -154,6 +160,15 @@ Module.register("weather", {
|
||||
if (this.weatherProvider.currentWeather()) {
|
||||
this.sendNotification("CURRENTWEATHER_TYPE", { type: this.weatherProvider.currentWeather().weatherType.replace("-", "_") });
|
||||
}
|
||||
|
||||
const notificationPayload = {
|
||||
currentWeather: this.weatherProvider?.currentWeatherObject?.simpleClone() ?? null,
|
||||
forecastArray: this.weatherProvider?.weatherForecastArray?.map((ar) => ar.simpleClone()) ?? [],
|
||||
hourlyArray: this.weatherProvider?.weatherHourlyArray?.map((ar) => ar.simpleClone()) ?? [],
|
||||
locationName: this.weatherProvider?.fetchedLocationName,
|
||||
providerName: this.weatherProvider.providerName
|
||||
};
|
||||
this.sendNotification("WEATHER_UPDATED", notificationPayload);
|
||||
},
|
||||
|
||||
scheduleUpdate: function (delay = null) {
|
||||
@@ -212,9 +227,7 @@ Module.register("weather", {
|
||||
"unit",
|
||||
function (value, type) {
|
||||
if (type === "temperature") {
|
||||
if (this.config.tempUnits === "metric" || this.config.tempUnits === "imperial") {
|
||||
value += "°";
|
||||
}
|
||||
value = this.roundValue(WeatherUtils.convertTemp(value, this.config.tempUnits)) + "°";
|
||||
if (this.config.degreeLabel) {
|
||||
if (this.config.tempUnits === "metric") {
|
||||
value += "C";
|
||||
@@ -236,8 +249,9 @@ Module.register("weather", {
|
||||
}
|
||||
} else if (type === "humidity") {
|
||||
value += "%";
|
||||
} else if (type === "wind") {
|
||||
value = WeatherUtils.convertWind(value, this.config.windUnits);
|
||||
}
|
||||
|
||||
return value;
|
||||
}.bind(this)
|
||||
);
|
||||
|
61
modules/default/weather/weatherobject.js
Executable file → Normal file
61
modules/default/weather/weatherobject.js
Executable file → Normal file
@@ -1,4 +1,4 @@
|
||||
/* global SunCalc */
|
||||
/* global SunCalc, WeatherUtils */
|
||||
|
||||
/* MagicMirror²
|
||||
* Module: Weather
|
||||
@@ -14,17 +14,8 @@
|
||||
class WeatherObject {
|
||||
/**
|
||||
* Constructor for a WeatherObject
|
||||
*
|
||||
* @param {string} units what units to use, "imperial" or "metric"
|
||||
* @param {string} tempUnits what tempunits to use
|
||||
* @param {string} windUnits what windunits to use
|
||||
* @param {boolean} useKmh use kmh if true, mps if false
|
||||
*/
|
||||
constructor(units, tempUnits, windUnits, useKmh) {
|
||||
this.units = units;
|
||||
this.tempUnits = tempUnits;
|
||||
this.windUnits = windUnits;
|
||||
this.useKmh = useKmh;
|
||||
constructor() {
|
||||
this.date = null;
|
||||
this.windSpeed = null;
|
||||
this.windDirection = null;
|
||||
@@ -78,21 +69,6 @@ class WeatherObject {
|
||||
}
|
||||
}
|
||||
|
||||
beaufortWindSpeed() {
|
||||
const windInKmh = this.windUnits === "imperial" ? this.windSpeed * 1.609344 : this.useKmh ? this.windSpeed : (this.windSpeed * 60 * 60) / 1000;
|
||||
const speeds = [1, 5, 11, 19, 28, 38, 49, 61, 74, 88, 102, 117, 1000];
|
||||
for (const [index, speed] of speeds.entries()) {
|
||||
if (speed > windInKmh) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return 12;
|
||||
}
|
||||
|
||||
kmhWindSpeed() {
|
||||
return this.windUnits === "imperial" ? this.windSpeed * 1.609344 : (this.windSpeed * 60 * 60) / 1000;
|
||||
}
|
||||
|
||||
nextSunAction() {
|
||||
return moment().isBetween(this.sunrise, this.sunset) ? "sunset" : "sunrise";
|
||||
}
|
||||
@@ -101,8 +77,8 @@ class WeatherObject {
|
||||
if (this.feelsLikeTemp) {
|
||||
return this.feelsLikeTemp;
|
||||
}
|
||||
const windInMph = this.windUnits === "imperial" ? this.windSpeed : this.windSpeed * 2.23694;
|
||||
const tempInF = this.tempUnits === "imperial" ? this.temperature : (this.temperature * 9) / 5 + 32;
|
||||
const windInMph = WeatherUtils.convertWind(this.windSpeed, "imperial");
|
||||
const tempInF = WeatherUtils.convertTemp(this.temperature, "imperial");
|
||||
let feelsLike = tempInF;
|
||||
|
||||
if (windInMph > 3 && tempInF < 50) {
|
||||
@@ -120,7 +96,7 @@ class WeatherObject {
|
||||
1.99 * Math.pow(10, -6) * tempInF * tempInF * this.humidity * this.humidity;
|
||||
}
|
||||
|
||||
return this.tempUnits === "imperial" ? feelsLike : ((feelsLike - 32) * 5) / 9;
|
||||
return ((feelsLike - 32) * 5) / 9;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,17 +110,34 @@ class WeatherObject {
|
||||
|
||||
/**
|
||||
* Update the sunrise / sunset time depending on the location. This can be
|
||||
* used if your provider doesnt provide that data by itself. Then SunCalc
|
||||
* used if your provider doesn't provide that data by itself. Then SunCalc
|
||||
* is used here to calculate them according to the location.
|
||||
*
|
||||
* @param {number} lat latitude
|
||||
* @param {number} lon longitude
|
||||
*/
|
||||
updateSunTime(lat, lon) {
|
||||
let now = !this.date ? new Date() : this.date.toDate();
|
||||
let times = SunCalc.getTimes(now, lat, lon);
|
||||
this.sunrise = moment(times.sunrise, "X");
|
||||
this.sunset = moment(times.sunset, "X");
|
||||
const now = !this.date ? new Date() : this.date.toDate();
|
||||
const times = SunCalc.getTimes(now, lat, lon);
|
||||
this.sunrise = moment(times.sunrise);
|
||||
this.sunset = moment(times.sunset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone to simple object to prevent mutating and deprecation of legacy library.
|
||||
*
|
||||
* Before being handed to other modules, mutable values must be cloned safely.
|
||||
* Especially 'moment' object is not immutable, so original 'date', 'sunrise', 'sunset' could be corrupted or changed by other modules.
|
||||
*
|
||||
* @returns {object} plained object clone of original weatherObject
|
||||
*/
|
||||
simpleClone() {
|
||||
const toFlat = ["date", "sunrise", "sunset"];
|
||||
let clone = { ...this };
|
||||
for (const prop of toFlat) {
|
||||
clone[prop] = clone?.[prop]?.valueOf() ?? clone?.[prop];
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* global Class */
|
||||
/* global Class, performWebRequest */
|
||||
|
||||
/* MagicMirror²
|
||||
* Module: Weather
|
||||
@@ -111,45 +111,23 @@ const WeatherProvider = Class.extend({
|
||||
this.delegate.updateAvailable(this);
|
||||
},
|
||||
|
||||
getCorsUrl: function () {
|
||||
if (this.config.mockData || typeof this.config.useCorsProxy === "undefined" || !this.config.useCorsProxy) {
|
||||
return "";
|
||||
} else {
|
||||
return location.protocol + "//" + location.host + "/cors?url=";
|
||||
/**
|
||||
* A convenience function to make requests.
|
||||
*
|
||||
* @param {string} url the url to fetch from
|
||||
* @param {string} type what contenttype to expect in the response, can be "json" or "xml"
|
||||
* @param {Array.<{name: string, value:string}>} requestHeaders the HTTP headers to send
|
||||
* @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to recieve
|
||||
* @returns {Promise} resolved when the fetch is done
|
||||
*/
|
||||
fetchData: async function (url, type = "json", requestHeaders = undefined, expectedResponseHeaders = undefined) {
|
||||
const mockData = this.config.mockData;
|
||||
if (mockData) {
|
||||
const data = mockData.substring(1, mockData.length - 1);
|
||||
return JSON.parse(data);
|
||||
}
|
||||
},
|
||||
|
||||
// A convenience function to make requests. It returns a promise.
|
||||
fetchData: function (url, method = "GET", type = "json") {
|
||||
url = this.getCorsUrl() + url;
|
||||
const getData = function (mockData) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (mockData) {
|
||||
let data = mockData;
|
||||
data = data.substring(1, data.length - 1);
|
||||
resolve(JSON.parse(data));
|
||||
} else {
|
||||
const request = new XMLHttpRequest();
|
||||
request.open(method, url, true);
|
||||
request.onreadystatechange = function () {
|
||||
if (this.readyState === 4) {
|
||||
if (this.status === 200) {
|
||||
if (type === "xml") {
|
||||
resolve(this.responseXML);
|
||||
} else {
|
||||
resolve(JSON.parse(this.response));
|
||||
}
|
||||
} else {
|
||||
reject(request);
|
||||
}
|
||||
}
|
||||
};
|
||||
request.send();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return getData(this.config.mockData);
|
||||
const useCorsProxy = typeof this.config.useCorsProxy !== "undefined" && this.config.useCorsProxy;
|
||||
return performWebRequest(url, type, useCorsProxy, requestHeaders, expectedResponseHeaders);
|
||||
}
|
||||
});
|
||||
|
||||
|
98
modules/default/weather/weatherutils.js
Normal file
98
modules/default/weather/weatherutils.js
Normal file
@@ -0,0 +1,98 @@
|
||||
/* MagicMirror²
|
||||
* Weather Util Methods
|
||||
*
|
||||
* By Rejas
|
||||
* MIT Licensed.
|
||||
*/
|
||||
const WeatherUtils = {
|
||||
/**
|
||||
* Convert wind (from m/s) to beaufort scale
|
||||
*
|
||||
* @param {number} speedInMS the windspeed you want to convert
|
||||
* @returns {number} the speed in beaufort
|
||||
*/
|
||||
beaufortWindSpeed(speedInMS) {
|
||||
const windInKmh = (speedInMS * 3600) / 1000;
|
||||
const speeds = [1, 5, 11, 19, 28, 38, 49, 61, 74, 88, 102, 117, 1000];
|
||||
for (const [index, speed] of speeds.entries()) {
|
||||
if (speed > windInKmh) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return 12;
|
||||
},
|
||||
|
||||
/**
|
||||
* Convert temp (from degrees C) into imperial or metric unit depending on
|
||||
* your config
|
||||
*
|
||||
* @param {number} tempInC the temperature in celsius you want to convert
|
||||
* @param {string} unit can be 'imperial' or 'metric'
|
||||
* @returns {number} the converted temperature
|
||||
*/
|
||||
convertTemp(tempInC, unit) {
|
||||
return unit === "imperial" ? tempInC * 1.8 + 32 : tempInC;
|
||||
},
|
||||
|
||||
/**
|
||||
* Convert wind speed into another unit.
|
||||
*
|
||||
* @param {number} windInMS the windspeed in meter/sec you want to convert
|
||||
* @param {string} unit can be 'beaufort', 'kmh', 'knots, 'imperial' (mph)
|
||||
* or 'metric' (mps)
|
||||
* @returns {number} the converted windspeed
|
||||
*/
|
||||
convertWind(windInMS, unit) {
|
||||
switch (unit) {
|
||||
case "beaufort":
|
||||
return this.beaufortWindSpeed(windInMS);
|
||||
case "kmh":
|
||||
return (windInMS * 3600) / 1000;
|
||||
case "knots":
|
||||
return windInMS * 1.943844;
|
||||
case "imperial":
|
||||
return windInMS * 2.2369362920544;
|
||||
case "metric":
|
||||
default:
|
||||
return windInMS;
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
* Convert the wind direction cardinal to value
|
||||
*/
|
||||
convertWindDirection(windDirection) {
|
||||
const windCardinals = {
|
||||
N: 0,
|
||||
NNE: 22,
|
||||
NE: 45,
|
||||
ENE: 67,
|
||||
E: 90,
|
||||
ESE: 112,
|
||||
SE: 135,
|
||||
SSE: 157,
|
||||
S: 180,
|
||||
SSW: 202,
|
||||
SW: 225,
|
||||
WSW: 247,
|
||||
W: 270,
|
||||
WNW: 292,
|
||||
NW: 315,
|
||||
NNW: 337
|
||||
};
|
||||
|
||||
return windCardinals.hasOwnProperty(windDirection) ? windCardinals[windDirection] : null;
|
||||
},
|
||||
|
||||
convertWindToMetric(mph) {
|
||||
return mph / 2.2369362920544;
|
||||
},
|
||||
|
||||
convertWindToMs(kmh) {
|
||||
return kmh * 0.27777777777778;
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof module !== "undefined") {
|
||||
module.exports = WeatherUtils;
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
/* eslint-disable */
|
||||
|
||||
/* MagicMirror²
|
||||
* Module: CurrentWeather
|
||||
*
|
||||
* By Michael Teeuw https://michaelteeuw.nl
|
||||
* MIT Licensed.
|
||||
*
|
||||
* This module is deprecated. Any additional feature will no longer be merged.
|
||||
*/
|
||||
Module.register("weatherforecast", {
|
||||
// Define start sequence.
|
||||
start: function () {
|
||||
Log.info("Starting module: " + this.name);
|
||||
},
|
||||
|
||||
// Override dom generator.
|
||||
getDom: function () {
|
||||
var wrapper = document.createElement("div");
|
||||
wrapper.className = this.config.tableClass;
|
||||
wrapper.innerHTML =
|
||||
"<style>text-decoration: none</style>" +
|
||||
"This module is deprecated since release v2.15 and removed with v2.19." +
|
||||
'<br>Please use the `weather` module as replacement, more info in the <a href="https://docs.magicmirror.builders/modules/weather.html" style="color: #ffffff">documentation</a>.';
|
||||
wrapper.className = "dimmed light small";
|
||||
return wrapper;
|
||||
},
|
||||
|
||||
// Override getHeader method.
|
||||
getHeader: function () {
|
||||
return "deprecated weatherforecast";
|
||||
}
|
||||
});
|
9043
package-lock.json
generated
9043
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
105
package.json
105
package.json
@@ -1,17 +1,19 @@
|
||||
{
|
||||
"name": "magicmirror",
|
||||
"version": "2.19.0",
|
||||
"version": "2.22.0",
|
||||
"description": "The open source modular smart mirror platform.",
|
||||
"main": "js/electron.js",
|
||||
"scripts": {
|
||||
"start": "DISPLAY=\"${DISPLAY:=:0}\" ./node_modules/.bin/electron js/electron.js",
|
||||
"start:dev": "DISPLAY=\"${DISPLAY:=:0}\" ./node_modules/.bin/electron js/electron.js dev",
|
||||
"server": "node ./serveronly",
|
||||
"install": "echo \"Installing vendor files ...\n\" && cd vendor && npm install --loglevel=error",
|
||||
"install-fonts": "echo \"Installing fonts ...\n\" && cd fonts && npm install --loglevel=error",
|
||||
"postinstall": "npm run install-fonts && echo \"MagicMirror² installation finished successfully! \n\"",
|
||||
"install-mm": "npm install --no-audit --no-fund --no-update-notifier --only=prod --omit=dev",
|
||||
"install-mm:dev": "npm install --no-audit --no-fund --no-update-notifier",
|
||||
"install-vendor": "echo \"Installing vendor files ...\n\" && cd vendor && npm install --loglevel=error --no-audit --no-fund --no-update-notifier",
|
||||
"install-fonts": "echo \"Installing fonts ...\n\" && cd fonts && npm install --loglevel=error --no-audit --no-fund --no-update-notifier",
|
||||
"postinstall": "npm run install-vendor && npm run install-fonts && echo \"MagicMirror² installation finished successfully! \n\"",
|
||||
"test": "NODE_ENV=test jest -i --forceExit",
|
||||
"test:coverage": "NODE_ENV=test nyc --reporter=lcov --reporter=text jest -i --forceExit",
|
||||
"test:coverage": "NODE_ENV=test jest --coverage -i --forceExit",
|
||||
"test:electron": "NODE_ENV=test jest --selectProjects electron -i --forceExit",
|
||||
"test:e2e": "NODE_ENV=test jest --selectProjects e2e -i --forceExit",
|
||||
"test:unit": "NODE_ENV=test jest --selectProjects unit -i --forceExit",
|
||||
@@ -48,93 +50,50 @@
|
||||
"homepage": "https://magicmirror.builders",
|
||||
"devDependencies": {
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-plugin-jest": "^26.1.3",
|
||||
"eslint-plugin-jsdoc": "^38.1.3",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"eslint-plugin-jest": "^27.1.7",
|
||||
"eslint-plugin-jsdoc": "^39.6.4",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"express-basic-auth": "^1.2.1",
|
||||
"husky": "^7.0.4",
|
||||
"jest": "^27.5.1",
|
||||
"jsdom": "^19.0.0",
|
||||
"husky": "^8.0.2",
|
||||
"jest": "^29.3.1",
|
||||
"jsdom": "^20.0.3",
|
||||
"lodash": "^4.17.21",
|
||||
"nyc": "^15.1.0",
|
||||
"playwright": "^1.20.1",
|
||||
"prettier": "^2.6.1",
|
||||
"playwright": "^1.29.1",
|
||||
"prettier": "^2.8.1",
|
||||
"pretty-quick": "^3.1.3",
|
||||
"sinon": "^13.0.1",
|
||||
"stylelint": "^14.6.1",
|
||||
"stylelint-config-prettier": "^9.0.3",
|
||||
"stylelint-config-standard": "^25.0.0",
|
||||
"sinon": "^15.0.1",
|
||||
"stylelint": "^14.16.0",
|
||||
"stylelint-config-prettier": "^9.0.4",
|
||||
"stylelint-config-standard": "^29.0.0",
|
||||
"stylelint-prettier": "^2.0.0",
|
||||
"suncalc": "^1.9.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"electron": "^17.2.0"
|
||||
"electron": "^22.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"colors": "^1.4.0",
|
||||
"console-stamp": "^3.0.4",
|
||||
"digest-fetch": "^1.2.1",
|
||||
"eslint": "^8.12.0",
|
||||
"express": "^4.17.3",
|
||||
"express-ipfilter": "^1.2.0",
|
||||
"console-stamp": "^3.1.0",
|
||||
"digest-fetch": "^2.0.1",
|
||||
"eslint": "^8.30.0",
|
||||
"express": "^4.18.2",
|
||||
"express-ipfilter": "^1.3.1",
|
||||
"feedme": "^2.0.2",
|
||||
"helmet": "^5.0.2",
|
||||
"helmet": "^6.0.1",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"luxon": "^1.21.3",
|
||||
"luxon": "^1.28.0",
|
||||
"module-alias": "^2.2.2",
|
||||
"moment": "^2.29.1",
|
||||
"moment": "^2.29.4",
|
||||
"node-fetch": "^2.6.7",
|
||||
"node-ical": "^0.15.1",
|
||||
"socket.io": "^4.4.1"
|
||||
"node-ical": "^0.15.3",
|
||||
"socket.io": "^4.5.4"
|
||||
},
|
||||
"_moduleAliases": {
|
||||
"node_helper": "js/node_helper.js",
|
||||
"logger": "js/logger.js"
|
||||
"logger": "js/logger.js",
|
||||
"fetch": "js/fetch.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"jest": {
|
||||
"verbose": true,
|
||||
"testTimeout": 20000,
|
||||
"testSequencer": "<rootDir>/tests/configs/test_sequencer.js",
|
||||
"projects": [
|
||||
{
|
||||
"displayName": "unit",
|
||||
"moduleNameMapper": {
|
||||
"logger": "<rootDir>/js/logger.js"
|
||||
},
|
||||
"testMatch": [
|
||||
"**/tests/unit/**/*.[jt]s?(x)"
|
||||
],
|
||||
"testPathIgnorePatterns": [
|
||||
"<rootDir>/tests/unit/mocks"
|
||||
]
|
||||
},
|
||||
{
|
||||
"displayName": "electron",
|
||||
"testMatch": [
|
||||
"**/tests/electron/**/*.[jt]s?(x)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"displayName": "e2e",
|
||||
"setupFilesAfterEnv": [
|
||||
"<rootDir>/tests/e2e/mock-console.js"
|
||||
],
|
||||
"testMatch": [
|
||||
"**/tests/e2e/**/*.[jt]s?(x)"
|
||||
],
|
||||
"modulePaths": [
|
||||
"<rootDir>/js/"
|
||||
],
|
||||
"testPathIgnorePatterns": [
|
||||
"<rootDir>/tests/e2e/modules/mocks",
|
||||
"<rootDir>/tests/e2e/modules/basic-auth.js",
|
||||
"<rootDir>/tests/e2e/global-setup.js",
|
||||
"<rootDir>/tests/e2e/mock-console.js"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@@ -1,33 +0,0 @@
|
||||
{
|
||||
"LOADING": "Loading …",
|
||||
|
||||
"TODAY": "Today",
|
||||
"TOMORROW": "Tomorrow",
|
||||
"DAYAFTERTOMORROW": "In 2 days",
|
||||
"RUNNING": "Ends in",
|
||||
"EMPTY": "No upcoming events.",
|
||||
|
||||
"WEEK": "Week {weekNumber}",
|
||||
|
||||
"N": "N",
|
||||
"NNE": "NNE",
|
||||
"NE": "NE",
|
||||
"ENE": "ENE",
|
||||
"E": "E",
|
||||
"ESE": "ESE",
|
||||
"SE": "SE",
|
||||
"SSE": "SSE",
|
||||
"S": "S",
|
||||
"SSW": "SSW",
|
||||
"SW": "SW",
|
||||
"WSW": "WSW",
|
||||
"W": "W",
|
||||
"WNW": "WNW",
|
||||
"NW": "NW",
|
||||
"NNW": "NNW",
|
||||
|
||||
"UPDATE_NOTIFICATION": "MagicMirror² update available.",
|
||||
"UPDATE_NOTIFICATION_MODULE": "Update available for MODULE_NAME module.",
|
||||
"UPDATE_INFO_SINGLE": "The current installation is COMMIT_COUNT commit behind on the BRANCH_NAME branch.",
|
||||
"UPDATE_INFO_MULTIPLE": "The current installation is COMMIT_COUNT commits behind on the BRANCH_NAME branch."
|
||||
}
|
@@ -3,7 +3,7 @@
|
||||
* By Rodrigo Ramírez Norambuena https://rodrigoramirez.com
|
||||
* MIT Licensed.
|
||||
*/
|
||||
exports.configFactory = function (options) {
|
||||
exports.configFactory = (options) => {
|
||||
return Object.assign(
|
||||
{
|
||||
electronOptions: {
|
||||
|
@@ -14,7 +14,7 @@ let config = {
|
||||
calendars: [
|
||||
{
|
||||
maximumNumberOfDays: 10000,
|
||||
url: "http://localhost:8080/tests/configs/data/calendar_test.ics",
|
||||
url: "http://localhost:8080/tests/mocks/calendar_test.ics",
|
||||
auth: {
|
||||
user: "MagicMirror",
|
||||
pass: "CallMeADog"
|
||||
|
@@ -14,7 +14,7 @@ let config = {
|
||||
calendars: [
|
||||
{
|
||||
maximumNumberOfDays: 10000,
|
||||
url: "http://localhost:8080/tests/configs/data/calendar_test.ics",
|
||||
url: "http://localhost:8080/tests/mocks/calendar_test.ics",
|
||||
auth: {
|
||||
user: "MagicMirror",
|
||||
pass: "CallMeADog",
|
||||
|
@@ -14,7 +14,7 @@ let config = {
|
||||
calendars: [
|
||||
{
|
||||
maximumNumberOfDays: 10000,
|
||||
url: "http://localhost:8010/tests/configs/data/calendar_test.ics",
|
||||
url: "http://localhost:8010/tests/mocks/calendar_test.ics",
|
||||
auth: {
|
||||
user: "MagicMirror",
|
||||
pass: "CallMeADog"
|
||||
|
@@ -18,7 +18,7 @@ let config = {
|
||||
symbol: "birthday-cake",
|
||||
fullDaySymbol: "calendar-day",
|
||||
recurringSymbol: "undo",
|
||||
url: "http://localhost:8080/tests/configs/data/calendar_test_icons.ics"
|
||||
url: "http://localhost:8080/tests/mocks/calendar_test_icons.ics"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ let config = {
|
||||
calendars: [
|
||||
{
|
||||
maximumNumberOfDays: 10000,
|
||||
url: "http://localhost:8080/tests/configs/data/calendar_test.ics"
|
||||
url: "http://localhost:8080/tests/mocks/calendar_test.ics"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ let config = {
|
||||
calendars: [
|
||||
{
|
||||
maximumNumberOfDays: 10000,
|
||||
url: "http://localhost:8020/tests/configs/data/calendar_test.ics",
|
||||
url: "http://localhost:8020/tests/mocks/calendar_test.ics",
|
||||
auth: {
|
||||
user: "MagicMirror",
|
||||
pass: "StairwayToHeaven",
|
||||
|
@@ -14,7 +14,7 @@ let config = {
|
||||
calendars: [
|
||||
{
|
||||
maximumNumberOfDays: 10000,
|
||||
url: "http://localhost:8080/tests/configs/data/calendar_test.ics",
|
||||
url: "http://localhost:8080/tests/mocks/calendar_test.ics",
|
||||
user: "MagicMirror",
|
||||
pass: "CallMeADog"
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ let config = {
|
||||
{
|
||||
maximumEntries: 6,
|
||||
maximumNumberOfDays: 3650,
|
||||
url: "http://localhost:8080/tests/configs/data/calendar_test_recurring.ics"
|
||||
url: "http://localhost:8080/tests/mocks/calendar_test_recurring.ics"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@@ -11,7 +11,6 @@ let config = {
|
||||
module: "compliments",
|
||||
position: "middle_center",
|
||||
config: {
|
||||
mockDate: "2020-01-01",
|
||||
compliments: {
|
||||
morning: [],
|
||||
afternoon: [],
|
||||
|
21
tests/configs/modules/compliments/compliments_remote.js
Normal file
21
tests/configs/modules/compliments/compliments_remote.js
Normal file
@@ -0,0 +1,21 @@
|
||||
/* MagicMirror² Test config compliments with remote file
|
||||
*
|
||||
* By Rejas
|
||||
* MIT Licensed.
|
||||
*/
|
||||
let config = {
|
||||
modules: [
|
||||
{
|
||||
module: "compliments",
|
||||
position: "middle_center",
|
||||
config: {
|
||||
remoteFile: "http://localhost:8080/tests/mocks/compliments_test.json"
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||
if (typeof module !== "undefined") {
|
||||
module.exports = config;
|
||||
}
|
@@ -14,7 +14,7 @@ let config = {
|
||||
feeds: [
|
||||
{
|
||||
title: "Rodrigo Ramirez Blog",
|
||||
url: "http://localhost:8080/tests/configs/data/feed_test_rodrigoramirez.xml"
|
||||
url: "http://localhost:8080/tests/mocks/newsfeed_test.xml"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ let config = {
|
||||
feeds: [
|
||||
{
|
||||
title: "Rodrigo Ramirez Blog",
|
||||
url: "http://localhost:8080/tests/configs/data/feed_test_rodrigoramirez.xml"
|
||||
url: "http://localhost:8080/tests/mocks/newsfeed_test.xml"
|
||||
}
|
||||
],
|
||||
ignoreOldItems: true
|
||||
|
@@ -13,7 +13,7 @@ let config = {
|
||||
feeds: [
|
||||
{
|
||||
title: "Rodrigo Ramirez Blog",
|
||||
url: "http://localhost:8080/tests/configs/data/feed_test_rodrigoramirez.xml"
|
||||
url: "http://localhost:8080/tests/mocks/newsfeed_test.xml"
|
||||
}
|
||||
],
|
||||
prohibitedWords: ["QPanel"],
|
||||
|
@@ -6,7 +6,7 @@
|
||||
let config = {
|
||||
modules:
|
||||
// Using exotic content. This is why don't accept go to JSON configuration file
|
||||
(function () {
|
||||
(() => {
|
||||
let positions = ["top_bar", "top_left", "top_center", "top_right", "upper_third", "middle_center", "lower_third", "bottom_left", "bottom_center", "bottom_right", "bottom_bar", "fullscreen_above", "fullscreen_below"];
|
||||
let modules = Array();
|
||||
for (let idx in positions) {
|
||||
|
@@ -11,7 +11,7 @@ let config = {
|
||||
config: {
|
||||
location: "Munich",
|
||||
mockData: '"#####WEATHERDATA#####"',
|
||||
useBeaufort: false,
|
||||
windUnits: "beaufort",
|
||||
showWindDirectionAsArrow: true,
|
||||
showSun: false,
|
||||
showHumidity: true,
|
||||
|
@@ -1,33 +1,27 @@
|
||||
const fetch = require("node-fetch");
|
||||
const helpers = require("./global-setup");
|
||||
const helpers = require("./helpers/global-setup");
|
||||
|
||||
describe("App environment", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/default.js");
|
||||
helpers.getDocument(done);
|
||||
describe("App environment", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/default.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
afterAll(function () {
|
||||
helpers.stopApplication();
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
it("get request from http://localhost:8080 should return 200", function (done) {
|
||||
fetch("http://localhost:8080").then((res) => {
|
||||
expect(res.status).toBe(200);
|
||||
done();
|
||||
});
|
||||
it("get request from http://localhost:8080 should return 200", async () => {
|
||||
const res = await helpers.fetch("http://localhost:8080");
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
|
||||
it("get request from http://localhost:8080/nothing should return 404", function (done) {
|
||||
fetch("http://localhost:8080/nothing").then((res) => {
|
||||
expect(res.status).toBe(404);
|
||||
done();
|
||||
});
|
||||
it("get request from http://localhost:8080/nothing should return 404", async () => {
|
||||
const res = await helpers.fetch("http://localhost:8080/nothing");
|
||||
expect(res.status).toBe(404);
|
||||
});
|
||||
|
||||
it("should show the title MagicMirror²", function () {
|
||||
helpers.waitForElement("title").then((elem) => {
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toBe("MagicMirror²");
|
||||
});
|
||||
it("should show the title MagicMirror²", async () => {
|
||||
const elem = await helpers.waitForElement("title");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toBe("MagicMirror²");
|
||||
});
|
||||
});
|
||||
|
@@ -1,7 +1,6 @@
|
||||
const fetch = require("node-fetch");
|
||||
const helpers = require("./global-setup");
|
||||
const helpers = require("./helpers/global-setup");
|
||||
|
||||
describe("All font files from roboto.css should be downloadable", function () {
|
||||
describe("All font files from roboto.css should be downloadable", () => {
|
||||
const fontFiles = [];
|
||||
// Statements below filters out all 'url' lines in the CSS file
|
||||
const fileContent = require("fs").readFileSync(__dirname + "/../../fonts/roboto.css", "utf8");
|
||||
@@ -14,18 +13,16 @@ describe("All font files from roboto.css should be downloadable", function () {
|
||||
match = regex.exec(fileContent);
|
||||
}
|
||||
|
||||
beforeAll(function () {
|
||||
helpers.startApplication("tests/configs/without_modules.js");
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/without_modules.js");
|
||||
});
|
||||
afterAll(function () {
|
||||
helpers.stopApplication();
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
test.each(fontFiles)("should return 200 HTTP code for file '%s'", (fontFile, done) => {
|
||||
test.each(fontFiles)("should return 200 HTTP code for file '%s'", async (fontFile) => {
|
||||
const fontUrl = "http://localhost:8080/fonts/" + fontFile;
|
||||
fetch(fontUrl).then((res) => {
|
||||
expect(res.status).toBe(200);
|
||||
done();
|
||||
});
|
||||
const res = await helpers.fetch(fontUrl);
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
});
|
@@ -1,55 +0,0 @@
|
||||
const jsdom = require("jsdom");
|
||||
|
||||
exports.startApplication = function (configFilename, exec) {
|
||||
jest.resetModules();
|
||||
if (global.app) {
|
||||
global.app.stop();
|
||||
}
|
||||
// Set config sample for use in test
|
||||
if (configFilename === "") {
|
||||
process.env.MM_CONFIG_FILE = "config/config.js";
|
||||
} else {
|
||||
process.env.MM_CONFIG_FILE = configFilename;
|
||||
}
|
||||
if (exec) exec;
|
||||
global.app = require("app.js");
|
||||
global.app.start();
|
||||
};
|
||||
|
||||
exports.stopApplication = function () {
|
||||
if (global.app) {
|
||||
global.app.stop();
|
||||
}
|
||||
};
|
||||
|
||||
exports.getDocument = function (callback) {
|
||||
const url = "http://" + (config.address || "localhost") + ":" + (config.port || "8080");
|
||||
jsdom.JSDOM.fromURL(url, { resources: "usable", runScripts: "dangerously" }).then((dom) => {
|
||||
dom.window.name = "jsdom";
|
||||
dom.window.onload = function () {
|
||||
global.MutationObserver = dom.window.MutationObserver;
|
||||
global.document = dom.window.document;
|
||||
callback();
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
exports.waitForElement = function (selector) {
|
||||
return new Promise((resolve) => {
|
||||
if (document.querySelector(selector) && document.querySelector(selector).value !== undefined) {
|
||||
return resolve(document.querySelector(selector));
|
||||
}
|
||||
|
||||
const observer = new MutationObserver(() => {
|
||||
if (document.querySelector(selector) && document.querySelector(selector).value !== undefined) {
|
||||
resolve(document.querySelector(selector));
|
||||
observer.disconnect();
|
||||
}
|
||||
});
|
||||
|
||||
observer.observe(document.body, {
|
||||
childList: true,
|
||||
subtree: true
|
||||
});
|
||||
});
|
||||
};
|
@@ -11,7 +11,7 @@ const basicAuth = auth({
|
||||
app.use(basicAuth);
|
||||
|
||||
// Set available directories
|
||||
const directories = ["/tests/configs"];
|
||||
const directories = ["/tests/configs", "/tests/mocks"];
|
||||
const rootPath = path.resolve(__dirname + "/../../../");
|
||||
|
||||
for (let directory of directories) {
|
||||
@@ -20,10 +20,10 @@ for (let directory of directories) {
|
||||
|
||||
let server;
|
||||
|
||||
exports.listen = function () {
|
||||
server = app.listen.apply(app, arguments);
|
||||
exports.listen = (...args) => {
|
||||
server = app.listen.apply(app, args);
|
||||
};
|
||||
|
||||
exports.close = function (callback) {
|
||||
server.close(callback);
|
||||
exports.close = async () => {
|
||||
await server.close();
|
||||
};
|
99
tests/e2e/helpers/global-setup.js
Normal file
99
tests/e2e/helpers/global-setup.js
Normal file
@@ -0,0 +1,99 @@
|
||||
const jsdom = require("jsdom");
|
||||
const corefetch = require("fetch");
|
||||
|
||||
exports.startApplication = async (configFilename, exec) => {
|
||||
jest.resetModules();
|
||||
if (global.app) {
|
||||
await this.stopApplication();
|
||||
}
|
||||
// Set config sample for use in test
|
||||
if (configFilename === "") {
|
||||
process.env.MM_CONFIG_FILE = "config/config.js";
|
||||
} else {
|
||||
process.env.MM_CONFIG_FILE = configFilename;
|
||||
}
|
||||
if (exec) exec;
|
||||
global.app = require("app.js");
|
||||
|
||||
return new Promise((resolve) => {
|
||||
global.app.start(resolve);
|
||||
});
|
||||
};
|
||||
|
||||
exports.stopApplication = async () => {
|
||||
if (global.app) {
|
||||
return new Promise((resolve) => {
|
||||
global.app.stop(resolve);
|
||||
delete global.app;
|
||||
});
|
||||
}
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
exports.getDocument = () => {
|
||||
return new Promise((resolve) => {
|
||||
const url = "http://" + (config.address || "localhost") + ":" + (config.port || "8080");
|
||||
jsdom.JSDOM.fromURL(url, { resources: "usable", runScripts: "dangerously" }).then((dom) => {
|
||||
dom.window.name = "jsdom";
|
||||
dom.window.fetch = corefetch;
|
||||
dom.window.onload = () => {
|
||||
global.document = dom.window.document;
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports.waitForElement = (selector, ignoreValue = "") => {
|
||||
return new Promise((resolve) => {
|
||||
let oldVal = "dummy12345";
|
||||
const interval = setInterval(() => {
|
||||
const element = document.querySelector(selector);
|
||||
if (element) {
|
||||
let newVal = element.textContent;
|
||||
if (newVal === oldVal) {
|
||||
clearInterval(interval);
|
||||
resolve(element);
|
||||
} else {
|
||||
if (ignoreValue === "") {
|
||||
oldVal = newVal;
|
||||
} else {
|
||||
if (!newVal.includes(ignoreValue)) oldVal = newVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
};
|
||||
|
||||
exports.waitForAllElements = (selector) => {
|
||||
return new Promise((resolve) => {
|
||||
let oldVal = 999999;
|
||||
const interval = setInterval(() => {
|
||||
const element = document.querySelectorAll(selector);
|
||||
if (element) {
|
||||
let newVal = element.length;
|
||||
if (newVal === oldVal) {
|
||||
clearInterval(interval);
|
||||
resolve(element);
|
||||
} else {
|
||||
if (newVal !== 0) oldVal = newVal;
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
};
|
||||
|
||||
exports.fetch = (url) => {
|
||||
return new Promise((resolve) => {
|
||||
corefetch(url).then((res) => {
|
||||
resolve(res);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports.testMatch = async (element, regex) => {
|
||||
const elem = await this.waitForElement(element);
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toMatch(regex);
|
||||
};
|
@@ -3,13 +3,13 @@
|
||||
*
|
||||
* @param {string} err The error message.
|
||||
*/
|
||||
function mockError(err) {
|
||||
const mockError = (err) => {
|
||||
if (err.includes("ECONNREFUSED") || err.includes("ECONNRESET") || err.includes("socket hang up") || err.includes("exports is not defined") || err.includes("write EPIPE")) {
|
||||
jest.fn();
|
||||
} else {
|
||||
console.dir(err);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
global.console = {
|
||||
log: jest.fn(),
|
29
tests/e2e/helpers/weather-functions.js
Normal file
29
tests/e2e/helpers/weather-functions.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const helpers = require("./global-setup");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const { generateWeather, generateWeatherForecast } = require("../../mocks/weather_test");
|
||||
|
||||
exports.getText = async (element, result) => {
|
||||
const elem = await helpers.waitForElement(element);
|
||||
expect(elem).not.toBe(null);
|
||||
expect(
|
||||
elem.textContent
|
||||
.trim()
|
||||
.replace(/(\r\n|\n|\r)/gm, "")
|
||||
.replace(/[ ]+/g, " ")
|
||||
).toBe(result);
|
||||
};
|
||||
|
||||
exports.startApp = async (configFile, additionalMockData) => {
|
||||
let mockWeather;
|
||||
if (configFile.includes("forecast")) {
|
||||
mockWeather = generateWeatherForecast(additionalMockData);
|
||||
} else {
|
||||
mockWeather = generateWeather(additionalMockData);
|
||||
}
|
||||
let content = fs.readFileSync(path.resolve(__dirname + "../../../../" + configFile)).toString();
|
||||
content = content.replace("#####WEATHERDATA#####", mockWeather);
|
||||
fs.writeFileSync(path.resolve(__dirname + "../../../../config/config.js"), content);
|
||||
await helpers.startApplication("");
|
||||
await helpers.getDocument();
|
||||
};
|
@@ -1,36 +1,31 @@
|
||||
const fetch = require("node-fetch");
|
||||
const helpers = require("./global-setup");
|
||||
const helpers = require("./helpers/global-setup");
|
||||
|
||||
describe("ipWhitelist directive configuration", function () {
|
||||
describe("Set ipWhitelist without access", function () {
|
||||
beforeAll(function () {
|
||||
helpers.startApplication("tests/configs/noIpWhiteList.js");
|
||||
describe("ipWhitelist directive configuration", () => {
|
||||
describe("Set ipWhitelist without access", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/noIpWhiteList.js");
|
||||
});
|
||||
afterAll(function () {
|
||||
helpers.stopApplication();
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
it("should return 403", function (done) {
|
||||
fetch("http://localhost:8080").then((res) => {
|
||||
expect(res.status).toBe(403);
|
||||
done();
|
||||
});
|
||||
it("should return 403", async () => {
|
||||
const res = await helpers.fetch("http://localhost:8080");
|
||||
expect(res.status).toBe(403);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Set ipWhitelist []", function () {
|
||||
beforeAll(function () {
|
||||
helpers.startApplication("tests/configs/empty_ipWhiteList.js");
|
||||
describe("Set ipWhitelist []", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/empty_ipWhiteList.js");
|
||||
});
|
||||
afterAll(function () {
|
||||
helpers.stopApplication();
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
it("should return 200", function (done) {
|
||||
fetch("http://localhost:8080").then((res) => {
|
||||
expect(res.status).toBe(200);
|
||||
done();
|
||||
});
|
||||
it("should return 200", async () => {
|
||||
const res = await helpers.fetch("http://localhost:8080");
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -1,18 +1,17 @@
|
||||
const helpers = require("../global-setup");
|
||||
const helpers = require("../helpers/global-setup");
|
||||
|
||||
describe("Alert module", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/alert/default.js");
|
||||
helpers.getDocument(done);
|
||||
describe("Alert module", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/alert/default.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
afterAll(function () {
|
||||
helpers.stopApplication();
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
it("should show the welcome message", function () {
|
||||
helpers.waitForElement(".ns-box .ns-box-inner .light.bright.small").then((elem) => {
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Welcome, start was successful!");
|
||||
});
|
||||
it("should show the welcome message", async () => {
|
||||
const elem = await helpers.waitForElement(".ns-box .ns-box-inner .light.bright.small");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Welcome, start was successful!");
|
||||
});
|
||||
});
|
||||
|
@@ -1,162 +1,160 @@
|
||||
const helpers = require("../global-setup");
|
||||
const serverBasicAuth = require("./basic-auth.js");
|
||||
const helpers = require("../helpers/global-setup");
|
||||
const serverBasicAuth = require("../helpers/basic-auth.js");
|
||||
|
||||
describe("Calendar module", function () {
|
||||
describe("Calendar module", () => {
|
||||
/**
|
||||
* @param {string} element css selector
|
||||
* @param {string} result expected number
|
||||
* @param {string} not reverse result
|
||||
*/
|
||||
function testElementLength(element, result, not) {
|
||||
helpers.waitForElement(element).then((elem) => {
|
||||
expect(elem).not.toBe(null);
|
||||
if (not === "not") {
|
||||
expect(elem.length).not.toBe(result);
|
||||
} else {
|
||||
expect(elem.length).toBe(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const testTextContain = function (element, text) {
|
||||
helpers.waitForElement(element).then((elem) => {
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain(text);
|
||||
});
|
||||
const testElementLength = async (element, result, not) => {
|
||||
const elem = await helpers.waitForAllElements(element);
|
||||
expect(elem).not.toBe(null);
|
||||
if (not === "not") {
|
||||
expect(elem.length).not.toBe(result);
|
||||
} else {
|
||||
expect(elem.length).toBe(result);
|
||||
}
|
||||
};
|
||||
|
||||
afterAll(function () {
|
||||
helpers.stopApplication();
|
||||
const testTextContain = async (element, text) => {
|
||||
const elem = await helpers.waitForElement(element, "undefinedLoading");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain(text);
|
||||
};
|
||||
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
describe("Default configuration", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/calendar/default.js");
|
||||
helpers.getDocument(done);
|
||||
describe("Default configuration", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/calendar/default.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show the default maximumEntries of 10", () => {
|
||||
testElementLength(".calendar .event", 10);
|
||||
it("should show the default maximumEntries of 10", async () => {
|
||||
await testElementLength(".calendar .event", 10);
|
||||
});
|
||||
|
||||
it("should show the default calendar symbol in each event", () => {
|
||||
testElementLength(".calendar .event .fa-calendar-alt", 0, "not");
|
||||
it("should show the default calendar symbol in each event", async () => {
|
||||
await testElementLength(".calendar .event .fa-calendar-alt", 0, "not");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Custom configuration", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/calendar/custom.js");
|
||||
helpers.getDocument(done);
|
||||
describe("Custom configuration", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/calendar/custom.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show the custom maximumEntries of 4", () => {
|
||||
testElementLength(".calendar .event", 4);
|
||||
it("should show the custom maximumEntries of 4", async () => {
|
||||
await testElementLength(".calendar .event", 4);
|
||||
});
|
||||
|
||||
it("should show the custom calendar symbol in each event", () => {
|
||||
testElementLength(".calendar .event .fa-birthday-cake", 4);
|
||||
it("should show the custom calendar symbol in each event", async () => {
|
||||
await testElementLength(".calendar .event .fa-birthday-cake", 4);
|
||||
});
|
||||
|
||||
it("should show two custom icons for repeating events", () => {
|
||||
testElementLength(".calendar .event .fa-undo", 2);
|
||||
it("should show two custom icons for repeating events", async () => {
|
||||
await testElementLength(".calendar .event .fa-undo", 2);
|
||||
});
|
||||
|
||||
it("should show two custom icons for day events", () => {
|
||||
testElementLength(".calendar .event .fa-calendar-day", 2);
|
||||
it("should show two custom icons for day events", async () => {
|
||||
await testElementLength(".calendar .event .fa-calendar-day", 2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Recurring event", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/calendar/recurring.js");
|
||||
helpers.getDocument(done);
|
||||
describe("Recurring event", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/calendar/recurring.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show the recurring birthday event 6 times", () => {
|
||||
testElementLength(".calendar .event", 6);
|
||||
it("should show the recurring birthday event 6 times", async () => {
|
||||
await testElementLength(".calendar .event", 6);
|
||||
});
|
||||
});
|
||||
|
||||
process.setMaxListeners(0);
|
||||
for (let i = -12; i < 12; i++) {
|
||||
describe("Recurring event per timezone", function () {
|
||||
beforeAll(function (done) {
|
||||
Date.prototype.getTimezoneOffset = function () {
|
||||
describe("Recurring event per timezone", () => {
|
||||
beforeAll(async () => {
|
||||
Date.prototype.getTimezoneOffset = () => {
|
||||
return i * 60;
|
||||
};
|
||||
helpers.startApplication("tests/configs/modules/calendar/recurring.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.startApplication("tests/configs/modules/calendar/recurring.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it('should contain text "Mar 25th" in timezone UTC ' + -i, () => {
|
||||
testTextContain(".calendar", "Mar 25th");
|
||||
it('should contain text "Mar 25th" in timezone UTC ' + -i, async () => {
|
||||
await testTextContain(".calendar", "Mar 25th");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
describe("Changed port", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/calendar/changed-port.js");
|
||||
describe("Changed port", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/calendar/changed-port.js");
|
||||
serverBasicAuth.listen(8010);
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
afterAll(function (done) {
|
||||
serverBasicAuth.close(done());
|
||||
afterAll(async () => {
|
||||
await serverBasicAuth.close();
|
||||
});
|
||||
|
||||
it("should return TestEvents", function () {
|
||||
testElementLength(".calendar .event", 0, "not");
|
||||
it("should return TestEvents", async () => {
|
||||
await testElementLength(".calendar .event", 0, "not");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Basic auth", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/calendar/basic-auth.js");
|
||||
helpers.getDocument(done);
|
||||
describe("Basic auth", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/calendar/basic-auth.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should return TestEvents", function () {
|
||||
testElementLength(".calendar .event", 0, "not");
|
||||
it("should return TestEvents", async () => {
|
||||
await testElementLength(".calendar .event", 0, "not");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Basic auth by default", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/calendar/auth-default.js");
|
||||
helpers.getDocument(done);
|
||||
describe("Basic auth by default", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/calendar/auth-default.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should return TestEvents", function () {
|
||||
testElementLength(".calendar .event", 0, "not");
|
||||
it("should return TestEvents", async () => {
|
||||
await testElementLength(".calendar .event", 0, "not");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Basic auth backward compatibility configuration: DEPRECATED", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/calendar/old-basic-auth.js");
|
||||
helpers.getDocument(done);
|
||||
describe("Basic auth backward compatibility configuration: DEPRECATED", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/calendar/old-basic-auth.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should return TestEvents", function () {
|
||||
testElementLength(".calendar .event", 0, "not");
|
||||
it("should return TestEvents", async () => {
|
||||
await testElementLength(".calendar .event", 0, "not");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Fail Basic auth", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/calendar/fail-basic-auth.js");
|
||||
describe("Fail Basic auth", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/calendar/fail-basic-auth.js");
|
||||
serverBasicAuth.listen(8020);
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
afterAll(function (done) {
|
||||
serverBasicAuth.close(done());
|
||||
afterAll(async () => {
|
||||
await serverBasicAuth.close();
|
||||
});
|
||||
|
||||
it("should show Unauthorized error", function () {
|
||||
testTextContain(".calendar", "Error in the calendar module. Authorization failed");
|
||||
it("should show Unauthorized error", async () => {
|
||||
await testTextContain(".calendar", "Error in the calendar module. Authorization failed");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -1,72 +1,65 @@
|
||||
const helpers = require("../global-setup");
|
||||
const helpers = require("../helpers/global-setup");
|
||||
|
||||
describe("Clock set to spanish language module", function () {
|
||||
afterAll(function () {
|
||||
helpers.stopApplication();
|
||||
describe("Clock set to spanish language module", () => {
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
const testMatch = function (element, regex) {
|
||||
helpers.waitForElement(element).then((elem) => {
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toMatch(regex);
|
||||
});
|
||||
};
|
||||
|
||||
describe("with default 24hr clock config", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/clock/es/clock_24hr.js");
|
||||
helpers.getDocument(done);
|
||||
describe("with default 24hr clock config", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/es/clock_24hr.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("shows date with correct format", function () {
|
||||
it("shows date with correct format", async () => {
|
||||
const dateRegex = /^(?:lunes|martes|miércoles|jueves|viernes|sábado|domingo), \d{1,2} de (?:enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre) de \d{4}$/;
|
||||
testMatch(".clock .date", dateRegex);
|
||||
await helpers.testMatch(".clock .date", dateRegex);
|
||||
});
|
||||
|
||||
it("shows time in 24hr format", function () {
|
||||
it("shows time in 24hr format", async () => {
|
||||
const timeRegex = /^(?:2[0-3]|[01]\d):[0-5]\d[0-5]\d$/;
|
||||
testMatch(".clock .time", timeRegex);
|
||||
await helpers.testMatch(".clock .time", timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with default 12hr clock config", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/clock/es/clock_12hr.js");
|
||||
helpers.getDocument(done);
|
||||
describe("with default 12hr clock config", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/es/clock_12hr.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("shows date with correct format", function () {
|
||||
it("shows date with correct format", async () => {
|
||||
const dateRegex = /^(?:lunes|martes|miércoles|jueves|viernes|sábado|domingo), \d{1,2} de (?:enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre) de \d{4}$/;
|
||||
testMatch(".clock .date", dateRegex);
|
||||
await helpers.testMatch(".clock .date", dateRegex);
|
||||
});
|
||||
|
||||
it("shows time in 12hr format", function () {
|
||||
it("shows time in 12hr format", async () => {
|
||||
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[ap]m$/;
|
||||
testMatch(".clock .time", timeRegex);
|
||||
await helpers.testMatch(".clock .time", timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with showPeriodUpper config enabled", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/clock/es/clock_showPeriodUpper.js");
|
||||
helpers.getDocument(done);
|
||||
describe("with showPeriodUpper config enabled", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/es/clock_showPeriodUpper.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("shows 12hr time with upper case AM/PM", function () {
|
||||
it("shows 12hr time with upper case AM/PM", async () => {
|
||||
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[AP]M$/;
|
||||
testMatch(".clock .time", timeRegex);
|
||||
await helpers.testMatch(".clock .time", timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with showWeek config enabled", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/clock/es/clock_showWeek.js");
|
||||
helpers.getDocument(done);
|
||||
describe("with showWeek config enabled", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/es/clock_showWeek.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("shows week with correct format", function () {
|
||||
it("shows week with correct format", async () => {
|
||||
const weekRegex = /^Semana [0-9]{1,2}$/;
|
||||
testMatch(".clock .week", weekRegex);
|
||||
await helpers.testMatch(".clock .week", weekRegex);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -1,120 +1,110 @@
|
||||
const helpers = require("../global-setup");
|
||||
const helpers = require("../helpers/global-setup");
|
||||
const moment = require("moment");
|
||||
|
||||
describe("Clock module", function () {
|
||||
afterAll(function () {
|
||||
helpers.stopApplication();
|
||||
describe("Clock module", () => {
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
const testMatch = function (element, regex) {
|
||||
helpers.waitForElement(element).then((elem) => {
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toMatch(regex);
|
||||
});
|
||||
};
|
||||
|
||||
describe("with default 24hr clock config", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/clock/clock_24hr.js");
|
||||
helpers.getDocument(done);
|
||||
describe("with default 24hr clock config", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/clock_24hr.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show the date in the correct format", function () {
|
||||
it("should show the date in the correct format", async () => {
|
||||
const dateRegex = /^(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}, \d{4}$/;
|
||||
testMatch(".clock .date", dateRegex);
|
||||
await helpers.testMatch(".clock .date", dateRegex);
|
||||
});
|
||||
|
||||
it("should show the time in 24hr format", function () {
|
||||
it("should show the time in 24hr format", async () => {
|
||||
const timeRegex = /^(?:2[0-3]|[01]\d):[0-5]\d[0-5]\d$/;
|
||||
testMatch(".clock .time", timeRegex);
|
||||
await helpers.testMatch(".clock .time", timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with default 12hr clock config", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/clock/clock_12hr.js");
|
||||
helpers.getDocument(done);
|
||||
describe("with default 12hr clock config", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/clock_12hr.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show the date in the correct format", function () {
|
||||
it("should show the date in the correct format", async () => {
|
||||
const dateRegex = /^(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}, \d{4}$/;
|
||||
testMatch(".clock .date", dateRegex);
|
||||
await helpers.testMatch(".clock .date", dateRegex);
|
||||
});
|
||||
|
||||
it("should show the time in 12hr format", function () {
|
||||
it("should show the time in 12hr format", async () => {
|
||||
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[ap]m$/;
|
||||
testMatch(".clock .time", timeRegex);
|
||||
await helpers.testMatch(".clock .time", timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with showPeriodUpper config enabled", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/clock/clock_showPeriodUpper.js");
|
||||
helpers.getDocument(done);
|
||||
describe("with showPeriodUpper config enabled", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/clock_showPeriodUpper.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show 12hr time with upper case AM/PM", function () {
|
||||
it("should show 12hr time with upper case AM/PM", async () => {
|
||||
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[AP]M$/;
|
||||
testMatch(".clock .time", timeRegex);
|
||||
await helpers.testMatch(".clock .time", timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with displaySeconds config disabled", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/clock/clock_displaySeconds_false.js");
|
||||
helpers.getDocument(done);
|
||||
describe("with displaySeconds config disabled", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/clock_displaySeconds_false.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show 12hr time without seconds am/pm", function () {
|
||||
it("should show 12hr time without seconds am/pm", async () => {
|
||||
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[ap]m$/;
|
||||
testMatch(".clock .time", timeRegex);
|
||||
await helpers.testMatch(".clock .time", timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with showTime config disabled", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/clock/clock_showTime.js");
|
||||
helpers.getDocument(done);
|
||||
describe("with showTime config disabled", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/clock_showTime.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show not show the time when digital clock is shown", function () {
|
||||
helpers.waitForElement(".clock .digital .time").then((elem) => {
|
||||
expect(elem).toBe(null);
|
||||
});
|
||||
it("should not show the time when digital clock is shown", async () => {
|
||||
const elem = await document.querySelector(".clock .digital .time");
|
||||
expect(elem).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with showWeek config enabled", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/clock/clock_showWeek.js");
|
||||
helpers.getDocument(done);
|
||||
describe("with showWeek config enabled", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/clock_showWeek.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show the week in the correct format", function () {
|
||||
it("should show the week in the correct format", async () => {
|
||||
const weekRegex = /^Week [0-9]{1,2}$/;
|
||||
testMatch(".clock .week", weekRegex);
|
||||
await helpers.testMatch(".clock .week", weekRegex);
|
||||
});
|
||||
|
||||
it("should show the week with the correct number of week of year", function () {
|
||||
it("should show the week with the correct number of week of year", async () => {
|
||||
const currentWeekNumber = moment().week();
|
||||
const weekToShow = "Week " + currentWeekNumber;
|
||||
helpers.waitForElement(".clock .week").then((elem) => {
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toBe(weekToShow);
|
||||
});
|
||||
const elem = await helpers.waitForElement(".clock .week");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toBe(weekToShow);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with analog clock face enabled", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/clock/clock_analog.js");
|
||||
helpers.getDocument(done);
|
||||
describe("with analog clock face enabled", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/clock_analog.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show the analog clock face", () => {
|
||||
helpers.waitForElement(".clockCircle").then((elem) => {
|
||||
expect(elem).not.toBe(null);
|
||||
});
|
||||
it("should show the analog clock face", async () => {
|
||||
const elem = helpers.waitForElement(".clockCircle");
|
||||
expect(elem).not.toBe(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -1,90 +1,55 @@
|
||||
const helpers = require("../global-setup");
|
||||
const helpers = require("../helpers/global-setup");
|
||||
|
||||
/**
|
||||
* move similar tests in function doTest
|
||||
*
|
||||
* @param {Array} complimentsArray The array of compliments.
|
||||
*/
|
||||
function doTest(complimentsArray) {
|
||||
helpers.waitForElement(".compliments").then((elem) => {
|
||||
describe("Compliments module", () => {
|
||||
/**
|
||||
* move similar tests in function doTest
|
||||
*
|
||||
* @param {Array} complimentsArray The array of compliments.
|
||||
*/
|
||||
const doTest = async (complimentsArray) => {
|
||||
let elem = await helpers.waitForElement(".compliments");
|
||||
expect(elem).not.toBe(null);
|
||||
helpers.waitForElement(".module-content").then((elem) => {
|
||||
expect(elem).not.toBe(null);
|
||||
expect(complimentsArray).toContain(elem.textContent);
|
||||
});
|
||||
});
|
||||
}
|
||||
elem = await helpers.waitForElement(".module-content");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(complimentsArray).toContain(elem.textContent);
|
||||
};
|
||||
|
||||
describe("Compliments module", function () {
|
||||
afterAll(function () {
|
||||
helpers.stopApplication();
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
describe("parts of days", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/compliments/compliments_parts_day.js");
|
||||
helpers.getDocument(done);
|
||||
});
|
||||
|
||||
it("if Morning compliments for that part of day", function () {
|
||||
const hour = new Date().getHours();
|
||||
if (hour >= 3 && hour < 12) {
|
||||
// if morning check
|
||||
doTest(["Hi", "Good Morning", "Morning test"]);
|
||||
}
|
||||
});
|
||||
|
||||
it("if Afternoon show Compliments for that part of day", function () {
|
||||
const hour = new Date().getHours();
|
||||
if (hour >= 12 && hour < 17) {
|
||||
// if afternoon check
|
||||
doTest(["Hello", "Good Afternoon", "Afternoon test"]);
|
||||
}
|
||||
});
|
||||
|
||||
it("if Evening show Compliments for that part of day", function () {
|
||||
const hour = new Date().getHours();
|
||||
if (!(hour >= 3 && hour < 12) && !(hour >= 12 && hour < 17)) {
|
||||
// if evening check
|
||||
doTest(["Hello There", "Good Evening", "Evening test"]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("Feature anytime in compliments module", function () {
|
||||
describe("Set anytime and empty compliments for morning, evening and afternoon ", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/compliments/compliments_anytime.js");
|
||||
helpers.getDocument(done);
|
||||
describe("Feature anytime in compliments module", () => {
|
||||
describe("Set anytime and empty compliments for morning, evening and afternoon ", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/compliments/compliments_anytime.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("Show anytime because if configure empty parts of day compliments and set anytime compliments", function () {
|
||||
doTest(["Anytime here"]);
|
||||
it("Show anytime because if configure empty parts of day compliments and set anytime compliments", async () => {
|
||||
await doTest(["Anytime here"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Only anytime present in configuration compliments", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/compliments/compliments_only_anytime.js");
|
||||
helpers.getDocument(done);
|
||||
describe("Only anytime present in configuration compliments", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/compliments/compliments_only_anytime.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("Show anytime compliments", function () {
|
||||
doTest(["Anytime here"]);
|
||||
it("Show anytime compliments", async () => {
|
||||
await doTest(["Anytime here"]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Feature date in compliments module", function () {
|
||||
describe("Set date and empty compliments for anytime, morning, evening and afternoon", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/compliments/compliments_date.js");
|
||||
helpers.getDocument(done);
|
||||
});
|
||||
describe("remoteFile option", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/compliments/compliments_remote.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("Show happy new year compliment on new years day", function () {
|
||||
doTest(["Happy new year!"]);
|
||||
});
|
||||
it("should show compliments from a remote file", async () => {
|
||||
await doTest(["Remote compliment file works!"]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -1,35 +1,33 @@
|
||||
const helpers = require("../global-setup");
|
||||
const helpers = require("../helpers/global-setup");
|
||||
|
||||
describe("Test helloworld module", function () {
|
||||
afterAll(function () {
|
||||
helpers.stopApplication();
|
||||
describe("Test helloworld module", () => {
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
describe("helloworld set config text", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/helloworld/helloworld.js");
|
||||
helpers.getDocument(done);
|
||||
describe("helloworld set config text", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/helloworld/helloworld.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("Test message helloworld module", function () {
|
||||
helpers.waitForElement(".helloworld").then((elem) => {
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Test HelloWorld Module");
|
||||
});
|
||||
it("Test message helloworld module", async () => {
|
||||
const elem = await helpers.waitForElement(".helloworld");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Test HelloWorld Module");
|
||||
});
|
||||
});
|
||||
|
||||
describe("helloworld default config text", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/helloworld/helloworld_default.js");
|
||||
helpers.getDocument(done);
|
||||
describe("helloworld default config text", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/helloworld/helloworld_default.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("Test message helloworld module", function () {
|
||||
helpers.waitForElement(".helloworld").then((elem) => {
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Hello World!");
|
||||
});
|
||||
it("Test message helloworld module", async () => {
|
||||
const elem = await helpers.waitForElement(".helloworld");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Hello World!");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -1,4 +0,0 @@
|
||||
const generateWeather = require("./weather_current");
|
||||
const generateWeatherForecast = require("./weather_forecast");
|
||||
|
||||
module.exports = { generateWeather, generateWeatherForecast };
|
@@ -1,64 +0,0 @@
|
||||
const _ = require("lodash");
|
||||
|
||||
/**
|
||||
* @param {object} extendedData extra data to add to the default mock data
|
||||
* @returns {string} mocked current weather data
|
||||
*/
|
||||
function generateWeather(extendedData = {}) {
|
||||
return JSON.stringify(
|
||||
_.merge(
|
||||
{},
|
||||
{
|
||||
coord: {
|
||||
lon: 11.58,
|
||||
lat: 48.14
|
||||
},
|
||||
weather: [
|
||||
{
|
||||
id: 615,
|
||||
main: "Snow",
|
||||
description: "light rain and snow",
|
||||
icon: "13d"
|
||||
},
|
||||
{
|
||||
id: 500,
|
||||
main: "Rain",
|
||||
description: "light rain",
|
||||
icon: "10d"
|
||||
}
|
||||
],
|
||||
base: "stations",
|
||||
main: {
|
||||
temp: 1.49,
|
||||
pressure: 1005,
|
||||
humidity: 93.7,
|
||||
temp_min: 1,
|
||||
temp_max: 2
|
||||
},
|
||||
visibility: 7000,
|
||||
wind: {
|
||||
speed: 11.8,
|
||||
deg: 250
|
||||
},
|
||||
clouds: {
|
||||
all: 75
|
||||
},
|
||||
dt: 1547387400,
|
||||
sys: {
|
||||
type: 1,
|
||||
id: 1267,
|
||||
message: 0.0031,
|
||||
country: "DE",
|
||||
sunrise: 1547362817,
|
||||
sunset: 1547394301
|
||||
},
|
||||
id: 2867714,
|
||||
name: "Munich",
|
||||
cod: 200
|
||||
},
|
||||
extendedData
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = generateWeather;
|
@@ -1,83 +1,77 @@
|
||||
const helpers = require("../global-setup");
|
||||
const helpers = require("../helpers/global-setup");
|
||||
|
||||
describe("Newsfeed module", function () {
|
||||
afterAll(function () {
|
||||
helpers.stopApplication();
|
||||
describe("Newsfeed module", () => {
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
describe("Default configuration", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/newsfeed/default.js");
|
||||
helpers.getDocument(done);
|
||||
describe("Default configuration", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/newsfeed/default.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show the newsfeed title", function () {
|
||||
helpers.waitForElement(".newsfeed .newsfeed-source").then((elem) => {
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Rodrigo Ramirez Blog");
|
||||
});
|
||||
it("should show the newsfeed title", async () => {
|
||||
const elem = await helpers.waitForElement(".newsfeed .newsfeed-source");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Rodrigo Ramirez Blog");
|
||||
});
|
||||
|
||||
it("should show the newsfeed article", function () {
|
||||
helpers.waitForElement(".newsfeed .newsfeed-title").then((elem) => {
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("QPanel");
|
||||
});
|
||||
it("should show the newsfeed article", async () => {
|
||||
const elem = await helpers.waitForElement(".newsfeed .newsfeed-title");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("QPanel");
|
||||
});
|
||||
|
||||
it("should NOT show the newsfeed description", () => {
|
||||
helpers.waitForElement(".newsfeed .newsfeed-desc").then((elem) => {
|
||||
expect(elem).toBe(null);
|
||||
});
|
||||
it("should NOT show the newsfeed description", async () => {
|
||||
await helpers.waitForElement(".newsfeed");
|
||||
const element = document.querySelector(".newsfeed .newsfeed-desc");
|
||||
expect(element).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Custom configuration", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/newsfeed/prohibited_words.js");
|
||||
helpers.getDocument(done);
|
||||
describe("Custom configuration", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/newsfeed/prohibited_words.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should not show articles with prohibited words", function () {
|
||||
helpers.waitForElement(".newsfeed .newsfeed-title").then((elem) => {
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Problema VirtualBox");
|
||||
});
|
||||
it("should not show articles with prohibited words", async () => {
|
||||
const elem = await helpers.waitForElement(".newsfeed .newsfeed-title");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Problema VirtualBox");
|
||||
});
|
||||
|
||||
it("should show the newsfeed description", () => {
|
||||
helpers.waitForElement(".newsfeed .newsfeed-desc").then((elem) => {
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent.length).not.toBe(0);
|
||||
});
|
||||
it("should show the newsfeed description", async () => {
|
||||
const elem = await helpers.waitForElement(".newsfeed .newsfeed-desc");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent.length).not.toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Invalid configuration", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/newsfeed/incorrect_url.js");
|
||||
helpers.getDocument(done);
|
||||
describe("Invalid configuration", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/newsfeed/incorrect_url.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show malformed url warning", function () {
|
||||
helpers.waitForElement(".newsfeed .small").then((elem) => {
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Error in the Newsfeed module. Malformed url.");
|
||||
});
|
||||
it("should show malformed url warning", async () => {
|
||||
const elem = await helpers.waitForElement(".newsfeed .small", "No news at the moment.");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Error in the Newsfeed module. Malformed url.");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Ignore items", function () {
|
||||
beforeAll(function (done) {
|
||||
helpers.startApplication("tests/configs/modules/newsfeed/ignore_items.js");
|
||||
helpers.getDocument(done);
|
||||
describe("Ignore items", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/newsfeed/ignore_items.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show empty items info message", function () {
|
||||
helpers.waitForElement(".newsfeed .small").then((elem) => {
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("No news at the moment.");
|
||||
});
|
||||
it("should show empty items info message", async () => {
|
||||
const elem = await helpers.waitForElement(".newsfeed .small");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("No news at the moment.");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
84
tests/e2e/modules/weather_current_spec.js
Normal file
84
tests/e2e/modules/weather_current_spec.js
Normal file
@@ -0,0 +1,84 @@
|
||||
const helpers = require("../helpers/global-setup");
|
||||
const weatherFunc = require("../helpers/weather-functions");
|
||||
|
||||
describe("Weather module", () => {
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
describe("Current weather", () => {
|
||||
describe("Default configuration", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApp("tests/configs/modules/weather/currentweather_default.js", {});
|
||||
});
|
||||
|
||||
it("should render wind speed and wind direction", async () => {
|
||||
await weatherFunc.getText(".weather .normal.medium span:nth-child(2)", "12 WSW");
|
||||
});
|
||||
|
||||
it("should render temperature with icon", async () => {
|
||||
await weatherFunc.getText(".weather .large.light span.bright", "1.5°");
|
||||
});
|
||||
|
||||
it("should render feels like temperature", async () => {
|
||||
await weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -5.6°");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Compliments Integration", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApp("tests/configs/modules/weather/currentweather_compliments.js", {});
|
||||
});
|
||||
|
||||
it("should render a compliment based on the current weather", async () => {
|
||||
await weatherFunc.getText(".compliments .module-content span", "snow");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Configuration Options", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApp("tests/configs/modules/weather/currentweather_options.js", {});
|
||||
});
|
||||
|
||||
it("should render windUnits in beaufort", async () => {
|
||||
await weatherFunc.getText(".weather .normal.medium span:nth-child(2)", "6");
|
||||
});
|
||||
|
||||
it("should render windDirection with an arrow", async () => {
|
||||
const elem = await helpers.waitForElement(".weather .normal.medium sup i.fa-long-arrow-alt-up");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.outerHTML).toContain("transform:rotate(250deg);");
|
||||
});
|
||||
|
||||
it("should render humidity", async () => {
|
||||
await weatherFunc.getText(".weather .normal.medium span:nth-child(3)", "93.7");
|
||||
});
|
||||
|
||||
it("should render degreeLabel for temp", async () => {
|
||||
await weatherFunc.getText(".weather .large.light span.bright", "1°C");
|
||||
});
|
||||
|
||||
it("should render degreeLabel for feels like", async () => {
|
||||
await weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -6°C");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Current weather with imperial units", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApp("tests/configs/modules/weather/currentweather_units.js", {});
|
||||
});
|
||||
|
||||
it("should render wind in imperial units", async () => {
|
||||
await weatherFunc.getText(".weather .normal.medium span:nth-child(2)", "26 WSW");
|
||||
});
|
||||
|
||||
it("should render temperatures in fahrenheit", async () => {
|
||||
await weatherFunc.getText(".weather .large.light span.bright", "34,7°");
|
||||
});
|
||||
|
||||
it("should render 'feels like' in fahrenheit", async () => {
|
||||
await weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 21,9°");
|
||||
});
|
||||
});
|
||||
});
|
96
tests/e2e/modules/weather_forecast_spec.js
Normal file
96
tests/e2e/modules/weather_forecast_spec.js
Normal file
@@ -0,0 +1,96 @@
|
||||
const helpers = require("../helpers/global-setup");
|
||||
const weatherFunc = require("../helpers/weather-functions");
|
||||
|
||||
describe("Weather module: Weather Forecast", () => {
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
describe("Default configuration", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApp("tests/configs/modules/weather/forecastweather_default.js", {});
|
||||
});
|
||||
|
||||
const days = ["Today", "Tomorrow", "Sun", "Mon", "Tue"];
|
||||
for (const [index, day] of days.entries()) {
|
||||
it("should render day " + day, async () => {
|
||||
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day);
|
||||
});
|
||||
}
|
||||
|
||||
const icons = ["day-cloudy", "rain", "day-sunny", "day-sunny", "day-sunny"];
|
||||
for (const [index, icon] of icons.entries()) {
|
||||
it("should render icon " + icon, async () => {
|
||||
const elem = await helpers.waitForElement(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(2) span.wi-${icon}`);
|
||||
expect(elem).not.toBe(null);
|
||||
});
|
||||
}
|
||||
|
||||
const maxTemps = ["24.4°", "21.0°", "22.9°", "23.4°", "20.6°"];
|
||||
for (const [index, temp] of maxTemps.entries()) {
|
||||
it("should render max temperature " + temp, async () => {
|
||||
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp);
|
||||
});
|
||||
}
|
||||
|
||||
const minTemps = ["15.3°", "13.6°", "13.8°", "13.9°", "10.9°"];
|
||||
for (const [index, temp] of minTemps.entries()) {
|
||||
it("should render min temperature " + temp, async () => {
|
||||
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(4)`, temp);
|
||||
});
|
||||
}
|
||||
|
||||
const opacities = [1, 1, 0.8, 0.5333333333333333, 0.2666666666666667];
|
||||
for (const [index, opacity] of opacities.entries()) {
|
||||
it("should render fading of rows with opacity=" + opacity, async () => {
|
||||
const elem = await helpers.waitForElement(`.weather table.small tr:nth-child(${index + 1})`);
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.outerHTML).toContain(`<tr style="opacity: ${opacity};">`);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("Absolute configuration", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApp("tests/configs/modules/weather/forecastweather_absolute.js", {});
|
||||
});
|
||||
|
||||
const days = ["Fri", "Sat", "Sun", "Mon", "Tue"];
|
||||
for (const [index, day] of days.entries()) {
|
||||
it("should render day " + day, async () => {
|
||||
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("Configuration Options", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApp("tests/configs/modules/weather/forecastweather_options.js", {});
|
||||
});
|
||||
|
||||
it("should render custom table class", async () => {
|
||||
const elem = await helpers.waitForElement(".weather table.myTableClass");
|
||||
expect(elem).not.toBe(null);
|
||||
});
|
||||
|
||||
it("should render colored rows", async () => {
|
||||
const table = await helpers.waitForElement(".weather table.myTableClass");
|
||||
expect(table).not.toBe(null);
|
||||
expect(table.rows).not.toBe(null);
|
||||
expect(table.rows.length).toBe(5);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Forecast weather units", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApp("tests/configs/modules/weather/forecastweather_units.js", {});
|
||||
});
|
||||
|
||||
const temperatures = ["75_9°", "69_8°", "73_2°", "74_1°", "69_1°"];
|
||||
for (const [index, temp] of temperatures.entries()) {
|
||||
it("should render custom decimalSymbol = '_' for temp " + temp, async () => {
|
||||
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
@@ -1,258 +0,0 @@
|
||||
const moment = require("moment");
|
||||
const helpers = require("../global-setup");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const { generateWeather, generateWeatherForecast } = require("./mocks");
|
||||
|
||||
describe("Weather module", function () {
|
||||
/**
|
||||
* @param {string} element css selector
|
||||
* @param {string} result Expected text in given selector
|
||||
*/
|
||||
function getText(element, result) {
|
||||
helpers.waitForElement(element).then((elem) => {
|
||||
expect(elem).not.toBe(null);
|
||||
expect(
|
||||
elem.textContent
|
||||
.trim()
|
||||
.replace(/(\r\n|\n|\r)/gm, "")
|
||||
.replace(/[ ]+/g, " ")
|
||||
).toBe(result);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} configFile path to configuration file
|
||||
* @param {string} additionalMockData special data for mocking
|
||||
* @param {string} callback callback
|
||||
*/
|
||||
function startApp(configFile, additionalMockData, callback) {
|
||||
let mockWeather;
|
||||
if (configFile.includes("forecast")) {
|
||||
mockWeather = generateWeatherForecast(additionalMockData);
|
||||
} else {
|
||||
mockWeather = generateWeather(additionalMockData);
|
||||
}
|
||||
let content = fs.readFileSync(path.resolve(__dirname + "../../../../" + configFile)).toString();
|
||||
content = content.replace("#####WEATHERDATA#####", mockWeather);
|
||||
fs.writeFileSync(path.resolve(__dirname + "../../../../config/config.js"), content);
|
||||
helpers.startApplication("");
|
||||
helpers.getDocument(callback);
|
||||
}
|
||||
|
||||
afterAll(function () {
|
||||
helpers.stopApplication();
|
||||
});
|
||||
|
||||
describe("Current weather", function () {
|
||||
describe("Default configuration", function () {
|
||||
beforeAll(function (done) {
|
||||
startApp("tests/configs/modules/weather/currentweather_default.js", {}, done);
|
||||
});
|
||||
|
||||
it("should render wind speed and wind direction", function () {
|
||||
getText(".weather .normal.medium span:nth-child(2)", "6 WSW");
|
||||
});
|
||||
|
||||
it("should render temperature with icon", function () {
|
||||
getText(".weather .large.light span.bright", "1.5°");
|
||||
});
|
||||
|
||||
it("should render feels like temperature", function () {
|
||||
getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -5.6°");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Default configuration with sunrise", function () {
|
||||
beforeAll(function (done) {
|
||||
const sunrise = moment().startOf("day").unix();
|
||||
const sunset = moment().startOf("day").unix();
|
||||
startApp("tests/configs/modules/weather/currentweather_default.js", { sys: { sunrise, sunset } }, done);
|
||||
});
|
||||
|
||||
it("should render sunrise", function () {
|
||||
getText(".weather .normal.medium span:nth-child(4)", "12:00 am");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Default configuration with sunset", function () {
|
||||
beforeAll(function (done) {
|
||||
const sunrise = moment().startOf("day").unix();
|
||||
const sunset = moment().endOf("day").unix();
|
||||
startApp("tests/configs/modules/weather/currentweather_default.js", { sys: { sunrise, sunset } }, done);
|
||||
});
|
||||
|
||||
it("should render sunset", function () {
|
||||
getText(".weather .normal.medium span:nth-child(4)", "11:59 pm");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Compliments Integration", function () {
|
||||
beforeAll(function (done) {
|
||||
startApp("tests/configs/modules/weather/currentweather_compliments.js", {}, done);
|
||||
});
|
||||
|
||||
it("should render a compliment based on the current weather", function () {
|
||||
getText(".compliments .module-content span", "snow");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Configuration Options", function () {
|
||||
beforeAll(function (done) {
|
||||
startApp("tests/configs/modules/weather/currentweather_options.js", {}, done);
|
||||
});
|
||||
|
||||
it("should render useBeaufort = false", function () {
|
||||
getText(".weather .normal.medium span:nth-child(2)", "12");
|
||||
});
|
||||
|
||||
it("should render showWindDirectionAsArrow = true", function () {
|
||||
helpers.waitForElement(".weather .normal.medium sup i.fa-long-arrow-alt-up").then((elem) => {
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.outerHTML).toContain("transform:rotate(250deg);");
|
||||
});
|
||||
});
|
||||
|
||||
it("should render showHumidity = true", function () {
|
||||
getText(".weather .normal.medium span:nth-child(3)", "93.7");
|
||||
});
|
||||
|
||||
it("should render degreeLabel = true", function () {
|
||||
getText(".weather .large.light span.bright", "1°C");
|
||||
getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -6°C");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Current weather units", function () {
|
||||
beforeAll(function (done) {
|
||||
startApp(
|
||||
"tests/configs/modules/weather/currentweather_units.js",
|
||||
{
|
||||
main: {
|
||||
temp: (1.49 * 9) / 5 + 32,
|
||||
temp_min: (1 * 9) / 5 + 32,
|
||||
temp_max: (2 * 9) / 5 + 32
|
||||
},
|
||||
wind: {
|
||||
speed: 11.8 * 2.23694
|
||||
}
|
||||
},
|
||||
done
|
||||
);
|
||||
});
|
||||
|
||||
it("should render imperial units", function () {
|
||||
getText(".weather .normal.medium span:nth-child(2)", "6 WSW");
|
||||
getText(".weather .large.light span.bright", "34,7°");
|
||||
getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°");
|
||||
});
|
||||
|
||||
it("should render custom decimalSymbol = ','", function () {
|
||||
getText(".weather .normal.medium span:nth-child(3)", "93,7");
|
||||
getText(".weather .large.light span.bright", "34,7°");
|
||||
getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Weather Forecast", function () {
|
||||
describe("Default configuration", function () {
|
||||
beforeAll(function (done) {
|
||||
startApp("tests/configs/modules/weather/forecastweather_default.js", {}, done);
|
||||
});
|
||||
|
||||
it("should render days", function () {
|
||||
const days = ["Today", "Tomorrow", "Sun", "Mon", "Tue"];
|
||||
|
||||
for (const [index, day] of days.entries()) {
|
||||
getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day);
|
||||
}
|
||||
});
|
||||
|
||||
it("should render icons", function () {
|
||||
const icons = ["day-cloudy", "rain", "day-sunny", "day-sunny", "day-sunny"];
|
||||
|
||||
for (const [index, icon] of icons.entries()) {
|
||||
helpers.waitForElement(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(2) span.wi-${icon}`).then((elem) => {
|
||||
expect(elem).not.toBe(null);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it("should render max temperatures", function () {
|
||||
const temperatures = ["24.4°", "21.0°", "22.9°", "23.4°", "20.6°"];
|
||||
|
||||
for (const [index, temp] of temperatures.entries()) {
|
||||
getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp);
|
||||
}
|
||||
});
|
||||
|
||||
it("should render min temperatures", function () {
|
||||
const temperatures = ["15.3°", "13.6°", "13.8°", "13.9°", "10.9°"];
|
||||
|
||||
for (const [index, temp] of temperatures.entries()) {
|
||||
getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(4)`, temp);
|
||||
}
|
||||
});
|
||||
|
||||
it("should render fading of rows", function () {
|
||||
const opacities = [1, 1, 0.8, 0.5333333333333333, 0.2666666666666667];
|
||||
|
||||
for (const [index, opacity] of opacities.entries()) {
|
||||
helpers.waitForElement(`.weather table.small tr:nth-child(${index + 1})`).then((elem) => {
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.outerHTML).toContain(`<tr style="opacity: ${opacity};">`);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("Absolute configuration", function () {
|
||||
beforeAll(function (done) {
|
||||
startApp("tests/configs/modules/weather/forecastweather_absolute.js", {}, done);
|
||||
});
|
||||
|
||||
it("should render days", function () {
|
||||
const days = ["Fri", "Sat", "Sun", "Mon", "Tue"];
|
||||
|
||||
for (const [index, day] of days.entries()) {
|
||||
getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("Configuration Options", function () {
|
||||
beforeAll(function (done) {
|
||||
startApp("tests/configs/modules/weather/forecastweather_options.js", {}, done);
|
||||
});
|
||||
|
||||
it("should render custom table class", function () {
|
||||
helpers.waitForElement(".weather table.myTableClass").then((elem) => {
|
||||
expect(elem).not.toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
it("should render colored rows", function () {
|
||||
helpers.waitForElement(".weather table.myTableClass").then((table) => {
|
||||
expect(table).not.toBe(null);
|
||||
expect(table.rows).not.toBe(null);
|
||||
expect(table.rows.length).toBe(5);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Forecast weather units", function () {
|
||||
beforeAll(function (done) {
|
||||
startApp("tests/configs/modules/weather/forecastweather_units.js", {}, done);
|
||||
});
|
||||
|
||||
it("should render custom decimalSymbol = '_'", function () {
|
||||
const temperatures = ["24_4°", "21_0°", "22_9°", "23_4°", "20_6°"];
|
||||
|
||||
for (const [index, temp] of temperatures.entries()) {
|
||||
getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user