Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .eslintrc.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Install Dependencies
run: npm clean-install
- name: Validate JS Sources
run: npm run validate:js
run: npm run lint:js
markdownlint:
runs-on: ubuntu-latest
name: 'MarkdownLint'
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 Christopher
Copyright (c) 2016 Christopher Fenner

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
30 changes: 15 additions & 15 deletions MMM-AirQuality.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,30 @@ Module.register('MMM-AirQuality', {
HAZARDOUS: '#7e0023',
UNKNOWN: '#333333',
},
start: function () {
start() {
const self = this
Log.info(`Starting module: ${this.name}`)
self.loaded = false

if (this.config.token !== '' && this.config.location !== '') {
setTimeout(function () {
setTimeout(() => {
self.sendSocketNotification(self.notifications.DATA, { identifier: self.identifier, config: self.config })
}, this.config.initialDelay * 1000)

// set auto-update
setInterval(function () {
setInterval(() => {
self.sendSocketNotification(self.notifications.DATA, { identifier: self.identifier, config: self.config })
}, this.config.updateInterval * 60 * 1000 + this.config.initialDelay * 1000)
}
},
updateData: function (response) {
updateData(response) {
this.loaded = true
this.data.city = response.data.city.name
this.data.value = response.data.aqi
this.data.impact = this.getImpact(response.data.aqi)
this.data.color = this.colors[this.data.impact]
},
getImpact: function (index) {
getImpact(index) {
if (index < 51) return 'GOOD'
if (index < 101) return 'MODERATE'
if (index < 151) return 'UNHEALTHY_FOR_SENSITIVE_GROUPS'
Expand All @@ -64,7 +64,7 @@ Module.register('MMM-AirQuality', {
return 'UNKNOWN'
},
// Override getHeader method.
getHeader: function () {
getHeader() {
let header = ''
if (this.data.header !== '') {
if (this.data.header === undefined) {
Expand All @@ -82,10 +82,10 @@ Module.register('MMM-AirQuality', {
}
return header
},
getTemplate: function () {
getTemplate() {
return `${this.name}.njk`
},
getTemplateData: function () {
getTemplateData() {
let message = ''
if (this.config.token === '') {
message = `Please set a token for ${this.name}!<br>You can acquire one at <a href='https://aqicn.org/data-platform/token/'>https://aqicn.org/data-platform/token/</a>.`
Expand All @@ -105,30 +105,30 @@ Module.register('MMM-AirQuality', {
message,
}
},
getTranslations: function () {
getTranslations() {
return {
en: 'l10n/en.json', // fallback language
de: 'l10n/de.json',
}
},
getScripts: function () {
getScripts() {
return ['//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.js']
},
getStyles: function () {
getStyles() {
return ['https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css']
},
socketNotificationReceived: function (notification, payload) {
socketNotificationReceived(notification, payload) {
const self = this
Log.debug('received ' + notification)
Log.debug(`received ${notification}`)
switch (notification) {
case self.notifications.DATA_RESPONSE:
if (payload.identifier === this.identifier) {
if (payload.status === 'OK') {
console.log('Data %o', payload.payloadReturn)
Log.log('Data %o', payload.payloadReturn)
self.updateData(payload.payloadReturn)
self.updateDom(this.animationSpeed)
} else {
console.log('DATA FAILED ' + payload.message)
Log.log(`DATA FAILED ${payload.message}`)
}
}
break
Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# MMM-AirQuality

A module for the [MagicMirror](https://github.com/MagicMirrorOrg/MagicMirror) to display a location's [*air quality index*](https://en.wikipedia.org/wiki/Air_quality_index) using data from [aqicn.org](http://aqicn.org/here/).
A module for [MagicMirror²](https://github.com/MagicMirrorOrg/MagicMirror) to display a location's [*air quality index*](https://en.wikipedia.org/wiki/Air_quality_index) using data from [aqicn.org](http://aqicn.org/here/).

## Preview

Expand All @@ -30,7 +30,15 @@ You need to install and configure the module for your MagicMirror.
Clone the module into your modules folder:

```shell
cd ~/MagicMirror/modules && git clone https://github.com/CFenner/MMM-AirQuality
cd ~/MagicMirror/modules
git clone https://github.com/CFenner/MMM-AirQuality
```

### Update

```shell
cd ~/MagicMirror/modules/MMM-AirQuality
git pull
```

### Configuration
Expand Down Expand Up @@ -110,3 +118,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

## Developer commands

- `npm install` - Install devDependencies like ESLint and markdownlint.
- `npm run lint` - Run linting and formatter checks.
- `npm run lint:fix` - Fix linting and formatter issues.
40 changes: 40 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import eslintPluginJs from '@eslint/js'
import eslintPluginStylistic from '@stylistic/eslint-plugin'
import globals from 'globals'

const config = [
{
files: ['**/*.js', '**/*.mjs'],
},
{
languageOptions: {
globals: {
...globals.browser,
...globals.node,
Log: 'readonly',
Module: 'readonly',
},
},
plugins: {
...eslintPluginStylistic.configs['recommended-flat'].plugins,
},
rules: {
...eslintPluginJs.configs.all.rules,
...eslintPluginStylistic.configs['recommended-flat'].rules,
'@stylistic/brace-style': ['error', '1tbs', { allowSingleLine: true }],
'@stylistic/comma-dangle': ['error', 'only-multiline'],
'capitalized-comments': 'off',
'consistent-this': 'off',
'curly': 'off',
'default-case': 'off',
'no-console': 'off',
'no-inline-comments': 'off',
'no-magic-numbers': 'off',
'no-undefined': 'off',
'one-var': ['error', 'never'],
'sort-keys': 'off',
},
}
]

export default config
6 changes: 3 additions & 3 deletions helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ module.exports = {
DATA: 'AIR_QUALITY_DATA',
DATA_RESPONSE: 'AIR_QUALITY_DATA_RESPONSE',
},
start: function () {
start() {
console.log('AirQuality helper started ...')
},
loadData: async function (payload) {
async loadData(payload) {
const self = this
const url = `https://${payload.config.apiBase}${payload.config.dataEndpoint}${payload.config.location}/?token=${payload.config.token}`
console.log(`AirQuality-Fetcher: ${url}`)
Expand All @@ -27,7 +27,7 @@ module.exports = {
identifier: payload.identifier,
})
},
socketNotificationReceived: function (notification, payload) {
socketNotificationReceived(notification, payload) {
switch (notification) {
case this.notifications.DATA:
console.log(`AirQuality-Fetcher: Loading data of ${payload.config.location} for module ${payload.identifier}`)
Expand Down
Loading