Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
parnic committed Aug 20, 2024
1 parent 4b168cd commit 7839beb
Show file tree
Hide file tree
Showing 6 changed files with 583 additions and 453 deletions.
24 changes: 0 additions & 24 deletions .eslintrc

This file was deleted.

28 changes: 14 additions & 14 deletions MMM-RingAlarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
* MIT Licensed.
*/

Module.register('MMM-RingAlarm',{
Module.register('MMM-RingAlarm', {
defaults: {
refreshToken: undefined,
pins: undefined, // array of arrays, e.g. [[1,2,3,4], [0,0,0,0]],
requirePinToArm: false,
requirePinToDisarm: true,
requirePinToDisarm: true
},

start: function() {
start: function () {
this.sendSocketNotification('RING_CONFIG', this.config);

this.createKeypad();
},

getStyles: function() {
getStyles: function () {
return ['ring.css'];
},

getDom: function() {
getDom: function () {
if (!this.initialized) {
let wrapper = document.createElement('div');
wrapper.innerHTML = 'Loading Ring...';
Expand Down Expand Up @@ -84,8 +84,8 @@ Module.register('MMM-RingAlarm',{

let btnStatus = document.createElement('div');
btnStatus.innerHTML = this.alarmMode === 'none' ?
'Status: <i class="fa fa-lock-open" aria-hidden="true"></i> Disarmed' :
'Status: <i class="fa fa-lock" aria-hidden="true"></i> Armed';
'Status: <i class="fa fa-lock-open" aria-hidden="true"></i> Disarmed'
: 'Status: <i class="fa fa-lock" aria-hidden="true"></i> Armed';
btn.appendChild(btnStatus);

let btnLabel = document.createElement('div');
Expand All @@ -95,7 +95,7 @@ Module.register('MMM-RingAlarm',{
return wrapper;
},

showKeypad: function(show) {
showKeypad: function (show) {
const pinBg = document.getElementById('ring-pin-bg');
if (show) {
pinBg.classList.remove('ring-d-none');
Expand All @@ -104,7 +104,7 @@ Module.register('MMM-RingAlarm',{
}
},

createKeypad: function() {
createKeypad: function () {
let bg = document.createElement('div');
bg.classList.add('ring-pin-bg', 'ring-d-none');
bg.id = 'ring-pin-bg';
Expand Down Expand Up @@ -137,7 +137,7 @@ Module.register('MMM-RingAlarm',{
root.appendChild(bg);
},

clickedKeypadButton: function(btn, evt) {
clickedKeypadButton: function (btn, evt) {
if (!this.pressedButtons) {
this.pressedButtons = [];
}
Expand All @@ -147,7 +147,7 @@ Module.register('MMM-RingAlarm',{

evt.stopPropagation();

const longestPin = this.config.pins.reduce((longest, val) => val.length > longest ? val.length: longest, 0);
const longestPin = this.config.pins.reduce((longest, val) => (val.length > longest ? val.length : longest), 0);
while (this.pressedButtons.length > longestPin) {
this.pressedButtons.shift();
}
Expand All @@ -171,13 +171,13 @@ Module.register('MMM-RingAlarm',{
Log.info('MMM-RingAlarm: no PINs matched entered sequence. Doing nothing.');
},

setAlarmMode: function(mode) {
setAlarmMode: function (mode) {
this.sendSocketNotification('RING_SET_ALARM_MODE', mode);
this.changingMode = mode;
this.updateDom();
},

socketNotificationReceived: function(notification, payload) {
socketNotificationReceived: function (notification, payload) {
if (notification === 'RING_ALARM_MODE_CHANGED') {
console.log('Alarm mode changed to', payload);
this.ringState = 'good';
Expand All @@ -194,7 +194,7 @@ Module.register('MMM-RingAlarm',{
}
},

translateMode: function(mode) {
translateMode: function (mode) {
switch (mode) {
case 'some':
return 'Armed Home';
Expand Down
33 changes: 33 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import globals from "globals";

export default [{
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},

ecmaVersion: 8,
sourceType: "module",
},

settings: {
"import/core-modules": ["node_helper"],
},

rules: {
"comma-dangle": 0,
indent: [2, 4],
"max-len": "off",
radix: [2, "as-needed"],
"no-console": 0,
"linebreak-style": "off",
"prettier/prettier": 0,
quotes: ["error", "single"],
"jsdoc/require-jsdoc": 0,
},

ignores: [
"eslint.config.mjs"
],
}];
22 changes: 11 additions & 11 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ let saved = {
};

module.exports = NodeHelper.create({
start: function() {
start: function () {
readConfig();
},

socketNotificationReceived: function(notification, payload) {
socketNotificationReceived: function (notification, payload) {
if (notification === 'RING_CONFIG') {
if (!this.config) {
this.config = payload;
Expand All @@ -42,7 +42,7 @@ module.exports = NodeHelper.create({
}
},

connect: async function() {
connect: async function () {
try {
// use the last-received refresh token from the api if we have one
let refreshToken = saved.receivedRefresh;
Expand All @@ -55,11 +55,11 @@ module.exports = NodeHelper.create({
writeConfig();
}

this.ringApi = new RingApi( {
this.ringApi = new RingApi({
refreshToken: refreshToken,
debug: true
} );
} catch(e) {
});
} catch (e) {
this.sendSocketNotification('RING_CONNECT_FAILED', e);
Log.error(`MMM-RingAlarm: unable to connect - error thrown when connecting: ${e}`);
return;
Expand Down Expand Up @@ -100,7 +100,7 @@ module.exports = NodeHelper.create({
}
},

setAlarmMode: function(state) {
setAlarmMode: function (state) {
if (!this.location) {
Log.error(`MMM-RingAlarm: attempted to set alarm to state ${state} but no location has been retrieved to set it on.`);
return;
Expand All @@ -114,7 +114,7 @@ module.exports = NodeHelper.create({
this.location.setAlarmMode(state);
},

refreshTokenUpdated: async function({newRefreshToken, oldRefreshToken}) {
refreshTokenUpdated: async function ({ newRefreshToken, oldRefreshToken }) {
Log.log('MMM-RingAlarm: Refresh Token Updated: ', newRefreshToken);

if (!oldRefreshToken) {
Expand All @@ -125,7 +125,7 @@ module.exports = NodeHelper.create({
writeConfig();
},

onConnected: function(location, connected, haveConnected) {
onConnected: function (location, connected, haveConnected) {
let retval = haveConnected;
if (!haveConnected && !connected) {
return retval;
Expand All @@ -140,7 +140,7 @@ module.exports = NodeHelper.create({
}
});

function readConfig() {
function readConfig () {
try {
const savedStr = fs.readFileSync(configFilename);
saved = JSON.parse(savedStr);
Expand All @@ -149,7 +149,7 @@ function readConfig() {
}
}

function writeConfig() {
function writeConfig () {
const savedStr = JSON.stringify(saved);
fs.writeFileSync(configFilename, savedStr);
}
Loading

0 comments on commit 7839beb

Please sign in to comment.