Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
arteck committed Oct 31, 2023
1 parent 93aa7f0 commit c0b9e1e
Show file tree
Hide file tree
Showing 6 changed files with 1,183 additions and 1,201 deletions.
18 changes: 0 additions & 18 deletions lib/axiosCommand.js

This file was deleted.

70 changes: 35 additions & 35 deletions lib/constants.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
'use strict';

const IConst = {
mqttEvents: ["background", "foreground", "screenOn", "screenOff", "pluggedAC", "pluggedUSB", "pluggedWireless", "unplugged", "networkReconnect", "networkDisconnect", "internetReconnect", "internetDisconnect", "powerOn", "powerOff", "showKeyboard", "hideKeyboard", "onMotion", "onDarkness", "onMovement", "volumeUp", "volumeDown", "onQrScanCancelled", "onBatteryLevelChanged", "onScreensaverStart", "onScreensaverStop", "onDaydreamStart", "onDaydreamStop", "onItemPlay", "onPlaylistPlay", "facesDetected"],
cmdsSwitches: [
{ id: "screenSwitch", name: "Turn Screen on and off", type: "boolean", cmdOn: "screenOn", cmdOff: "screenOff", mqttOn: "screenOn", mqttOff: "screenOff" },
{ id: "screensaverSwitch", name: "Turn Screensaver on and off", type: "boolean", cmdOn: "startScreensaver", cmdOff: "stopScreensaver", mqttOn: "onScreensaverStart", mqttOff: "onScreensaverStop" },
{ id: "daydreamSwitch", name: "Turn Daydream on and off", type: "boolean", cmdOn: "startDaydream", cmdOff: "stopDaydream", mqttOn: "onDaydreamStart", mqttOff: "onDaydreamStop" },
{ id: "lockedModeSwitch", name: "Turn Locked Mode on and off", type: "boolean", cmdOn: "enableLockedMode", cmdOff: "disableLockedMode" },
{ id: "isInForeground", name: "Bring Fully in foreground or background", type: "boolean", cmdOn: "toForeground", cmdOff: "toBackground", mqttOn: "foreground", mqttOff: "background" }
],
cmds: [
{ id: "clearCache", name: "Clear Cache", type: "boolean" },
{ id: "clearCookies", name: "Clear Cookies", type: "boolean" },
{ id: "clearWebstorage", name: "Clear Webstorage", type: "boolean" },
{ id: "disableLockedMode", name: "Disable Locked Mode", type: "boolean" },
{ id: "enableLockedMode", name: "Enable Locked Mode", type: "boolean" },
{ id: "exitApp", name: "Exit App", type: "boolean" },
{ id: "forceSleep", name: "Force Sleep", type: "boolean" },
{ id: "loadStartURL", name: "Load Start URL", type: "boolean" },
{ id: "popFragment", name: "Pop Fragment", type: "boolean" },
{ id: "restartApp", name: "Restart App", type: "boolean" },
{ id: "screenOff", name: "Screen Off", type: "boolean" },
{ id: "screenOn", name: "Screen On", type: "boolean" },
{ id: "startDaydream", name: "Start Daydream", type: "boolean" },
{ id: "startScreensaver", name: "Start Screensaver", type: "boolean" },
{ id: "stopDaydream", name: "Stop Daydream", type: "boolean" },
{ id: "stopScreensaver", name: "Stop Screensaver", type: "boolean" },
{ id: "toBackground", name: "Bring Fully to Background", type: "boolean" },
{ id: "toForeground", name: "Bring Fully to Foreground", type: "boolean" },
{ id: "triggerMotion", name: "Trigger Motion", type: "boolean" },
{ id: "loadURL", name: "Load URL", type: "string" },
{ id: "setStringSetting", name: "Set String Setting", type: "string" },
{ id: "startApplication", name: "Start Application", type: "string" },
{ id: "textToSpeech", name: "Text To Speech", type: "string" },
{ id: "screenBrightness", name: "Screen Brightness", type: "number" },
{ id: "setAudioVolume", name: "Audio Volume", type: "number" }
]
mqttEvents: ['background', 'foreground', 'screenOn', 'screenOff', 'pluggedAC', 'pluggedUSB', 'pluggedWireless', 'unplugged', 'networkReconnect', 'networkDisconnect', 'internetReconnect', 'internetDisconnect', 'powerOn', 'powerOff', 'showKeyboard', 'hideKeyboard', 'onMotion', 'onDarkness', 'onMovement', 'volumeUp', 'volumeDown', 'onQrScanCancelled', 'onBatteryLevelChanged', 'onScreensaverStart', 'onScreensaverStop', 'onDaydreamStart', 'onDaydreamStop', 'onItemPlay', 'onPlaylistPlay', 'facesDetected'],
cmdsSwitches: [
{ id: 'screenSwitch', name: 'Turn Screen on and off', type: 'boolean', cmdOn: 'screenOn', cmdOff: 'screenOff', mqttOn: 'screenOn', mqttOff: 'screenOff' },
{ id: 'screensaverSwitch', name: 'Turn Screensaver on and off', type: 'boolean', cmdOn: 'startScreensaver', cmdOff: 'stopScreensaver', mqttOn: 'onScreensaverStart', mqttOff: 'onScreensaverStop' },
{ id: 'daydreamSwitch', name: 'Turn Daydream on and off', type: 'boolean', cmdOn: 'startDaydream', cmdOff: 'stopDaydream', mqttOn: 'onDaydreamStart', mqttOff: 'onDaydreamStop' },
{ id: 'lockedModeSwitch', name: 'Turn Locked Mode on and off', type: 'boolean', cmdOn: 'enableLockedMode', cmdOff: 'disableLockedMode' },
{ id: 'isInForeground', name: 'Bring Fully in foreground or background', type: 'boolean', cmdOn: 'toForeground', cmdOff: 'toBackground', mqttOn: 'foreground', mqttOff: 'background' }
],
cmds: [
{ id: 'clearCache', name: 'Clear Cache', type: 'boolean' },
{ id: 'clearCookies', name: 'Clear Cookies', type: 'boolean' },
{ id: 'clearWebstorage', name: 'Clear Webstorage', type: 'boolean' },
{ id: 'disableLockedMode', name: 'Disable Locked Mode', type: 'boolean' },
{ id: 'enableLockedMode', name: 'Enable Locked Mode', type: 'boolean' },
{ id: 'exitApp', name: 'Exit App', type: 'boolean' },
{ id: 'forceSleep', name: 'Force Sleep', type: 'boolean' },
{ id: 'loadStartURL', name: 'Load Start URL', type: 'boolean' },
{ id: 'popFragment', name: 'Pop Fragment', type: 'boolean' },
{ id: 'restartApp', name: 'Restart App', type: 'boolean' },
{ id: 'screenOff', name: 'Screen Off', type: 'boolean' },
{ id: 'screenOn', name: 'Screen On', type: 'boolean' },
{ id: 'startDaydream', name: 'Start Daydream', type: 'boolean' },
{ id: 'startScreensaver', name: 'Start Screensaver', type: 'boolean' },
{ id: 'stopDaydream', name: 'Stop Daydream', type: 'boolean' },
{ id: 'stopScreensaver', name: 'Stop Screensaver', type: 'boolean' },
{ id: 'toBackground', name: 'Bring Fully to Background', type: 'boolean' },
{ id: 'toForeground', name: 'Bring Fully to Foreground', type: 'boolean' },
{ id: 'triggerMotion', name: 'Trigger Motion', type: 'boolean' },
{ id: 'loadURL', name: 'Load URL', type: 'string' },
{ id: 'setStringSetting', name: 'Set String Setting', type: 'string' },
{ id: 'startApplication', name: 'Start Application', type: 'string' },
{ id: 'textToSpeech', name: 'Text To Speech', type: 'string' },
{ id: 'screenBrightness', name: 'Screen Brightness', type: 'number' },
{ id: 'setAudioVolume', name: 'Audio Volume', type: 'number' }
]
};

module.exports = IConst;
Expand Down
118 changes: 59 additions & 59 deletions lib/methods.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
'use strict';
function err2Str(error) {
if (error instanceof Error) {
if (error.stack)
return error.stack;
if (error.message)
return error.message;
return JSON.stringify(error);
} else {
if (typeof error === "string")
return error;
return JSON.stringify(error);
}
if (error instanceof Error) {
if (error.stack)
return error.stack;
if (error.message)
return error.message;
return JSON.stringify(error);
} else {
if (typeof error === 'string')
return error;
return JSON.stringify(error);
}
}
function cleanDeviceName(str) {
let res = str.replace(this.FORBIDDEN_CHARS, "");
res = res.replace(/\./g, "");
res = res.replace(/\s{2,}/g, " ");
res = res.trim();
res = res.replace(/\s/g, "_");
if (res.replace(/_/g, "").length === 0)
res = "";
return res;
let res = str.replace(this.FORBIDDEN_CHARS, '');
res = res.replace(/\./g, '');
res = res.replace(/\s{2,}/g, ' ');
res = res.trim();
res = res.replace(/\s/g, '_');
if (res.replace(/_/g, '').length === 0)
res = '';
return res;
}
function isIpAddressValid(ip) {
const pattern = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
if (pattern.test(ip)) {
return true;
} else {
return false;
}
const pattern = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
if (pattern.test(ip)) {
return true;
} else {
return false;
}
}
function getConfigValuePerKey(config, key1, key1Value, key2) {
for (const lpConfDevice of config) {
if (lpConfDevice[key1] === key1Value) {
if (lpConfDevice[key2] === void 0) {
return -1;
} else {
return lpConfDevice[key2];
}
for (const lpConfDevice of config) {
if (lpConfDevice[key1] === key1Value) {
if (lpConfDevice[key2] === void 0) {
return -1;
} else {
return lpConfDevice[key2];
}
}
}
}
return -1;
return -1;
}
function isEmpty(toCheck) {
if (toCheck === null || typeof toCheck === "undefined")
return true;
if (typeof toCheck === "function")
return false;
let x = JSON.stringify(toCheck);
x = x.replace(/\s+/g, "");
x = x.replace(/"+/g, "");
x = x.replace(/'+/g, "");
x = x.replace(/\[+/g, "");
x = x.replace(/\]+/g, "");
x = x.replace(/\{+/g, "");
x = x.replace(/\}+/g, "");
return x === "" ? true : false;
if (toCheck === null || typeof toCheck === 'undefined')
return true;
if (typeof toCheck === 'function')
return false;
let x = JSON.stringify(toCheck);
x = x.replace(/\s+/g, '');
x = x.replace(/"+/g, '');
x = x.replace(/'+/g, '');
x = x.replace(/\[+/g, '');
x = x.replace(/\]+/g, '');
x = x.replace(/\{+/g, '');
x = x.replace(/\}+/g, '');
return x === '' ? true : false;
}
async function wait(ms) {
try {
await new Promise((w) => setTimeout(w, ms));
} catch (e) {
this.log.error(this.err2Str(e));
return;
}
try {
await new Promise((w) => setTimeout(w, ms));
} catch (e) {
this.log.error(this.err2Str(e));
return;
}
}

module.exports = {
cleanDeviceName,
err2Str,
getConfigValuePerKey,
isEmpty,
isIpAddressValid,
wait
cleanDeviceName,
err2Str,
getConfigValuePerKey,
isEmpty,
isIpAddressValid,
wait
};

Loading

0 comments on commit c0b9e1e

Please sign in to comment.