From 45b2161ce532341a88dec514726025d0ac5a961e Mon Sep 17 00:00:00 2001 From: Farmer Date: Sun, 4 Feb 2024 18:43:03 -0600 Subject: [PATCH] Correct issues with login --- package-lock.json | 325 ++++++++++ package.json | 3 +- src/index.js | 1460 +++++++++++++++++++++++++++++---------------- 3 files changed, 1258 insertions(+), 530 deletions(-) diff --git a/package-lock.json b/package-lock.json index 239dd30..56e4e2a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ ], "license": "MIT", "dependencies": { + "@ptkdev/logger": "1.8.0", "axios": "1.5.0", "base64-js": "1.5.1", "colorsys": "^1.0.22", @@ -26,6 +27,43 @@ "uuid-by-string": "4.0.0" } }, + "node_modules/@ptkdev/logger": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/@ptkdev/logger/-/logger-1.8.0.tgz", + "integrity": "sha512-gwg0pleMUyzsZIErDtzz2OP4F2Q3nzRGjhUTP+831/eogq17LpG7PgbHo1n1HZ/dlz/v2xvotfUcPLO3IzwEVQ==", + "dependencies": { + "chalk": "^4.1.2", + "fs-extra": "^10.0.0", + "lowdb": "^1.0.0", + "rotating-file-stream": "^2.1.5", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "engines": { + "node": ">=8" + } + }, + "node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -84,6 +122,37 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, "node_modules/colorsys": { "version": "1.0.22", "resolved": "https://registry.npmjs.org/colorsys/-/colorsys-1.0.22.tgz", @@ -221,6 +290,19 @@ "pause-stream": "~0.0.11" } }, + "node_modules/fs-extra": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", + "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", @@ -254,6 +336,19 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/graceful-fs": { + "version": "4.2.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==" + }, + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "engines": { + "node": ">=8" + } + }, "node_modules/has-property-descriptors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.1.tgz", @@ -298,6 +393,11 @@ "node": ">= 0.4" } }, + "node_modules/is-promise": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.2.2.tgz", + "integrity": "sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==" + }, "node_modules/js-md5": { "version": "0.7.3", "resolved": "https://registry.npmjs.org/js-md5/-/js-md5-0.7.3.tgz", @@ -308,6 +408,37 @@ "resolved": "https://registry.npmjs.org/js-sha1/-/js-sha1-0.6.0.tgz", "integrity": "sha512-01gwBFreYydzmU9BmZxpVk6svJJHrVxEN3IOiGl6VO93bVKYETJ0sIth6DASI6mIFdt7NmfX9UiByRzsYHGU9w==" }, + "node_modules/jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dependencies": { + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, + "node_modules/lowdb": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/lowdb/-/lowdb-1.0.0.tgz", + "integrity": "sha512-2+x8esE/Wb9SQ1F9IHaYWfsC9FIecLOPrK4g17FGEayjUWH172H6nwicRovGvSE2CPZouc2MCIqCI7h9d+GftQ==", + "dependencies": { + "graceful-fs": "^4.1.3", + "is-promise": "^2.1.0", + "lodash": "4", + "pify": "^3.0.0", + "steno": "^0.4.1" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/mime": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz", @@ -425,6 +556,14 @@ "through": "~2.3" } }, + "node_modules/pify": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", + "integrity": "sha512-C3FsVNH1udSEX48gGX1xfvwTWfsYWj5U+8/uK15BGzIGrKoUpghX8hWZwa/OFnakBiiVNmBvemTJR5mcy7iPcg==", + "engines": { + "node": ">=4" + } + }, "node_modules/proxy-from-env": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", @@ -462,6 +601,17 @@ "node": ">=0.4.x" } }, + "node_modules/rotating-file-stream": { + "version": "2.1.6", + "resolved": "https://registry.npmjs.org/rotating-file-stream/-/rotating-file-stream-2.1.6.tgz", + "integrity": "sha512-qS0ndAlDu80MMXeRonqGMXslF0FErzcUSbcXhus3asRG4cvCS79hc5f7s0x4bPAsH6wAwyHVIeARg69VUe3JmQ==", + "engines": { + "node": ">=10.0" + }, + "funding": { + "url": "https://www.blockchain.com/btc/address/12p1p5q7sK75tPyuesZmssiMYr4TKzpSCN" + } + }, "node_modules/semver": { "version": "5.7.2", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", @@ -497,6 +647,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/steno": { + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/steno/-/steno-0.4.4.tgz", + "integrity": "sha512-EEHMVYHNXFHfGtgjNITnka0aHhiAlo93F7z2/Pwd+g0teG9CnM3JIINM7hVVB5/rhw9voufD7Wukwgtw2uqh6w==", + "dependencies": { + "graceful-fs": "^4.1.3" + } + }, "node_modules/streamsearch": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", @@ -505,6 +663,28 @@ "node": ">=10.0.0" } }, + "node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", @@ -521,6 +701,14 @@ "node": ">=14.0" } }, + "node_modules/universalify": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", + "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", + "engines": { + "node": ">= 10.0.0" + } + }, "node_modules/urllib": { "version": "3.18.0", "resolved": "https://registry.npmjs.org/urllib/-/urllib-3.18.0.tgz", @@ -589,6 +777,31 @@ } }, "dependencies": { + "@ptkdev/logger": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/@ptkdev/logger/-/logger-1.8.0.tgz", + "integrity": "sha512-gwg0pleMUyzsZIErDtzz2OP4F2Q3nzRGjhUTP+831/eogq17LpG7PgbHo1n1HZ/dlz/v2xvotfUcPLO3IzwEVQ==", + "requires": { + "chalk": "^4.1.2", + "fs-extra": "^10.0.0", + "lowdb": "^1.0.0", + "rotating-file-stream": "^2.1.5", + "strip-ansi": "^6.0.0" + } + }, + "ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==" + }, + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "requires": { + "color-convert": "^2.0.1" + } + }, "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -627,6 +840,28 @@ "set-function-length": "^1.1.1" } }, + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, "colorsys": { "version": "1.0.22", "resolved": "https://registry.npmjs.org/colorsys/-/colorsys-1.0.22.tgz", @@ -725,6 +960,16 @@ "pause-stream": "~0.0.11" } }, + "fs-extra": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", + "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + } + }, "function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", @@ -749,6 +994,16 @@ "get-intrinsic": "^1.1.3" } }, + "graceful-fs": { + "version": "4.2.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==" + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" + }, "has-property-descriptors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.1.tgz", @@ -775,6 +1030,11 @@ "function-bind": "^1.1.2" } }, + "is-promise": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.2.2.tgz", + "integrity": "sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==" + }, "js-md5": { "version": "0.7.3", "resolved": "https://registry.npmjs.org/js-md5/-/js-md5-0.7.3.tgz", @@ -785,6 +1045,32 @@ "resolved": "https://registry.npmjs.org/js-sha1/-/js-sha1-0.6.0.tgz", "integrity": "sha512-01gwBFreYydzmU9BmZxpVk6svJJHrVxEN3IOiGl6VO93bVKYETJ0sIth6DASI6mIFdt7NmfX9UiByRzsYHGU9w==" }, + "jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "requires": { + "graceful-fs": "^4.1.6", + "universalify": "^2.0.0" + } + }, + "lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, + "lowdb": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/lowdb/-/lowdb-1.0.0.tgz", + "integrity": "sha512-2+x8esE/Wb9SQ1F9IHaYWfsC9FIecLOPrK4g17FGEayjUWH172H6nwicRovGvSE2CPZouc2MCIqCI7h9d+GftQ==", + "requires": { + "graceful-fs": "^4.1.3", + "is-promise": "^2.1.0", + "lodash": "4", + "pify": "^3.0.0", + "steno": "^0.4.1" + } + }, "mime": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz", @@ -856,6 +1142,11 @@ "through": "~2.3" } }, + "pify": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", + "integrity": "sha512-C3FsVNH1udSEX48gGX1xfvwTWfsYWj5U+8/uK15BGzIGrKoUpghX8hWZwa/OFnakBiiVNmBvemTJR5mcy7iPcg==" + }, "proxy-from-env": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", @@ -883,6 +1174,11 @@ "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.1.tgz", "integrity": "sha512-wkvS7mL/JMugcup3/rMitHmd9ecIGd2lhFhK9N3UUQ450h66d1r3Y9nvXzQAW1Lq+wyx61k/1pfKS5KuKiyEbg==" }, + "rotating-file-stream": { + "version": "2.1.6", + "resolved": "https://registry.npmjs.org/rotating-file-stream/-/rotating-file-stream-2.1.6.tgz", + "integrity": "sha512-qS0ndAlDu80MMXeRonqGMXslF0FErzcUSbcXhus3asRG4cvCS79hc5f7s0x4bPAsH6wAwyHVIeARg69VUe3JmQ==" + }, "semver": { "version": "5.7.2", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", @@ -909,11 +1205,35 @@ "object-inspect": "^1.9.0" } }, + "steno": { + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/steno/-/steno-0.4.4.tgz", + "integrity": "sha512-EEHMVYHNXFHfGtgjNITnka0aHhiAlo93F7z2/Pwd+g0teG9CnM3JIINM7hVVB5/rhw9voufD7Wukwgtw2uqh6w==", + "requires": { + "graceful-fs": "^4.1.3" + } + }, "streamsearch": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==" }, + "strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "requires": { + "ansi-regex": "^5.0.1" + } + }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "requires": { + "has-flag": "^4.0.0" + } + }, "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", @@ -927,6 +1247,11 @@ "busboy": "^1.6.0" } }, + "universalify": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", + "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==" + }, "urllib": { "version": "3.18.0", "resolved": "https://registry.npmjs.org/urllib/-/urllib-3.18.0.tgz", diff --git a/package.json b/package.json index efabb87..0e22194 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,8 @@ "colorsys": "^1.0.22", "base64-js": "1.5.1", "querystring": "0.2.1", - "uuid-by-string": "4.0.0" + "uuid-by-string": "4.0.0", + "@ptkdev/logger": "1.8.0" }, "funding": [ { diff --git a/src/index.js b/src/index.js index 6da1d19..5da6ac8 100644 --- a/src/index.js +++ b/src/index.js @@ -1,131 +1,144 @@ -const axios = require('axios') -const fs = require('fs').promises -const path = require('path') -const getUuid = require('uuid-by-string') +const axios = require("axios"); +const fs = require("fs").promises; +const path = require("path"); +const getUuid = require("uuid-by-string"); -const payloadFactory = require('./payloadFactory') -const crypto = require('./crypto') -const constants = require('./constants') -const util = require('./util') +const payloadFactory = require("./payloadFactory"); +const crypto = require("./crypto"); +const constants = require("./constants"); +const util = require("./util"); module.exports = class WyzeAPI { constructor(options, log) { - this.log = log - this.persistPath = options.persistPath - this.refreshTokenTimerEnabled = options.refreshTokenTimerEnabled || false - this.lowBatteryPercentage = options.lowBatteryPercentage || 30 + this.log = log; + this.persistPath = options.persistPath; + this.refreshTokenTimerEnabled = options.refreshTokenTimerEnabled || false; + this.lowBatteryPercentage = options.lowBatteryPercentage || 30; // User login parameters - this.username = options.username - this.password = options.password - this.mfaCode = options.mfaCode - this.apiKey = options.apiKey - this.keyId = options.keyId + this.username = options.username; + this.password = options.password; + this.mfaCode = options.mfaCode; + this.apiKey = options.apiKey; + this.keyId = options.keyId; // Logging - this.logLevel = options.logLevel - this.apiLogEnabled = options.apiLogEnabled + this.logLevel = options.logLevel; + this.apiLogEnabled = options.apiLogEnabled; // URLs - this.authBaseUrl = options.authBaseUrl || constants.authBaseUrl - this.apiBaseUrl = options.apiBaseUrl || options.baseUrl || constants.apiBaseUrl + this.authBaseUrl = options.authBaseUrl || constants.authBaseUrl; + this.apiBaseUrl = + options.apiBaseUrl || options.baseUrl || constants.apiBaseUrl; // App emulation constants - this.authApiKey = options.authApiKey || constants.authApiKey - this.phoneId = options.phoneId || constants.phoneId - this.appName = options.appName || constants.appName - this.appVer = options.appVer || constants.appVer - this.appVersion = options.appVersion || constants.appVersion - this.userAgent = options.userAgent || constants.userAgent - this.sc = options.sc || constants.sc - this.sv = options.sv || constants.sv + this.authApiKey = options.authApiKey || constants.authApiKey; + this.phoneId = options.phoneId || constants.phoneId; + this.appName = options.appName || constants.appName; + this.appVer = options.appVer || constants.appVer; + this.appVersion = options.appVersion || constants.appVersion; + this.userAgent = options.userAgent || constants.userAgent; + this.sc = options.sc || constants.sc; + this.sv = options.sv || constants.sv; // Crypto Secrets - this.fordAppKey = options.fordAppKey || constants.fordAppKey // Required for Locks - this.fordAppSecret = options.fordAppSecret || constants.fordAppSecret // Required for Locks - this.oliveSigningSecret = options.oliveSigningSecret || constants.oliveSigningSecret // Required for the thermostat - this.oliveAppId = options.oliveAppId || constants.oliveAppId // Required for the thermostat - this.appInfo = options.appInfo || constants.appInfo // Required for the thermostat + this.fordAppKey = options.fordAppKey || constants.fordAppKey; // Required for Locks + this.fordAppSecret = options.fordAppSecret || constants.fordAppSecret; // Required for Locks + this.oliveSigningSecret = + options.oliveSigningSecret || constants.oliveSigningSecret; // Required for the thermostat + this.oliveAppId = options.oliveAppId || constants.oliveAppId; // Required for the thermostat + this.appInfo = options.appInfo || constants.appInfo; // Required for the thermostat // Login tokens - this.access_token = '' - this.refresh_token = '' + this.access_token = ""; + this.refresh_token = ""; - this.dumpData = false // Set this to true to log the Wyze object data blob one time at startup. + this.dumpData = false; // Set this to true to log the Wyze object data blob one time at startup. // Token is good for 216,000 seconds (60 hours) but 48 hours seems like a reasonable refresh interval 172800 if (this.refreshTokenTimerEnabled === true) { - setInterval(this.refreshToken.bind(this), 172800) + setInterval(this.refreshToken.bind(this), 172800); } } getRequestData(data = {}) { return { - 'access_token': this.access_token, - 'app_name': this.appName, - 'app_ver': this.appVer, - 'app_version': this.appVersion, - 'phone_id': this.phoneId, - 'phone_system_type': '1', - 'sc': this.sc, - 'sv': this.sv, - 'ts': (new Date).getTime(), + access_token: this.access_token, + app_name: this.appName, + app_ver: this.appVer, + app_version: this.appVersion, + phone_id: this.phoneId, + phone_system_type: "1", + sc: this.sc, + sv: this.sv, + ts: new Date().getTime(), ...data, - } + }; } async request(url, data = {}) { - await this.maybeLogin() + await this.maybeLogin(); try { - return await this._performRequest(url, this.getRequestData(data)) + return await this._performRequest(url, this.getRequestData(data)); } catch (e) { - this.log.error(e) + this.log.error(e); if (this.refresh_token) { - this.log.error('Error, refreshing access token and trying again') + this.log.error("Error, refreshing access token and trying again"); try { - await this.refreshToken() - return await this._performRequest(url, this.getRequestData(data)) + await this.refreshToken(); + return await this._performRequest(url, this.getRequestData(data)); } catch (e) { // } } - this.log.error('Error, logging in and trying again') + this.log.error("Error, logging in and trying again"); - await this.login() - return this._performRequest(url, this.getRequestData(data)) + await this.login(); + return this._performRequest(url, this.getRequestData(data)); } } async _performRequest(url, data = {}, config = {}) { config = { - method: 'POST', + method: "POST", url, data, baseURL: this.apiBaseUrl, - ...config - } + ...config, + }; - if (this.apiLogEnabled) this.log.debug(`Performing request: ${url}`) - if (this.apiLogEnabled) this.log.debug(`Request config: ${JSON.stringify(config)}`) + if (this.apiLogEnabled) this.log.debug(`Performing request: ${url}`); + if (this.apiLogEnabled) + this.log.debug(`Request config: ${JSON.stringify(config)}`); - let result + let result; try { - result = await axios(config) - if (this.apiLogEnabled) this.log.debug(`API response PerformRequest: ${JSON.stringify(result.data)}`) + result = await axios(config); + if (this.apiLogEnabled) + this.log.debug( + `API response PerformRequest: ${JSON.stringify(result.data)}` + ); if (this.dumpData) { - if (this.apiLogEnabled) this.log.debug(`API response PerformRequest: ${JSON.stringify(result.data)}`) - this.dumpData = false // Only want to do this once at start-up + if (this.apiLogEnabled) + this.log.debug( + `API response PerformRequest: ${JSON.stringify(result.data)}` + ); + this.dumpData = false; // Only want to do this once at start-up } } catch (e) { - this.log.error(`Request failed: ${e}`) + this.log.error(`Request failed: ${e}`); if (e.response) { - this.log.error(`Response PerformRequest (${e.response}): ${JSON.stringify(e.response.data)}`) + this.log.error( + `Response PerformRequest (${e.response}): ${JSON.stringify( + e.response.data + )}` + ); } - throw e + throw e; } if (result.data.msg) { if (result.data.msg == "DeviceIsOffline" || result.data.msg == "SUCCESS") { return result } else @@ -134,117 +147,123 @@ module.exports = class WyzeAPI { } _performLoginRequest(data = {}) { - let url = 'user/login' + let url = "user/login"; data = { email: this.username, password: util.createPassword(this.password), - ...data - } + ...data, + }; const config = { baseURL: this.authBaseUrl, - headers: { 'x-api-key': this.authApiKey, 'User-Agent': this.userAgent } - } + headers: { "x-api-key": this.authApiKey, "User-Agent": this.userAgent }, + }; if (this.apiKey && this.keyId) { - url = 'api/user/login' - config.headers = { 'apikey': this.apiKey, 'keyid': this.keyId, 'User-Agent': this.userAgent }; + url = "api/user/login"; + config.headers = { + apikey: this.apiKey, + keyid: this.keyId, + "User-Agent": this.userAgent, + }; } - return this._performRequest(url, data, config) + return this._performRequest(url, data, config); } async login() { - let result = await this._performLoginRequest() + let result = await this._performLoginRequest(); // Do we need to perform a 2-factor login? if (!result.data.access_token && result.data.mfa_details) { if (!this.mfaCode) { - throw new Error('Your account has 2-factor auth enabled. Please provide the "mfaCode" parameter in config.json.') + throw new Error( + 'Your account has 2-factor auth enabled. Please provide the "mfaCode" parameter in config.json.' + ); } const data = { - mfa_type: 'TotpVerificationCode', + mfa_type: "TotpVerificationCode", verification_id: result.data.mfa_details.totp_apps[0].app_id, - verification_code: this.mfaCode - } + verification_code: this.mfaCode, + }; - result = await this._performLoginRequest(data) + result = await this._performLoginRequest(data); } - await this._updateTokens(result.data) + await this._updateTokens(result.data); - if (this.apiLogEnabled) this.log.debug('Successfully logged into Wyze API') + if (this.apiLogEnabled) this.log.debug("Successfully logged into Wyze API"); } async maybeLogin() { if (!this.access_token) { - await this._loadPersistedTokens() + await this._loadPersistedTokens(); } if (!this.access_token) { - await this.login() + await this.login(); } } async refreshToken() { const data = { ...this.getRequestData(), - refresh_token: this.refresh_token - } + refresh_token: this.refresh_token, + }; - const result = await this._performRequest('app/user/refresh_token', data) + const result = await this._performRequest("app/user/refresh_token", data); - await this._updateTokens(result.data.data) + await this._updateTokens(result.data.data); } async _updateTokens({ access_token, refresh_token }) { - this.access_token = access_token - this.refresh_token = refresh_token - await this._persistTokens() + this.access_token = access_token; + this.refresh_token = refresh_token; + await this._persistTokens(); } _tokenPersistPath() { // const uuid = 'test' - const uuid = getUuid(this.username) - return path.join(this.persistPath, `wyze-${uuid}.json`) + const uuid = getUuid(this.username); + return path.join(this.persistPath, `wyze-${uuid}.json`); } async _persistTokens() { const data = { access_token: this.access_token, - refresh_token: this.refresh_token - } - this.log.debug(this._tokenPersistPath()) - await fs.writeFile(this._tokenPersistPath(), JSON.stringify(data)) + refresh_token: this.refresh_token, + }; + this.log.debug(this._tokenPersistPath()); + await fs.writeFile(this._tokenPersistPath(), JSON.stringify(data)); } async _loadPersistedTokens() { try { - let data = await fs.readFile(this._tokenPersistPath()) - data = JSON.parse(data) - this.access_token = data.access_token - this.refresh_token = data.refresh_token + let data = await fs.readFile(this._tokenPersistPath()); + data = JSON.parse(data); + this.access_token = data.access_token; + this.refresh_token = data.refresh_token; } catch (e) { // } } async getObjectList() { - const result = await this.request('app/v2/home_page/get_object_list') + const result = await this.request("app/v2/home_page/get_object_list"); - return result.data + return result.data; } async getPropertyList(deviceMac, deviceModel) { const data = { device_mac: deviceMac, - device_model: deviceModel - } + device_model: deviceModel, + }; - const result = await this.request('app/v2/device/get_property_list', data) + const result = await this.request("app/v2/device/get_property_list", data); - return result.data + return result.data; } async setProperty(deviceMac, deviceModel, propertyId, propertyValue) { @@ -252,445 +271,579 @@ module.exports = class WyzeAPI { device_mac: deviceMac, device_model: deviceModel, pid: propertyId, - pvalue: propertyValue - } + pvalue: propertyValue, + }; - const result = await this.request('app/v2/device/set_property', data) - return result.data + const result = await this.request("app/v2/device/set_property", data); + return result.data; } async runAction(deviceMac, deviceModel, actionKey) { - const data = { instance_id: deviceMac, provider_key: deviceModel, action_key: actionKey, action_params: {}, - custom_string: '' - } + custom_string: "", + }; - if (this.apiLogEnabled) this.log.debug(`run_action Data Body: ${JSON.stringify(data)}`) + if (this.apiLogEnabled) + this.log.debug(`run_action Data Body: ${JSON.stringify(data)}`); - const result = await this.request('app/v2/auto/run_action', data) + const result = await this.request("app/v2/auto/run_action", data); - return result.data + return result.data; } - async runActionList(deviceMac, deviceModel, propertyId, propertyValue, actionKey) { + async runActionList( + deviceMac, + deviceModel, + propertyId, + propertyValue, + actionKey + ) { const plist = [ { pid: propertyId, - pvalue: String(propertyValue) - } - ] - if (propertyId !== 'P3') { + pvalue: String(propertyValue), + }, + ]; + if (propertyId !== "P3") { plist.push({ - pid: 'P3', - pvalue: '1' - }) + pid: "P3", + pvalue: "1", + }); } const innerList = [ { mac: deviceMac, - plist - } - ] + plist, + }, + ]; const actionParams = { - list: innerList - } + list: innerList, + }; const actionList = [ { instance_id: deviceMac, action_params: actionParams, provider_key: deviceModel, - action_key: actionKey - } - ] + action_key: actionKey, + }, + ]; const data = { - action_list: actionList - } - if (this.apiLogEnabled) this.log.debug(`run_action_list Data Body: ${JSON.stringify(data)}`) + action_list: actionList, + }; + if (this.apiLogEnabled) + this.log.debug(`run_action_list Data Body: ${JSON.stringify(data)}`); - const result = await this.request('app/v2/auto/run_action_list', data) + const result = await this.request("app/v2/auto/run_action_list", data); - return result.data + return result.data; } async controlLock(deviceMac, deviceModel, action) { - await this.maybeLogin() - let path = '/openapi/lock/v1/control' + await this.maybeLogin(); + let path = "/openapi/lock/v1/control"; let payload = { - "uuid": this.getUuid(deviceMac, deviceModel), - "action": action // "remoteLock" or "remoteUnlock" - } + uuid: this.getUuid(deviceMac, deviceModel), + action: action, // "remoteLock" or "remoteUnlock" + }; - let result + let result; try { - payload = payloadFactory.fordCreatePayload(this.access_token, payload, path, "post") - - let urlPath = 'https://yd-saas-toc.wyzecam.com/openapi/lock/v1/control' - result = await axios.post(urlPath, payload) - if (this.apiLogEnabled) this.log(`API response ControLock: ${JSON.stringify(result.data)}`) + payload = payloadFactory.fordCreatePayload( + this.access_token, + payload, + path, + "post" + ); + + let urlPath = "https://yd-saas-toc.wyzecam.com/openapi/lock/v1/control"; + result = await axios.post(urlPath, payload); + if (this.apiLogEnabled) + this.log(`API response ControLock: ${JSON.stringify(result.data)}`); } catch (e) { - this.log.error(`Request failed: ${e}`) + this.log.error(`Request failed: ${e}`); if (e.response) { - if (this.apiLogEnabled) this.log(`Response ControLock (${e.response.statusText}): ${JSON.stringify(e.response.data, null, '\t')}`) + if (this.apiLogEnabled) + this.log( + `Response ControLock (${e.response.statusText}): ${JSON.stringify( + e.response.data, + null, + "\t" + )}` + ); } - throw e + throw e; } - return result.data + return result.data; } async getLockInfo(deviceMac, deviceModel) { - await this.maybeLogin() + await this.maybeLogin(); - let result - let url_path = "/openapi/lock/v1/info" + let result; + let url_path = "/openapi/lock/v1/info"; let payload = { - "uuid": this.getUuid(deviceMac, deviceModel), - "with_keypad": '1' - } + uuid: this.getUuid(deviceMac, deviceModel), + with_keypad: "1", + }; try { let config = { - params: payload - } - payload = payloadFactory.fordCreatePayload(this.access_token, payload, url_path, "get") - - const url = 'https://yd-saas-toc.wyzecam.com/openapi/lock/v1/info' - result = await axios.get(url, config) - if (this.apiLogEnabled) this.log.debug(`API response GetLockInfo: ${JSON.stringify(result.data)}`) + params: payload, + }; + payload = payloadFactory.fordCreatePayload( + this.access_token, + payload, + url_path, + "get" + ); + + const url = "https://yd-saas-toc.wyzecam.com/openapi/lock/v1/info"; + result = await axios.get(url, config); + if (this.apiLogEnabled) + this.log.debug( + `API response GetLockInfo: ${JSON.stringify(result.data)}` + ); } catch (e) { - this.log.error(`Request failed: ${e}`) + this.log.error(`Request failed: ${e}`); if (e.response) { - if (this.apiLogEnabled) this.log(`Response GetLockInfo (${e.response.statusText}): ${JSON.stringify(e.response.data, null, '\t')}`) + if (this.apiLogEnabled) + this.log( + `Response GetLockInfo (${e.response.statusText}): ${JSON.stringify( + e.response.data, + null, + "\t" + )}` + ); } - throw e + throw e; } - return result.data + return result.data; } async getIotProp(deviceMac) { - let keys = "iot_state,switch-power,switch-iot,single_press_type, double_press_type, triple_press_type, long_press_type" - await this.maybeLogin() - let result + let keys = + "iot_state,switch-power,switch-iot,single_press_type, double_press_type, triple_press_type, long_press_type"; + await this.maybeLogin(); + let result; let payload = payloadFactory.oliveCreateGetPayload(deviceMac, keys); let signature = crypto.oliveCreateSignature(payload, this.access_token); let config = { headers: { - 'Accept-Encoding': 'gzip', - 'User-Agent': this.userAgent, - 'appid': constants.oliveAppId, - 'appinfo': constants.appInfo, - 'phoneid': this.phoneId, - 'access_token': this.access_token, - 'signature2': signature + "Accept-Encoding": "gzip", + "User-Agent": this.userAgent, + appid: constants.oliveAppId, + appinfo: constants.appInfo, + phoneid: this.phoneId, + access_token: this.access_token, + signature2: signature, }, - params: payload - } + params: payload, + }; try { - let url = 'https://wyze-sirius-service.wyzecam.com/plugin/sirius/get_iot_prop' - if (this.apiLogEnabled) this.log(`Performing request: ${url}`) - result = await axios.get(url, config) - if (this.apiLogEnabled) this.log(`API response GetIotProp: ${JSON.stringify(result.data)}`) + let url = + "https://wyze-sirius-service.wyzecam.com/plugin/sirius/get_iot_prop"; + if (this.apiLogEnabled) this.log(`Performing request: ${url}`); + result = await axios.get(url, config); + if (this.apiLogEnabled) + this.log(`API response GetIotProp: ${JSON.stringify(result.data)}`); } catch (e) { - this.log.error(`Request failed: ${e}`) + this.log.error(`Request failed: ${e}`); if (e.response) { - if (this.apiLogEnabled) this.log(`Response GetIotProp (${e.response.statusText}): ${JSON.stringify(e.response.data, null, '\t')}`) + if (this.apiLogEnabled) + this.log( + `Response GetIotProp (${e.response.statusText}): ${JSON.stringify( + e.response.data, + null, + "\t" + )}` + ); } - throw e + throw e; } - return result.data + return result.data; } async setIotProp(deviceMac, product_model, propKey, value) { - await this.maybeLogin() - let result - let payload = payloadFactory.oliveCreatePostPayload(deviceMac, product_model, propKey, value); - let signature = crypto.oliveCreateSignatureSingle(JSON.stringify(payload), this.access_token); + await this.maybeLogin(); + let result; + let payload = payloadFactory.oliveCreatePostPayload( + deviceMac, + product_model, + propKey, + value + ); + let signature = crypto.oliveCreateSignatureSingle( + JSON.stringify(payload), + this.access_token + ); const config = { headers: { - 'Accept-Encoding': 'gzip', - 'Content-Type': 'application/json', - 'User-Agent': 'myapp', - 'appid': constants.oliveAppId, - 'appinfo': constants.appInfo, - 'phoneid': this.phoneId, - 'access_token': this.access_token, - 'signature2': signature - } - } + "Accept-Encoding": "gzip", + "Content-Type": "application/json", + "User-Agent": "myapp", + appid: constants.oliveAppId, + appinfo: constants.appInfo, + phoneid: this.phoneId, + access_token: this.access_token, + signature2: signature, + }, + }; try { - const url = 'https://wyze-sirius-service.wyzecam.com/plugin/sirius/set_iot_prop_by_topic' - result = await axios.post(url, JSON.stringify(payload), config) + const url = + "https://wyze-sirius-service.wyzecam.com/plugin/sirius/set_iot_prop_by_topic"; + result = await axios.post(url, JSON.stringify(payload), config); //if(this.apiLogEnabled) this.log(`API response SetIotProp: ${JSON.stringify(result.data)}`) - console.result + console.result; } catch (e) { - this.log.error(`Request failed: ${e}`) + this.log.error(`Request failed: ${e}`); if (e.response) { //if(this.apiLogEnabled) this.log(`Response SetIotProp (${e.response.statusText}): ${JSON.stringify(e.response.data, null, '\t')}`) - console.log(e.response) + console.log(e.response); } - throw e + throw e; } - return result.data + return result.data; } async getUserProfile() { - await this.maybeLogin() + await this.maybeLogin(); - let result + let result; let payload = payloadFactory.oliveCreateUserInfoPayload(); let signature = crypto.oliveCreateSignature(payload, this.access_token); let config = { headers: { - 'Accept-Encoding': 'gzip', - 'User-Agent': 'myapp', - 'appid': constants.oliveAppId, - 'appinfo': constants.appInfo, - 'phoneid': this.phoneId, - 'access_token': this.access_token, - 'signature2': signature - + "Accept-Encoding": "gzip", + "User-Agent": "myapp", + appid: constants.oliveAppId, + appinfo: constants.appInfo, + phoneid: this.phoneId, + access_token: this.access_token, + signature2: signature, }, - params: payload - } + params: payload, + }; try { - let url = 'https://wyze-platform-service.wyzecam.com/app/v2/platform/get_user_profile'; - if (this.apiLogEnabled) this.log.debug(`Performing request: ${url}`) - result = await axios.get(url, config) - if (this.apiLogEnabled) this.log.debug(`API response GetUserProfile: ${JSON.stringify(result.data)}`) + let url = + "https://wyze-platform-service.wyzecam.com/app/v2/platform/get_user_profile"; + if (this.apiLogEnabled) this.log.debug(`Performing request: ${url}`); + result = await axios.get(url, config); + if (this.apiLogEnabled) + this.log.debug( + `API response GetUserProfile: ${JSON.stringify(result.data)}` + ); } catch (e) { - this.log.error(`Request failed: ${e}`) + this.log.error(`Request failed: ${e}`); if (e.response) { - if (this.apiLogEnabled) this.log.debug(`Response GetUserProfile (${e.response.statusText}): ${JSON.stringify(e.response.data, null, '\t')}`) + if (this.apiLogEnabled) + this.log.debug( + `Response GetUserProfile (${ + e.response.statusText + }): ${JSON.stringify(e.response.data, null, "\t")}` + ); } - throw e + throw e; } - return result.data + return result.data; } async disableRemeAlarm(hms_id) { - await this.maybeLogin() - let result + await this.maybeLogin(); + let result; let config = { headers: { - 'Authorization': this.access_token, - 'User-Agent': this.userAgent, + Authorization: this.access_token, + "User-Agent": this.userAgent, }, data: { - 'hms_id': hms_id, - 'remediation_id': 'emergency' - } - } + hms_id: hms_id, + remediation_id: "emergency", + }, + }; try { - const url = 'https://hms.api.wyze.com/api/v1/reme-alarm'; - if (this.apiLogEnabled) this.log.debug(`Performing request: ${url}`) - result = await axios.delete(url, config) - if (this.apiLogEnabled) this.log.debug(`API response DisableRemeAlarm: ${JSON.stringify(result.data)}`) + const url = "https://hms.api.wyze.com/api/v1/reme-alarm"; + if (this.apiLogEnabled) this.log.debug(`Performing request: ${url}`); + result = await axios.delete(url, config); + if (this.apiLogEnabled) + this.log.debug( + `API response DisableRemeAlarm: ${JSON.stringify(result.data)}` + ); } catch (e) { - this.log.error(`Request failed: ${e}`) + this.log.error(`Request failed: ${e}`); if (e.response) { - if (this.apiLogEnabled) this.log.debug(`Response DisableRemeAlarm (${e.response.statusText}): ${JSON.stringify(e.response.data, null, '\t')}`) + if (this.apiLogEnabled) + this.log.debug( + `Response DisableRemeAlarm (${ + e.response.statusText + }): ${JSON.stringify(e.response.data, null, "\t")}` + ); } - throw e + throw e; } - return result.data + return result.data; } async getPlanBindingListByUser() { - await this.maybeLogin() - let result - let payload = payloadFactory.oliveCreateHmsPayload() + await this.maybeLogin(); + let result; + let payload = payloadFactory.oliveCreateHmsPayload(); let signature = crypto.oliveCreateSignature(payload, this.access_token); let config = { headers: { - 'Accept-Encoding': 'gzip', - 'User-Agent': this.userAgent, - 'appid': constants.oliveAppId, - 'appinfo': constants.appInfo, - 'phoneid': this.phoneId, - 'access_token': this.access_token, - 'signature2': signature + "Accept-Encoding": "gzip", + "User-Agent": this.userAgent, + appid: constants.oliveAppId, + appinfo: constants.appInfo, + phoneid: this.phoneId, + access_token: this.access_token, + signature2: signature, }, - params: payload - } + params: payload, + }; try { - const url = 'https://wyze-membership-service.wyzecam.com/platform/v2/membership/get_plan_binding_list_by_user'; - if (this.apiLogEnabled) this.log.debug(`Performing request: ${url}`) - result = await axios.get(url, config) - if (this.apiLogEnabled) this.log.debug(`API response GetPlanBindingListByUser: ${JSON.stringify(result.data)}`) + const url = + "https://wyze-membership-service.wyzecam.com/platform/v2/membership/get_plan_binding_list_by_user"; + if (this.apiLogEnabled) this.log.debug(`Performing request: ${url}`); + result = await axios.get(url, config); + if (this.apiLogEnabled) + this.log.debug( + `API response GetPlanBindingListByUser: ${JSON.stringify( + result.data + )}` + ); } catch (e) { - this.log.error(`Request failed: ${e}`) + this.log.error(`Request failed: ${e}`); if (e.response) { - if (this.apiLogEnabled) this.log.debug(`Response GetPlanBindingListByUser (${e.response.statusText}): ${JSON.stringify(e.response.data, null, '\t')}`) + if (this.apiLogEnabled) + this.log.debug( + `Response GetPlanBindingListByUser (${ + e.response.statusText + }): ${JSON.stringify(e.response.data, null, "\t")}` + ); } - throw e + throw e; } - return result.data + return result.data; } async monitoringProfileStateStatus(hms_id) { - await this.maybeLogin() - let result + await this.maybeLogin(); + let result; let query = payloadFactory.oliveCreateHmsGetPayload(hms_id); let signature = crypto.oliveCreateSignature(query, this.access_token); let config = { headers: { - 'User-Agent': this.userAgent, - 'appid': constants.oliveAppId, - 'appinfo': constants.appInfo, - 'phoneid': this.phoneId, - 'access_token': this.access_token, - 'signature2': signature, - 'Authorization': this.access_token, - 'Content-Type': 'application/json' + "User-Agent": this.userAgent, + appid: constants.oliveAppId, + appinfo: constants.appInfo, + phoneid: this.phoneId, + access_token: this.access_token, + signature2: signature, + Authorization: this.access_token, + "Content-Type": "application/json", }, - params: query - } + params: query, + }; try { - const url = 'https://hms.api.wyze.com/api/v1/monitoring/v1/profile/state-status' - if (this.apiLogEnabled) this.log.debug(`Performing request: ${url}`) - result = await axios.get(url, config) - if (this.apiLogEnabled) this.log.debug(`API response MonitoringProfileStateStatus: ${JSON.stringify(result.data)}`) + const url = + "https://hms.api.wyze.com/api/v1/monitoring/v1/profile/state-status"; + if (this.apiLogEnabled) this.log.debug(`Performing request: ${url}`); + result = await axios.get(url, config); + if (this.apiLogEnabled) + this.log.debug( + `API response MonitoringProfileStateStatus: ${JSON.stringify( + result.data + )}` + ); } catch (e) { - this.log.error(`Request failed: ${e}`) + this.log.error(`Request failed: ${e}`); if (e.response) { - if (this.apiLogEnabled) this.log.debug(`Response MonitoringProfileStateStatus (${e.response.statusText}): ${JSON.stringify(e.response.data, null, '\t')}`) + if (this.apiLogEnabled) + this.log.debug( + `Response MonitoringProfileStateStatus (${ + e.response.statusText + }): ${JSON.stringify(e.response.data, null, "\t")}` + ); } - throw e + throw e; } - return result.data + return result.data; } async monitoringProfileActive(hms_id, home, away) { - await this.maybeLogin() - let result + await this.maybeLogin(); + let result; const payload = payloadFactory.oliveCreateHmsPatchPayload(hms_id); - const signature = crypto.oliveCreateSignature(payload, this.access_token) + const signature = crypto.oliveCreateSignature(payload, this.access_token); const config = { headers: { - 'User-Agent': this.userAgent, - 'appid': constants.oliveAppId, - 'appinfo': constants.appInfo, - 'phoneid': constants.phoneId, - 'access_token': this.access_token, - 'signature2': signature, - 'Authorization': this.access_token + "User-Agent": this.userAgent, + appid: constants.oliveAppId, + appinfo: constants.appInfo, + phoneid: constants.phoneId, + access_token: this.access_token, + signature2: signature, + Authorization: this.access_token, }, - params: payload - } + params: payload, + }; const data = [ { - "state": "home", - "active": home + state: "home", + active: home, }, { - "state": "away", - "active": away - } - ] + state: "away", + active: away, + }, + ]; try { - const url = "https://hms.api.wyze.com/api/v1/monitoring/v1/profile/active"; - if (this.apiLogEnabled) this.log.debug(`Performing request: ${url}`) - result = await axios.patch(url, data, config) - if (this.apiLogEnabled) this.log.debug(`API response MonitoringProfileActive: ${JSON.stringify(result.data)}`) + const url = + "https://hms.api.wyze.com/api/v1/monitoring/v1/profile/active"; + if (this.apiLogEnabled) this.log.debug(`Performing request: ${url}`); + result = await axios.patch(url, data, config); + if (this.apiLogEnabled) + this.log.debug( + `API response MonitoringProfileActive: ${JSON.stringify(result.data)}` + ); } catch (e) { - this.log.error(`Request failed: ${e}`) + this.log.error(`Request failed: ${e}`); if (e.response) { - if (this.apiLogEnabled) this.log.debug(`Response MonitoringProfileActive (${e.response.statusText}): ${JSON.stringify(e.response.data, null, '\t')}`) + if (this.apiLogEnabled) + this.log.debug( + `Response MonitoringProfileActive (${ + e.response.statusText + }): ${JSON.stringify(e.response.data, null, "\t")}` + ); } - throw e + throw e; } - return result.data + return result.data; } async thermostatGetIotProp(deviceMac) { - await this.maybeLogin() - let result - let keys = "trigger_off_val,emheat,temperature,humidity,time2temp_val,protect_time,mode_sys,heat_sp,cool_sp, current_scenario,config_scenario,temp_unit,fan_mode,iot_state,w_city_id,w_lat,w_lon,working_state, dev_hold,dev_holdtime,asw_hold,app_version,setup_state,wiring_logic_id,save_comfort_balance, kid_lock,calibrate_humidity,calibrate_temperature,fancirc_time,query_schedule" + await this.maybeLogin(); + let result; + let keys = + "trigger_off_val,emheat,temperature,humidity,time2temp_val,protect_time,mode_sys,heat_sp,cool_sp, current_scenario,config_scenario,temp_unit,fan_mode,iot_state,w_city_id,w_lat,w_lon,working_state, dev_hold,dev_holdtime,asw_hold,app_version,setup_state,wiring_logic_id,save_comfort_balance, kid_lock,calibrate_humidity,calibrate_temperature,fancirc_time,query_schedule"; let payload = payloadFactory.oliveCreateGetPayload(deviceMac, keys); let signature = crypto.oliveCreateSignature(payload, this.access_token); let config = { headers: { - 'Accept-Encoding': 'gzip', - 'User-Agent': this.userAgent, - 'appid': constants.oliveAppId, - 'appinfo': constants.appInfo, - 'phoneid': constants.phoneId, - 'access_token': this.access_token, - 'signature2': signature + "Accept-Encoding": "gzip", + "User-Agent": this.userAgent, + appid: constants.oliveAppId, + appinfo: constants.appInfo, + phoneid: constants.phoneId, + access_token: this.access_token, + signature2: signature, }, - params: payload - } + params: payload, + }; try { - let url = 'https://wyze-earth-service.wyzecam.com/plugin/earth/get_iot_prop' - if (this.apiLogEnabled) this.log.debug(`Performing request: ${url}`) - result = await axios.get(url, config) - if (this.apiLogEnabled) this.log.debug(`API response ThermostatGetIotProp: ${JSON.stringify(result.data)}`) + let url = + "https://wyze-earth-service.wyzecam.com/plugin/earth/get_iot_prop"; + if (this.apiLogEnabled) this.log.debug(`Performing request: ${url}`); + result = await axios.get(url, config); + if (this.apiLogEnabled) + this.log.debug( + `API response ThermostatGetIotProp: ${JSON.stringify(result.data)}` + ); } catch (e) { - this.log.error(`Request failed: ${e}`) + this.log.error(`Request failed: ${e}`); if (e.response) { - if (this.apiLogEnabled) this.log.debug(`Response ThermostatGetIotProp (${e.response.statusText}): ${JSON.stringify(e.response.data, null, '\t')}`) + if (this.apiLogEnabled) + this.log.debug( + `Response ThermostatGetIotProp (${ + e.response.statusText + }): ${JSON.stringify(e.response.data, null, "\t")}` + ); } - throw e + throw e; } - return result.data + return result.data; } async thermostatSetIotProp(deviceMac, deviceModel, propKey, value) { - await this.maybeLogin() - let result - let payload = payloadFactory.oliveCreatePostPayload(deviceMac, deviceModel, propKey, value); - let signature = crypto.oliveCreateSignatureSingle(JSON.stringify(payload), this.access_token) + await this.maybeLogin(); + let result; + let payload = payloadFactory.oliveCreatePostPayload( + deviceMac, + deviceModel, + propKey, + value + ); + let signature = crypto.oliveCreateSignatureSingle( + JSON.stringify(payload), + this.access_token + ); const config = { headers: { - 'Accept-Encoding': 'gzip', - 'Content-Type': 'application/json', - 'User-Agent': 'myapp', - 'appid': constants.oliveAppId, - 'appinfo': constants.appInfo, - 'phoneid': this.phoneId, - 'access_token': this.access_token, - 'signature2': signature - } - } + "Accept-Encoding": "gzip", + "Content-Type": "application/json", + "User-Agent": "myapp", + appid: constants.oliveAppId, + appinfo: constants.appInfo, + phoneid: this.phoneId, + access_token: this.access_token, + signature2: signature, + }, + }; try { - const url = 'https://wyze-earth-service.wyzecam.com/plugin/earth/set_iot_prop_by_topic'; - result = await axios.post(url, JSON.stringify(payload), config) - if (this.apiLogEnabled) this.log.debug(`API response ThermostatSetIotProp: ${JSON.stringify(result.data)}`) + const url = + "https://wyze-earth-service.wyzecam.com/plugin/earth/set_iot_prop_by_topic"; + result = await axios.post(url, JSON.stringify(payload), config); + if (this.apiLogEnabled) + this.log.debug( + `API response ThermostatSetIotProp: ${JSON.stringify(result.data)}` + ); } catch (e) { - this.log.error(`Request failed: ${e}`) + this.log.error(`Request failed: ${e}`); if (e.response) { - if (this.apiLogEnabled) this.log.debug(`Response ThermostatSetIotProp (${e.response.statusText}): ${JSON.stringify(e.response.data, null, '\t')}`) + if (this.apiLogEnabled) + this.log.debug( + `Response ThermostatSetIotProp (${ + e.response.statusText + }): ${JSON.stringify(e.response.data, null, "\t")}` + ); } - throw e + throw e; } - return result.data + return result.data; } - async localBulbCommand(deviceMac, deviceEnr, deviceIp, propertyId, propertyValue) { + async localBulbCommand( + deviceMac, + deviceEnr, + deviceIp, + propertyId, + propertyValue + ) { const characteristics = { mac: deviceMac.toUpperCase(), index: "1", @@ -698,323 +851,572 @@ module.exports = class WyzeAPI { plist: [ { pid: propertyId, - pvalue: String(propertyValue) - } - ] - } + pvalue: String(propertyValue), + }, + ], + }; - const characteristics_str = JSON.stringify(characteristics) - const characteristics_enc = util.encrypt(deviceEnr, characteristics_str) + const characteristics_str = JSON.stringify(characteristics); + const characteristics_enc = util.encrypt(deviceEnr, characteristics_str); const payload = { request: "set_status", isSendQueue: 0, - characteristics: characteristics_enc - } - const payload_str = JSON.stringify(payload) - - const url = `http://${deviceIp}:88/device_request` + characteristics: characteristics_enc, + }; + const payload_str = JSON.stringify(payload); + const url = `http://${deviceIp}:88/device_request`; try { //const response = await fetch(url, { method: "POST",body: payload_str}) - let result = await axios.post(url, payload_str) - if (this.apiLogEnabled) this.log.debug(`API response Local Bulb: ${(result.data)}`) - + let result = await axios.post(url, payload_str); + if (this.apiLogEnabled) + this.log.debug(`API response Local Bulb: ${result.data}`); } catch (error) { - console.log(error) + console.log(error); console.log( `Failed to connect to bulb ${deviceMac}, reverting to cloud.` - ) + ); //await this.runActionList(bulb, plist) } } /** - * Helper functions - */ + * Helper functions + */ - getUuid(deviceMac, deviceModel) { return deviceMac.replace(`${deviceModel}.`, '') } + getUuid(deviceMac, deviceModel) { + return deviceMac.replace(`${deviceModel}.`, ""); + } async getObjects() { - const result = await this.getObjectList() - return result + const result = await this.getObjectList(); + return result; } async getDeviceList() { - const result = await this.getObjectList() - return result.data.device_list + const result = await this.getObjectList(); + return result.data.device_list; } async getDeviceByName(nickname) { - const result = await this.getDeviceList() - const device = result.find(device => device.nickname.toLowerCase() === nickname.toLowerCase()) - return device + const result = await this.getDeviceList(); + const device = result.find( + (device) => device.nickname.toLowerCase() === nickname.toLowerCase() + ); + return device; } async getDeviceByMac(mac) { - const result = await this.getDeviceList() - const device = result.find(device => device.mac === mac) - return device + const result = await this.getDeviceList(); + const device = result.find((device) => device.mac === mac); + return device; } async getDevicesByType(type) { - const result = await this.getDeviceList() - const devices = result.filter(device => device.product_type.toLowerCase() === type.toLowerCase()) - return devices + const result = await this.getDeviceList(); + const devices = result.filter( + (device) => device.product_type.toLowerCase() === type.toLowerCase() + ); + return devices; } async getDevicesByModel(model) { - const result = await this.getDeviceList() - const devices = result.filter(device => device.product_model.toLowerCase() === model.toLowerCase()) - return devices + const result = await this.getDeviceList(); + const devices = result.filter( + (device) => device.product_model.toLowerCase() === model.toLowerCase() + ); + return devices; } async getDeviceGroupsList() { - const result = await this.getObjectList() - return result.data.device_group_list + const result = await this.getObjectList(); + return result.data.device_group_list; } async getDeviceSortList() { - const result = await this.getObjectList() - return result.data.device_sort_list + const result = await this.getObjectList(); + return result.data.device_sort_list; + } + async getDeviceStatus(device) { + return device.device_params; } - async getDeviceStatus(device) { return device.device_params } - async getDevicePID(deviceMac, deviceModel) { return await this.getPropertyList(deviceMac, deviceModel) } + async getDevicePID(deviceMac, deviceModel) { + return await this.getPropertyList(deviceMac, deviceModel); + } - async cameraPrivacy(deviceMac, deviceModel, value) { await this.runAction(deviceMac, deviceModel, value) } - async cameraTurnOn(deviceMac, deviceModel) { await this.runAction(deviceMac, deviceModel, 'power_on') } - async cameraTurnOff(deviceMac, deviceModel) { await this.runAction(deviceMac, deviceModel, 'power_off') } + async cameraPrivacy(deviceMac, deviceModel, value) { + await this.runAction(deviceMac, deviceModel, value); + } + async cameraTurnOn(deviceMac, deviceModel) { + await this.runAction(deviceMac, deviceModel, "power_on"); + } + async cameraTurnOff(deviceMac, deviceModel) { + await this.runAction(deviceMac, deviceModel, "power_off"); + } /** * Open or Close Garage Door Depending on current state - * @param {string} deviceMac - * @param {string} deviceModel + * @param {string} deviceMac + * @param {string} deviceModel */ - async garageDoor(deviceMac, deviceModel) { await this.runAction(deviceMac, deviceModel, 'garage_door_trigger') } + async garageDoor(deviceMac, deviceModel) { + await this.runAction(deviceMac, deviceModel, "garage_door_trigger"); + } - async cameraSiren(deviceMac, deviceModel, value) { await this.runAction(deviceMac, deviceModel, value) } + async cameraSiren(deviceMac, deviceModel, value) { + await this.runAction(deviceMac, deviceModel, value); + } /** * Turn Camera Siren ON - * @param {string} deviceMac - * @param {string} deviceModel + * @param {string} deviceMac + * @param {string} deviceModel */ - async cameraSirenOn(deviceMac, deviceModel) { await this.runAction(deviceMac, deviceModel, 'siren_on') } + async cameraSirenOn(deviceMac, deviceModel) { + await this.runAction(deviceMac, deviceModel, "siren_on"); + } /** * Turn Camera Siren OFF - * @param {string} deviceMac - * @param {string} deviceModel + * @param {string} deviceMac + * @param {string} deviceModel */ - async cameraSirenOff(deviceMac, deviceModel) { await this.runAction(deviceMac, deviceModel, 'siren_off') } + async cameraSirenOff(deviceMac, deviceModel) { + await this.runAction(deviceMac, deviceModel, "siren_off"); + } - async turnMeshOn(deviceMac, deviceModel) { return await this.runActionList(deviceMac, deviceModel, 'P3', '1', 'set_mesh_property') } - async turnMeshOff(deviceMac, deviceModel) { return await this.runActionList(deviceMac, deviceModel, 'P3', '0', 'set_mesh_property') } + async turnMeshOn(deviceMac, deviceModel) { + return await this.runActionList( + deviceMac, + deviceModel, + "P3", + "1", + "set_mesh_property" + ); + } + async turnMeshOff(deviceMac, deviceModel) { + return await this.runActionList( + deviceMac, + deviceModel, + "P3", + "0", + "set_mesh_property" + ); + } - async unlockLock(device) { return await this.controlLock(device.mac, device.product_model, 'remoteUnlock') } - async lockLock(device) { return await this.controlLock(device.mac, device.product_model, 'remoteLock') } + async unlockLock(device) { + return await this.controlLock( + device.mac, + device.product_model, + "remoteUnlock" + ); + } + async lockLock(device) { + return await this.controlLock( + device.mac, + device.product_model, + "remoteLock" + ); + } - async lockInfo(device) { return await this.getLockInfo(device.mac, device.product_model) } + async lockInfo(device) { + return await this.getLockInfo(device.mac, device.product_model); + } - async cameraFloodLight(deviceMac, deviceModel, value) { await this.setProperty(deviceMac, deviceModel, "P1056", value) } - async cameraFloodLightOn(deviceMac, deviceModel) { await this.setProperty(deviceMac, deviceModel, "P1056", "1") } - async cameraFloodLightOff(deviceMac, deviceModel) { await this.setProperty(deviceMac, deviceModel, "P1056", "2") } + async cameraFloodLight(deviceMac, deviceModel, value) { + await this.setProperty(deviceMac, deviceModel, "P1056", value); + } + async cameraFloodLightOn(deviceMac, deviceModel) { + await this.setProperty(deviceMac, deviceModel, "P1056", "1"); + } + async cameraFloodLightOff(deviceMac, deviceModel) { + await this.setProperty(deviceMac, deviceModel, "P1056", "2"); + } - async cameraSpotLight(deviceMac, deviceModel, value) { await this.setProperty(deviceMac, deviceModel, "P1056", value) } - async cameraSpotLightOn(deviceMac, deviceModel) { await this.setProperty(deviceMac, deviceModel, "P1056", "1") } - async cameraSpotLightOff(deviceMac, deviceModel) { await this.setProperty(deviceMac, deviceModel, "P1056", "2") } + async cameraSpotLight(deviceMac, deviceModel, value) { + await this.setProperty(deviceMac, deviceModel, "P1056", value); + } + async cameraSpotLightOn(deviceMac, deviceModel) { + await this.setProperty(deviceMac, deviceModel, "P1056", "1"); + } + async cameraSpotLightOff(deviceMac, deviceModel) { + await this.setProperty(deviceMac, deviceModel, "P1056", "2"); + } - async cameraMotionOn(deviceMac, deviceModel) { await this.setProperty(deviceMac, deviceModel, "P1001", 1) } - async cameraMotionOff(deviceMac, deviceModel) { await this.setProperty(deviceMac, deviceModel, "P1001", 0) } + async cameraMotionOn(deviceMac, deviceModel) { + await this.setProperty(deviceMac, deviceModel, "P1001", 1); + } + async cameraMotionOff(deviceMac, deviceModel) { + await this.setProperty(deviceMac, deviceModel, "P1001", 0); + } - async cameraSoundNotificationOn(deviceMac, deviceModel) { await this.setProperty(deviceMac, deviceModel, "P1048", '1') } - async cameraSoundNotificationOff(deviceMac, deviceModel) { await this.setProperty(deviceMac, deviceModel, "P1048", '0') } + async cameraSoundNotificationOn(deviceMac, deviceModel) { + await this.setProperty(deviceMac, deviceModel, "P1048", "1"); + } + async cameraSoundNotificationOff(deviceMac, deviceModel) { + await this.setProperty(deviceMac, deviceModel, "P1048", "0"); + } - async cameraNotifications(deviceMac, deviceModel, value) { await this.setProperty(deviceMac, deviceModel, 'P1', value) } - async cameraNotificationsOn(deviceMac, deviceModel) { await this.setProperty(deviceMac, deviceModel, 'P1', '1') } - async cameraNotificationsOff(deviceMac, deviceModel) { await this.setProperty(deviceMac, deviceModel, 'P1', '0') } + async cameraNotifications(deviceMac, deviceModel, value) { + await this.setProperty(deviceMac, deviceModel, "P1", value); + } + async cameraNotificationsOn(deviceMac, deviceModel) { + await this.setProperty(deviceMac, deviceModel, "P1", "1"); + } + async cameraNotificationsOff(deviceMac, deviceModel) { + await this.setProperty(deviceMac, deviceModel, "P1", "0"); + } - async cameraMotionRecording(deviceMac, deviceModel, value) { await this.setProperty(deviceMac, deviceModel, 'P1047', value) } - async cameraMotionRecordingOn(deviceMac, deviceModel) { await this.setProperty(deviceMac, deviceModel, 'P1047', '1') } - async cameraMotionRecordingOff(deviceMac, deviceModel) { await this.setProperty(deviceMac, deviceModel, 'P1047', '0') } + async cameraMotionRecording(deviceMac, deviceModel, value) { + await this.setProperty(deviceMac, deviceModel, "P1047", value); + } + async cameraMotionRecordingOn(deviceMac, deviceModel) { + await this.setProperty(deviceMac, deviceModel, "P1047", "1"); + } + async cameraMotionRecordingOff(deviceMac, deviceModel) { + await this.setProperty(deviceMac, deviceModel, "P1047", "0"); + } /** * Turn Plug 0 = off or 1 = on - * @param {string} deviceMac - * @param {string} deviceModel + * @param {string} deviceMac + * @param {string} deviceModel * @param {number} value */ - async plugPower(deviceMac, deviceModel, value) { await this.setProperty(deviceMac, deviceModel, "P3", value) } - async plugTurnOn(deviceMac, deviceModel) { await this.setProperty(deviceMac, deviceModel, "P3", "0") } - async plugTurnOff(deviceMac, deviceModel) { await this.setProperty(deviceMac, deviceModel, "P3", "1") } + async plugPower(deviceMac, deviceModel, value) { + await this.setProperty(deviceMac, deviceModel, "P3", value); + } + async plugTurnOn(deviceMac, deviceModel) { + await this.setProperty(deviceMac, deviceModel, "P3", "0"); + } + async plugTurnOff(deviceMac, deviceModel) { + await this.setProperty(deviceMac, deviceModel, "P3", "1"); + } //WyzeLight /** * Turn Light Bulb 0 = off or 1 = on - * @param {string} deviceMac - * @param {string} deviceModel + * @param {string} deviceMac + * @param {string} deviceModel * @param {number} value */ - async lightPower(deviceMac, deviceModel, value) { await this.setProperty(deviceMac, deviceModel, 'P3', value) } - async lightTurnOn(deviceMac, deviceModel) { await this.setProperty(deviceMac, deviceModel, 'P3', '0') } - async lightTurnOff(deviceMac, deviceModel) { await this.setProperty(deviceMac, deviceModel, "P3", "1") } - - async setBrightness(deviceMac, deviceModel, value) { await this.setProperty(deviceMac, deviceModel, "P1501", value) } - async setColorTemperature(deviceMac, deviceModel, value) { await this.setProperty(deviceMac, deviceModel, "P1502", value) } + async lightPower(deviceMac, deviceModel, value) { + await this.setProperty(deviceMac, deviceModel, "P3", value); + } + async lightTurnOn(deviceMac, deviceModel) { + await this.setProperty(deviceMac, deviceModel, "P3", "0"); + } + async lightTurnOff(deviceMac, deviceModel) { + await this.setProperty(deviceMac, deviceModel, "P3", "1"); + } + async setBrightness(deviceMac, deviceModel, value) { + await this.setProperty(deviceMac, deviceModel, "P1501", value); + } + async setColorTemperature(deviceMac, deviceModel, value) { + await this.setProperty(deviceMac, deviceModel, "P1502", value); + } /** * Turn Mesh Device on or off - * @param {string} deviceMac - * @param {string} deviceModel - * @param {boolean} value + * @param {string} deviceMac + * @param {string} deviceModel + * @param {boolean} value */ - async lightMeshPower(deviceMac, deviceModel, value) { await this.runActionList(deviceMac, deviceModel, 'P3', value, 'set_mesh_property') } + async lightMeshPower(deviceMac, deviceModel, value) { + await this.runActionList( + deviceMac, + deviceModel, + "P3", + value, + "set_mesh_property" + ); + } /** * Turn Mesh Device On - * @param {string} deviceMac - * @param {string} deviceModel + * @param {string} deviceMac + * @param {string} deviceModel */ - async lightMeshOn(deviceMac, deviceModel) { await this.runActionList(deviceMac, deviceModel, 'P3', '1', 'set_mesh_property') } + async lightMeshOn(deviceMac, deviceModel) { + await this.runActionList( + deviceMac, + deviceModel, + "P3", + "1", + "set_mesh_property" + ); + } /** * Turn Mesh Device Off - * @param {string} deviceMac - * @param {string} deviceModel + * @param {string} deviceMac + * @param {string} deviceModel */ - async lightMeshOff(deviceMac, deviceModel) { await this.runActionList(deviceMac, deviceModel, 'P3', '0', 'set_mesh_property') } + async lightMeshOff(deviceMac, deviceModel) { + await this.runActionList( + deviceMac, + deviceModel, + "P3", + "0", + "set_mesh_property" + ); + } /** * Set Mesh Brightness 0 - 100 - * @param {string} deviceMac - * @param {string} deviceModel - * @param {number} value + * @param {string} deviceMac + * @param {string} deviceModel + * @param {number} value */ - async setMeshBrightness(deviceMac, deviceModel, value) { await this.runActionList(deviceMac, deviceModel, "P1501", value, 'set_mesh_property') } + async setMeshBrightness(deviceMac, deviceModel, value) { + await this.runActionList( + deviceMac, + deviceModel, + "P1501", + value, + "set_mesh_property" + ); + } /** * Set Color Temperature 2700 - 6500 - * @param {string} deviceMac - * @param {string} deviceModel - * @param {number} value + * @param {string} deviceMac + * @param {string} deviceModel + * @param {number} value */ - async setMeshColorTemperature(deviceMac, deviceModel, value) { await this.runActionList(deviceMac, deviceModel, "P1502", value, 'set_mesh_property') } + async setMeshColorTemperature(deviceMac, deviceModel, value) { + await this.runActionList( + deviceMac, + deviceModel, + "P1502", + value, + "set_mesh_property" + ); + } /** - * - * @param {string} deviceMac - * @param {string} deviceModel - * @param {*} value + * + * @param {string} deviceMac + * @param {string} deviceModel + * @param {*} value */ - async setMeshHue(deviceMac, deviceModel, value) { await this.runActionList(deviceMac, deviceModel, "P1507", value, 'set_mesh_property') } + async setMeshHue(deviceMac, deviceModel, value) { + await this.runActionList( + deviceMac, + deviceModel, + "P1507", + value, + "set_mesh_property" + ); + } /** - * - * @param {string} deviceMac - * @param {string} deviceModel - * @param {*} value + * + * @param {string} deviceMac + * @param {string} deviceModel + * @param {*} value */ - async setMeshSaturation(deviceMac, deviceModel, value) { await this.runActionList(deviceMac, deviceModel, "P1507", value, 'set_mesh_property') } + async setMeshSaturation(deviceMac, deviceModel, value) { + await this.runActionList( + deviceMac, + deviceModel, + "P1507", + value, + "set_mesh_property" + ); + } /** * Turn wall switch on or off - * @param {string} deviceMac - * @param {string} deviceModel - * @param {boolean} value + * @param {string} deviceMac + * @param {string} deviceModel + * @param {boolean} value */ - async wallSwitchPower(deviceMac, deviceModel, value) { await this.setIotProp(deviceMac, deviceModel, 'switch-power', value) } + async wallSwitchPower(deviceMac, deviceModel, value) { + await this.setIotProp(deviceMac, deviceModel, "switch-power", value); + } /** * Turn wall switch on - * @param {string} deviceMac - * @param {string} deviceModel + * @param {string} deviceMac + * @param {string} deviceModel */ - async wallSwitchPowerOn(deviceMac, deviceModel) { await this.setIotProp(deviceMac, deviceModel, 'switch-power', true) } + async wallSwitchPowerOn(deviceMac, deviceModel) { + await this.setIotProp(deviceMac, deviceModel, "switch-power", true); + } /** * Turn wall switch off - * @param {string} deviceMac - * @param {string} deviceModel + * @param {string} deviceMac + * @param {string} deviceModel */ - async wallSwitchPowerOff(deviceMac, deviceModel) { await this.setIotProp(deviceMac, deviceModel, 'switch-power', false) } + async wallSwitchPowerOff(deviceMac, deviceModel) { + await this.setIotProp(deviceMac, deviceModel, "switch-power", false); + } /** - * - * @param {string} deviceMac - * @param {string} deviceModel - * @param {boolean} value + * + * @param {string} deviceMac + * @param {string} deviceModel + * @param {boolean} value */ - async wallSwitchIot(deviceMac, deviceModel, value) { await this.setIotProp(deviceMac, deviceModel, 'switch-iot', value) } - async wallSwitchIotOn(deviceMac, deviceModel) { await this.setIotProp(deviceMac, deviceModel, 'switch-iot', true) } - async wallSwitchIotOff(deviceMac, deviceModel) { await this.setIotProp(deviceMac, deviceModel, 'switch-iot', false) } + async wallSwitchIot(deviceMac, deviceModel, value) { + await this.setIotProp(deviceMac, deviceModel, "switch-iot", value); + } + async wallSwitchIotOn(deviceMac, deviceModel) { + await this.setIotProp(deviceMac, deviceModel, "switch-iot", true); + } + async wallSwitchIotOff(deviceMac, deviceModel) { + await this.setIotProp(deviceMac, deviceModel, "switch-iot", false); + } - async wallSwitchLedStateOn(deviceMac, deviceModel) { await this.setIotProp(deviceMac, deviceModel, 'led_state', true) } - async wallSwitchLedStateOff(deviceMac, deviceModel) { await this.setIotProp(deviceMac, deviceModel, 'led_state', false) } + async wallSwitchLedStateOn(deviceMac, deviceModel) { + await this.setIotProp(deviceMac, deviceModel, "led_state", true); + } + async wallSwitchLedStateOff(deviceMac, deviceModel) { + await this.setIotProp(deviceMac, deviceModel, "led_state", false); + } /** - * Wall Switch Turn Vacation Mode on - * @param {string} deviceMac - * @param {string} deviceModel - */ - async wallSwitchVacationModeOn(deviceMac, deviceModel) { await this.setIotProp(deviceMac, deviceModel, 'vacation_mode', 0) } + * Wall Switch Turn Vacation Mode on + * @param {string} deviceMac + * @param {string} deviceModel + */ + async wallSwitchVacationModeOn(deviceMac, deviceModel) { + await this.setIotProp(deviceMac, deviceModel, "vacation_mode", 0); + } /** * Wall Switch Turn Vacation Mode off - * @param {string} deviceMac - * @param {string} deviceModel + * @param {string} deviceMac + * @param {string} deviceModel */ - async wallSwitchVacationModeOff(deviceMac, deviceModel) { await this.setIotProp(deviceMac, deviceModel, 'vacation_mode', 1) } + async wallSwitchVacationModeOff(deviceMac, deviceModel) { + await this.setIotProp(deviceMac, deviceModel, "vacation_mode", 1); + } - async getHmsID() { await this.getPlanBindingListByUser() } + async getHmsID() { + await this.getPlanBindingListByUser(); + } async setHMSState(hms_id, mode) { if (mode == "off") { - await this.disableRemeAlarm(hms_id) - await this.monitoringProfileActive(hms_id, 0, 0) + await this.disableRemeAlarm(hms_id); + await this.monitoringProfileActive(hms_id, 0, 0); } else if (mode === "away") { - await this.monitoringProfileActive(hms_id, 0, 1) + await this.monitoringProfileActive(hms_id, 0, 1); } else if (mode === "home") { - await this.monitoringProfileActive(hms_id, 1, 0) + await this.monitoringProfileActive(hms_id, 1, 0); } } - async getHmsUpdate(hms_id) { return await this.plugin.client.monitoringProfileStateStatus(hms_id) } + async getHmsUpdate(hms_id) { + return await this.plugin.client.monitoringProfileStateStatus(hms_id); + } async getDeviceState(device) { - let state = device.device_params.power_switch !== undefined ? (device.device_params.power_switch === 1 ? 'on' : 'off') : '' + let state = + device.device_params.power_switch !== undefined + ? device.device_params.power_switch === 1 + ? "on" + : "off" + : ""; if (!state) { - state = device.device_params.open_close_state !== undefined ? (device.device_params.open_close_state === 1 ? 'open' : 'closed') : '' + state = + device.device_params.open_close_state !== undefined + ? device.device_params.open_close_state === 1 + ? "open" + : "closed" + : ""; } - return state + return state; } async getDeviceStatePID(deviceMac, deviceModel, pid) { - const prop = await this.getDevicePID(deviceMac, deviceModel) + const prop = await this.getDevicePID(deviceMac, deviceModel); for (const property of prop.data.property_list) { if (pid == property.pid) { - return property.value !== undefined ? (property.value === '1' ? 1 : 0) : '' + return property.value !== undefined + ? property.value === "1" + ? 1 + : 0 + : ""; } } } + getLockDoorState(deviceState) { + if (deviceState >= 2) { + return 1; + } else { + return deviceState; + } + } + getLeakSensorState(deviceState) { + if (deviceState >= 2) { + return 1; + } else { + return deviceState; + } + } + getLockState(deviceState) { + if (deviceState == 2) { + return 0; + } else { + return 1; + } + } + checkBatteryVoltage(value) { + if (value >= 100) { + return 100; + } else if (value == "undefined" || value == null) { + return 1; + } else { + return value; + } + } + rangeToFloat(value, min, max) { + return (value - min) / (max - min); + } + floatToRange(value, min, max) { + return Math.round(value * (max - min) + min); + } + kelvinToMired(value) { + return Math.round(1000000 / value); + } + checkBrightnessValue(value) { + if (value >= 1 || value <= 100) { + return value; + } else return value; + } + checkColorTemp(color) { + if (color >= 500) { + return 500; + } else { + return color; + } + } + checkLowBattery(batteryVolts) { + if (this.checkBatteryVoltage(batteryVolts) <= this.lowBatteryPercentage) { + return 1; + } else return 0; + } - getLockDoorState(deviceState) { if (deviceState >= 2) { return 1 } else { return deviceState } } - getLeakSensorState(deviceState) { if (deviceState >= 2) { return 1 } else { return deviceState } } - getLockState(deviceState) { if (deviceState == 2) { return 0 } else { return 1 } } - checkBatteryVoltage(value) { if (value >= 100) { return 100 } else if (value == "undefined" || value == null) { return 1 } else { return value } } - rangeToFloat(value, min, max) { return (value - min) / (max - min) } - floatToRange(value, min, max) { return Math.round((value * (max - min)) + min) } - kelvinToMired(value) { return Math.round(1000000 / value) } - checkBrightnessValue(value) { if (value >= 1 || value <= 100) { return value } else return value } - checkColorTemp(color) { if (color >= 500) { return 500 } else { return color } } - checkLowBattery(batteryVolts) { if (this.checkBatteryVoltage(batteryVolts) <= this.lowBatteryPercentage) { return 1 } else return 0 } - - fahrenheit2celsius(fahrenheit) { return ((fahrenheit) - 32.0) / 1.8 } - celsius2fahrenheit(celsius) { return ((celsius) * 1.8) + 32.0 } + fahrenheit2celsius(fahrenheit) { + return (fahrenheit - 32.0) / 1.8; + } + celsius2fahrenheit(celsius) { + return celsius * 1.8 + 32.0; + } - clamp(number, min, max) { return Math.max(min, Math.min(number, max)) } + clamp(number, min, max) { + return Math.max(min, Math.min(number, max)); + } - sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms * 1000)) } -} + sleep(ms) { + return new Promise((resolve) => setTimeout(resolve, ms * 1000)); + } +};