From 257a442cb7fc3830e00cbf69033f528928a6c67c Mon Sep 17 00:00:00 2001 From: DEV2DEV-DE Date: Sun, 3 Dec 2023 20:31:14 +0100 Subject: [PATCH] Implemented improvements mentioned in review --- .commitmessage | 4 -- README.md | 3 + main.js | 19 +++--- package-lock.json | 149 +++++++++++++--------------------------------- package.json | 3 +- 5 files changed, 58 insertions(+), 120 deletions(-) delete mode 100644 .commitmessage diff --git a/.commitmessage b/.commitmessage deleted file mode 100644 index 9c02d21..0000000 --- a/.commitmessage +++ /dev/null @@ -1,4 +0,0 @@ -chore: release v0.0.2-beta.3 - -* Switched recurring refresh from interval to timeout -* Manage internal list of already created states \ No newline at end of file diff --git a/README.md b/README.md index e51e79f..46ee531 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,9 @@ https://www.jablotron.com/de/katalog-produktu/alarme/jablotron-100/ ## Changelog +### **WORK IN PROGRESS** +* Implemented improvements mentioned in review + ### 0.0.2 (2023-11-30) * Provide an appropriate role for any state * Readme extended diff --git a/main.js b/main.js index 5ade215..46a749e 100644 --- a/main.js +++ b/main.js @@ -137,7 +137,7 @@ class Jablotron extends utils.Adapter { const serviceId = service['service-id']; await this.createChannel(`services.${serviceId}`, `Service ${serviceId}`); for (const state in service) { - await this.createState(`services.${serviceId}.${state}`, `${state}`, true, false, service[state]); + await this.doCreateState(`services.${serviceId}.${state}`, `${state}`, true, false, service[state]); } await this.getSections(headers, cookie, serviceId); await this.getProgrammableGates(headers, cookie, serviceId); @@ -154,7 +154,7 @@ class Jablotron extends utils.Adapter { * @returns {Promise} */ async recurringRefresh() { - this.timeout = setTimeout(() => { + this.timeout = this.setTimeout(() => { this.log.debug('Fetch data from jablonet.net'); this.getExtendedData(headers, this.sessionId); this.recurringRefresh(); @@ -208,11 +208,11 @@ class Jablotron extends utils.Adapter { const id = sections[section]['cloud-component-id']; await this.createChannel(`services.${serviceId}.sections.${id}`, `${id}`); for (const key in sections[section]) { - await this.createState(`services.${serviceId}.sections.${id}.${key}`, `${key}`, true, false, sections[section][key]); + await this.doCreateState(`services.${serviceId}.sections.${id}.${key}`, `${key}`, true, false, sections[section][key]); } const state = states.find(state => state['cloud-component-id'] === id); if (state) { // es wurde ein state zur section gefunden - await this.createState(`services.${serviceId}.sections.${id}.state`, 'state', true, false, state.state); + await this.doCreateState(`services.${serviceId}.sections.${id}.state`, 'state', true, false, state.state); } } } catch (error) { @@ -246,10 +246,10 @@ class Jablotron extends utils.Adapter { const id = gates[gate]['cloud-component-id']; await this.createChannel(`services.${serviceId}.programmable-gates.${id}`, `${id}`); for (const key in gates[gate]) { - await this.createState(`services.${serviceId}.programmable-gates.${id}.${key}`, `${key}`, true, false, gates[gate][key]); + await this.doCreateState(`services.${serviceId}.programmable-gates.${id}.${key}`, `${key}`, true, false, gates[gate][key]); const state = states.find(state => state['cloud-component-id'] === id); if (state) { // es wurde ein state zum gate gefunden - await this.createState(`services.${serviceId}.programmable-gates.${id}.state`, 'state', true, false, state.state); + await this.doCreateState(`services.${serviceId}.programmable-gates.${id}.state`, 'state', true, false, state.state); } } } @@ -318,11 +318,12 @@ class Jablotron extends utils.Adapter { * @param {boolean} write * @param {any} value */ - async createState(id, name, read, write, value) { - let type = undefined; - let role = 'state'; + async doCreateState(id, name, read, write, value) { + let type = ''; + let role = ''; switch (typeof (value)) { case 'object': type = 'object'; + role = 'json'; value = JSON.stringify(value); break; case 'string': type = 'string'; diff --git a/package-lock.json b/package-lock.json index 15e79f4..ef16677 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,8 @@ "version": "0.0.2", "license": "MIT", "dependencies": { - "@iobroker/adapter-core": "^3.0.4" + "@iobroker/adapter-core": "^3.0.4", + "axios": "^1.6.2" }, "devDependencies": { "@alcalzone/release-script": "^3.7.0", @@ -61,17 +62,6 @@ "tiny-glob": "^0.2.9" } }, - "node_modules/@alcalzone/pak/node_modules/axios": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", - "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", - "dev": true, - "dependencies": { - "follow-redirects": "^1.15.0", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/@alcalzone/pak/node_modules/execa": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/execa/-/execa-5.0.1.tgz", @@ -191,17 +181,6 @@ "node": ">=12.20" } }, - "node_modules/@alcalzone/release-script-plugin-iobroker/node_modules/axios": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", - "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", - "dev": true, - "dependencies": { - "follow-redirects": "^1.15.0", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/@alcalzone/release-script-plugin-license": { "version": "3.7.0", "resolved": "https://registry.npmjs.org/@alcalzone/release-script-plugin-license/-/release-script-plugin-license-3.7.0.tgz", @@ -260,17 +239,6 @@ "node": ">=12.20" } }, - "node_modules/@alcalzone/release-script/node_modules/axios": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", - "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", - "dev": true, - "dependencies": { - "follow-redirects": "^1.15.0", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/@babel/parser": { "version": "7.23.4", "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.4.tgz", @@ -637,6 +605,16 @@ "node": ">=12.0.0" } }, + "node_modules/@iobroker/adapter-dev/node_modules/axios": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", + "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", + "dev": true, + "dependencies": { + "follow-redirects": "^1.14.9", + "form-data": "^4.0.0" + } + }, "node_modules/@iobroker/testing": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/@iobroker/testing/-/testing-4.1.0.tgz", @@ -1156,17 +1134,16 @@ "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "dev": true + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "node_modules/axios": { - "version": "0.27.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", - "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", - "dev": true, + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", + "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", "dependencies": { - "follow-redirects": "^1.14.9", - "form-data": "^4.0.0" + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" } }, "node_modules/balanced-match": { @@ -1425,7 +1402,6 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, "dependencies": { "delayed-stream": "~1.0.0" }, @@ -1504,7 +1480,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "dev": true, "engines": { "node": ">=0.4.0" } @@ -2366,7 +2341,6 @@ "version": "1.15.3", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", - "dev": true, "funding": [ { "type": "individual", @@ -2386,7 +2360,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dev": true, "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -3229,7 +3202,6 @@ "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "dev": true, "engines": { "node": ">= 0.6" } @@ -3238,7 +3210,6 @@ "version": "2.1.35", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "dev": true, "dependencies": { "mime-db": "1.52.0" }, @@ -3805,8 +3776,7 @@ "node_modules/proxy-from-env": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", - "dev": true + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" }, "node_modules/proxyquire": { "version": "2.1.3", @@ -4565,17 +4535,6 @@ "tiny-glob": "^0.2.9" }, "dependencies": { - "axios": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", - "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", - "dev": true, - "requires": { - "follow-redirects": "^1.15.0", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "execa": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/execa/-/execa-5.0.1.tgz", @@ -4615,19 +4574,6 @@ "semver": "^7.5.2", "source-map-support": "^0.5.21", "yargs": "^17.4.1" - }, - "dependencies": { - "axios": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", - "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", - "dev": true, - "requires": { - "follow-redirects": "^1.15.0", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - } } }, "@alcalzone/release-script-core": { @@ -4681,19 +4627,6 @@ "axios": "^1.6.2", "fs-extra": "^10.1.0", "semver": "^7.5.2" - }, - "dependencies": { - "axios": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", - "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", - "dev": true, - "requires": { - "follow-redirects": "^1.15.0", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - } } }, "@alcalzone/release-script-plugin-license": { @@ -4973,6 +4906,18 @@ "fs-extra": "^10.1.0", "tiny-glob": "^0.2.9", "yargs": "^17.6.0" + }, + "dependencies": { + "axios": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", + "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", + "dev": true, + "requires": { + "follow-redirects": "^1.14.9", + "form-data": "^4.0.0" + } + } } }, "@iobroker/testing": { @@ -5435,17 +5380,16 @@ "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "dev": true + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "axios": { - "version": "0.27.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", - "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", - "dev": true, + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", + "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", "requires": { - "follow-redirects": "^1.14.9", - "form-data": "^4.0.0" + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" } }, "balanced-match": { @@ -5636,7 +5580,6 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, "requires": { "delayed-stream": "~1.0.0" } @@ -5691,8 +5634,7 @@ "delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "dev": true + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==" }, "diff": { "version": "5.0.0", @@ -6244,14 +6186,12 @@ "follow-redirects": { "version": "1.15.3", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", - "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", - "dev": true + "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==" }, "form-data": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dev": true, "requires": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -6902,14 +6842,12 @@ "mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "dev": true + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==" }, "mime-types": { "version": "2.1.35", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "dev": true, "requires": { "mime-db": "1.52.0" } @@ -7340,8 +7278,7 @@ "proxy-from-env": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", - "dev": true + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" }, "proxyquire": { "version": "2.1.3", diff --git a/package.json b/package.json index ae1cd4a..373623b 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "node": ">= 16" }, "dependencies": { - "@iobroker/adapter-core": "^3.0.4" + "@iobroker/adapter-core": "^3.0.4", + "axios": "^1.6.2" }, "devDependencies": { "@alcalzone/release-script": "^3.7.0",