Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
relm923 committed Feb 10, 2018
0 parents commit 3f89f9c
Show file tree
Hide file tree
Showing 15 changed files with 3,226 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"rules": {
"indent": ["error", "tab", { "SwitchCase": 1 }],
"quotes": ["error", "single"],
"max-len": ["error", 100],
"curly": "error",
"camelcase": ["error", {"properties": "never"}],
"no-trailing-spaces": ["error"],
"no-irregular-whitespace": ["error"]
},
"env": {
"browser": true,
"node": true,
"es6": true
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Dependency directories
node_modules/
5 changes: 5 additions & 0 deletions .stylelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "stylelint-config-standard",
"font-family-name-quotes": "double-where-recommended",
"block-no-empty": false
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# MMM-Roomba980 Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).


## [1.0.0] - 2017-02-10

First public release
66 changes: 66 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
module.exports = function(grunt) {
require('time-grunt')(grunt);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
eslint: {
options: {
configFile: '.eslintrc.json'
},
target: ['*.js']
},
stylelint: {
simple: {
options: {
configFile: '.stylelintrc'
},
src: ['*.css']
}
},
jsonlint: {
main: {
src: ['package.json', 'translations/*.json'],
options: {
reporter: 'jshint'
}
}
},
markdownlint: {
all: {
options: {
config: {
'default': true,
'line-length': false,
'blanks-around-headers': false,
'no-duplicate-header': false,
'no-inline-html': false,
'MD010': false,
'MD001': false,
'MD031': false,
'MD040': false,
'MD002': false,
'MD029': false,
'MD041': false,
'MD032': false,
'MD036': false,
'MD037': false,
'MD009': false,
'MD018': false,
'MD012': false,
'MD026': false,
'MD038': false
}
},
src: ['README.md', 'CHANGELOG.md', 'LICENSE.txt']
}
},
yamllint: {
all: ['.travis.yml']
}
});
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-stylelint');
grunt.loadNpmTasks('grunt-jsonlint');
grunt.loadNpmTasks('grunt-yamllint');
grunt.loadNpmTasks('grunt-markdownlint');
grunt.registerTask('default', ['eslint', 'stylelint', 'jsonlint', 'markdownlint', 'yamllint']);
};
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017 Reagan Elm

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.
15 changes: 15 additions & 0 deletions MMM-Roomba980.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.MMM-Roomba980 .name {
padding-left: 0;
padding-right: 25px;
text-align: left;
}

.MMM-Roomba980 .phase {
padding-left: 0;
padding-right: 15px;
}

.MMM-Roomba980 .battery {
padding-left: 30px;
padding-right: 0;
}
164 changes: 164 additions & 0 deletions MMM-Roomba980.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/* global Module */

/* Magic Mirror
* Module: MMM-Roomba980
*
* By Reagan Elm
* MIT Licensed.
*/

Module.register('MMM-Roomba980', {
defaults: {
username: '',
password: '',
ipAddress: '',
updateInterval: 60 * 1000, // 1 miniute
animationSpeed: 2 * 1000, // 2 seconds
},

requiresVersion: '2.1.0',

start() {
const self = this;

self.loaded = false;
self.stats = {};

self.sendSocketNotification('START', self.config);
Log.info('Starting module: ' + self.name);
},

getDom() {
const self = this;

if (self.error) {
return self.renderError();
}

if (!self.loaded) {
return self.renderLoading();
}

return self.renderStats();
},

renderError() {
const self = this;

let wrapper = document.createElement('div');
wrapper.className = 'dimmed light small';
wrapper.innerHTML = self.error;
return wrapper;
},

renderLoading() {
const self = this;

let wrapper = document.createElement('div');
wrapper.className = 'dimmed light small';
wrapper.innerHTML = self.translate('LOADING');

return wrapper;
},

renderStats() {
const self = this;

let wrapper = document.createElement('table');
wrapper.className = 'small';
wrapper.innerHTML = `
<tr>
${self.renderName()}
${self.renderPhase()}
${self.renderBinStatus()}
${self.renderBatteryStatus()}
</tr>
`;

return wrapper;
},

renderName() {
return `<td class="name">${this.stats.name}</td>`;
},

renderPhase() {
const self = this;

let phaseText;
switch (self.stats.phase) {
case 'charge':
phaseText = self.translate('CHARGING');
break;
case 'hmUsrDock':
phaseText = self.translate('RETURNING_HOME');
break;
case 'run':
phaseText = self.translate('CLEANING');
break;
case 'stop':
phaseText = self.translate('PAUSED');
break;
default:
phaseText = `${self.translate('UNKNOWN')}: ${self.stats.phase}`;
}

return `<td class="phase title bright">${phaseText}</td>`;
},

renderBinStatus() {
const self = this;

let statusHtml = '';
if (self.stats.binFull) {
statusHtml = `
<td class="bin title bright">
<i class="fa fa-trash"></i> ${self.translate('FULL')}
</td>
`;
}

return statusHtml;
},

renderBatteryStatus() {
return `
<td class="battery">
<i class="fa fa-bolt"></i> ${this.stats.batteryPercent}%
</td>`;
},

socketNotificationReceived(notification, payload) {
const self = this;

switch (notification) {
case 'STATS':
self.loaded = true;
self.stats = payload;
break;
case 'ERROR':
self.error = payload;
break;
}

this.updateDom(self.config.animationSpeed);
},

getScripts() {
return [];
},

getStyles() {
return [
'MMM-Roomba980.css',
'font-awesome.css',
];
},

getTranslations() {
return {
en: 'translations/en.json',
es: 'translations/es.json'
};
},
});
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# MMM-Roomba980

This is a module for the [MagicMirror²](https://github.com/MichMich/MagicMirror/). It pulls data (name + job, bin and battery status) from a Roomba running on the local network using [Dorita980](https://github.com/koalazak/dorita980) and displays them on the mirror.

![Alt text](/screenshots/charging_full.png?raw=true "Screenshot")

## Installation
1. Navigate into your MagicMirror's `modules` folder and execute `git clone https://github.com/relm/MMM-Roomba980.git`. A new folder will appear navigate into it.
2. Execute `npm install` to install the node dependencies.

## Using the module

To use this module, add the following configuration block to the modules array in the `config/config.js` file:
```js
var config = {
modules: [
{
module: 'MMM-Roomba980',
position: 'top_right',
header: 'Roomba', // Optional
config: {
// See below for configurable options
username: 'xxxxxxxxxxxxx',
password: ':1:1486937829:gktkDoYpWaDxCfGh',
ipAddress: '192.168.1.44'
}
}
]
}
```

## Configuration options

| Option | Description
|----------------- |-----------
| `username` | *Required* Username of Roomba. See [Dorita980](https://github.com/koalazak/dorita980) for more information.
| `password` | *Required* Password of Roomba. See [Dorita980](https://github.com/koalazak/dorita980) for more information.
| `ipAddress` | *Required* Local IP address of Roomba. See [Dorita980](https://github.com/koalazak/dorita980) for more information.
| `updateInterval` | *Optional* How often the content will be fetched. <br><br>**Type:** `int`(milliseconds) <br>Default 60000 (1 minute)
| `animationSpeed` | *Optional* Speed of the update animation. <br><br>**Type:** `int`(milliseconds) <br>Default 2000 milliseconds (2 seconds)

## Dependencies
- [Dorita980](https://github.com/koalazak/dorita980) (installed via `npm install`)
Loading

0 comments on commit 3f89f9c

Please sign in to comment.