Initial commit

Framework for a MagicMirror module to talk to MyQ about
registered devices. This just makes sure we can use the api library to
get information. Actually hooking it up to the display is forthcoming.
This commit is contained in:
2020-08-19 22:47:35 -05:00
commit 0b1ae8af8f
14 changed files with 3604 additions and 0 deletions

13
.editorconfig Normal file
View File

@ -0,0 +1,13 @@
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4
[{*.json, *.yml}]
indent_style = space
indent_size = 2

18
.eslintrc Normal file
View File

@ -0,0 +1,18 @@
{
"extends": "airbnb-base",
"rules": {
"comma-dangle": 0,
"indent": [2, 4],
"max-len": [2, 120, { "ignoreStrings": true }],
"radix": [2, "as-needed"],
"no-console": 0
},
"settings": {
"import/core-modules": [ "node_helper" ]
},
"env": {
"browser": true,
"node": true,
"es6": true
}
}

28
.github/workflows/nodejs.yml vendored Normal file
View File

@ -0,0 +1,28 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

7
.markdownlint.json Normal file
View File

@ -0,0 +1,7 @@
{
"default": true,
"no-duplicate-header": {
"siblings_only": true
},
"line-length": false
}

6
.stylelintrc Normal file
View File

@ -0,0 +1,6 @@
{
"extends": "stylelint-config-standard",
"rules": {
"indentation": 4
}
}

5
CHANGELOG.md Normal file
View File

@ -0,0 +1,5 @@
# MMM-MyQ Changelog
## [1.0.0]
Initial version

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 parnic
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

20
MMM-MyQ.css Normal file
View File

@ -0,0 +1,20 @@
.MMM-MyQ .table {
border-spacing: 10px 0;
border-collapse: separate;
text-align: center;
}
.MMM-MyQ .icon {
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
}
.MMM-MyQ .row {
vertical-align: middle;
}
.MMM-MyQ .live {
font-size: 10px;
line-height: 15px;
display: block;
}

67
MMM-MyQ.js Normal file
View File

@ -0,0 +1,67 @@
/* Magic Mirror
* Module: MMM-MyQ
*
* By parnic https://github.com/parnic/MMM-MyQ
* MIT Licensed.
*/
Module.register('MMM-MyQ', {
defaults: {
colored: false,
email: 'email',
password: 'password',
types: ['wifigaragedooropener'],
updateInterval: 5 * 60 * 1000 // every 5 minutes
},
getStyles() {
return ['MMM-MyQ.css'];
},
start() {
Log.info(`Starting module: ${this.name}`);
this.sendSocketNotification('MYQ_CONFIG', this.config);
this.sendSocketNotification('MYQ_UPDATE');
},
socketNotificationReceived(notification, payload) {
if (notification === 'SCORES') {
this.scores = payload.scores;
this.details = payload.details;
}
},
getDom() {
const wrapper = document.createElement('div');
const scores = document.createElement('div');
const header = document.createElement('header');
header.innerHTML = 'MyQ';
scores.appendChild(header);
if (!this.scores) {
const text = document.createElement('div');
text.innerHTML = this.translate('LOADING');
text.classList.add('dimmed', 'light');
scores.appendChild(text);
} else {
const table = document.createElement('table');
table.classList.add('small', 'table');
table.appendChild(this.createLabelRow());
const max = Math.min(
this.rotateIndex + this.config.matches,
this.scores.length
);
for (let i = this.rotateIndex; i < max; i += 1) {
this.appendDataRow(this.scores[i], table);
}
scores.appendChild(table);
}
wrapper.appendChild(scores);
return wrapper;
}
});

36
README.md Normal file
View File

@ -0,0 +1,36 @@
# MMM-MyQ
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://raw.githubusercontent.com/parnic/MMM-MyQ/main/LICENSE)
MyQ module for MagicMirror²
## Dependencies
* An installation of [MagicMirror²](https://github.com/MichMich/MagicMirror)
* npm
## Installation
1. Clone this repo into `~/MagicMirror/modules` directory.
1. Configure your `~/MagicMirror/config/config.js`:
```json
{
module: 'MMM-MyQ',
position: 'top_right',
config: {
email: 'you@example.com',
password: 'correct horse battery stapler'
}
}
```
1. Run command `npm install --production` in your `modules/MMM-MyQ` directory.
## Config Options
| **Option** | **Default** | **Description** |
| --- | --- | --- |
| `email` | `''` | Your MyQ login address. (required) |
| `password` | `''` | Your MyQ login password. (required) |
| `updateInterval` | `5 * 60 * 1000` | How often to update the state of your devices, in milliseconds. |

77
node_helper.js Normal file
View File

@ -0,0 +1,77 @@
/* Magic Mirror
* Module: MMM-MyQ
*
* By parnic https://github.com/parnic/MMM-MyQ
* MIT Licensed.
*/
/* eslint-env node */
const NodeHelper = require('node_helper');
const { myQ, _ } = require('myq-api');
module.exports = NodeHelper.create({
start() {
console.log(`Starting module helper: ${this.name}`);
},
socketNotificationReceived(notification, payload) {
if (notification === 'MYQ_CONFIG') {
this.config = payload;
this.account = new myQ(this.config.email, this.config.password);
console.log('config received');
this.account
.login()
.then((result) => {
console.log('login complete');
if (result.returnCode !== 0) {
throw new Error('login failure');
}
this.sendSocketNotification('MYQ_LOGGED_IN');
this.getData();
})
.catch((err) => {
this.sendSocketNotification('MYQ_ERROR');
console.error(`login error: ${err}`);
});
setInterval(() => {
this.getData();
}, this.config.updateInterval);
}
},
getData() {
console.log('retrieving devices');
this.account
.getDevices()
.then((result) => {
console.log('devices retrieved');
result.devices.forEach((device) => {
if (this.config.types.includes(device.type)) {
this.sendSocketNotification('MYQ_DEVICE_FOUND', device);
console.log('getting door state');
console.log(device);
this.account
.getDoorState(device.serialNumber)
.then((state) => {
console.log('state');
console.log(state);
if (state.returnCode === 0) {
this.sendSocketNotification(
'MYQ_DEVICE_STATE',
{ device, state }
);
}
});
}
});
})
.catch((err) => {
this.sendSocketNotification('MYQ_ERROR');
console.error(`getData error: ${err}`);
});
}
});

3274
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

31
package.json Normal file
View File

@ -0,0 +1,31 @@
{
"name": "mmm-myq",
"version": "1.0.0",
"description": "MyQ module for MagicMirror2",
"scripts": {
"lint": "./node_modules/.bin/eslint . && ./node_modules/.bin/stylelint ."
},
"repository": "github:parnic/MMM-MyQ",
"keywords": [
"MagicMirror",
"MyQ",
"Chamberlain",
"LiftMaster"
],
"author": "parnic",
"license": "MIT",
"bugs": {
"url": "https://github.com/parnic/MMM-MyQ/issues"
},
"homepage": "https://github.com/parnic/MMM-MyQ#readme",
"devDependencies": {
"eslint": "^7.7.0",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-plugin-import": "^2.2.0",
"stylelint": "^13.6.1",
"stylelint-config-standard": "^20.0.0"
},
"dependencies": {
"myq-api": "parnic/myq-api#9402fed007a9039b06d5b73c6fa6138cae2723d5"
}
}