homebridge-meross
Version:
Homebridge plugin to control Meross devices.
38 lines (32 loc) • 944 B
JavaScript
/* jshint node: true,esversion: 9, -W014, -W033 */
/* eslint-disable new-cap */
module.exports = {
hasProperty: (obj, prop) => {
return Object.prototype.hasOwnProperty.call(obj, prop)
},
sleep: ms => {
return new Promise(resolve => setTimeout(resolve, ms))
},
parseError: (err, hideStack = []) => {
let toReturn = err.message
if (err.stack && err.stack.length > 0 && !hideStack.includes(err.message)) {
const stack = err.stack.split('\n')
if (stack[1]) {
toReturn += stack[1].replace(' ', '')
}
}
return toReturn
},
generateRandomString: length => {
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789'
let nonce = ''
while (nonce.length < length) {
nonce += chars.charAt(Math.floor(Math.random() * chars.length))
}
return nonce
},
encodeParams: params => {
return Buffer.from(JSON.stringify(params)).toString('base64')
}
}