From 0be83b68850897a1b19ea3dea0d977f824ac9cde Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Sun, 8 Sep 2024 22:09:13 +0200 Subject: [PATCH 01/12] Update to eslint 9 --- .eslintignore | 7 - .eslintrc.json | 55 --- .github/workflows/update_deps.yml | 2 +- .prettierrc | 20 +- eslint.config.mjs | 33 ++ package-lock.json | 548 +++++++++++++----------------- package.json | 15 +- 7 files changed, 287 insertions(+), 393 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc.json create mode 100644 eslint.config.mjs diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 32fa9fa91f027..0000000000000 --- a/.eslintignore +++ /dev/null @@ -1,7 +0,0 @@ -node_modules/* -test/* -index.* -converters/* -devices/* -lib/* -scripts/* \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 9e71cbcb24329..0000000000000 --- a/.eslintrc.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "env": { - "es6": true, - "node": true - }, - "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"], - "parser": "@typescript-eslint/parser", - "plugins": ["@typescript-eslint", "eslint-plugin-tsdoc", "perfectionist"], - "root": true, - "parserOptions": { - "project": "./tsconfig.json" - }, - "rules": { - "require-jsdoc": "off", - "no-prototype-builtins": "off", - "@typescript-eslint/no-empty-function": "off", - "@typescript-eslint/ban-ts-comment": "off", - "@typescript-eslint/no-unused-vars": "off", - "@typescript-eslint/no-floating-promises": "error", - "tsdoc/syntax": "warn", - "valid-jsdoc": "off", - "perfectionist/sort-imports": [ - "error", - { - "groups": [ - "type", - ["builtin", "external"], - "internal-type", - "internal", - ["parent-type", "sibling-type", "index-type"], - ["parent", "sibling", "index"], - "object", - "unknown" - ], - "customGroups": { - "value": {}, - "type": {} - }, - "newlinesBetween": "always", - "internalPattern": ["~/**"], - "type": "natural", - "order": "asc", - "ignoreCase": false - } - ] - }, - "overrides": [ - { - "files": ["**/*.js"], - "rules": { - "@typescript-eslint/no-var-requires": "off" - } - } - ] -} diff --git a/.github/workflows/update_deps.yml b/.github/workflows/update_deps.yml index a0f8cab804b55..5a4f81c41c071 100644 --- a/.github/workflows/update_deps.yml +++ b/.github/workflows/update_deps.yml @@ -20,7 +20,7 @@ jobs: with: node-version: 20 cache: npm - - run: npx npm-check-updates -u -x eslint + - run: npx npm-check-updates -u - run: rm -f package-lock.json - run: npm install - uses: peter-evans/create-pull-request@v7 diff --git a/.prettierrc b/.prettierrc index 0267e1af9c7ef..0c99705e7fdc5 100644 --- a/.prettierrc +++ b/.prettierrc @@ -5,5 +5,23 @@ "printWidth": 150, "bracketSpacing": false, "endOfLine": "lf", - "tabWidth": 4 + "tabWidth": 4, + "importOrder": [ + "", + "^(node:)", + "", + "", + "", + "^[.]", + "", + "", + "", + "", + "", + "^zigbee", + "", + "^[.]" + ], + "importOrderParserPlugins": ["typescript", "decorators"], + "plugins": ["@ianvs/prettier-plugin-sort-imports"] } diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000000000..d49d9aaed67a3 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,33 @@ +// @ts-check + +import eslint from '@eslint/js'; +import eslintConfigPrettier from 'eslint-config-prettier'; +import tseslint from 'typescript-eslint'; + +export default tseslint.config( + eslint.configs.recommended, + ...tseslint.configs.recommended, + { + languageOptions: { + parserOptions: { + project: true, + }, + }, + rules: { + '@typescript-eslint/await-thenable': 'off', // TODO error + '@typescript-eslint/ban-ts-comment': 'off', // TODO error + '@typescript-eslint/explicit-function-return-type': 'off', // TODO error + '@typescript-eslint/no-explicit-any': 'error', + '@typescript-eslint/no-unused-vars': 'off', // TODO error + 'array-bracket-spacing': ['error', 'never'], + 'no-return-await': 'off', // TODO error + 'object-curly-spacing': ['error', 'never'], + '@typescript-eslint/no-floating-promises': 'error', + 'no-prototype-builtins': 'off', // TODO remove (error by default) + }, + }, + { + ignores: ['test/', 'index.*', 'converters/', 'devices/', 'lib/', 'scripts/', '**/*.mjs'], + }, + eslintConfigPrettier, +); diff --git a/package-lock.json b/package-lock.json index b9c00b6664741..43e6e90d856af 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,18 +18,16 @@ "zigbee-herdsman": "^0.57.3" }, "devDependencies": { + "@eslint/js": "^9.10.0", + "@ianvs/prettier-plugin-sort-imports": "^4.3.1", "@types/buffer-crc32": "^0.2.4", + "@types/eslint__js": "^8.42.3", "@types/jest": "^29.5.12", "@types/node": "^22.5.4", "@types/semver": "^7.5.8", "@types/tar-stream": "^3.1.3", - "@typescript-eslint/eslint-plugin": "^8.4.0", - "@typescript-eslint/parser": "^8.4.0", - "eslint": "^8.57.0", + "eslint": "^9.10.0", "eslint-config-prettier": "^9.1.0", - "eslint-plugin-jest": "^28.8.3", - "eslint-plugin-perfectionist": "^3.5.0", - "eslint-plugin-tsdoc": "^0.3.0", "fast-deep-equal": "*", "husky": "^9.1.5", "jest": "^29.7.0", @@ -37,7 +35,8 @@ "rimraf": "^6.0.1", "ts-jest": "^29.2.5", "ts-morph": "^23.0.0", - "typescript": "^5.5.4" + "typescript": "^5.5.4", + "typescript-eslint": "^8.4.0" } }, "node_modules/@ampproject/remapping": { @@ -704,17 +703,52 @@ "node": "^12.0.0 || ^14.0.0 || >=16.0.0" } }, + "node_modules/@eslint/config-array": { + "version": "0.18.0", + "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.18.0.tgz", + "integrity": "sha512-fTxvnS1sRMu3+JjXwJG0j/i4RT9u4qJ+lqS/yCGap4lH4zZGzQ7tu+xZqQmcMZq5OBZDL4QRxQzRjkWcGt8IVw==", + "dev": true, + "dependencies": { + "@eslint/object-schema": "^2.1.4", + "debug": "^4.3.1", + "minimatch": "^3.1.2" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/config-array/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/@eslint/config-array/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, "node_modules/@eslint/eslintrc": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.1.4.tgz", - "integrity": "sha512-269Z39MS6wVJtsoUl10L60WdkhJVdPG24Q4eZTH3nnF6lpvSShEK3wQjDX9JRWAUPvPh7COouPpU9IrqaZFvtQ==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.1.0.tgz", + "integrity": "sha512-4Bfj15dVJdoy3RfZmmo86RK1Fwzn6SstsvK9JS+BaVKqC6QQQQyXekNaC+g+LKNgkQ+2VhGAzm6hO40AhMR3zQ==", "dev": true, - "license": "MIT", "dependencies": { "ajv": "^6.12.4", "debug": "^4.3.2", - "espree": "^9.6.0", - "globals": "^13.19.0", + "espree": "^10.0.1", + "globals": "^14.0.0", "ignore": "^5.2.0", "import-fresh": "^3.2.1", "js-yaml": "^4.1.0", @@ -722,7 +756,7 @@ "strip-json-comments": "^3.1.1" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "url": "https://opencollective.com/eslint" @@ -733,7 +767,6 @@ "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, - "license": "MIT", "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -744,7 +777,6 @@ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "dev": true, - "license": "ISC", "dependencies": { "brace-expansion": "^1.1.7" }, @@ -753,53 +785,33 @@ } }, "node_modules/@eslint/js": { - "version": "8.57.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.57.0.tgz", - "integrity": "sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g==", + "version": "9.10.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.10.0.tgz", + "integrity": "sha512-fuXtbiP5GWIn8Fz+LWoOMVf/Jxm+aajZYkhi6CuEm4SxymFM+eUWzbO9qXT+L0iCkL5+KGYMCSGxo686H19S1g==", "dev": true, - "license": "MIT", "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, - "node_modules/@humanwhocodes/config-array": { - "version": "0.11.14", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.14.tgz", - "integrity": "sha512-3T8LkOmg45BV5FICb15QQMsyUSWrQ8AygVfC7ZG32zOalnqrilm018ZVCw0eapXux8FtA33q8PSRSstjee3jSg==", - "deprecated": "Use @eslint/config-array instead", + "node_modules/@eslint/object-schema": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-2.1.4.tgz", + "integrity": "sha512-BsWiH1yFGjXXS2yvrf5LyuoSIIbPrGUWob917o+BTKuZ7qJdxX8aJLRxs1fS9n6r7vESrq1OUqb68dANcFXuQQ==", "dev": true, - "license": "Apache-2.0", - "dependencies": { - "@humanwhocodes/object-schema": "^2.0.2", - "debug": "^4.3.1", - "minimatch": "^3.0.5" - }, "engines": { - "node": ">=10.10.0" - } - }, - "node_modules/@humanwhocodes/config-array/node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, - "license": "MIT", - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, - "node_modules/@humanwhocodes/config-array/node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "node_modules/@eslint/plugin-kit": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.1.0.tgz", + "integrity": "sha512-autAXT203ixhqei9xt+qkYOvY8l6LAFIdT2UXc/RPNeUVfqRF1BV94GTJyVPFKT8nFM6MyVJhjLj9E8JWvf5zQ==", "dev": true, - "license": "ISC", "dependencies": { - "brace-expansion": "^1.1.7" + "levn": "^0.4.1" }, "engines": { - "node": "*" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, "node_modules/@humanwhocodes/module-importer": { @@ -816,13 +828,41 @@ "url": "https://github.com/sponsors/nzakas" } }, - "node_modules/@humanwhocodes/object-schema": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.3.tgz", - "integrity": "sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==", - "deprecated": "Use @eslint/object-schema instead", + "node_modules/@humanwhocodes/retry": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.3.0.tgz", + "integrity": "sha512-d2CGZR2o7fS6sWB7DG/3a95bGKQyHMACZ5aW8qGkkqQpUoZV6C0X7Pc7l4ZNMZkfNBf4VWNe9E1jRsf0G146Ew==", "dev": true, - "license": "BSD-3-Clause" + "engines": { + "node": ">=18.18" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/nzakas" + } + }, + "node_modules/@ianvs/prettier-plugin-sort-imports": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/@ianvs/prettier-plugin-sort-imports/-/prettier-plugin-sort-imports-4.3.1.tgz", + "integrity": "sha512-ZHwbyjkANZOjaBm3ZosADD2OUYGFzQGxfy67HmGZU94mHqe7g1LCMA7YYKB1Cq+UTPCBqlAYapY0KXAjKEw8Sg==", + "dev": true, + "dependencies": { + "@babel/core": "^7.24.0", + "@babel/generator": "^7.23.6", + "@babel/parser": "^7.24.0", + "@babel/traverse": "^7.24.0", + "@babel/types": "^7.24.0", + "semver": "^7.5.2" + }, + "peerDependencies": { + "@vue/compiler-sfc": "2.7.x || 3.x", + "prettier": "2 || 3" + }, + "peerDependenciesMeta": { + "@vue/compiler-sfc": { + "optional": true + } + } }, "node_modules/@isaacs/cliui": { "version": "8.0.2", @@ -1395,50 +1435,6 @@ "integrity": "sha512-Vo+PSpZG2/fmgmiNzYK9qWRh8h/CHrwD0mo1h1DzL4yzHNSfWYujGTYsWGreD000gcgmZ7K4Ys6Tx9TxtsKdDw==", "license": "MIT" }, - "node_modules/@microsoft/tsdoc": { - "version": "0.15.0", - "resolved": "https://registry.npmjs.org/@microsoft/tsdoc/-/tsdoc-0.15.0.tgz", - "integrity": "sha512-HZpPoABogPvjeJOdzCOSJsXeL/SMCBgBZMVC3X3d7YYp2gf31MfxhUoYUNwf1ERPJOnQc0wkFn9trqI6ZEdZuA==", - "dev": true, - "license": "MIT" - }, - "node_modules/@microsoft/tsdoc-config": { - "version": "0.17.0", - "resolved": "https://registry.npmjs.org/@microsoft/tsdoc-config/-/tsdoc-config-0.17.0.tgz", - "integrity": "sha512-v/EYRXnCAIHxOHW+Plb6OWuUoMotxTN0GLatnpOb1xq0KuTNw/WI3pamJx/UbsoJP5k9MCw1QxvvhPcF9pH3Zg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@microsoft/tsdoc": "0.15.0", - "ajv": "~8.12.0", - "jju": "~1.4.0", - "resolve": "~1.22.2" - } - }, - "node_modules/@microsoft/tsdoc-config/node_modules/ajv": { - "version": "8.12.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz", - "integrity": "sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==", - "dev": true, - "license": "MIT", - "dependencies": { - "fast-deep-equal": "^3.1.1", - "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2", - "uri-js": "^4.2.2" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/epoberezkin" - } - }, - "node_modules/@microsoft/tsdoc-config/node_modules/json-schema-traverse": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", - "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", - "dev": true, - "license": "MIT" - }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -1713,6 +1709,31 @@ "@types/node": "*" } }, + "node_modules/@types/eslint": { + "version": "9.6.1", + "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-9.6.1.tgz", + "integrity": "sha512-FXx2pKgId/WyYo2jXw63kk7/+TY7u7AziEJxJAnSFzHlqTAS3Ync6SvgYAN/k4/PQpnnVuzoMuVnByKK2qp0ag==", + "dev": true, + "dependencies": { + "@types/estree": "*", + "@types/json-schema": "*" + } + }, + "node_modules/@types/eslint__js": { + "version": "8.42.3", + "resolved": "https://registry.npmjs.org/@types/eslint__js/-/eslint__js-8.42.3.tgz", + "integrity": "sha512-alfG737uhmPdnvkrLdZLcEKJ/B8s9Y4hrZ+YAdzUeoArBlSUERA2E87ROfOaS4jd/C45fzOoZzidLc1IPwLqOw==", + "dev": true, + "dependencies": { + "@types/eslint": "*" + } + }, + "node_modules/@types/estree": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", + "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", + "dev": true + }, "node_modules/@types/graceful-fs": { "version": "4.1.9", "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.9.tgz", @@ -1761,6 +1782,12 @@ "pretty-format": "^29.0.0" } }, + "node_modules/@types/json-schema": { + "version": "7.0.15", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", + "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", + "dev": true + }, "node_modules/@types/node": { "version": "22.5.4", "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.4.tgz", @@ -2002,19 +2029,11 @@ "url": "https://opencollective.com/typescript-eslint" } }, - "node_modules/@ungap/structured-clone": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", - "integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==", - "dev": true, - "license": "ISC" - }, "node_modules/acorn": { "version": "8.12.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", "integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", "dev": true, - "license": "MIT", "bin": { "acorn": "bin/acorn" }, @@ -2027,7 +2046,6 @@ "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", "dev": true, - "license": "MIT", "peerDependencies": { "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } @@ -2049,7 +2067,6 @@ "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", "dev": true, - "license": "MIT", "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -2134,8 +2151,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true, - "license": "Python-2.0" + "dev": true }, "node_modules/async": { "version": "3.2.6", @@ -2728,19 +2744,6 @@ "node": ">=6" } }, - "node_modules/doctrine": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", - "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", - "dev": true, - "license": "Apache-2.0", - "dependencies": { - "esutils": "^2.0.2" - }, - "engines": { - "node": ">=6.0.0" - } - }, "node_modules/eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", @@ -2825,44 +2828,39 @@ } }, "node_modules/eslint": { - "version": "8.57.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.57.0.tgz", - "integrity": "sha512-dZ6+mexnaTIbSBZWgou51U6OmzIhYM2VcNdtiTtI7qPNZm35Akpr0f6vtw3w1Kmn5PYo+tZVfh13WrhpS6oLqQ==", + "version": "9.10.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.10.0.tgz", + "integrity": "sha512-Y4D0IgtBZfOcOUAIQTSXBKoNGfY0REGqHJG6+Q81vNippW5YlKjHFj4soMxamKK1NXHUWuBZTLdU3Km+L/pcHw==", "dev": true, - "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", - "@eslint-community/regexpp": "^4.6.1", - "@eslint/eslintrc": "^2.1.4", - "@eslint/js": "8.57.0", - "@humanwhocodes/config-array": "^0.11.14", + "@eslint-community/regexpp": "^4.11.0", + "@eslint/config-array": "^0.18.0", + "@eslint/eslintrc": "^3.1.0", + "@eslint/js": "9.10.0", + "@eslint/plugin-kit": "^0.1.0", "@humanwhocodes/module-importer": "^1.0.1", + "@humanwhocodes/retry": "^0.3.0", "@nodelib/fs.walk": "^1.2.8", - "@ungap/structured-clone": "^1.2.0", "ajv": "^6.12.4", "chalk": "^4.0.0", "cross-spawn": "^7.0.2", "debug": "^4.3.2", - "doctrine": "^3.0.0", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^7.2.2", - "eslint-visitor-keys": "^3.4.3", - "espree": "^9.6.1", - "esquery": "^1.4.2", + "eslint-scope": "^8.0.2", + "eslint-visitor-keys": "^4.0.0", + "espree": "^10.1.0", + "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", - "file-entry-cache": "^6.0.1", + "file-entry-cache": "^8.0.0", "find-up": "^5.0.0", "glob-parent": "^6.0.2", - "globals": "^13.19.0", - "graphemer": "^1.4.0", "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", "is-path-inside": "^3.0.3", - "js-yaml": "^4.1.0", "json-stable-stringify-without-jsonify": "^1.0.1", - "levn": "^0.4.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", @@ -2874,10 +2872,18 @@ "eslint": "bin/eslint.js" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { - "url": "https://opencollective.com/eslint" + "url": "https://eslint.org/donate" + }, + "peerDependencies": { + "jiti": "*" + }, + "peerDependenciesMeta": { + "jiti": { + "optional": true + } } }, "node_modules/eslint-config-prettier": { @@ -2893,92 +2899,17 @@ "eslint": ">=7.0.0" } }, - "node_modules/eslint-plugin-jest": { - "version": "28.8.3", - "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-28.8.3.tgz", - "integrity": "sha512-HIQ3t9hASLKm2IhIOqnu+ifw7uLZkIlR7RYNv7fMcEi/p0CIiJmfriStQS2LDkgtY4nyLbIZAD+JL347Yc2ETQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@typescript-eslint/utils": "^6.0.0 || ^7.0.0 || ^8.0.0" - }, - "engines": { - "node": "^16.10.0 || ^18.12.0 || >=20.0.0" - }, - "peerDependencies": { - "@typescript-eslint/eslint-plugin": "^6.0.0 || ^7.0.0 || ^8.0.0", - "eslint": "^7.0.0 || ^8.0.0 || ^9.0.0", - "jest": "*" - }, - "peerDependenciesMeta": { - "@typescript-eslint/eslint-plugin": { - "optional": true - }, - "jest": { - "optional": true - } - } - }, - "node_modules/eslint-plugin-perfectionist": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-perfectionist/-/eslint-plugin-perfectionist-3.5.0.tgz", - "integrity": "sha512-vwDNuxlAlbZJ3DjHo6GnfZrmMlJBLFrkOLBV/rYvVnLFD+x54u9VyJcGOfJ2DK9d1cd3a/C/vtBrbBNgAC6Mrg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@typescript-eslint/types": "^8.4.0", - "@typescript-eslint/utils": "^8.4.0", - "minimatch": "^9.0.5", - "natural-compare-lite": "^1.4.0" - }, - "engines": { - "node": "^18.0.0 || >=20.0.0" - }, - "peerDependencies": { - "astro-eslint-parser": "^1.0.2", - "eslint": ">=8.0.0", - "svelte": ">=3.0.0", - "svelte-eslint-parser": "^0.41.0", - "vue-eslint-parser": ">=9.0.0" - }, - "peerDependenciesMeta": { - "astro-eslint-parser": { - "optional": true - }, - "svelte": { - "optional": true - }, - "svelte-eslint-parser": { - "optional": true - }, - "vue-eslint-parser": { - "optional": true - } - } - }, - "node_modules/eslint-plugin-tsdoc": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-tsdoc/-/eslint-plugin-tsdoc-0.3.0.tgz", - "integrity": "sha512-0MuFdBrrJVBjT/gyhkP2BqpD0np1NxNLfQ38xXDlSs/KVVpKI2A6vN7jx2Rve/CyUsvOsMGwp9KKrinv7q9g3A==", - "dev": true, - "license": "MIT", - "dependencies": { - "@microsoft/tsdoc": "0.15.0", - "@microsoft/tsdoc-config": "0.17.0" - } - }, "node_modules/eslint-scope": { - "version": "7.2.2", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz", - "integrity": "sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg==", + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.0.2.tgz", + "integrity": "sha512-6E4xmrTw5wtxnLA5wYL3WDfhZ/1bUBGOXV0zQvVRDOtrR8D0p6W7fs3JweNYhwRYeGvd/1CKX2se0/2s7Q/nJA==", "dev": true, - "license": "BSD-2-Clause", "dependencies": { "esrecurse": "^4.3.0", "estraverse": "^5.2.0" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "url": "https://opencollective.com/eslint" @@ -3008,6 +2939,18 @@ "concat-map": "0.0.1" } }, + "node_modules/eslint/node_modules/eslint-visitor-keys": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.0.0.tgz", + "integrity": "sha512-OtIRv/2GyiF6o/d8K7MYKKbXrOUBIK6SfkIRM4Z0dY3w+LiQ0vy3F57m0Z71bjbyeiWFiHJ8brqnmE6H6/jEuw==", + "dev": true, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, "node_modules/eslint/node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -3022,18 +2965,29 @@ } }, "node_modules/espree": { - "version": "9.6.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz", - "integrity": "sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==", + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-10.1.0.tgz", + "integrity": "sha512-M1M6CpiE6ffoigIOWYO9UDP8TMUw9kqb21tf+08IgDYjCsOvCuDt4jQcZmoYxx+w7zlKw9/N0KXfto+I8/FrXA==", "dev": true, - "license": "BSD-2-Clause", "dependencies": { - "acorn": "^8.9.0", + "acorn": "^8.12.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^3.4.1" + "eslint-visitor-keys": "^4.0.0" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/espree/node_modules/eslint-visitor-keys": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.0.0.tgz", + "integrity": "sha512-OtIRv/2GyiF6o/d8K7MYKKbXrOUBIK6SfkIRM4Z0dY3w+LiQ0vy3F57m0Z71bjbyeiWFiHJ8brqnmE6H6/jEuw==", + "dev": true, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "url": "https://opencollective.com/eslint" @@ -3071,7 +3025,6 @@ "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", "dev": true, - "license": "BSD-2-Clause", "dependencies": { "estraverse": "^5.2.0" }, @@ -3094,7 +3047,6 @@ "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", "dev": true, - "license": "BSD-2-Clause", "engines": { "node": ">=0.10.0" } @@ -3226,16 +3178,15 @@ } }, "node_modules/file-entry-cache": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", - "integrity": "sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz", + "integrity": "sha512-XXTUwCvisa5oacNGRP9SfNtYBNAMi+RPwBFmblZEF7N7swHYQS6/Zfk7SRwx4D5j3CH211YNRco1DEMNVfZCnQ==", "dev": true, - "license": "MIT", "dependencies": { - "flat-cache": "^3.0.4" + "flat-cache": "^4.0.0" }, "engines": { - "node": "^10.12.0 || >=12.0.0" + "node": ">=16.0.0" } }, "node_modules/filelist": { @@ -3292,43 +3243,23 @@ } }, "node_modules/flat-cache": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.2.0.tgz", - "integrity": "sha512-CYcENa+FtcUKLmhhqyctpclsq7QF38pKjZHsGNiSQF5r4FtoKDWabFDl3hzaEQMvT1LHEysw5twgLvpYYb4vbw==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-4.0.1.tgz", + "integrity": "sha512-f7ccFPK3SXFHpx15UIGyRJ/FJQctuKZ0zVuN3frBo4HnK3cay9VEW0R6yPYFHC0AgqhukPzKjq22t5DmAyqGyw==", "dev": true, - "license": "MIT", "dependencies": { "flatted": "^3.2.9", - "keyv": "^4.5.3", - "rimraf": "^3.0.2" + "keyv": "^4.5.4" }, "engines": { - "node": "^10.12.0 || >=12.0.0" - } - }, - "node_modules/flat-cache/node_modules/rimraf": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", - "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", - "deprecated": "Rimraf versions prior to v4 are no longer supported", - "dev": true, - "license": "ISC", - "dependencies": { - "glob": "^7.1.3" - }, - "bin": { - "rimraf": "bin.js" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" + "node": ">=16" } }, "node_modules/flatted": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.1.tgz", "integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==", - "dev": true, - "license": "ISC" + "dev": true }, "node_modules/follow-redirects": { "version": "1.15.9", @@ -3529,16 +3460,12 @@ } }, "node_modules/globals": { - "version": "13.24.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", - "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", + "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", "dev": true, - "license": "MIT", - "dependencies": { - "type-fest": "^0.20.2" - }, "engines": { - "node": ">=8" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -3654,7 +3581,6 @@ "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", "dev": true, - "license": "MIT", "dependencies": { "parent-module": "^1.0.0", "resolve-from": "^4.0.0" @@ -4537,13 +4463,6 @@ "url": "https://github.com/chalk/supports-color?sponsor=1" } }, - "node_modules/jju": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/jju/-/jju-1.4.0.tgz", - "integrity": "sha512-8wb9Yw966OSxApiCt0K3yNJL8pnNeIv+OEq2YMidz4FKP6nonSRoOXc80iXY4JaN2FC11B9qsNmDsm+ZOfMROA==", - "dev": true, - "license": "MIT" - }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -4556,7 +4475,6 @@ "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", "dev": true, - "license": "MIT", "dependencies": { "argparse": "^2.0.1" }, @@ -4581,8 +4499,7 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==", - "dev": true, - "license": "MIT" + "dev": true }, "node_modules/json-parse-even-better-errors": { "version": "2.3.1", @@ -4595,8 +4512,7 @@ "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", - "dev": true, - "license": "MIT" + "dev": true }, "node_modules/json-stable-stringify-without-jsonify": { "version": "1.0.1", @@ -4623,7 +4539,6 @@ "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==", "dev": true, - "license": "MIT", "dependencies": { "json-buffer": "3.0.1" } @@ -4881,13 +4796,6 @@ "dev": true, "license": "MIT" }, - "node_modules/natural-compare-lite": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/natural-compare-lite/-/natural-compare-lite-1.4.0.tgz", - "integrity": "sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==", - "dev": true, - "license": "MIT" - }, "node_modules/node-addon-api": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-7.0.0.tgz", @@ -5040,7 +4948,6 @@ "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", "dev": true, - "license": "MIT", "dependencies": { "callsites": "^3.0.0" }, @@ -5382,16 +5289,6 @@ "node": ">=0.10.0" } }, - "node_modules/require-from-string": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", - "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/resolve": { "version": "1.22.8", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", @@ -5438,7 +5335,6 @@ "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", "dev": true, - "license": "MIT", "engines": { "node": ">=4" } @@ -6013,19 +5909,6 @@ "node": ">=4" } }, - "node_modules/type-fest": { - "version": "0.20.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", - "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", - "dev": true, - "license": "(MIT OR CC0-1.0)", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/typescript": { "version": "5.5.4", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", @@ -6040,6 +5923,29 @@ "node": ">=14.17" } }, + "node_modules/typescript-eslint": { + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.4.0.tgz", + "integrity": "sha512-67qoc3zQZe3CAkO0ua17+7aCLI0dU+sSQd1eKPGq06QE4rfQjstVXR6woHO5qQvGUa550NfGckT4tzh3b3c8Pw==", + "dev": true, + "dependencies": { + "@typescript-eslint/eslint-plugin": "8.4.0", + "@typescript-eslint/parser": "8.4.0", + "@typescript-eslint/utils": "8.4.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, "node_modules/undici-types": { "version": "6.19.8", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", diff --git a/package.json b/package.json index 40f11413619b8..c30b18440aa67 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "zigbee-shepherd" ], "scripts": { - "eslint": "eslint src/ --max-warnings=0", + "eslint": "eslint --max-warnings=0", "pretty:write": "prettier --write .", "pretty:check": "prettier --check .", "test": "jest test --silent --maxWorkers=50%", @@ -54,18 +54,16 @@ "zigbee-herdsman": "^0.57.3" }, "devDependencies": { + "@eslint/js": "^9.10.0", + "@ianvs/prettier-plugin-sort-imports": "^4.3.1", "@types/buffer-crc32": "^0.2.4", + "@types/eslint__js": "^8.42.3", "@types/jest": "^29.5.12", "@types/node": "^22.5.4", "@types/semver": "^7.5.8", "@types/tar-stream": "^3.1.3", - "@typescript-eslint/eslint-plugin": "^8.4.0", - "@typescript-eslint/parser": "^8.4.0", - "eslint": "^8.57.0", + "eslint": "^9.10.0", "eslint-config-prettier": "^9.1.0", - "eslint-plugin-jest": "^28.8.3", - "eslint-plugin-perfectionist": "^3.5.0", - "eslint-plugin-tsdoc": "^0.3.0", "fast-deep-equal": "*", "husky": "^9.1.5", "jest": "^29.7.0", @@ -73,7 +71,8 @@ "rimraf": "^6.0.1", "ts-jest": "^29.2.5", "ts-morph": "^23.0.0", - "typescript": "^5.5.4" + "typescript": "^5.5.4", + "typescript-eslint": "^8.4.0" }, "jest": { "preset": "ts-jest", From 79dc9dd2e9614296d9aa7a42ddcd3906dd9a870b Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Sun, 8 Sep 2024 22:10:12 +0200 Subject: [PATCH 02/12] Automatic changes --- src/converters/fromZigbee.ts | 14 +++--- src/converters/toZigbee.ts | 2 +- src/devices/ITCommander.ts | 3 +- src/devices/acova.ts | 1 + src/devices/aeotec.ts | 8 ++-- src/devices/akuvox.ts | 1 + src/devices/aldi.ts | 1 + src/devices/alecto.ts | 1 + src/devices/atlantic.ts | 2 + src/devices/aubess.ts | 1 + src/devices/aurora_lighting.ts | 7 +-- src/devices/avatto.ts | 1 + src/devices/axis.ts | 1 + src/devices/bitron.ts | 9 ++-- src/devices/bituo_technik.ts | 1 + src/devices/blaupunkt.ts | 1 + src/devices/blitzwolf.ts | 1 + src/devices/bosch.ts | 21 ++++----- src/devices/brimate.ts | 1 + src/devices/bseed.ts | 1 + src/devices/bticino.ts | 3 +- src/devices/byun.ts | 1 + src/devices/casaia.ts | 5 ++- src/devices/centralite.ts | 5 ++- src/devices/cleverio.ts | 1 + src/devices/ctm.ts | 5 ++- src/devices/current_products_corp.ts | 1 + src/devices/custom_devices_diy.ts | 27 ++++++------ src/devices/danalock.ts | 1 + src/devices/danfoss.ts | 1 + src/devices/datek.ts | 1 + src/devices/dawon_dns.ts | 1 + src/devices/develco.ts | 3 +- src/devices/digi.ts | 1 + src/devices/dlink.ts | 1 + src/devices/easyaccess.ts | 1 + src/devices/easyiot.ts | 3 +- src/devices/echostar.ts | 1 + src/devices/ecodim.ts | 5 ++- src/devices/ecolink.ts | 1 + src/devices/ecozy.ts | 1 + src/devices/efekta.ts | 14 +++--- src/devices/enbrighten.ts | 2 +- src/devices/enocean.ts | 1 + src/devices/envilar.ts | 5 ++- src/devices/eurotronic.ts | 1 + src/devices/evanell.ts | 1 + src/devices/evology.ts | 1 + src/devices/ewelink.ts | 1 + src/devices/fantem.ts | 5 ++- src/devices/feibit.ts | 10 ++--- src/devices/fireangel.ts | 1 + src/devices/frankever.ts | 1 + src/devices/frient.ts | 1 + src/devices/gewiss.ts | 1 + src/devices/giex.ts | 1 + src/devices/gledopto.ts | 4 +- src/devices/gmmts.ts | 3 +- src/devices/gs.ts | 12 +++--- src/devices/halemeier.ts | 2 +- src/devices/heiman.ts | 7 +-- src/devices/heimgard_technologies.ts | 5 ++- src/devices/hommyn.ts | 1 + src/devices/hzc.ts | 1 + src/devices/hzc_electric.ts | 1 + src/devices/ihorn.ts | 1 + src/devices/ikea.ts | 54 ++++++++++++------------ src/devices/iluminize.ts | 12 +++--- src/devices/imhotepcreation.ts | 2 +- src/devices/index.ts | 4 +- src/devices/innr.ts | 5 ++- src/devices/inovelli.ts | 2 +- src/devices/insta.ts | 1 + src/devices/iotperfect.ts | 1 + src/devices/iris.ts | 3 +- src/devices/javis.ts | 1 + src/devices/jxuan.ts | 5 ++- src/devices/kami.ts | 1 + src/devices/keen_home.ts | 1 + src/devices/kmpcil.ts | 1 + src/devices/kwikset.ts | 1 + src/devices/legrand.ts | 3 +- src/devices/lellki.ts | 5 ++- src/devices/letv.ts | 1 + src/devices/leviton.ts | 1 + src/devices/lidl.ts | 9 ++-- src/devices/lifecontrol.ts | 2 +- src/devices/linkind.ts | 7 +-- src/devices/linptech.ts | 2 +- src/devices/livolo.ts | 1 + src/devices/lixee.ts | 13 +++--- src/devices/ls.ts | 1 + src/devices/lumi.ts | 28 ++++++------ src/devices/lupus.ts | 5 ++- src/devices/lutron.ts | 1 + src/devices/lux.ts | 1 + src/devices/lytko.ts | 4 +- src/devices/meazon.ts | 1 + src/devices/mercator.ts | 1 + src/devices/miboxer.ts | 3 +- src/devices/moes.ts | 6 ++- src/devices/muller_licht.ts | 2 +- src/devices/namron.ts | 4 +- src/devices/neo.ts | 5 ++- src/devices/net2grid.ts | 1 + src/devices/netvox.ts | 1 + src/devices/nexelec.ts | 2 +- src/devices/niko.ts | 3 +- src/devices/ninja_blocks.ts | 1 + src/devices/nodon.ts | 5 ++- src/devices/nordtronic.ts | 2 +- src/devices/nous.ts | 1 + src/devices/novo.ts | 1 + src/devices/nyce.ts | 1 + src/devices/onesti.ts | 1 + src/devices/openlumi.ts | 1 + src/devices/orvibo.ts | 2 +- src/devices/osram.ts | 2 +- src/devices/oujiabao.ts | 1 + src/devices/owon.ts | 1 + src/devices/paulmann.ts | 2 +- src/devices/peq.ts | 1 + src/devices/perenio.ts | 5 ++- src/devices/philips.ts | 4 +- src/devices/plaid.ts | 1 + src/devices/plugwise.ts | 6 ++- src/devices/pushok.ts | 14 +++--- src/devices/qa.ts | 3 +- src/devices/qmotion.ts | 3 +- src/devices/qoto.ts | 1 + src/devices/rgb_genie.ts | 5 ++- src/devices/robb.ts | 12 +++--- src/devices/roome.ts | 1 + src/devices/rtx.ts | 1 + src/devices/salus_controls.ts | 1 + src/devices/saswell.ts | 1 + src/devices/sber.ts | 1 + src/devices/schlage.ts | 1 + src/devices/schneider_electric.ts | 17 ++++---- src/devices/securifi.ts | 1 + src/devices/sengled.ts | 4 +- src/devices/sercomm.ts | 1 + src/devices/shade_control.ts | 1 + src/devices/shinasystem.ts | 2 +- src/devices/siglis.ts | 4 +- src/devices/sinope.ts | 5 ++- src/devices/siterwell.ts | 1 + src/devices/skydance.ts | 1 + src/devices/smart9.ts | 1 + src/devices/smartenit.ts | 1 + src/devices/smartwings.ts | 1 + src/devices/somgoms.ts | 1 + src/devices/sonoff.ts | 13 +++--- src/devices/stelpro.ts | 3 +- src/devices/sunricher.ts | 18 ++++---- src/devices/swann.ts | 1 + src/devices/tapestry.ts | 1 + src/devices/technicolor.ts | 1 + src/devices/third_reality.ts | 3 +- src/devices/titan_products.ts | 1 + src/devices/tplink.ts | 1 + src/devices/tuya.ts | 20 ++++----- src/devices/ubisys.ts | 3 +- src/devices/uhome.ts | 1 + src/devices/universal_electronics_inc.ts | 3 +- src/devices/vesternet.ts | 1 + src/devices/viessmann.ts | 1 + src/devices/vimar.ts | 3 +- src/devices/visonic.ts | 1 + src/devices/wally.ts | 1 + src/devices/waxman.ts | 1 + src/devices/weiser.ts | 1 + src/devices/wirenboard.ts | 6 ++- src/devices/woolley.ts | 1 + src/devices/woox.ts | 1 + src/devices/wyze.ts | 1 + src/devices/xyzroe.ts | 3 +- src/devices/yale.ts | 1 + src/devices/yookee.ts | 1 + src/devices/zemismart.ts | 5 ++- src/devices/zen.ts | 1 + src/index.ts | 41 +++++++++--------- src/lib/color.ts | 4 +- src/lib/develco.ts | 8 ++-- src/lib/ewelink.ts | 2 +- src/lib/ikea.ts | 27 ++++++------ src/lib/ledvance.ts | 2 +- src/lib/legacy.ts | 10 +++-- src/lib/legrand.ts | 2 +- src/lib/light.ts | 2 +- src/lib/lumi.ts | 40 +++++++++--------- src/lib/modernExtend.ts | 52 +++++++++++------------ src/lib/ota/common.ts | 10 +++-- src/lib/ota/gmmts.ts | 3 +- src/lib/ota/index.ts | 10 ++--- src/lib/ota/inovelli.ts | 7 +-- src/lib/ota/jethome.ts | 7 +-- src/lib/ota/ledvance.ts | 7 +-- src/lib/ota/lixee.ts | 5 ++- src/lib/ota/salus.ts | 5 ++- src/lib/ota/securifi.ts | 2 +- src/lib/ota/tradfri.ts | 7 +-- src/lib/ota/ubisys.ts | 5 ++- src/lib/ota/zigbeeOTA.ts | 7 +-- src/lib/philips.ts | 2 +- src/lib/reporting.ts | 3 +- src/lib/store.ts | 2 +- src/lib/tuya.ts | 23 +++++----- src/lib/types.ts | 4 +- src/lib/ubisys.ts | 4 +- test/generateDefinition.test.ts | 11 ++--- test/modernExtend.test.ts | 4 +- test/ota.test.ts | 10 +++-- test/otaCommon.test.ts | 1 + test/sonoff.test.ts | 3 +- test/utils.ts | 9 ++-- 216 files changed, 587 insertions(+), 412 deletions(-) diff --git a/src/converters/fromZigbee.ts b/src/converters/fromZigbee.ts index 6f43425bde93d..114ad0d72109f 100644 --- a/src/converters/fromZigbee.ts +++ b/src/converters/fromZigbee.ts @@ -5,16 +5,16 @@ import {logger} from '../lib/logger'; import * as globalStore from '../lib/store'; import {Fz, KeyValue, KeyValueAny, KeyValueNumberString} from '../lib/types'; import { - precisionRound, - mapNumberRange, + addActionGroup, + batteryVoltageToPercentage, + getKey, + hasAlreadyProcessedMessage, isLegacyEnabled, - toLocalISOString, + mapNumberRange, numberWithinRange, - hasAlreadyProcessedMessage, - addActionGroup, postfixWithEndpointName, - getKey, - batteryVoltageToPercentage, + precisionRound, + toLocalISOString, } from '../lib/utils'; import * as utils from '../lib/utils'; diff --git a/src/converters/toZigbee.ts b/src/converters/toZigbee.ts index edf08691f5f26..758ad4a865698 100644 --- a/src/converters/toZigbee.ts +++ b/src/converters/toZigbee.ts @@ -7,7 +7,7 @@ import * as legacy from '../lib/legacy'; import * as light from '../lib/light'; import {logger} from '../lib/logger'; import * as globalStore from '../lib/store'; -import {Tz, KeyValue, KeyValueAny} from '../lib/types'; +import {KeyValue, KeyValueAny, Tz} from '../lib/types'; import * as utils from '../lib/utils'; const NS = 'zhc:tz'; diff --git a/src/devices/ITCommander.ts b/src/devices/ITCommander.ts index 80ceba04f863b..100f750456844 100644 --- a/src/devices/ITCommander.ts +++ b/src/devices/ITCommander.ts @@ -1,8 +1,9 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; +import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; -import * as reporting from '../lib/reporting'; const definitions: DefinitionWithExtend[] = [ { diff --git a/src/devices/acova.ts b/src/devices/acova.ts index c7cdb0459300c..465db1e86d319 100644 --- a/src/devices/acova.ts +++ b/src/devices/acova.ts @@ -3,6 +3,7 @@ import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/aeotec.ts b/src/devices/aeotec.ts index 3c5ceb9002193..070365b0659cd 100644 --- a/src/devices/aeotec.ts +++ b/src/devices/aeotec.ts @@ -1,14 +1,14 @@ import fz from '../converters/fromZigbee'; import { + commandsLevelCtrl, + commandsOnOff, + commandsWindowCovering, deviceEndpoints, deviceTemperature, + electricityMeter, identify, onOff, - electricityMeter, windowCovering, - commandsWindowCovering, - commandsOnOff, - commandsLevelCtrl, } from '../lib/modernExtend'; import {DefinitionWithExtend} from '../lib/types'; diff --git a/src/devices/akuvox.ts b/src/devices/akuvox.ts index aa2160654c8f7..54af23beaa25c 100644 --- a/src/devices/akuvox.ts +++ b/src/devices/akuvox.ts @@ -2,6 +2,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/aldi.ts b/src/devices/aldi.ts index 74c234958136a..22efd078cae5d 100644 --- a/src/devices/aldi.ts +++ b/src/devices/aldi.ts @@ -1,6 +1,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/alecto.ts b/src/devices/alecto.ts index b37210bc98882..76b246d0ba1fb 100644 --- a/src/devices/alecto.ts +++ b/src/devices/alecto.ts @@ -3,6 +3,7 @@ import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/atlantic.ts b/src/devices/atlantic.ts index fc1e5a077a087..e6d821bbe7ce0 100644 --- a/src/devices/atlantic.ts +++ b/src/devices/atlantic.ts @@ -1,4 +1,5 @@ import assert from 'assert'; + import {Zcl} from 'zigbee-herdsman'; import fz from '../converters/fromZigbee'; @@ -7,6 +8,7 @@ import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend, KeyValue, Tz} from '../lib/types'; import * as utils from '../lib/utils'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/aubess.ts b/src/devices/aubess.ts index fc9eae02b9081..3f8fa1f07b470 100644 --- a/src/devices/aubess.ts +++ b/src/devices/aubess.ts @@ -1,5 +1,6 @@ import {DefinitionWithExtend} from '../lib/types'; import * as zosung from '../lib/zosung'; + const fzZosung = zosung.fzZosung; const tzZosung = zosung.tzZosung; const ez = zosung.presetsZosung; diff --git a/src/devices/aurora_lighting.ts b/src/devices/aurora_lighting.ts index 94d9b33730b22..19d14e5b532a0 100644 --- a/src/devices/aurora_lighting.ts +++ b/src/devices/aurora_lighting.ts @@ -1,13 +1,14 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; -import * as reporting from '../lib/reporting'; -import {Configure, DefinitionWithExtend, Fz, OnEvent, Tz, Zh} from '../lib/types'; -const e = exposes.presets; import {identify, light} from '../lib/modernExtend'; import * as ota from '../lib/ota'; +import * as reporting from '../lib/reporting'; +import {Configure, DefinitionWithExtend, Fz, OnEvent, Tz, Zh} from '../lib/types'; import * as utils from '../lib/utils'; +const e = exposes.presets; + const ea = exposes.access; const tzLocal = { diff --git a/src/devices/avatto.ts b/src/devices/avatto.ts index 4ead4252178d0..5706c42c76bac 100644 --- a/src/devices/avatto.ts +++ b/src/devices/avatto.ts @@ -1,6 +1,7 @@ import * as exposes from '../lib/exposes'; import * as tuya from '../lib/tuya'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/axis.ts b/src/devices/axis.ts index efe2bc00690a0..465186dd3460c 100644 --- a/src/devices/axis.ts +++ b/src/devices/axis.ts @@ -3,6 +3,7 @@ import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ { diff --git a/src/devices/bitron.ts b/src/devices/bitron.ts index b9e6454955a93..e1268df572dbc 100644 --- a/src/devices/bitron.ts +++ b/src/devices/bitron.ts @@ -1,14 +1,15 @@ +import {Zcl} from 'zigbee-herdsman'; + import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; +import {light, onOff} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; +import {DefinitionWithExtend, Fz, KeyValueAny, Tz} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; -import {Zcl} from 'zigbee-herdsman'; - -import {onOff, light} from '../lib/modernExtend'; -import {KeyValueAny, Fz, Tz, DefinitionWithExtend} from '../lib/types'; const manufacturerOptions = {manufacturerCode: Zcl.ManufacturerCode.ASTREL_GROUP_SRL}; diff --git a/src/devices/bituo_technik.ts b/src/devices/bituo_technik.ts index 877f403b0b904..eaffc29bbf558 100644 --- a/src/devices/bituo_technik.ts +++ b/src/devices/bituo_technik.ts @@ -2,6 +2,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/blaupunkt.ts b/src/devices/blaupunkt.ts index 2a9b3eadbbd34..ec1bf1b3afb80 100644 --- a/src/devices/blaupunkt.ts +++ b/src/devices/blaupunkt.ts @@ -3,6 +3,7 @@ import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/blitzwolf.ts b/src/devices/blitzwolf.ts index 06cf80ea1286b..9d15dbe62a455 100644 --- a/src/devices/blitzwolf.ts +++ b/src/devices/blitzwolf.ts @@ -3,6 +3,7 @@ import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import {deviceEndpoints, onOff} from '../lib/modernExtend'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/bosch.ts b/src/devices/bosch.ts index fc6328ebcea5e..36839666d6dbe 100644 --- a/src/devices/bosch.ts +++ b/src/devices/bosch.ts @@ -6,25 +6,26 @@ import * as constants from '../lib/constants'; import * as exposes from '../lib/exposes'; import {logger} from '../lib/logger'; import { - identify, - light, - onOff, - quirkCheckinInterval, - deviceAddCustomCluster, + battery, binary, - numeric, + bindCluster, + deviceAddCustomCluster, + deviceEndpoints, enumLookup, - battery, humidity, iasZoneAlarm, - bindCluster, + identify, + light, + numeric, + onOff, ota, - deviceEndpoints, + quirkCheckinInterval, } from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import * as globalStore from '../lib/store'; -import {Tz, Fz, DefinitionWithExtend, KeyValue, ModernExtend, Expose} from '../lib/types'; +import {DefinitionWithExtend, Expose, Fz, KeyValue, ModernExtend, Tz} from '../lib/types'; import * as utils from '../lib/utils'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/brimate.ts b/src/devices/brimate.ts index 8e93f981f6ba8..0b80f97ba188c 100644 --- a/src/devices/brimate.ts +++ b/src/devices/brimate.ts @@ -1,6 +1,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/bseed.ts b/src/devices/bseed.ts index 1ae22bc6dcd9d..6e9ce1bef43da 100644 --- a/src/devices/bseed.ts +++ b/src/devices/bseed.ts @@ -1,6 +1,7 @@ import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/bticino.ts b/src/devices/bticino.ts index 3a85d40072031..ea8dd4aa7aca4 100644 --- a/src/devices/bticino.ts +++ b/src/devices/bticino.ts @@ -1,11 +1,12 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; -import {fzLegrand, tzLegrand, eLegrand} from '../lib/legrand'; +import {eLegrand, fzLegrand, tzLegrand} from '../lib/legrand'; import {electricityMeter, light, onOff} from '../lib/modernExtend'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/byun.ts b/src/devices/byun.ts index 938db0e230162..71495d7773c4b 100644 --- a/src/devices/byun.ts +++ b/src/devices/byun.ts @@ -1,6 +1,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/casaia.ts b/src/devices/casaia.ts index 6639282e40aac..e08676b0c2335 100644 --- a/src/devices/casaia.ts +++ b/src/devices/casaia.ts @@ -1,10 +1,11 @@ import fz from '../converters/fromZigbee'; +import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; +import {onOff} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; -import tz from '../converters/toZigbee'; -import {onOff} from '../lib/modernExtend'; const definitions: DefinitionWithExtend[] = [ { diff --git a/src/devices/centralite.ts b/src/devices/centralite.ts index 7855dc5fc95fa..f32bc7a3d4c93 100644 --- a/src/devices/centralite.ts +++ b/src/devices/centralite.ts @@ -2,14 +2,15 @@ import {Zcl} from 'zigbee-herdsman'; import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; +import * as constants from '../lib/constants'; import * as exposes from '../lib/exposes'; +import {light, onOff} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import * as globalStore from '../lib/store'; import {DefinitionWithExtend, Fz} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; -import * as constants from '../lib/constants'; -import {light, onOff} from '../lib/modernExtend'; const fzLocal = { thermostat_3156105: { diff --git a/src/devices/cleverio.ts b/src/devices/cleverio.ts index d1a24257f1e33..07d88085e9898 100644 --- a/src/devices/cleverio.ts +++ b/src/devices/cleverio.ts @@ -4,6 +4,7 @@ import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import * as tuya from '../lib/tuya'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/ctm.ts b/src/devices/ctm.ts index 2c57e60f1d965..235137a5867eb 100644 --- a/src/devices/ctm.ts +++ b/src/devices/ctm.ts @@ -4,11 +4,12 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as constants from '../lib/constants'; import * as exposes from '../lib/exposes'; -import {battery, temperature, identify, light} from '../lib/modernExtend'; +import {battery, identify, light, temperature} from '../lib/modernExtend'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; -import {KeyValue, DefinitionWithExtend, Tz, Fz} from '../lib/types'; +import {DefinitionWithExtend, Fz, KeyValue, Tz} from '../lib/types'; import * as utils from '../lib/utils'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/current_products_corp.ts b/src/devices/current_products_corp.ts index 89a91bf5a6f13..68f50377c7da0 100644 --- a/src/devices/current_products_corp.ts +++ b/src/devices/current_products_corp.ts @@ -3,6 +3,7 @@ import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/custom_devices_diy.ts b/src/devices/custom_devices_diy.ts index 3780eda1620c1..b2f64f9159b06 100644 --- a/src/devices/custom_devices_diy.ts +++ b/src/devices/custom_devices_diy.ts @@ -4,25 +4,26 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; -import * as ota from '../lib/ota'; -import * as reporting from '../lib/reporting'; -import {DefinitionWithExtend, Tz, Fz, KeyValue, KeyValueAny, Zh, Expose} from '../lib/types'; -const e = exposes.presets; -const ea = exposes.access; import { - light, - onOff, battery, - temperature, - humidity, - enumLookup, binary, + commandsOnOff, + deviceEndpoints, + enumLookup, + humidity, + light, numeric, + onOff, quirkAddEndpointCluster, - deviceEndpoints, - commandsOnOff, + temperature, } from '../lib/modernExtend'; -import {getFromLookup, getKey, postfixWithEndpointName, isEndpoint} from '../lib/utils'; +import * as ota from '../lib/ota'; +import * as reporting from '../lib/reporting'; +import {DefinitionWithExtend, Expose, Fz, KeyValue, KeyValueAny, Tz, Zh} from '../lib/types'; +import {getFromLookup, getKey, isEndpoint, postfixWithEndpointName} from '../lib/utils'; + +const e = exposes.presets; +const ea = exposes.access; const switchTypesList = { switch: 0x00, diff --git a/src/devices/danalock.ts b/src/devices/danalock.ts index 9fd1aea6c4bc9..b450de2db87ce 100644 --- a/src/devices/danalock.ts +++ b/src/devices/danalock.ts @@ -4,6 +4,7 @@ import * as exposes from '../lib/exposes'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/danfoss.ts b/src/devices/danfoss.ts index f0ec903555fa5..5e913d0e22228 100644 --- a/src/devices/danfoss.ts +++ b/src/devices/danfoss.ts @@ -7,6 +7,7 @@ import * as exposes from '../lib/exposes'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/datek.ts b/src/devices/datek.ts index d5ba5eec49ff0..9eb7a29dfabee 100644 --- a/src/devices/datek.ts +++ b/src/devices/datek.ts @@ -8,6 +8,7 @@ import * as exposes from '../lib/exposes'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/dawon_dns.ts b/src/devices/dawon_dns.ts index 798bb7fe678cb..d7de6068a823b 100644 --- a/src/devices/dawon_dns.ts +++ b/src/devices/dawon_dns.ts @@ -4,6 +4,7 @@ import * as exposes from '../lib/exposes'; import {deviceEndpoints, forcePowerSource, onOff} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend, Fz, Tz} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/develco.ts b/src/devices/develco.ts index f633d420948dc..e622135b8e5d0 100644 --- a/src/devices/develco.ts +++ b/src/devices/develco.ts @@ -10,8 +10,9 @@ import {battery, humidity, illuminance} from '../lib/modernExtend'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import * as globalStore from '../lib/store'; -import {DefinitionWithExtend, Fz, Tz, Zh, KeyValue} from '../lib/types'; +import {DefinitionWithExtend, Fz, KeyValue, Tz, Zh} from '../lib/types'; import * as utils from '../lib/utils'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/digi.ts b/src/devices/digi.ts index f0756b02198d7..f4be1d3b3c457 100644 --- a/src/devices/digi.ts +++ b/src/devices/digi.ts @@ -1,4 +1,5 @@ import {DefinitionWithExtend} from '../lib/types'; + const definitions: DefinitionWithExtend[] = [ { fingerprint: [ diff --git a/src/devices/dlink.ts b/src/devices/dlink.ts index bad854549b187..2b3af246dc97e 100644 --- a/src/devices/dlink.ts +++ b/src/devices/dlink.ts @@ -2,6 +2,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend, Fz} from '../lib/types'; + const e = exposes.presets; const fzLocal = { diff --git a/src/devices/easyaccess.ts b/src/devices/easyaccess.ts index 838655b414986..77870df79a228 100644 --- a/src/devices/easyaccess.ts +++ b/src/devices/easyaccess.ts @@ -3,6 +3,7 @@ import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/easyiot.ts b/src/devices/easyiot.ts index 98a1c9ba043f0..f376f0cd9a235 100644 --- a/src/devices/easyiot.ts +++ b/src/devices/easyiot.ts @@ -2,8 +2,7 @@ import * as iconv from 'iconv-lite'; import * as exposes from '../lib/exposes'; import {logger} from '../lib/logger'; -import {DefinitionWithExtend} from '../lib/types'; -import {Fz, Tz} from '../lib/types'; +import {DefinitionWithExtend, Fz, Tz} from '../lib/types'; const NS = 'zhc:easyiot'; const ea = exposes.access; diff --git a/src/devices/echostar.ts b/src/devices/echostar.ts index 0b3eca3bd847c..518beafb79e71 100644 --- a/src/devices/echostar.ts +++ b/src/devices/echostar.ts @@ -1,6 +1,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/ecodim.ts b/src/devices/ecodim.ts index 31e4df9dfe4fc..b189849d83be7 100644 --- a/src/devices/ecodim.ts +++ b/src/devices/ecodim.ts @@ -1,10 +1,11 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; -import {DefinitionWithExtend} from '../lib/types'; -const e = exposes.presets; import {deviceEndpoints, light} from '../lib/modernExtend'; import * as ota from '../lib/ota'; import * as tuya from '../lib/tuya'; +import {DefinitionWithExtend} from '../lib/types'; + +const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ { diff --git a/src/devices/ecolink.ts b/src/devices/ecolink.ts index 123e1ae4ec8ce..8027a73ec78f8 100644 --- a/src/devices/ecolink.ts +++ b/src/devices/ecolink.ts @@ -2,6 +2,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/ecozy.ts b/src/devices/ecozy.ts index b9c909d2f0d74..991ead63ae740 100644 --- a/src/devices/ecozy.ts +++ b/src/devices/ecozy.ts @@ -4,6 +4,7 @@ import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/efekta.ts b/src/devices/efekta.ts index 64d7b3e3fdde4..bd51d7e23d3a2 100644 --- a/src/devices/efekta.ts +++ b/src/devices/efekta.ts @@ -1,17 +1,17 @@ import {Zcl} from 'zigbee-herdsman'; import { - deviceEndpoints, - temperature, - humidity, - enumLookup, + battery, binary, - numeric, co2, + deviceEndpoints, + enumLookup, + humidity, illuminance, - soilMoisture, - battery, + numeric, pressure, + soilMoisture, + temperature, } from '../lib/modernExtend'; import {DefinitionWithExtend} from '../lib/types'; diff --git a/src/devices/enbrighten.ts b/src/devices/enbrighten.ts index 7838241e6cd62..c8aa70f7c9be9 100644 --- a/src/devices/enbrighten.ts +++ b/src/devices/enbrighten.ts @@ -1,5 +1,5 @@ import fz from '../converters/fromZigbee'; -import {onOff, light, electricityMeter} from '../lib/modernExtend'; +import {electricityMeter, light, onOff} from '../lib/modernExtend'; import {DefinitionWithExtend} from '../lib/types'; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/enocean.ts b/src/devices/enocean.ts index 78e36bf1870a0..00c5e7961bf48 100644 --- a/src/devices/enocean.ts +++ b/src/devices/enocean.ts @@ -1,6 +1,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/envilar.ts b/src/devices/envilar.ts index 40fe955db10c1..ea77f32c84170 100644 --- a/src/devices/envilar.ts +++ b/src/devices/envilar.ts @@ -1,8 +1,9 @@ +import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; +import {deviceEndpoints, electricityMeter, identify, light, onOff} from '../lib/modernExtend'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; -import fz from '../converters/fromZigbee'; -import {deviceEndpoints, light, onOff, identify, electricityMeter} from '../lib/modernExtend'; const definitions: DefinitionWithExtend[] = [ { diff --git a/src/devices/eurotronic.ts b/src/devices/eurotronic.ts index 4845fb7d0df5c..19126ddbf39ae 100644 --- a/src/devices/eurotronic.ts +++ b/src/devices/eurotronic.ts @@ -7,6 +7,7 @@ import * as exposes from '../lib/exposes'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/evanell.ts b/src/devices/evanell.ts index 63051e3aed420..7a6d3dd8f0213 100644 --- a/src/devices/evanell.ts +++ b/src/devices/evanell.ts @@ -3,6 +3,7 @@ import * as legacy from '../lib/legacy'; import * as reporting from '../lib/reporting'; import * as tuya from '../lib/tuya'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/evology.ts b/src/devices/evology.ts index 29e9a57c324ea..e2a23ce45176c 100644 --- a/src/devices/evology.ts +++ b/src/devices/evology.ts @@ -3,6 +3,7 @@ import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/ewelink.ts b/src/devices/ewelink.ts index b8f4c5760c7e5..8185f5c4f529c 100644 --- a/src/devices/ewelink.ts +++ b/src/devices/ewelink.ts @@ -3,6 +3,7 @@ import * as exposes from '../lib/exposes'; import {logger} from '../lib/logger'; import {deviceEndpoints, onOff} from '../lib/modernExtend'; import {DefinitionWithExtend, Fz} from '../lib/types'; + const e = exposes.presets; const NS = 'zhc:ewelink'; diff --git a/src/devices/fantem.ts b/src/devices/fantem.ts index 85e9e3171d068..3e2a83d1e4897 100644 --- a/src/devices/fantem.ts +++ b/src/devices/fantem.ts @@ -1,11 +1,12 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; +import {light} from '../lib/modernExtend'; +import * as tuya from '../lib/tuya'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; -import {light} from '../lib/modernExtend'; -import * as tuya from '../lib/tuya'; const definitions: DefinitionWithExtend[] = [ { diff --git a/src/devices/feibit.ts b/src/devices/feibit.ts index 1d324aee06d6d..f6ae55d35e817 100644 --- a/src/devices/feibit.ts +++ b/src/devices/feibit.ts @@ -2,15 +2,15 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import { + battery, + commandsLevelCtrl, + commandsOnOff, deviceEndpoints, + electricityMeter, identify, - onOff, light, - commandsOnOff, + onOff, windowCovering, - electricityMeter, - battery, - commandsLevelCtrl, } from '../lib/modernExtend'; import {philipsLight} from '../lib/philips'; import * as reporting from '../lib/reporting'; diff --git a/src/devices/fireangel.ts b/src/devices/fireangel.ts index cf4a6b39cc9ec..96095c157a0cc 100644 --- a/src/devices/fireangel.ts +++ b/src/devices/fireangel.ts @@ -1,6 +1,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/frankever.ts b/src/devices/frankever.ts index 8abc71869e3b0..81a24e5e67b3f 100644 --- a/src/devices/frankever.ts +++ b/src/devices/frankever.ts @@ -1,6 +1,7 @@ import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/frient.ts b/src/devices/frient.ts index 41ffbfc7a4659..35b425c06ee89 100644 --- a/src/devices/frient.ts +++ b/src/devices/frient.ts @@ -3,6 +3,7 @@ import * as exposes from '../lib/exposes'; import {electricityMeter, onOff, ota} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/gewiss.ts b/src/devices/gewiss.ts index c44b5c810f4a5..73bd77212d007 100644 --- a/src/devices/gewiss.ts +++ b/src/devices/gewiss.ts @@ -4,6 +4,7 @@ import * as exposes from '../lib/exposes'; import {deviceEndpoints, onOff} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/giex.ts b/src/devices/giex.ts index 65c9eb5b96bda..e43fc5eb15f7c 100644 --- a/src/devices/giex.ts +++ b/src/devices/giex.ts @@ -2,6 +2,7 @@ import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import * as tuya from '../lib/tuya'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const {presets: ep, access: ea} = exposes; diff --git a/src/devices/gledopto.ts b/src/devices/gledopto.ts index 77a9c39420118..1efe808766333 100644 --- a/src/devices/gledopto.ts +++ b/src/devices/gledopto.ts @@ -2,10 +2,10 @@ import tz from '../converters/toZigbee'; import * as libColor from '../lib/color'; import * as exposes from '../lib/exposes'; import {logger} from '../lib/logger'; -import {light, LightArgs, OnOffArgs, onOff, identify} from '../lib/modernExtend'; +import {identify, light, LightArgs, onOff, OnOffArgs} from '../lib/modernExtend'; import * as ota from '../lib/ota'; import * as globalStore from '../lib/store'; -import {Configure, DefinitionWithExtend, KeyValue, OnEventType, Zh, Tz, ModernExtend} from '../lib/types'; +import {Configure, DefinitionWithExtend, KeyValue, ModernExtend, OnEventType, Tz, Zh} from '../lib/types'; import * as utils from '../lib/utils'; const NS = 'zhc:gledopto'; diff --git a/src/devices/gmmts.ts b/src/devices/gmmts.ts index 73bcabe2989fb..591a9fb3d0473 100644 --- a/src/devices/gmmts.ts +++ b/src/devices/gmmts.ts @@ -1,4 +1,5 @@ import {Buffer} from 'buffer'; + import {Zcl} from 'zigbee-herdsman'; import {Device} from 'zigbee-herdsman/dist/controller/model'; @@ -9,7 +10,7 @@ import {logger} from '../lib/logger'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import * as globalStore from '../lib/store'; -import {DefinitionWithExtend, Fz, Tz, KeyValue, Zh, Expose} from '../lib/types'; +import {DefinitionWithExtend, Expose, Fz, KeyValue, Tz, Zh} from '../lib/types'; const ea = exposes.access; const e = exposes.presets; diff --git a/src/devices/gs.ts b/src/devices/gs.ts index 5483be1e006b7..5974200c4af9d 100644 --- a/src/devices/gs.ts +++ b/src/devices/gs.ts @@ -1,14 +1,14 @@ import { - light, - onOff, + battery, electricityMeter, - iasZoneAlarm, - temperature, humidity, - battery, - ignoreClusterReport, iasWarning, + iasZoneAlarm, identify, + ignoreClusterReport, + light, + onOff, + temperature, } from '../lib/modernExtend'; import {DefinitionWithExtend} from '../lib/types'; diff --git a/src/devices/halemeier.ts b/src/devices/halemeier.ts index d7b286e955d7a..0abe524130e45 100644 --- a/src/devices/halemeier.ts +++ b/src/devices/halemeier.ts @@ -1,7 +1,7 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; -import {light, battery, identify} from '../lib/modernExtend'; +import {battery, identify, light} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; diff --git a/src/devices/heiman.ts b/src/devices/heiman.ts index 87ecffc6d5c8e..64753916bfb57 100644 --- a/src/devices/heiman.ts +++ b/src/devices/heiman.ts @@ -3,12 +3,13 @@ import tz from '../converters/toZigbee'; import * as constants from '../lib/constants'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; +import {battery, iasZoneAlarm, light} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; -import {DefinitionWithExtend, Zh, Reporting} from '../lib/types'; +import * as tuya from '../lib/tuya'; +import {DefinitionWithExtend, Reporting, Zh} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; -import {light, battery, iasZoneAlarm} from '../lib/modernExtend'; -import * as tuya from '../lib/tuya'; const definitions: DefinitionWithExtend[] = [ { diff --git a/src/devices/heimgard_technologies.ts b/src/devices/heimgard_technologies.ts index fdc623c5cc109..bac961bc8187b 100644 --- a/src/devices/heimgard_technologies.ts +++ b/src/devices/heimgard_technologies.ts @@ -1,11 +1,12 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; +import {battery} from '../lib/modernExtend'; +import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; -import {battery} from '../lib/modernExtend'; -import * as ota from '../lib/ota'; const definitions: DefinitionWithExtend[] = [ { diff --git a/src/devices/hommyn.ts b/src/devices/hommyn.ts index 62a5ecf84834f..366019dc59a40 100644 --- a/src/devices/hommyn.ts +++ b/src/devices/hommyn.ts @@ -1,6 +1,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/hzc.ts b/src/devices/hzc.ts index 91b82ca0635d8..f0e232e575a99 100644 --- a/src/devices/hzc.ts +++ b/src/devices/hzc.ts @@ -3,6 +3,7 @@ import * as exposes from '../lib/exposes'; import {light} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/hzc_electric.ts b/src/devices/hzc_electric.ts index ac8908b671b77..1852c5ba46bb2 100644 --- a/src/devices/hzc_electric.ts +++ b/src/devices/hzc_electric.ts @@ -2,6 +2,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import {deviceEndpoints, light} from '../lib/modernExtend'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/ihorn.ts b/src/devices/ihorn.ts index c1423d540dc3a..8152e2e7fd66e 100644 --- a/src/devices/ihorn.ts +++ b/src/devices/ihorn.ts @@ -3,6 +3,7 @@ import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import {battery, iasZoneAlarm} from '../lib/modernExtend'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/ikea.ts b/src/devices/ikea.ts index 9fd42fc2b8d7b..b890419c758ed 100644 --- a/src/devices/ikea.ts +++ b/src/devices/ikea.ts @@ -1,46 +1,46 @@ import {Zcl} from 'zigbee-herdsman'; import { + addCustomClusterManuSpecificIkeaAirPurifier, + addCustomClusterManuSpecificIkeaUnknown, + addCustomClusterManuSpecificIkeaVocIndexMeasurement, + ikeaAirPurifier, + ikeaArrowClick, + ikeaBattery, + ikeaConfigureGenPollCtrl, ikeaConfigureRemote, - ikeaLight, - ikeaOta, ikeaConfigureStyrbar, - ikeaBattery, - ikeaAirPurifier, + ikeaDotsClick, legacy as ikeaLegacy, + ikeaLight, + ikeaMediaCommands, + ikeaOta, ikeaVoc, - ikeaConfigureGenPollCtrl, + styrbarCommandOn, + tradfriCommandsLevelCtrl, + tradfriCommandsOnOff, tradfriOccupancy, tradfriRequestedBrightness, - tradfriCommandsOnOff, - tradfriCommandsLevelCtrl, - styrbarCommandOn, - ikeaDotsClick, - ikeaArrowClick, - ikeaMediaCommands, - addCustomClusterManuSpecificIkeaUnknown, - addCustomClusterManuSpecificIkeaAirPurifier, - addCustomClusterManuSpecificIkeaVocIndexMeasurement, } from '../lib/ikea'; import { - onOff, battery, - iasZoneAlarm, - identify, + bindCluster, + commandsLevelCtrl, + commandsOnOff, + commandsWindowCovering, + deviceAddCustomCluster, + deviceEndpoints, forcePowerSource, - temperature, humidity, - occupancy, + iasZoneAlarm, + identify, illuminance, - windowCovering, - commandsOnOff, - commandsLevelCtrl, - commandsWindowCovering, - pm25, linkQuality, - deviceEndpoints, - deviceAddCustomCluster, - bindCluster, + occupancy, + onOff, + pm25, + temperature, + windowCovering, } from '../lib/modernExtend'; import * as ota from '../lib/ota'; import {DefinitionWithExtend} from '../lib/types'; diff --git a/src/devices/iluminize.ts b/src/devices/iluminize.ts index c7fcf1c79d507..930fa90a5d45a 100644 --- a/src/devices/iluminize.ts +++ b/src/devices/iluminize.ts @@ -2,15 +2,15 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import { - deviceEndpoints, - light, - onOff, battery, - identify, - commandsOnOff, - commandsLevelCtrl, commandsColorCtrl, + commandsLevelCtrl, + commandsOnOff, commandsScenes, + deviceEndpoints, + identify, + light, + onOff, } from '../lib/modernExtend'; import * as ota from '../lib/ota'; import {DefinitionWithExtend} from '../lib/types'; diff --git a/src/devices/imhotepcreation.ts b/src/devices/imhotepcreation.ts index 2c78b5191f443..3b7edf22c4593 100644 --- a/src/devices/imhotepcreation.ts +++ b/src/devices/imhotepcreation.ts @@ -3,7 +3,7 @@ import tz from '../converters/toZigbee'; import * as constants from '../lib/constants'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; -import {Zh, DefinitionWithExtend} from '../lib/types'; +import {DefinitionWithExtend, Zh} from '../lib/types'; const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/index.ts b/src/devices/index.ts index 455c0462c99e3..6502dad10da2a 100644 --- a/src/devices/index.ts +++ b/src/devices/index.ts @@ -166,6 +166,7 @@ import lixee from './lixee'; import lonsonho from './lonsonho'; import ls from './ls'; import lubeez from './lubeez'; +import lumi from './lumi'; import lupus from './lupus'; import lutron from './lutron'; import lux from './lux'; @@ -214,6 +215,7 @@ import plugwise from './plugwise'; import profalux from './profalux'; import prolight from './prolight'; import pushok from './pushok'; +import qa from './qa'; import qmotion from './qmotion'; import qoto from './qoto'; import quotra from './quotra'; @@ -284,7 +286,6 @@ import villeroy_boch from './villeroy_boch'; import vimar from './vimar'; import visonic from './visonic'; import vrey from './vrey'; -import lumi from './lumi'; import wally from './wally'; import waxman from './waxman'; import weiser from './weiser'; @@ -304,7 +305,6 @@ import zemismart from './zemismart'; import zen from './zen'; import zigbeetlc from './zigbeetlc'; import zipato from './zipato'; -import qa from './qa'; export default [ ...acova, diff --git a/src/devices/innr.ts b/src/devices/innr.ts index 6fe0a37abfcad..7cdaa9ee08026 100644 --- a/src/devices/innr.ts +++ b/src/devices/innr.ts @@ -1,10 +1,11 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; +import {electricityMeter, light, onOff, reconfigureReportingsOnDeviceAnnounce} from '../lib/modernExtend'; +import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; -import {light, onOff, electricityMeter, reconfigureReportingsOnDeviceAnnounce} from '../lib/modernExtend'; -import * as ota from '../lib/ota'; const definitions: DefinitionWithExtend[] = [ { diff --git a/src/devices/inovelli.ts b/src/devices/inovelli.ts index af03c7d8a5906..2b17f7979589e 100644 --- a/src/devices/inovelli.ts +++ b/src/devices/inovelli.ts @@ -3,7 +3,7 @@ import {Zcl} from 'zigbee-herdsman'; import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; -import {identify, deviceAddCustomCluster} from '../lib/modernExtend'; +import {deviceAddCustomCluster, identify} from '../lib/modernExtend'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import * as globalStore from '../lib/store'; diff --git a/src/devices/insta.ts b/src/devices/insta.ts index a9a4513285dac..b5b0cd23850ec 100644 --- a/src/devices/insta.ts +++ b/src/devices/insta.ts @@ -6,6 +6,7 @@ import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; import * as utils from '../lib/utils'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/iotperfect.ts b/src/devices/iotperfect.ts index 0ffc43dc4e12c..ab118f8d2cc62 100644 --- a/src/devices/iotperfect.ts +++ b/src/devices/iotperfect.ts @@ -2,6 +2,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/iris.ts b/src/devices/iris.ts index 705457d190a23..fe763dcd83b83 100644 --- a/src/devices/iris.ts +++ b/src/devices/iris.ts @@ -1,10 +1,11 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; +import {forcePowerSource, onOff} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; -import {forcePowerSource, onOff} from '../lib/modernExtend'; const definitions: DefinitionWithExtend[] = [ { diff --git a/src/devices/javis.ts b/src/devices/javis.ts index 401db96484e8f..409f3da06ee28 100644 --- a/src/devices/javis.ts +++ b/src/devices/javis.ts @@ -2,6 +2,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/jxuan.ts b/src/devices/jxuan.ts index e6ac1504a9373..19d5cc04b54b4 100644 --- a/src/devices/jxuan.ts +++ b/src/devices/jxuan.ts @@ -1,10 +1,11 @@ +import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; +import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; -import fz from '../converters/fromZigbee'; -import * as reporting from '../lib/reporting'; const definitions: DefinitionWithExtend[] = [ { diff --git a/src/devices/kami.ts b/src/devices/kami.ts index 6426d6afeff6a..6c02ff4a1a8cf 100644 --- a/src/devices/kami.ts +++ b/src/devices/kami.ts @@ -1,6 +1,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/keen_home.ts b/src/devices/keen_home.ts index f118bdf8aa9ff..136612e6931c7 100644 --- a/src/devices/keen_home.ts +++ b/src/devices/keen_home.ts @@ -4,6 +4,7 @@ import * as exposes from '../lib/exposes'; import * as lumi from '../lib/lumi'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/kmpcil.ts b/src/devices/kmpcil.ts index d3ff8d0a90226..a7532cfc5c03e 100644 --- a/src/devices/kmpcil.ts +++ b/src/devices/kmpcil.ts @@ -8,6 +8,7 @@ import * as reporting from '../lib/reporting'; import * as globalStore from '../lib/store'; import {DefinitionWithExtend, Fz, KeyValue, Publish} from '../lib/types'; import * as utils from '../lib/utils'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/kwikset.ts b/src/devices/kwikset.ts index 056e6b99d0ec7..a70b5b9fc938a 100644 --- a/src/devices/kwikset.ts +++ b/src/devices/kwikset.ts @@ -3,6 +3,7 @@ import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/legrand.ts b/src/devices/legrand.ts index 77ee2cd6d5299..42af6814a83f7 100644 --- a/src/devices/legrand.ts +++ b/src/devices/legrand.ts @@ -2,11 +2,12 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; -import {tzLegrand, fzLegrand, readInitialBatteryState, _067776, eLegrand, legrandOptions} from '../lib/legrand'; +import {_067776, eLegrand, fzLegrand, legrandOptions, readInitialBatteryState, tzLegrand} from '../lib/legrand'; import {deviceEndpoints, electricityMeter, light, onOff} from '../lib/modernExtend'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/lellki.ts b/src/devices/lellki.ts index 1fb7f330279d0..055a9d48f9ed9 100644 --- a/src/devices/lellki.ts +++ b/src/devices/lellki.ts @@ -1,12 +1,13 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; +import {deviceEndpoints, onOff} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; +import * as tuya from '../lib/tuya'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; -import {deviceEndpoints, onOff} from '../lib/modernExtend'; -import * as tuya from '../lib/tuya'; const definitions: DefinitionWithExtend[] = [ { diff --git a/src/devices/letv.ts b/src/devices/letv.ts index 965c5f1043527..4f8c9160bb6fa 100644 --- a/src/devices/letv.ts +++ b/src/devices/letv.ts @@ -1,6 +1,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/leviton.ts b/src/devices/leviton.ts index fb9f77fde9735..a1865c6dc0dc4 100644 --- a/src/devices/leviton.ts +++ b/src/devices/leviton.ts @@ -6,6 +6,7 @@ import {light, onOff} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend, Fz} from '../lib/types'; import * as utils from '../lib/utils'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/lidl.ts b/src/devices/lidl.ts index 2de3b0f0eca49..1e1b8c1b0b3fb 100644 --- a/src/devices/lidl.ts +++ b/src/devices/lidl.ts @@ -2,16 +2,17 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; -import * as reporting from '../lib/reporting'; -import {DefinitionWithExtend, Fz, Tz, KeyValue, Publish} from '../lib/types'; -const e = exposes.presets; -const ea = exposes.access; import {battery, iasZoneAlarm} from '../lib/modernExtend'; import * as ota from '../lib/ota'; +import * as reporting from '../lib/reporting'; import * as globalStore from '../lib/store'; import * as tuya from '../lib/tuya'; +import {DefinitionWithExtend, Fz, KeyValue, Publish, Tz} from '../lib/types'; import * as utils from '../lib/utils'; +const e = exposes.presets; +const ea = exposes.access; + const fzLocal = { FB20002_on: { cluster: 'genOnOff', diff --git a/src/devices/lifecontrol.ts b/src/devices/lifecontrol.ts index 71e49ff17e2fc..d58a63b773f2c 100644 --- a/src/devices/lifecontrol.ts +++ b/src/devices/lifecontrol.ts @@ -10,7 +10,7 @@ import { setupConfigureForReporting, } from '../lib/modernExtend'; import * as globalStore from '../lib/store'; -import {DefinitionWithExtend, ModernExtend, Fz, Expose, Configure, OnEvent} from '../lib/types'; +import {Configure, DefinitionWithExtend, Expose, Fz, ModernExtend, OnEvent} from '../lib/types'; const e = exposes.presets; diff --git a/src/devices/linkind.ts b/src/devices/linkind.ts index cccd77fa5ec2c..f6b6b9eb59238 100644 --- a/src/devices/linkind.ts +++ b/src/devices/linkind.ts @@ -1,13 +1,14 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; -import * as reporting from '../lib/reporting'; -const e = exposes.presets; -const ea = exposes.access; import {light, onOff} from '../lib/modernExtend'; +import * as reporting from '../lib/reporting'; import * as globalStore from '../lib/store'; import {DefinitionWithExtend} from '../lib/types'; +const e = exposes.presets; +const ea = exposes.access; + const definitions: DefinitionWithExtend[] = [ { zigbeeModel: ['ZB-KeypadGeneric-D0002'], diff --git a/src/devices/linptech.ts b/src/devices/linptech.ts index 59b46b5044412..0c06ae23d8549 100644 --- a/src/devices/linptech.ts +++ b/src/devices/linptech.ts @@ -1,7 +1,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import * as tuya from '../lib/tuya'; -import {KeyValue, DefinitionWithExtend, Tz, Fz} from '../lib/types'; +import {DefinitionWithExtend, Fz, KeyValue, Tz} from '../lib/types'; import * as utils from '../lib/utils'; const e = exposes.presets; diff --git a/src/devices/livolo.ts b/src/devices/livolo.ts index 93433af34d5c2..a799b5c13745b 100644 --- a/src/devices/livolo.ts +++ b/src/devices/livolo.ts @@ -3,6 +3,7 @@ import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as globalStore from '../lib/store'; import {DefinitionWithExtend, Zh} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/lixee.ts b/src/devices/lixee.ts index 3780aac525638..f3e4479b7b6d2 100644 --- a/src/devices/lixee.ts +++ b/src/devices/lixee.ts @@ -1,16 +1,17 @@ +import {Buffer} from 'buffer'; + import fz from '../converters/fromZigbee'; import {repInterval} from '../lib/constants'; import * as exposes from '../lib/exposes'; +import {logger} from '../lib/logger'; +import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import * as globalStore from '../lib/store'; -import {DefinitionWithExtend, Fz, Tz, KeyValue, Zh} from '../lib/types'; +import {DefinitionWithExtend, Fz, KeyValue, Tz, Zh} from '../lib/types'; +import * as utils from '../lib/utils'; + const ea = exposes.access; const e = exposes.presets; -import {Buffer} from 'buffer'; - -import {logger} from '../lib/logger'; -import * as ota from '../lib/ota'; -import * as utils from '../lib/utils'; const NS = 'zhc:lixee'; /* Start ZiPulses */ diff --git a/src/devices/ls.ts b/src/devices/ls.ts index 4671db46e6474..4ac57c2eb8548 100644 --- a/src/devices/ls.ts +++ b/src/devices/ls.ts @@ -1,6 +1,7 @@ import * as exposes from '../lib/exposes'; import {light} from '../lib/modernExtend'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/lumi.ts b/src/devices/lumi.ts index ab0d997b349e6..953969c6311d7 100644 --- a/src/devices/lumi.ts +++ b/src/devices/lumi.ts @@ -2,29 +2,33 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as constants from '../lib/constants'; import * as exposes from '../lib/exposes'; +import {logger} from '../lib/logger'; +import * as lumi from '../lib/lumi'; import { - light, - numeric, + battery, binary, + customTimeResponse, + deviceEndpoints, enumLookup, forceDeviceType, - temperature, - humidity, forcePowerSource, + humidity, + identify, + light, + numeric, + onOff, quirkAddEndpointCluster, quirkCheckinInterval, - customTimeResponse, - deviceEndpoints, - battery, - identify, + temperature, windowCovering, - onOff, } from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; +import * as globalStore from '../lib/store'; +import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; -import * as lumi from '../lib/lumi'; -import * as globalStore from '../lib/store'; + const { lumiAction, lumiOperationMode, @@ -67,8 +71,6 @@ const { lumiCommandMode, lumiBattery, } = lumi.modernExtend; -import {logger} from '../lib/logger'; -import {DefinitionWithExtend} from '../lib/types'; const NS = 'zhc:lumi'; const {manufacturerCode} = lumi; diff --git a/src/devices/lupus.ts b/src/devices/lupus.ts index ed92075d1ca12..fa238dce68486 100644 --- a/src/devices/lupus.ts +++ b/src/devices/lupus.ts @@ -1,12 +1,13 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; +import {deviceEndpoints, onOff} from '../lib/modernExtend'; +import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; -import {deviceEndpoints, onOff} from '../lib/modernExtend'; -import * as ota from '../lib/ota'; const definitions: DefinitionWithExtend[] = [ { diff --git a/src/devices/lutron.ts b/src/devices/lutron.ts index f7849571cf2ba..374c085ac4fb1 100644 --- a/src/devices/lutron.ts +++ b/src/devices/lutron.ts @@ -3,6 +3,7 @@ import * as legacy from '../lib/legacy'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/lux.ts b/src/devices/lux.ts index 94c3c2990bc1f..045b6592dcffa 100644 --- a/src/devices/lux.ts +++ b/src/devices/lux.ts @@ -3,6 +3,7 @@ import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/lytko.ts b/src/devices/lytko.ts index bac43ebff4917..0966e2505c822 100644 --- a/src/devices/lytko.ts +++ b/src/devices/lytko.ts @@ -6,8 +6,8 @@ import * as constants from '../lib/constants'; import * as exposes from '../lib/exposes'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; -import {DefinitionWithExtend, Fz, Tz, KeyValue} from '../lib/types'; -import {precisionRound, getFromLookup, postfixWithEndpointName, getKey, toNumber} from '../lib/utils'; +import {DefinitionWithExtend, Fz, KeyValue, Tz} from '../lib/types'; +import {getFromLookup, getKey, postfixWithEndpointName, precisionRound, toNumber} from '../lib/utils'; const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/meazon.ts b/src/devices/meazon.ts index 0f01c720fa8f9..cd5c2a85725e2 100644 --- a/src/devices/meazon.ts +++ b/src/devices/meazon.ts @@ -7,6 +7,7 @@ import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/mercator.ts b/src/devices/mercator.ts index 2dfb23bccdc5e..d0630faca9f3c 100644 --- a/src/devices/mercator.ts +++ b/src/devices/mercator.ts @@ -4,6 +4,7 @@ import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import * as tuya from '../lib/tuya'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/miboxer.ts b/src/devices/miboxer.ts index 276ade903496a..c44889e210876 100644 --- a/src/devices/miboxer.ts +++ b/src/devices/miboxer.ts @@ -1,8 +1,9 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; +import * as tuya from '../lib/tuya'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; -import * as tuya from '../lib/tuya'; const definitions: DefinitionWithExtend[] = [ { diff --git a/src/devices/moes.ts b/src/devices/moes.ts index a1fe0ba5d4692..db1cf58e688f4 100644 --- a/src/devices/moes.ts +++ b/src/devices/moes.ts @@ -2,13 +2,15 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; +import {actionEnumLookup, battery, deviceEndpoints, onOff} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import * as tuya from '../lib/tuya'; import {DefinitionWithExtend} from '../lib/types'; +import * as zosung from '../lib/zosung'; + const e = exposes.presets; const ea = exposes.access; -import {onOff, deviceEndpoints, actionEnumLookup, battery} from '../lib/modernExtend'; -import * as zosung from '../lib/zosung'; + const fzZosung = zosung.fzZosung; const tzZosung = zosung.tzZosung; const ez = zosung.presetsZosung; diff --git a/src/devices/muller_licht.ts b/src/devices/muller_licht.ts index c60c00b6883a0..a69fbaf3cfb31 100644 --- a/src/devices/muller_licht.ts +++ b/src/devices/muller_licht.ts @@ -2,7 +2,7 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; -import {light as lightDontUse, onOff, LightArgs} from '../lib/modernExtend'; +import {LightArgs, light as lightDontUse, onOff} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import * as tuya from '../lib/tuya'; import {DefinitionWithExtend, Zh} from '../lib/types'; diff --git a/src/devices/namron.ts b/src/devices/namron.ts index 958e622ae9317..fc9cf07204eb1 100644 --- a/src/devices/namron.ts +++ b/src/devices/namron.ts @@ -4,12 +4,12 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as constants from '../lib/constants'; import * as exposes from '../lib/exposes'; -import {forcePowerSource, light, onOff, electricityMeter} from '../lib/modernExtend'; +import {electricityMeter, forcePowerSource, light, onOff} from '../lib/modernExtend'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import * as globalStore from '../lib/store'; import * as tuya from '../lib/tuya'; -import {DefinitionWithExtend, Fz, Tz, KeyValue} from '../lib/types'; +import {DefinitionWithExtend, Fz, KeyValue, Tz} from '../lib/types'; import * as utils from '../lib/utils'; const ea = exposes.access; diff --git a/src/devices/neo.ts b/src/devices/neo.ts index 386100bacb7d3..6e6ea1a1a9dac 100644 --- a/src/devices/neo.ts +++ b/src/devices/neo.ts @@ -1,11 +1,12 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; -const e = exposes.presets; -const ea = exposes.access; import * as tuya from '../lib/tuya'; import {DefinitionWithExtend} from '../lib/types'; +const e = exposes.presets; +const ea = exposes.access; + const definitions: DefinitionWithExtend[] = [ { fingerprint: [{modelID: 'TS0601', manufacturerName: '_TZE200_d0yu2xgi'}], diff --git a/src/devices/net2grid.ts b/src/devices/net2grid.ts index 3f94a34250d18..819b05a77a2ef 100644 --- a/src/devices/net2grid.ts +++ b/src/devices/net2grid.ts @@ -4,6 +4,7 @@ import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/netvox.ts b/src/devices/netvox.ts index 3bc010bf9bce7..a6742602e4d74 100644 --- a/src/devices/netvox.ts +++ b/src/devices/netvox.ts @@ -3,6 +3,7 @@ import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/nexelec.ts b/src/devices/nexelec.ts index fd01370c48592..f387a26f1707c 100644 --- a/src/devices/nexelec.ts +++ b/src/devices/nexelec.ts @@ -1,4 +1,4 @@ -import {temperature, humidity, co2, battery, identify} from '../lib/modernExtend'; +import {battery, co2, humidity, identify, temperature} from '../lib/modernExtend'; import {DefinitionWithExtend} from '../lib/types'; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/niko.ts b/src/devices/niko.ts index 9eb85fa358bfb..50812429dad0a 100644 --- a/src/devices/niko.ts +++ b/src/devices/niko.ts @@ -2,8 +2,9 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; -import {DefinitionWithExtend, Fz, Tz, KeyValue} from '../lib/types'; +import {DefinitionWithExtend, Fz, KeyValue, Tz} from '../lib/types'; import * as utils from '../lib/utils'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/ninja_blocks.ts b/src/devices/ninja_blocks.ts index 998974267d1be..b3e1c7ff3b9f0 100644 --- a/src/devices/ninja_blocks.ts +++ b/src/devices/ninja_blocks.ts @@ -3,6 +3,7 @@ import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/nodon.ts b/src/devices/nodon.ts index 6784666c84e65..a77aa41fa684b 100644 --- a/src/devices/nodon.ts +++ b/src/devices/nodon.ts @@ -1,13 +1,14 @@ import {Zcl} from 'zigbee-herdsman'; +import fz from '../converters/fromZigbee'; +import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import {battery, deviceEndpoints, humidity, numeric, NumericArgs, onOff, temperature, windowCovering} from '../lib/modernExtend'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; -import fz from '../converters/fromZigbee'; -import tz from '../converters/toZigbee'; const nodonModernExtend = { calibrationVerticalRunTimeUp: (args?: Partial) => diff --git a/src/devices/nordtronic.ts b/src/devices/nordtronic.ts index 8c10cd13eebfa..05eb2a60f427a 100644 --- a/src/devices/nordtronic.ts +++ b/src/devices/nordtronic.ts @@ -1,4 +1,4 @@ -import {light, onOff, electricityMeter, battery, identify, commandsOnOff, commandsLevelCtrl, commandsColorCtrl} from '../lib/modernExtend'; +import {battery, commandsColorCtrl, commandsLevelCtrl, commandsOnOff, electricityMeter, identify, light, onOff} from '../lib/modernExtend'; import {DefinitionWithExtend} from '../lib/types'; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/nous.ts b/src/devices/nous.ts index cab6700d1bb94..f388b3b10e71f 100644 --- a/src/devices/nous.ts +++ b/src/devices/nous.ts @@ -4,6 +4,7 @@ import * as legacy from '../lib/legacy'; import * as reporting from '../lib/reporting'; import * as tuya from '../lib/tuya'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/novo.ts b/src/devices/novo.ts index 677e4c49ab18d..cdbb55f5cb25a 100644 --- a/src/devices/novo.ts +++ b/src/devices/novo.ts @@ -2,6 +2,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/nyce.ts b/src/devices/nyce.ts index 28b3535d18fb3..d911e3c8ea79a 100644 --- a/src/devices/nyce.ts +++ b/src/devices/nyce.ts @@ -2,6 +2,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/onesti.ts b/src/devices/onesti.ts index d68078ca67151..7d6538e17dc86 100644 --- a/src/devices/onesti.ts +++ b/src/devices/onesti.ts @@ -4,6 +4,7 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/openlumi.ts b/src/devices/openlumi.ts index 82253a3e093f9..cfea6e2f6c256 100644 --- a/src/devices/openlumi.ts +++ b/src/devices/openlumi.ts @@ -3,6 +3,7 @@ import * as constants from '../lib/constants'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/orvibo.ts b/src/devices/orvibo.ts index 4e97bd25ba68b..410c4ea0b251d 100644 --- a/src/devices/orvibo.ts +++ b/src/devices/orvibo.ts @@ -1,7 +1,7 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; -import {deviceEndpoints, light, onOff, battery, humidity, temperature} from '../lib/modernExtend'; +import {battery, deviceEndpoints, humidity, light, onOff, temperature} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend, Tz} from '../lib/types'; diff --git a/src/devices/osram.ts b/src/devices/osram.ts index 477f78b67de22..aeaf3ef70166e 100644 --- a/src/devices/osram.ts +++ b/src/devices/osram.ts @@ -1,6 +1,6 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; -import {ledvanceLight, ledvanceFz, ledvanceOnOff} from '../lib/ledvance'; +import {ledvanceFz, ledvanceLight, ledvanceOnOff} from '../lib/ledvance'; import * as legacy from '../lib/legacy'; import {deviceEndpoints} from '../lib/modernExtend'; import * as ota from '../lib/ota'; diff --git a/src/devices/oujiabao.ts b/src/devices/oujiabao.ts index b5060b9a3d2fb..09ced01868d01 100644 --- a/src/devices/oujiabao.ts +++ b/src/devices/oujiabao.ts @@ -1,6 +1,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/owon.ts b/src/devices/owon.ts index 6544588d0d1b4..5ecfaa1e03fb1 100644 --- a/src/devices/owon.ts +++ b/src/devices/owon.ts @@ -7,6 +7,7 @@ import {battery, iasZoneAlarm} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import * as tuya from '../lib/tuya'; import {DefinitionWithExtend, Fz, KeyValue} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/paulmann.ts b/src/devices/paulmann.ts index b43d23930beca..04383779597b0 100644 --- a/src/devices/paulmann.ts +++ b/src/devices/paulmann.ts @@ -1,6 +1,6 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; -import {light, onOff, deviceEndpoints, battery, commandsOnOff, commandsLevelCtrl, commandsColorCtrl, commandsScenes} from '../lib/modernExtend'; +import {battery, commandsColorCtrl, commandsLevelCtrl, commandsOnOff, commandsScenes, deviceEndpoints, light, onOff} from '../lib/modernExtend'; import {DefinitionWithExtend} from '../lib/types'; const e = exposes.presets; diff --git a/src/devices/peq.ts b/src/devices/peq.ts index 75d4c2ce745ef..8987f634310c1 100644 --- a/src/devices/peq.ts +++ b/src/devices/peq.ts @@ -2,6 +2,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/perenio.ts b/src/devices/perenio.ts index 2a3d3bdf25a36..34d1b383504ff 100644 --- a/src/devices/perenio.ts +++ b/src/devices/perenio.ts @@ -1,12 +1,13 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; +import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; -import {DefinitionWithExtend, Fz, Tz, KeyValue} from '../lib/types'; +import {DefinitionWithExtend, Fz, KeyValue, Tz} from '../lib/types'; import * as utils from '../lib/utils'; + const e = exposes.presets; const ea = exposes.access; -import * as ota from '../lib/ota'; const switchTypeValues = ['maintained_state', 'maintained_toggle', 'momentary_state', 'momentary_press', 'momentary_release']; diff --git a/src/devices/philips.ts b/src/devices/philips.ts index 6e9674cee5dfd..8acf79e35928b 100644 --- a/src/devices/philips.ts +++ b/src/devices/philips.ts @@ -4,9 +4,9 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; -import {deviceEndpoints, quirkCheckinInterval, identify} from '../lib/modernExtend'; +import {deviceEndpoints, identify, quirkCheckinInterval} from '../lib/modernExtend'; import * as ota from '../lib/ota'; -import {philipsOnOff, philipsLight, philipsFz, philipsTz} from '../lib/philips'; +import {philipsFz, philipsLight, philipsOnOff, philipsTz} from '../lib/philips'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; diff --git a/src/devices/plaid.ts b/src/devices/plaid.ts index 82b040eec9f0d..cf2a1d99424b5 100644 --- a/src/devices/plaid.ts +++ b/src/devices/plaid.ts @@ -2,6 +2,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/plugwise.ts b/src/devices/plugwise.ts index 4f729b342858f..755d6d436837c 100644 --- a/src/devices/plugwise.ts +++ b/src/devices/plugwise.ts @@ -1,12 +1,14 @@ +import * as zigbeeHerdsman from 'zigbee-herdsman/dist'; + import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; -import {DefinitionWithExtend, Fz, Tz, KeyValue} from '../lib/types'; +import {DefinitionWithExtend, Fz, KeyValue, Tz} from '../lib/types'; import * as utils from '../lib/utils'; + const e = exposes.presets; const ea = exposes.access; -import * as zigbeeHerdsman from 'zigbee-herdsman/dist'; const manufacturerOptions = {manufacturerCode: zigbeeHerdsman.Zcl.ManufacturerCode.PLUGWISE_B_V}; diff --git a/src/devices/pushok.ts b/src/devices/pushok.ts index a4f9cb6187885..fbd8f4314756c 100644 --- a/src/devices/pushok.ts +++ b/src/devices/pushok.ts @@ -1,16 +1,16 @@ import { - identify, - onOff, - temperature, + battery, binary, - numeric, enumLookup, - battery, + EnumLookupArgs, humidity, + identify, illuminance, - ota, - EnumLookupArgs, + numeric, NumericArgs, + onOff, + ota, + temperature, } from '../lib/modernExtend'; import {DefinitionWithExtend} from '../lib/types'; diff --git a/src/devices/qa.ts b/src/devices/qa.ts index f224c27a65b06..d951b98111fe2 100644 --- a/src/devices/qa.ts +++ b/src/devices/qa.ts @@ -2,10 +2,11 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; -import {deviceEndpoints, actionEnumLookup, light} from '../lib/modernExtend'; +import {actionEnumLookup, deviceEndpoints, light} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import * as tuya from '../lib/tuya'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/qmotion.ts b/src/devices/qmotion.ts index 0e042d924801c..64fa2f23fd91a 100644 --- a/src/devices/qmotion.ts +++ b/src/devices/qmotion.ts @@ -1,10 +1,11 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; +import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; -import * as reporting from '../lib/reporting'; const definitions: DefinitionWithExtend[] = [ { diff --git a/src/devices/qoto.ts b/src/devices/qoto.ts index 0922fd8ba76fe..9f65b11282848 100644 --- a/src/devices/qoto.ts +++ b/src/devices/qoto.ts @@ -3,6 +3,7 @@ import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import * as tuya from '../lib/tuya'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/rgb_genie.ts b/src/devices/rgb_genie.ts index a09b8473ddc68..d600e57e2597f 100644 --- a/src/devices/rgb_genie.ts +++ b/src/devices/rgb_genie.ts @@ -1,11 +1,12 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; +import {light} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend, Fz} from '../lib/types'; -const e = exposes.presets; -import {light} from '../lib/modernExtend'; import * as utils from '../lib/utils'; +const e = exposes.presets; + const fzLocal = { // ZB-1026 requires separate on/off converters since it re-uses the transaction number // https://github.com/Koenkk/zigbee2mqtt/issues/12957 diff --git a/src/devices/robb.ts b/src/devices/robb.ts index a360e574055c3..5fd07f34ad180 100644 --- a/src/devices/robb.ts +++ b/src/devices/robb.ts @@ -2,17 +2,17 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import { + battery, deviceEndpoints, electricityMeter, + humidity, + iasZoneAlarm, + identify, + illuminance, light, - onOff, - battery, occupancy, + onOff, temperature, - illuminance, - humidity, - identify, - iasZoneAlarm, } from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; diff --git a/src/devices/roome.ts b/src/devices/roome.ts index d334e8f3a077a..17c6172a908db 100644 --- a/src/devices/roome.ts +++ b/src/devices/roome.ts @@ -1,6 +1,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/rtx.ts b/src/devices/rtx.ts index 292acc13bfa0b..fa46db5f1cde8 100644 --- a/src/devices/rtx.ts +++ b/src/devices/rtx.ts @@ -3,6 +3,7 @@ import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import * as tuya from '../lib/tuya'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/salus_controls.ts b/src/devices/salus_controls.ts index f1402637a8d53..ef9f498a68fa0 100644 --- a/src/devices/salus_controls.ts +++ b/src/devices/salus_controls.ts @@ -5,6 +5,7 @@ import {electricityMeter, onOff} from '../lib/modernExtend'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/saswell.ts b/src/devices/saswell.ts index 35b9f453e0d37..669a8f391fa9f 100644 --- a/src/devices/saswell.ts +++ b/src/devices/saswell.ts @@ -4,6 +4,7 @@ import * as legacy from '../lib/legacy'; import * as reporting from '../lib/reporting'; import * as tuya from '../lib/tuya'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/sber.ts b/src/devices/sber.ts index 5f979c275097b..0d09286f42403 100644 --- a/src/devices/sber.ts +++ b/src/devices/sber.ts @@ -1,6 +1,7 @@ import {battery, humidity, iasZoneAlarm, ignoreClusterReport, temperature} from '../lib/modernExtend'; import {modernExtend as tuyaModernExtend} from '../lib/tuya'; import {DefinitionWithExtend} from '../lib/types'; + const {tuyaMagicPacket, tuyaOnOffActionLegacy} = tuyaModernExtend; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/schlage.ts b/src/devices/schlage.ts index 805b323fdccf1..2941896bfe55a 100644 --- a/src/devices/schlage.ts +++ b/src/devices/schlage.ts @@ -3,6 +3,7 @@ import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/schneider_electric.ts b/src/devices/schneider_electric.ts index a5f6083907e34..bf39d05327362 100644 --- a/src/devices/schneider_electric.ts +++ b/src/devices/schneider_electric.ts @@ -6,22 +6,23 @@ import * as constants from '../lib/constants'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import { - onOff, - commandsOnOff, - commandsLevelCtrl, - light, battery, + commandsLevelCtrl, + commandsOnOff, + deviceAddCustomCluster, + deviceEndpoints, electricityMeter, - identify, enumLookup, - deviceEndpoints, - deviceAddCustomCluster, + identify, + light, + onOff, } from '../lib/modernExtend'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; -import {DefinitionWithExtend, Fz, Tz, KeyValue, ModernExtend} from '../lib/types'; +import {DefinitionWithExtend, Fz, KeyValue, ModernExtend, Tz} from '../lib/types'; import * as utils from '../lib/utils'; import {postfixWithEndpointName} from '../lib/utils'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/securifi.ts b/src/devices/securifi.ts index 8f8b7815378a7..6d3a39af7a1d0 100644 --- a/src/devices/securifi.ts +++ b/src/devices/securifi.ts @@ -4,6 +4,7 @@ import * as exposes from '../lib/exposes'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/sengled.ts b/src/devices/sengled.ts index 1fe77d66d8b71..8ca61b4904a6b 100644 --- a/src/devices/sengled.ts +++ b/src/devices/sengled.ts @@ -1,6 +1,6 @@ import {presets} from '../lib/exposes'; -import {onOff, LightArgs, light as lightDontUse, electricityMeter, forcePowerSource, ota, iasZoneAlarm, battery} from '../lib/modernExtend'; -import {DefinitionWithExtend, Expose, ModernExtend, Fz, KeyValueAny} from '../lib/types'; +import {battery, electricityMeter, forcePowerSource, iasZoneAlarm, LightArgs, light as lightDontUse, onOff, ota} from '../lib/modernExtend'; +import {DefinitionWithExtend, Expose, Fz, KeyValueAny, ModernExtend} from '../lib/types'; export function sengledLight(args?: LightArgs) { return lightDontUse({effect: false, powerOnBehavior: false, ...args}); diff --git a/src/devices/sercomm.ts b/src/devices/sercomm.ts index c5710bee4c924..f4c639fe57b0f 100644 --- a/src/devices/sercomm.ts +++ b/src/devices/sercomm.ts @@ -3,6 +3,7 @@ import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/shade_control.ts b/src/devices/shade_control.ts index d5028a4a75907..98792bfb3a47d 100644 --- a/src/devices/shade_control.ts +++ b/src/devices/shade_control.ts @@ -3,6 +3,7 @@ import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/shinasystem.ts b/src/devices/shinasystem.ts index eac17a7df118e..cda75e8931e75 100644 --- a/src/devices/shinasystem.ts +++ b/src/devices/shinasystem.ts @@ -1,7 +1,7 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; -import {onOff, numeric, enumLookup, deviceEndpoints} from '../lib/modernExtend'; +import {deviceEndpoints, enumLookup, numeric, onOff} from '../lib/modernExtend'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import * as globalStore from '../lib/store'; diff --git a/src/devices/siglis.ts b/src/devices/siglis.ts index cf7a217fa13f7..bec6793d65143 100644 --- a/src/devices/siglis.ts +++ b/src/devices/siglis.ts @@ -1,10 +1,10 @@ -/* eslint-disable linebreak-style */ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; -import {DefinitionWithExtend, Fz, Tz, KeyValue, Zh} from '../lib/types'; +import {DefinitionWithExtend, Fz, KeyValue, Tz, Zh} from '../lib/types'; import * as utils from '../lib/utils'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/sinope.ts b/src/devices/sinope.ts index 2796d2923b400..5694b64bc85b7 100644 --- a/src/devices/sinope.ts +++ b/src/devices/sinope.ts @@ -5,13 +5,14 @@ import tz from '../converters/toZigbee'; import * as constants from '../lib/constants'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; +import {electricityMeter, light, onOff} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend, Fz, KeyValue, KeyValueAny, Tz} from '../lib/types'; import * as utils from '../lib/utils'; +import {precisionRound} from '../lib/utils'; + const e = exposes.presets; const ea = exposes.access; -import {onOff, electricityMeter, light} from '../lib/modernExtend'; -import {precisionRound} from '../lib/utils'; const manuSinope = {manufacturerCode: Zcl.ManufacturerCode.SINOPE_TECHNOLOGIES}; diff --git a/src/devices/siterwell.ts b/src/devices/siterwell.ts index 7cba68769b999..4dc66c9e25092 100644 --- a/src/devices/siterwell.ts +++ b/src/devices/siterwell.ts @@ -2,6 +2,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/skydance.ts b/src/devices/skydance.ts index 545094978242e..9d1b40d91116b 100644 --- a/src/devices/skydance.ts +++ b/src/devices/skydance.ts @@ -2,6 +2,7 @@ import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import * as tuya from '../lib/tuya'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/smart9.ts b/src/devices/smart9.ts index 946cd0a7e639f..488db8cb6f465 100644 --- a/src/devices/smart9.ts +++ b/src/devices/smart9.ts @@ -2,6 +2,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/smartenit.ts b/src/devices/smartenit.ts index beacc2e53be9c..2c9bc86cbb13c 100644 --- a/src/devices/smartenit.ts +++ b/src/devices/smartenit.ts @@ -3,6 +3,7 @@ import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/smartwings.ts b/src/devices/smartwings.ts index ec2dede8add4b..c4c01f81bb839 100644 --- a/src/devices/smartwings.ts +++ b/src/devices/smartwings.ts @@ -3,6 +3,7 @@ import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/somgoms.ts b/src/devices/somgoms.ts index 5d00b292882f1..4135116c16953 100644 --- a/src/devices/somgoms.ts +++ b/src/devices/somgoms.ts @@ -2,6 +2,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/sonoff.ts b/src/devices/sonoff.ts index 863e1d8105791..c342f117828cc 100644 --- a/src/devices/sonoff.ts +++ b/src/devices/sonoff.ts @@ -7,23 +7,24 @@ import {modernExtend as ewelinkModernExtend} from '../lib/ewelink'; import * as exposes from '../lib/exposes'; import {logger} from '../lib/logger'; import { + battery, binary, + bindCluster, + customTimeResponse, + deviceAddCustomCluster, enumLookup, forcePowerSource, + humidity, + iasZoneAlarm, numeric, onOff, - customTimeResponse, - battery, ota, - deviceAddCustomCluster, temperature, - humidity, - bindCluster, - iasZoneAlarm, } from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend, Fz, KeyValue, KeyValueAny, ModernExtend, Tz} from '../lib/types'; import * as utils from '../lib/utils'; + const {ewelinkAction} = ewelinkModernExtend; const NS = 'zhc:sonoff'; diff --git a/src/devices/stelpro.ts b/src/devices/stelpro.ts index 554fb88a2fcaf..2c8a6449bdfa8 100644 --- a/src/devices/stelpro.ts +++ b/src/devices/stelpro.ts @@ -1,11 +1,12 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; +import * as constants from '../lib/constants'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend, Fz} from '../lib/types'; + const e = exposes.presets; -import * as constants from '../lib/constants'; const fzLocal = { power: { diff --git a/src/devices/sunricher.ts b/src/devices/sunricher.ts index 4b9d2a5fd1c97..7e4a7b20c4653 100644 --- a/src/devices/sunricher.ts +++ b/src/devices/sunricher.ts @@ -7,20 +7,20 @@ import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import {logger} from '../lib/logger'; import { + battery, + commandsColorCtrl, + commandsLevelCtrl, + commandsOnOff, + commandsScenes, deviceEndpoints, electricityMeter, - light, - onOff, - battery, + humidity, identify, + illuminance, + light, occupancy, + onOff, temperature, - humidity, - illuminance, - commandsOnOff, - commandsLevelCtrl, - commandsColorCtrl, - commandsScenes, } from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import * as globalStore from '../lib/store'; diff --git a/src/devices/swann.ts b/src/devices/swann.ts index 7c196ae07f7fe..83dfd4bd44137 100644 --- a/src/devices/swann.ts +++ b/src/devices/swann.ts @@ -2,6 +2,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/tapestry.ts b/src/devices/tapestry.ts index 7b002c961ea86..4a828bcbeb51a 100644 --- a/src/devices/tapestry.ts +++ b/src/devices/tapestry.ts @@ -1,6 +1,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/technicolor.ts b/src/devices/technicolor.ts index a4aea7349f0d2..8d697ab8f1fbc 100644 --- a/src/devices/technicolor.ts +++ b/src/devices/technicolor.ts @@ -4,6 +4,7 @@ import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import * as globalStore from '../lib/store'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/third_reality.ts b/src/devices/third_reality.ts index 60f1f0492b95b..7d9739907888f 100644 --- a/src/devices/third_reality.ts +++ b/src/devices/third_reality.ts @@ -3,8 +3,7 @@ import {Zcl} from 'zigbee-herdsman'; import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; -import {forcePowerSource, iasZoneAlarm, light, onOff} from '../lib/modernExtend'; -import {temperature, humidity, battery, deviceAddCustomCluster} from '../lib/modernExtend'; +import {battery, deviceAddCustomCluster, forcePowerSource, humidity, iasZoneAlarm, light, onOff, temperature} from '../lib/modernExtend'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend, Fz, KeyValue} from '../lib/types'; diff --git a/src/devices/titan_products.ts b/src/devices/titan_products.ts index 6f3c7a7efe674..a0a31570db3bd 100644 --- a/src/devices/titan_products.ts +++ b/src/devices/titan_products.ts @@ -2,6 +2,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/tplink.ts b/src/devices/tplink.ts index a688f1496eac3..ab1ebb2fe3cf5 100644 --- a/src/devices/tplink.ts +++ b/src/devices/tplink.ts @@ -2,6 +2,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/tuya.ts b/src/devices/tuya.ts index 715ccfe5b69fd..2de8c8ed41990 100644 --- a/src/devices/tuya.ts +++ b/src/devices/tuya.ts @@ -6,26 +6,26 @@ import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import {logger} from '../lib/logger'; import { - onOff, - quirkCheckinInterval, + actionEnumLookup, battery, + commandsLevelCtrl, + commandsOnOff, deviceEndpoints, - light, - iasZoneAlarm, - temperature, + electricityMeter, humidity, + iasZoneAlarm, identify, - actionEnumLookup, - commandsOnOff, - commandsLevelCtrl, - electricityMeter, + light, + onOff, + quirkCheckinInterval, + temperature, windowCovering, } from '../lib/modernExtend'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import * as globalStore from '../lib/store'; import * as tuya from '../lib/tuya'; -import {KeyValue, DefinitionWithExtend, Zh, Tz, Fz, Expose, KeyValueAny, KeyValueString, ModernExtend} from '../lib/types'; +import {DefinitionWithExtend, Expose, Fz, KeyValue, KeyValueAny, KeyValueString, ModernExtend, Tz, Zh} from '../lib/types'; import * as utils from '../lib/utils'; import {addActionGroup, hasAlreadyProcessedMessage, postfixWithEndpointName} from '../lib/utils'; import * as zosung from '../lib/zosung'; diff --git a/src/devices/ubisys.ts b/src/devices/ubisys.ts index df72dcce8ca70..5af18d611f1b6 100644 --- a/src/devices/ubisys.ts +++ b/src/devices/ubisys.ts @@ -1,4 +1,5 @@ import * as semver from 'semver'; + import {Zcl} from 'zigbee-herdsman'; import fz from '../converters/fromZigbee'; @@ -10,7 +11,7 @@ import {logger} from '../lib/logger'; import {commandsColorCtrl, commandsLevelCtrl, commandsOnOff, deviceEndpoints, electricityMeter, identify, onOff} from '../lib/modernExtend'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; -import {DefinitionWithExtend, Fz, OnEventType, Tz, OnEventData, Zh, KeyValue, KeyValueAny} from '../lib/types'; +import {DefinitionWithExtend, Fz, KeyValue, KeyValueAny, OnEventData, OnEventType, Tz, Zh} from '../lib/types'; import {ubisysModernExtend} from '../lib/ubisys'; import * as utils from '../lib/utils'; diff --git a/src/devices/uhome.ts b/src/devices/uhome.ts index cdab74c821371..11f04ed8b2783 100644 --- a/src/devices/uhome.ts +++ b/src/devices/uhome.ts @@ -4,6 +4,7 @@ import * as exposes from '../lib/exposes'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/universal_electronics_inc.ts b/src/devices/universal_electronics_inc.ts index 858d9d92804bb..10b0a17de0c4f 100644 --- a/src/devices/universal_electronics_inc.ts +++ b/src/devices/universal_electronics_inc.ts @@ -2,10 +2,11 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; +import * as globalStore from '../lib/store'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; -import * as globalStore from '../lib/store'; const definitions: DefinitionWithExtend[] = [ { diff --git a/src/devices/vesternet.ts b/src/devices/vesternet.ts index 9b7cfcea2e6b8..8a791667d82ce 100644 --- a/src/devices/vesternet.ts +++ b/src/devices/vesternet.ts @@ -4,6 +4,7 @@ import * as exposes from '../lib/exposes'; import {electricityMeter, light} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/viessmann.ts b/src/devices/viessmann.ts index 3da261f86ac42..67635e756cb2f 100644 --- a/src/devices/viessmann.ts +++ b/src/devices/viessmann.ts @@ -6,6 +6,7 @@ import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/vimar.ts b/src/devices/vimar.ts index 7dbcba7deaf71..8782d4bbd516a 100644 --- a/src/devices/vimar.ts +++ b/src/devices/vimar.ts @@ -1,9 +1,10 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; -import {onOff, light} from '../lib/modernExtend'; +import {light, onOff} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/visonic.ts b/src/devices/visonic.ts index 4f9dbb4bd8dd0..cdaf40914c135 100644 --- a/src/devices/visonic.ts +++ b/src/devices/visonic.ts @@ -3,6 +3,7 @@ import * as exposes from '../lib/exposes'; import {battery, iasZoneAlarm, temperature} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/wally.ts b/src/devices/wally.ts index 89c906d7b5e50..c6257d8ab1f1d 100644 --- a/src/devices/wally.ts +++ b/src/devices/wally.ts @@ -2,6 +2,7 @@ import fz from '../converters/fromZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/waxman.ts b/src/devices/waxman.ts index 8a152a4880dfb..1f2d1df1400ae 100644 --- a/src/devices/waxman.ts +++ b/src/devices/waxman.ts @@ -3,6 +3,7 @@ import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/weiser.ts b/src/devices/weiser.ts index 863ea2ad6bea5..8620a948c9df7 100644 --- a/src/devices/weiser.ts +++ b/src/devices/weiser.ts @@ -4,6 +4,7 @@ import * as constants from '../lib/constants'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/wirenboard.ts b/src/devices/wirenboard.ts index ca1574ed5004d..8cc000e91187b 100644 --- a/src/devices/wirenboard.ts +++ b/src/devices/wirenboard.ts @@ -2,12 +2,14 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as constants from '../lib/constants'; import * as exposes from '../lib/exposes'; +import * as modernExtend from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import {Configure, DefinitionWithExtend, Fz, KeyValueAny, ModernExtend, Tz} from '../lib/types'; +import {assertString, getFromLookup, getOptions, toNumber} from '../lib/utils'; + const e = exposes.presets; const ea = exposes.access; -import * as modernExtend from '../lib/modernExtend'; -import {assertString, getFromLookup, getOptions, toNumber} from '../lib/utils'; + const {forcePowerSource, temperature, humidity, co2, deviceEndpoints, onOff, illuminance, occupancy, ota} = modernExtend; const sprutCode = 0x6666; diff --git a/src/devices/woolley.ts b/src/devices/woolley.ts index 45de463ea1d3e..d02b2b84bc6c7 100644 --- a/src/devices/woolley.ts +++ b/src/devices/woolley.ts @@ -4,6 +4,7 @@ import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend, Fz, KeyValue} from '../lib/types'; import * as utils from '../lib/utils'; + const e = exposes.presets; const fzLocal = { diff --git a/src/devices/woox.ts b/src/devices/woox.ts index 07eaab15d5168..7c64cfbb150bd 100644 --- a/src/devices/woox.ts +++ b/src/devices/woox.ts @@ -5,6 +5,7 @@ import * as legacy from '../lib/legacy'; import * as reporting from '../lib/reporting'; import * as tuya from '../lib/tuya'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/wyze.ts b/src/devices/wyze.ts index 3c6181617ee82..251a8d08062e7 100644 --- a/src/devices/wyze.ts +++ b/src/devices/wyze.ts @@ -3,6 +3,7 @@ import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/xyzroe.ts b/src/devices/xyzroe.ts index a7c1ae4f3d629..44329792c3046 100644 --- a/src/devices/xyzroe.ts +++ b/src/devices/xyzroe.ts @@ -2,8 +2,9 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; -import {DefinitionWithExtend, Tz, Fz, KeyValueAny} from '../lib/types'; +import {DefinitionWithExtend, Fz, KeyValueAny, Tz} from '../lib/types'; import * as utils from '../lib/utils'; + const e = exposes.presets; const ea = exposes.access; diff --git a/src/devices/yale.ts b/src/devices/yale.ts index fa29951ea0b91..c7af4d5375fb5 100644 --- a/src/devices/yale.ts +++ b/src/devices/yale.ts @@ -1,4 +1,5 @@ import {DefinitionWithExtend, Fz, ModernExtend, Reporting, Tz} from 'src/lib/types'; + import {KeyValue} from 'zigbee-herdsman/dist/controller/tstype'; import fz from '../converters/fromZigbee'; diff --git a/src/devices/yookee.ts b/src/devices/yookee.ts index 8469205146789..f39195748dfb0 100644 --- a/src/devices/yookee.ts +++ b/src/devices/yookee.ts @@ -3,6 +3,7 @@ import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/devices/zemismart.ts b/src/devices/zemismart.ts index 0cc1dbcd72ebf..4e43079631e07 100644 --- a/src/devices/zemismart.ts +++ b/src/devices/zemismart.ts @@ -2,11 +2,12 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; +import {battery, deviceEndpoints, forcePowerSource, identify, light, onOff} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; +import * as tuya from '../lib/tuya'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; -import {forcePowerSource, light, onOff, identify, deviceEndpoints, battery} from '../lib/modernExtend'; -import * as tuya from '../lib/tuya'; const ea = exposes.access; diff --git a/src/devices/zen.ts b/src/devices/zen.ts index 21543794f5d6d..a620d06df2011 100644 --- a/src/devices/zen.ts +++ b/src/devices/zen.ts @@ -5,6 +5,7 @@ import * as legacy from '../lib/legacy'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend} from '../lib/types'; + const e = exposes.presets; const definitions: DefinitionWithExtend[] = [ diff --git a/src/index.ts b/src/index.ts index d9ba72206d630..780b915c61268 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,33 +1,36 @@ +import type {Binary, Climate, Composite, Cover, Enum, Fan, Feature, Light, List, Lock, Numeric, Switch, Text} from './lib/exposes'; + +import assert from 'assert'; + +import {Zcl} from 'zigbee-herdsman'; + +import fromZigbee from './converters/fromZigbee'; +import toZigbee from './converters/toZigbee'; +import allDefinitions from './devices'; import * as configureKey from './lib/configureKey'; import * as exposesLib from './lib/exposes'; -import type {Feature, Numeric, Enum, Binary, Text, Composite, List, Light, Climate, Switch, Lock, Cover, Fan} from './lib/exposes'; import {Enum as EnumClass} from './lib/exposes'; -import toZigbee from './converters/toZigbee'; -import fromZigbee from './converters/fromZigbee'; -import assert from 'assert'; +import {generateDefinition} from './lib/generateDefinition'; +import * as logger from './lib/logger'; import * as ota from './lib/ota'; -import allDefinitions from './devices'; -import * as utils from './lib/utils'; import { - DefinitionWithExtend, + Configure, Definition, + DefinitionExposes, + DefinitionExposesFunction, + DefinitionWithExtend, + Expose, Fingerprint, - Zh, + KeyValue, + OnEvent, OnEventData, OnEventType, - Configure, - Expose, Option, - Tz, OtaUpdateAvailableResult, - KeyValue, - OnEvent, - DefinitionExposes, - DefinitionExposesFunction, + Tz, + Zh, } from './lib/types'; -import {generateDefinition} from './lib/generateDefinition'; -import {Zcl} from 'zigbee-herdsman'; -import * as logger from './lib/logger'; +import * as utils from './lib/utils'; const NS = 'zhc'; @@ -209,7 +212,7 @@ function processExtensions(definition: DefinitionWithExtend): Definition { exposes = allExposes; } else { exposes = (device: Zh.Device | undefined, options: KeyValue | undefined) => { - let result: Expose[] = []; + const result: Expose[] = []; for (const item of allExposes) { if (typeof item === 'function') { result.push(...item(device, options)); diff --git a/src/lib/color.ts b/src/lib/color.ts index c36b17746c663..0f3304080d5b9 100644 --- a/src/lib/color.ts +++ b/src/lib/color.ts @@ -1,6 +1,6 @@ import kelvinToXyLookup from './kelvinToXy'; -import {findColorTempRange, clampColorTemp} from './light'; -import {KeyValueAny, Tz, Zh, KeyValue} from './types'; +import {clampColorTemp, findColorTempRange} from './light'; +import {KeyValue, KeyValueAny, Tz, Zh} from './types'; import {precisionRound} from './utils'; /** diff --git a/src/lib/develco.ts b/src/lib/develco.ts index 5daedcecbe5e2..e7afd82a9130e 100644 --- a/src/lib/develco.ts +++ b/src/lib/develco.ts @@ -3,15 +3,15 @@ import {Zcl} from 'zigbee-herdsman'; import {presets as e, access as ea} from './exposes'; import {logger} from './logger'; import { + deviceAddCustomCluster, + deviceTemperature, numeric, NumericArgs, ScaleFunction, - temperature, - deviceTemperature, - deviceAddCustomCluster, setupConfigureForReporting, + temperature, } from './modernExtend'; -import {Fz, Tz, ModernExtend, Configure} from './types'; +import {Configure, Fz, ModernExtend, Tz} from './types'; const NS = 'zhc:develco'; const manufacturerOptions = {manufacturerCode: Zcl.ManufacturerCode.DEVELCO}; diff --git a/src/lib/ewelink.ts b/src/lib/ewelink.ts index 1073e57780794..1eca52eb50930 100644 --- a/src/lib/ewelink.ts +++ b/src/lib/ewelink.ts @@ -1,6 +1,6 @@ import {presets} from './exposes'; import {setupConfigureForBinding} from './modernExtend'; -import {Expose, Fz, ModernExtend, KeyValueAny, Configure} from './types'; +import {Configure, Expose, Fz, KeyValueAny, ModernExtend} from './types'; export const ewelinkModernExtend = { ewelinkAction: (): ModernExtend => { diff --git a/src/lib/ikea.ts b/src/lib/ikea.ts index 86b2aa93a76d5..5fd47d30e52f5 100644 --- a/src/lib/ikea.ts +++ b/src/lib/ikea.ts @@ -1,36 +1,37 @@ import * as semver from 'semver'; + import {Zcl} from 'zigbee-herdsman'; import tz from '../converters/toZigbee'; import * as constants from '../lib/constants'; -import {presets, access, options} from '../lib/exposes'; +import {access, options, presets} from '../lib/exposes'; import { + deviceAddCustomCluster, LightArgs, light as lightDontUse, - ota, - ReportingConfigWithoutAttribute, - timeLookup, numeric, NumericArgs, + ota, + ReportingConfigWithoutAttribute, setupConfigureForBinding, setupConfigureForReporting, - deviceAddCustomCluster, + timeLookup, } from '../lib/modernExtend'; import {tradfri as ikea} from '../lib/ota'; import * as reporting from '../lib/reporting'; import * as globalStore from '../lib/store'; -import {Fz, Tz, OnEvent, Configure, KeyValue, Range, ModernExtend, Expose, KeyValueAny} from '../lib/types'; +import {Configure, Expose, Fz, KeyValue, KeyValueAny, ModernExtend, OnEvent, Range, Tz} from '../lib/types'; import { - postfixWithEndpointName, - precisionRound, - isObject, - replaceInArray, - isLegacyEnabled, - hasAlreadyProcessedMessage, assertString, + getEndpointName, getFromLookup, + hasAlreadyProcessedMessage, + isLegacyEnabled, + isObject, mapNumberRange, - getEndpointName, + postfixWithEndpointName, + precisionRound, + replaceInArray, } from '../lib/utils'; export const manufacturerOptions = {manufacturerCode: Zcl.ManufacturerCode.IKEA_OF_SWEDEN}; diff --git a/src/lib/ledvance.ts b/src/lib/ledvance.ts index 60067a082a0ab..2286eb0bb66a8 100644 --- a/src/lib/ledvance.ts +++ b/src/lib/ledvance.ts @@ -1,7 +1,7 @@ import {Zcl} from 'zigbee-herdsman'; import * as ota from '../lib/ota'; -import {Tz, Fz, KeyValue} from '../lib/types'; +import {Fz, KeyValue, Tz} from '../lib/types'; import * as utils from '../lib/utils'; import * as modernExtend from './modernExtend'; import {isObject} from './utils'; diff --git a/src/lib/legacy.ts b/src/lib/legacy.ts index a5ff12e1cc8b9..c3026afe4342a 100644 --- a/src/lib/legacy.ts +++ b/src/lib/legacy.ts @@ -1,15 +1,17 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ + import fs from 'fs'; import fromZigbeeConverters from '../converters/fromZigbee'; -import * as globalStore from './store'; -import * as utils from './utils'; -const fromZigbeeStore: KeyValueAny = {}; import * as constants from './constants'; import * as exposes from './exposes'; import * as light from './light'; import {logger} from './logger'; -import {Zh, KeyValueNumberString, Definition, Fz, Publish, Tz} from './types'; +import * as globalStore from './store'; +import {Definition, Fz, KeyValueNumberString, Publish, Tz, Zh} from './types'; +import * as utils from './utils'; + +const fromZigbeeStore: KeyValueAny = {}; interface KeyValueAny { [s: string]: any; diff --git a/src/lib/legrand.ts b/src/lib/legrand.ts index 605ea0e9bd9d0..6de716f4606a8 100644 --- a/src/lib/legrand.ts +++ b/src/lib/legrand.ts @@ -1,6 +1,6 @@ import {Zcl} from 'zigbee-herdsman'; -import {Fz, Tz, Zh, OnEvent, KeyValueString, KeyValueAny} from '../lib/types'; +import {Fz, KeyValueAny, KeyValueString, OnEvent, Tz, Zh} from '../lib/types'; import * as utils from '../lib/utils'; import * as exposes from './exposes'; import {logger} from './logger'; diff --git a/src/lib/light.ts b/src/lib/light.ts index 6b30e48c59190..10c5f9f83350b 100644 --- a/src/lib/light.ts +++ b/src/lib/light.ts @@ -1,5 +1,5 @@ import {logger} from './logger'; -import {Zh, Tz} from './types'; +import {Tz, Zh} from './types'; import * as utils from './utils'; const NS = 'zhc:light'; diff --git a/src/lib/lumi.ts b/src/lib/lumi.ts index 9ee800b67e98c..83927001a1be8 100644 --- a/src/lib/lumi.ts +++ b/src/lib/lumi.ts @@ -7,41 +7,41 @@ import * as modernExtend from './modernExtend'; import * as ota from './ota'; import * as globalStore from './store'; import { - Fz, + BatteryLinearVoltage, + BatteryNonLinearVoltage, + Configure, Definition, + Expose, + Fz, KeyValue, KeyValueAny, - Tz, - ModernExtend, - Range, KeyValueNumberString, + ModernExtend, OnEvent, - Expose, - Configure, - BatteryNonLinearVoltage, - BatteryLinearVoltage, + Range, + Tz, } from './types'; import { - batteryVoltageToPercentage, - postfixWithEndpointName, - precisionRound, + assertEndpoint, assertNumber, + assertObject, + assertString, + batteryVoltageToPercentage, + calibrateAndPrecisionRoundOptions, getFromLookup, getKey, - printNumbersAsHexSequence, - toNumber, - assertEndpoint, - assertString, + getOptions, hasAlreadyProcessedMessage, + isEndpoint, isLegacyEnabled, - noOccupancySince, isObject, - isEndpoint, isString, - getOptions, - assertObject, - calibrateAndPrecisionRoundOptions, + noOccupancySince, + postfixWithEndpointName, + precisionRound, + printNumbersAsHexSequence, sleep, + toNumber, } from './utils'; const NS = 'zhc:lumi'; diff --git a/src/lib/modernExtend.ts b/src/lib/modernExtend.ts index abd5bb0e5040d..4964c5e157835 100644 --- a/src/lib/modernExtend.ts +++ b/src/lib/modernExtend.ts @@ -7,45 +7,45 @@ import * as globalLegacy from '../lib/legacy'; import {logger} from '../lib/logger'; import {zigbeeOTA} from '../lib/ota'; import * as globalStore from '../lib/store'; -import {presets as e, access as ea, options as opt, Cover, Numeric} from './exposes'; +import {Cover, presets as e, access as ea, Numeric, options as opt} from './exposes'; import {configure as lightConfigure} from './light'; import { - Fz, - Tz, - ModernExtend, - Range, - Zh, - DefinitionOta, - OnEvent, Access, - KeyValueString, - KeyValue, + BatteryLinearVoltage, + BatteryNonLinearVoltage, Configure, - Expose, + DefinitionExposesFunction, DefinitionMeta, + DefinitionOta, + Expose, + Fz, + KeyValue, KeyValueAny, - DefinitionExposesFunction, - BatteryNonLinearVoltage, - BatteryLinearVoltage, + KeyValueString, + ModernExtend, + OnEvent, + Range, + Tz, + Zh, } from './types'; import { - getFromLookupByValue, - isString, - isNumber, - isObject, - isEndpoint, - getFromLookup, - getEndpointName, + addActionGroup, assertNumber, - postfixWithEndpointName, - noOccupancySince, - precisionRound, batteryVoltageToPercentage, + flatten, + getEndpointName, + getFromLookup, + getFromLookupByValue, getOptions, hasAlreadyProcessedMessage, - addActionGroup, + isEndpoint, isLegacyEnabled, - flatten, + isNumber, + isObject, + isString, + noOccupancySince, + postfixWithEndpointName, + precisionRound, } from './utils'; function getEndpointsWithCluster(device: Zh.Device, cluster: string | number, type: 'input' | 'output') { diff --git a/src/lib/ota/common.ts b/src/lib/ota/common.ts index 93dfc5369f99e..9e8a622e4239b 100644 --- a/src/lib/ota/common.ts +++ b/src/lib/ota/common.ts @@ -1,17 +1,19 @@ import assert from 'assert'; -import axios from 'axios'; -import crc32 from 'buffer-crc32'; import crypto from 'crypto'; import {readFileSync} from 'fs'; import https from 'https'; -import {HttpsProxyAgent} from 'https-proxy-agent'; import path from 'path'; import tls from 'tls'; + +import axios from 'axios'; +import crc32 from 'buffer-crc32'; +import {HttpsProxyAgent} from 'https-proxy-agent'; import * as URI from 'uri-js'; + import {Zcl} from 'zigbee-herdsman'; import {logger} from '../logger'; -import {Zh, Ota, KeyValueAny, KeyValue, OtaUpdateAvailableResult} from '../types'; +import {KeyValue, KeyValueAny, Ota, OtaUpdateAvailableResult, Zh} from '../types'; import {sleep} from '../utils'; interface Request { diff --git a/src/lib/ota/gmmts.ts b/src/lib/ota/gmmts.ts index 9ea7ecd8d1d38..ce0593d0b7a36 100644 --- a/src/lib/ota/gmmts.ts +++ b/src/lib/ota/gmmts.ts @@ -1,6 +1,7 @@ import {logger} from '../logger'; -import {Zh, Ota} from '../types'; +import {Ota, Zh} from '../types'; import * as common from './common'; + const axios = common.getAxios(); const firmwareManifest = 'https://update.gammatroniques.fr/ticmeter/manifest.json'; diff --git a/src/lib/ota/index.ts b/src/lib/ota/index.ts index 5e1b448392ad1..45d1ae0bbc3ca 100644 --- a/src/lib/ota/index.ts +++ b/src/lib/ota/index.ts @@ -1,15 +1,15 @@ +import {Ota} from '../types'; +import * as common from './common'; +import * as gmmts from './gmmts'; import * as inovelli from './inovelli'; +import * as jethome from './jethome'; import * as ledvance from './ledvance'; -import * as salus from './salus'; import * as lixee from './lixee'; +import * as salus from './salus'; import * as securifi from './securifi'; import * as tradfri from './tradfri'; import * as ubisys from './ubisys'; -import * as common from './common'; import * as zigbeeOTA from './zigbeeOTA'; -import * as jethome from './jethome'; -import * as gmmts from './gmmts'; -import {Ota} from '../types'; const {setDataDir} = common; diff --git a/src/lib/ota/inovelli.ts b/src/lib/ota/inovelli.ts index b954271bb9e2e..118f8b90e758d 100644 --- a/src/lib/ota/inovelli.ts +++ b/src/lib/ota/inovelli.ts @@ -1,3 +1,7 @@ +import {logger} from '../logger'; +import {KeyValueAny, Ota, Zh} from '../types'; +import * as common from './common'; + /** * Helper functions * @@ -5,9 +9,6 @@ */ const url = 'https://files.inovelli.com/firmware/firmware.json'; -import {logger} from '../logger'; -import {Zh, Ota, KeyValueAny} from '../types'; -import * as common from './common'; const NS = 'zhc:ota:inovelli'; const axios = common.getAxios(); diff --git a/src/lib/ota/jethome.ts b/src/lib/ota/jethome.ts index 66e032e630de8..b2c0138e3ef05 100644 --- a/src/lib/ota/jethome.ts +++ b/src/lib/ota/jethome.ts @@ -1,9 +1,10 @@ -const baseurl = 'https://fw.jethome.ru'; -const deviceurl = `${baseurl}/api/devices/`; import {logger} from '../logger'; -import {Zh, Ota} from '../types'; +import {Ota, Zh} from '../types'; import * as common from './common'; +const baseurl = 'https://fw.jethome.ru'; +const deviceurl = `${baseurl}/api/devices/`; + const NS = 'zhc:ota:jethome'; const axios = common.getAxios(); diff --git a/src/lib/ota/ledvance.ts b/src/lib/ota/ledvance.ts index 8142dbcaf81cf..60cca26886e9d 100644 --- a/src/lib/ota/ledvance.ts +++ b/src/lib/ota/ledvance.ts @@ -1,9 +1,10 @@ -const updateCheckUrl = 'https://api.update.ledvance.com/v1/zigbee/firmwares/newer'; -const updateDownloadUrl = 'https://api.update.ledvance.com/v1/zigbee/firmwares/download'; import {logger} from '../logger'; -import {Zh, Ota} from '../types'; +import {Ota, Zh} from '../types'; import * as common from './common'; +const updateCheckUrl = 'https://api.update.ledvance.com/v1/zigbee/firmwares/newer'; +const updateDownloadUrl = 'https://api.update.ledvance.com/v1/zigbee/firmwares/download'; + const NS = 'zhc:ota:ledvance'; const axios = common.getAxios(); diff --git a/src/lib/ota/lixee.ts b/src/lib/ota/lixee.ts index 9e7ff18818af5..7b9572bdefbea 100644 --- a/src/lib/ota/lixee.ts +++ b/src/lib/ota/lixee.ts @@ -1,8 +1,9 @@ -const firmwareOrigin = 'https://api.github.com/repos/fairecasoimeme/Zlinky_TIC/releases'; import {logger} from '../logger'; -import {Zh, Ota, KeyValueAny} from '../types'; +import {KeyValueAny, Ota, Zh} from '../types'; import * as common from './common'; +const firmwareOrigin = 'https://api.github.com/repos/fairecasoimeme/Zlinky_TIC/releases'; + const NS = 'zhc:ota:lixee'; const axios = common.getAxios(); diff --git a/src/lib/ota/salus.ts b/src/lib/ota/salus.ts index f640ea21cd5cc..49eb1e5f9eb0d 100644 --- a/src/lib/ota/salus.ts +++ b/src/lib/ota/salus.ts @@ -1,10 +1,11 @@ -const url = 'https://eu.salusconnect.io/demo/default/status/firmware?timestamp=0'; import tar from 'tar-stream'; import {logger} from '../logger'; -import {Zh, Ota, KeyValue, KeyValueAny} from '../types'; +import {KeyValue, KeyValueAny, Ota, Zh} from '../types'; import * as common from './common'; +const url = 'https://eu.salusconnect.io/demo/default/status/firmware?timestamp=0'; + const NS = 'zhc:ota:salus'; const axios = common.getAxios(); diff --git a/src/lib/ota/securifi.ts b/src/lib/ota/securifi.ts index e5f023da5c79d..01ed9cc82d15c 100644 --- a/src/lib/ota/securifi.ts +++ b/src/lib/ota/securifi.ts @@ -1,4 +1,4 @@ -import {Zh, Ota} from '../types'; +import {Ota, Zh} from '../types'; import * as common from './common'; import * as zigbeeOTA from './zigbeeOTA'; diff --git a/src/lib/ota/tradfri.ts b/src/lib/ota/tradfri.ts index f09a11fb4ca4a..42ac00be732ef 100644 --- a/src/lib/ota/tradfri.ts +++ b/src/lib/ota/tradfri.ts @@ -1,9 +1,10 @@ -const productionURL = 'http://fw.ota.homesmart.ikea.net/feed/version_info.json'; -const testURL = 'http://fw.test.ota.homesmart.ikea.net/feed/version_info.json'; import {logger} from '../logger'; -import {Ota, Zh, KeyValue} from '../types'; +import {KeyValue, Ota, Zh} from '../types'; import * as common from './common'; +const productionURL = 'http://fw.ota.homesmart.ikea.net/feed/version_info.json'; +const testURL = 'http://fw.test.ota.homesmart.ikea.net/feed/version_info.json'; + const NS = 'zhc:ota:tradfri'; const axios = common.getAxios(); let useTestURL = false; diff --git a/src/lib/ota/ubisys.ts b/src/lib/ota/ubisys.ts index 01fb2b095b0be..bd4634c759e79 100644 --- a/src/lib/ota/ubisys.ts +++ b/src/lib/ota/ubisys.ts @@ -1,11 +1,12 @@ -const firmwareHtmlPageUrl = 'http://fwu.ubisys.de/smarthome/OTA/release/index'; -const imageRegex = /10F2-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{8})\S*ota1?\.zigbee/gi; import url from 'url'; import {logger} from '../logger'; import {Ota, Zh} from '../types'; import * as common from './common'; +const firmwareHtmlPageUrl = 'http://fwu.ubisys.de/smarthome/OTA/release/index'; +const imageRegex = /10F2-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{8})\S*ota1?\.zigbee/gi; + const NS = 'zhc:ota:ubisys'; const axios = common.getAxios(); diff --git a/src/lib/ota/zigbeeOTA.ts b/src/lib/ota/zigbeeOTA.ts index 2e059ddfada72..b119fea963304 100644 --- a/src/lib/ota/zigbeeOTA.ts +++ b/src/lib/ota/zigbeeOTA.ts @@ -1,9 +1,10 @@ -const url = 'https://raw.githubusercontent.com/Koenkk/zigbee-OTA/master/index.json'; -const caBundleUrl = 'https://raw.githubusercontent.com/Koenkk/zigbee-OTA/master/cacerts.pem'; import {logger} from '../logger'; -import {Zh, Ota, KeyValueAny} from '../types'; +import {KeyValueAny, Ota, Zh} from '../types'; import * as common from './common'; +const url = 'https://raw.githubusercontent.com/Koenkk/zigbee-OTA/master/index.json'; +const caBundleUrl = 'https://raw.githubusercontent.com/Koenkk/zigbee-OTA/master/cacerts.pem'; + const NS = 'zhc:ota'; const axios = common.getAxios(); diff --git a/src/lib/philips.ts b/src/lib/philips.ts index 839dae5bd2739..2cd894fcdb804 100644 --- a/src/lib/philips.ts +++ b/src/lib/philips.ts @@ -1,7 +1,7 @@ import {Zcl} from 'zigbee-herdsman'; import tz from '../converters/toZigbee'; -import {ColorXY, ColorRGB} from './color'; +import {ColorRGB, ColorXY} from './color'; import * as libColor from './color'; import * as exposes from './exposes'; import {logger} from './logger'; diff --git a/src/lib/reporting.ts b/src/lib/reporting.ts index c54214cce1c36..91e9d2ab445f8 100644 --- a/src/lib/reporting.ts +++ b/src/lib/reporting.ts @@ -1,6 +1,7 @@ /* eslint camelcase: 0 */ + import {repInterval} from './constants'; -import {Zh, Reporting} from './types'; +import {Reporting, Zh} from './types'; export function payload(attribute: string | number, min: number, max: number, change: number, overrides?: Reporting.Override) { const payload = { diff --git a/src/lib/store.ts b/src/lib/store.ts index f4a6d6f8cc56e..9e4e9d8dd35ef 100644 --- a/src/lib/store.ts +++ b/src/lib/store.ts @@ -1,5 +1,5 @@ import {Zh} from './types'; -import {isGroup, isEndpoint, isDevice} from './utils'; +import {isDevice, isEndpoint, isGroup} from './utils'; let store = new Map(); diff --git a/src/lib/tuya.ts b/src/lib/tuya.ts index 0e7b13ddf3073..7fb9b1e361f24 100644 --- a/src/lib/tuya.ts +++ b/src/lib/tuya.ts @@ -8,23 +8,24 @@ import {logger} from './logger'; import * as modernExtend from './modernExtend'; import * as globalStore from './store'; import { - Tuya, - OnEventType, - OnEventData, - Zh, + DefinitionExposesFunction, + Expose, + Fz, KeyValue, KeyValueAny, - Tz, - Fz, - Expose, - OnEvent, - ModernExtend, - Range, KeyValueNumberString, - DefinitionExposesFunction, + ModernExtend, + OnEvent, + OnEventData, + OnEventType, Publish, + Range, + Tuya, + Tz, + Zh, } from './types'; import * as utils from './utils'; + // import {Color} from './color'; const NS = 'zhc:tuya'; diff --git a/src/lib/types.ts b/src/lib/types.ts index 0ebf948cbd639..e8a9ecb585d56 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -1,5 +1,5 @@ -/* eslint-disable no-unused-vars */ /* eslint-disable @typescript-eslint/no-namespace */ + import type {Device as ZHDevice, Endpoint as ZHEndpoint, Group as ZHGroup} from 'zigbee-herdsman/dist/controller/model'; import type {Header as ZHZclHeader} from 'zigbee-herdsman/dist/zspec/zcl'; import type {FrameControl} from 'zigbee-herdsman/dist/zspec/zcl/definition/tstype'; @@ -81,7 +81,7 @@ export interface MockProperty { property: string; value: KeyValue | string; } -// eslint-disable-next-line camelcase + export interface DiscoveryEntry { mockProperties: MockProperty[]; type: string; diff --git a/src/lib/ubisys.ts b/src/lib/ubisys.ts index 6f315ab91f22a..863382723e2a7 100644 --- a/src/lib/ubisys.ts +++ b/src/lib/ubisys.ts @@ -2,8 +2,8 @@ import {Zcl} from 'zigbee-herdsman'; import {presets as e, access as ea} from './exposes'; import {logger} from './logger'; -import {numeric, NumericArgs, binary, BinaryArgs, deviceAddCustomCluster, setupConfigureForReporting} from './modernExtend'; -import {Fz, Tz, ModernExtend, Configure} from './types'; +import {binary, BinaryArgs, deviceAddCustomCluster, numeric, NumericArgs, setupConfigureForReporting} from './modernExtend'; +import {Configure, Fz, ModernExtend, Tz} from './types'; const NS = 'zhc:ubisys'; diff --git a/test/generateDefinition.test.ts b/test/generateDefinition.test.ts index 3edcf5da2b499..98add34900a77 100644 --- a/test/generateDefinition.test.ts +++ b/test/generateDefinition.test.ts @@ -1,11 +1,12 @@ -import {Definition} from '../src/lib/types'; -import fz from '../src/converters/fromZigbee'; import * as zh from 'zigbee-herdsman/dist'; -import {repInterval} from '../src/lib/constants'; -import {assertDefintion, AssertDefinitionArgs, mockDevice, reportingItem} from './utils'; -import {findByDevice, generateExternalDefinitionSource} from '../src'; import Device from 'zigbee-herdsman/dist/controller/model/device'; +import {findByDevice, generateExternalDefinitionSource} from '../src'; +import fz from '../src/converters/fromZigbee'; +import {repInterval} from '../src/lib/constants'; +import {Definition} from '../src/lib/types'; +import {AssertDefinitionArgs, assertDefintion, mockDevice, reportingItem} from './utils'; + const assertGeneratedDefinition = async (args: AssertDefinitionArgs & {externalDefintionSource?: string}) => { const getDefinition = async (device: Device): Promise => findByDevice(device, true); const definition = await getDefinition(args.device); diff --git a/test/modernExtend.test.ts b/test/modernExtend.test.ts index 6be33d4c07ca9..4d33e9ca2e52b 100644 --- a/test/modernExtend.test.ts +++ b/test/modernExtend.test.ts @@ -1,7 +1,7 @@ +import fz from '../src/converters/fromZigbee'; import {repInterval} from '../src/lib/constants'; -import {philipsFz} from '../src/lib/philips'; import {fromZigbee as lumiFz} from '../src/lib/lumi'; -import fz from '../src/converters/fromZigbee'; +import {philipsFz} from '../src/lib/philips'; import {assertDefintion, mockDevice, reportingItem} from './utils'; describe('ModernExtend', () => { diff --git a/test/ota.test.ts b/test/ota.test.ts index acb94d2d8ff84..a498757e9172f 100644 --- a/test/ota.test.ts +++ b/test/ota.test.ts @@ -1,11 +1,13 @@ -import {join} from 'path'; import {readFileSync} from 'fs'; +import {join} from 'path'; import {EventEmitter} from 'stream'; -import {updateToLatest, parseImage, UPGRADE_FILE_IDENTIFIER, getNewImage} from '../src/lib/ota/common'; -import {KeyValueAny, Ota} from '../src/lib/types'; + import {Zcl} from 'zigbee-herdsman'; -import Waitress from 'zigbee-herdsman/dist/utils/waitress'; import ZclTransactionSequenceNumber from 'zigbee-herdsman/dist/controller/helpers/zclTransactionSequenceNumber'; +import Waitress from 'zigbee-herdsman/dist/utils/waitress'; + +import {getNewImage, parseImage, updateToLatest, UPGRADE_FILE_IDENTIFIER} from '../src/lib/ota/common'; +import {KeyValueAny, Ota} from '../src/lib/types'; interface WaitressMatcher { clusterID: number; diff --git a/test/otaCommon.test.ts b/test/otaCommon.test.ts index e6b8338115f66..a3005ad20ee17 100644 --- a/test/otaCommon.test.ts +++ b/test/otaCommon.test.ts @@ -1,6 +1,7 @@ import crypto from 'crypto'; import {readFileSync} from 'fs'; import {join} from 'path'; + import * as common from '../src/lib/ota/common'; describe('OTA Common', () => { diff --git a/test/sonoff.test.ts b/test/sonoff.test.ts index 142a53f534de5..008d942e46685 100644 --- a/test/sonoff.test.ts +++ b/test/sonoff.test.ts @@ -1,6 +1,7 @@ +import {Endpoint, Entity} from 'zigbee-herdsman/dist/controller/model'; + import * as index from '../src/index'; import {Definition, Fz, KeyValueAny, Tz, Zh} from '../src/lib/types'; -import {Endpoint, Entity} from 'zigbee-herdsman/dist/controller/model'; interface State { readonly weekly_schedule: { diff --git a/test/utils.ts b/test/utils.ts index 55e56485ce1a8..8198d66c3efad 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -1,10 +1,11 @@ -import {findByDevice} from '../src/index'; -import * as utils from '../src/lib/utils'; -import {Zh, DefinitionMeta, Fz, Definition} from '../src/lib/types'; -import tz from '../src/converters/toZigbee'; import {Device} from 'zigbee-herdsman/dist/controller/model'; import {Clusters} from 'zigbee-herdsman/dist/zspec/zcl/definition/cluster'; +import tz from '../src/converters/toZigbee'; +import {findByDevice} from '../src/index'; +import {Definition, DefinitionMeta, Fz, Zh} from '../src/lib/types'; +import * as utils from '../src/lib/utils'; + interface MockEndpointArgs { ID?: number; inputClusters?: string[]; From b2cf736b13944ccf620dd4db9364402d46a999b4 Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Sun, 8 Sep 2024 22:24:20 +0200 Subject: [PATCH 03/12] Manual changes --- src/devices/tuya.ts | 2 +- src/index.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/devices/tuya.ts b/src/devices/tuya.ts index 2de8c8ed41990..280572ac9e356 100644 --- a/src/devices/tuya.ts +++ b/src/devices/tuya.ts @@ -2545,7 +2545,7 @@ const definitions: DefinitionWithExtend[] = [ e.binary('motor_reversal', ea.ALL, 'ON', 'OFF'), e.numeric('calibration_time', ea.STATE).withUnit('s').withDescription('Calibration time'), ]; - if (!device || device.manufacturerName !== ('_TZ3210_xbpt8ewc' || '_TZ3000_1dd0d5yi')) { + if (device?.manufacturerName !== '_TZ3210_xbpt8ewc' && device?.manufacturerName !== '_TZ3000_1dd0d5yi') { exps.push(tuya.exposes.indicatorMode(), tuya.exposes.backlightModeOffOn()); } exps.push(e.linkquality()); diff --git a/src/index.ts b/src/index.ts index 780b915c61268..306d3f7ed6c01 100644 --- a/src/index.ts +++ b/src/index.ts @@ -121,15 +121,20 @@ function processExtensions(definition: DefinitionWithExtend): Definition { } // Modern extend, merges properties, e.g. when both extend and definition has toZigbee, toZigbee will be combined let { + // eslint-disable-next-line prefer-const extend, toZigbee, fromZigbee, + // eslint-disable-next-line prefer-const exposes: definitionExposes, meta, endpoint, ota, + // eslint-disable-next-line prefer-const configure: definitionConfigure, + // eslint-disable-next-line prefer-const onEvent: definitionOnEvent, + // eslint-disable-next-line prefer-const ...definitionWithoutExtend } = definition; @@ -140,7 +145,11 @@ function processExtensions(definition: DefinitionWithExtend): Definition { }; let allExposes: (Expose | DefinitionExposesFunction)[] = []; if (definitionExposes) { - typeof definitionExposes === 'function' ? allExposes.push(definitionExposes) : allExposes.push(...definitionExposes); + if (typeof definitionExposes === 'function') { + allExposes.push(definitionExposes); + } else { + allExposes.push(...definitionExposes); + } } toZigbee = [...(toZigbee ?? [])]; fromZigbee = [...(fromZigbee ?? [])]; From f2356c8fc054bf13a2f428897228b1b7aa37ea72 Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Sun, 8 Sep 2024 22:29:42 +0200 Subject: [PATCH 04/12] fix no-return-await --- eslint.config.mjs | 2 +- src/converters/toZigbee.ts | 20 ++++++++++---------- src/devices/custom_devices_diy.ts | 4 ++-- src/devices/gledopto.ts | 10 +++++----- src/devices/livolo.ts | 8 ++++---- src/devices/sunricher.ts | 2 +- src/devices/tuya.ts | 2 +- src/lib/legacy.ts | 14 +++++++------- src/lib/lumi.ts | 6 +++--- src/lib/ota/common.ts | 2 +- src/lib/philips.ts | 2 +- src/lib/tuya.ts | 12 ++++++------ 12 files changed, 42 insertions(+), 42 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index d49d9aaed67a3..5bca856225b1c 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -20,7 +20,7 @@ export default tseslint.config( '@typescript-eslint/no-explicit-any': 'error', '@typescript-eslint/no-unused-vars': 'off', // TODO error 'array-bracket-spacing': ['error', 'never'], - 'no-return-await': 'off', // TODO error + 'no-return-await': 'error', 'object-curly-spacing': ['error', 'never'], '@typescript-eslint/no-floating-promises': 'error', 'no-prototype-builtins': 'off', // TODO remove (error by default) diff --git a/src/converters/toZigbee.ts b/src/converters/toZigbee.ts index 758ad4a865698..9d94e8e8df9a2 100644 --- a/src/converters/toZigbee.ts +++ b/src/converters/toZigbee.ts @@ -966,7 +966,7 @@ const converters2 = { options: [exposes.options.color_sync(), exposes.options.transition()], convertSet: async (entity, key, value, meta) => { if (key == 'color') { - return await converters1.light_color.convertSet(entity, key, value, meta); + return converters1.light_color.convertSet(entity, key, value, meta); } else if (key == 'color_temp' || key == 'color_temp_percent') { utils.assertNumber(value); const xy = libColor.ColorXY.fromMireds(value); @@ -4371,10 +4371,10 @@ const converters3 = { message.brightness = deviceState.brightness; } - return await converters2.light_onoff_brightness.convertSet(entity, key, value, meta); + return converters2.light_onoff_brightness.convertSet(entity, key, value, meta); }, convertGet: async (entity, key, meta) => { - return await converters2.light_onoff_brightness.convertGet(entity, key, meta); + return converters2.light_onoff_brightness.convertGet(entity, key, meta); }, } satisfies Tz.Converter, RM01_light_onoff_brightness: { @@ -4383,7 +4383,7 @@ const converters3 = { convertSet: async (entity, key, value, meta) => { if (utils.hasEndpoints(meta.device, [0x12])) { const endpoint = meta.device.getEndpoint(0x12); - return await converters2.light_onoff_brightness.convertSet(endpoint, key, value, meta); + return converters2.light_onoff_brightness.convertSet(endpoint, key, value, meta); } else { throw new Error('OnOff and LevelControl not supported on this RM01 device.'); } @@ -4391,7 +4391,7 @@ const converters3 = { convertGet: async (entity, key, meta) => { if (utils.hasEndpoints(meta.device, [0x12])) { const endpoint = meta.device.getEndpoint(0x12); - return await converters2.light_onoff_brightness.convertGet(endpoint, key, meta); + return converters2.light_onoff_brightness.convertGet(endpoint, key, meta); } else { throw new Error('OnOff and LevelControl not supported on this RM01 device.'); } @@ -4403,7 +4403,7 @@ const converters3 = { convertSet: async (entity, key, value, meta) => { if (utils.hasEndpoints(meta.device, [0x12])) { const endpoint = meta.device.getEndpoint(0x12); - return await converters2.light_brightness_step.convertSet(endpoint, key, value, meta); + return converters2.light_brightness_step.convertSet(endpoint, key, value, meta); } else { throw new Error('LevelControl not supported on this RM01 device.'); } @@ -4414,7 +4414,7 @@ const converters3 = { convertSet: async (entity, key, value, meta) => { if (utils.hasEndpoints(meta.device, [0x12])) { const endpoint = meta.device.getEndpoint(0x12); - return await converters2.light_brightness_move.convertSet(endpoint, key, value, meta); + return converters2.light_brightness_move.convertSet(endpoint, key, value, meta); } else { throw new Error('LevelControl not supported on this RM01 device.'); } @@ -4441,7 +4441,7 @@ const converters3 = { message.state = 'off'; message.brightness = 1; } - return await converters2.light_onoff_brightness.convertSet(entity, key, value, meta); + return converters2.light_onoff_brightness.convertSet(entity, key, value, meta); } else { throw new Error('LevelControl not supported on this endpoint.'); } @@ -4450,7 +4450,7 @@ const converters3 = { const cluster = 'genLevelCtrl'; utils.assertEndpoint(entity); if (entity.supportsInputCluster(cluster) || entity.supportsOutputCluster(cluster)) { - return await converters2.light_onoff_brightness.convertGet(entity, key, meta); + return converters2.light_onoff_brightness.convertGet(entity, key, meta); } else { throw new Error('LevelControl not supported on this endpoint.'); } @@ -4484,7 +4484,7 @@ const converters3 = { convertSet: async (entity, key, value, meta) => { const {message, state} = meta; if (message.state === 'OFF' || (message.hasOwnProperty('state') && !message.hasOwnProperty('brightness'))) { - return await converters1.on_off.convertSet(entity, key, value, meta); + return converters1.on_off.convertSet(entity, key, value, meta); } else if (message.hasOwnProperty('brightness')) { // set brightness if (state.state === 'OFF') { diff --git a/src/devices/custom_devices_diy.ts b/src/devices/custom_devices_diy.ts index b2f64f9159b06..f6f5074acefc7 100644 --- a/src/devices/custom_devices_diy.ts +++ b/src/devices/custom_devices_diy.ts @@ -56,12 +56,12 @@ const tzLocal = { ptvo_on_off: { key: ['state'], convertSet: async (entity, key, value, meta) => { - return await tz.on_off.convertSet(entity, key, value, meta); + return tz.on_off.convertSet(entity, key, value, meta); }, convertGet: async (entity, key, meta) => { const cluster = 'genOnOff'; if (isEndpoint(entity) && (entity.supportsInputCluster(cluster) || entity.supportsOutputCluster(cluster))) { - return await tz.on_off.convertGet(entity, key, meta); + return tz.on_off.convertGet(entity, key, meta); } return; }, diff --git a/src/devices/gledopto.ts b/src/devices/gledopto.ts index 1efe808766333..df53eabd90ca8 100644 --- a/src/devices/gledopto.ts +++ b/src/devices/gledopto.ts @@ -29,10 +29,10 @@ const tzLocal1 = { } } - return await tz.light_onoff_brightness.convertSet(entity, key, value, meta); + return tz.light_onoff_brightness.convertSet(entity, key, value, meta); }, convertGet: async (entity, key, meta) => { - return await tz.light_onoff_brightness.convertGet(entity, key, meta); + return tz.light_onoff_brightness.convertGet(entity, key, meta); }, } satisfies Tz.Converter, gledopto_light_colortemp: { @@ -54,7 +54,7 @@ const tzLocal1 = { return result; }, convertGet: async (entity, key, meta) => { - return await tz.light_colortemp.convertGet(entity, key, meta); + return tz.light_colortemp.convertGet(entity, key, meta); }, } satisfies Tz.Converter, gledopto_light_color: { @@ -81,7 +81,7 @@ const tzLocal1 = { return result; }, convertGet: async (entity, key, meta) => { - return await tz.light_color.convertGet(entity, key, meta); + return tz.light_color.convertGet(entity, key, meta); }, } satisfies Tz.Converter, }; @@ -108,7 +108,7 @@ const tzLocal = { } }, convertGet: async (entity, key, meta) => { - return await tz.light_color_colortemp.convertGet(entity, key, meta); + return tz.light_color_colortemp.convertGet(entity, key, meta); }, } satisfies Tz.Converter, }; diff --git a/src/devices/livolo.ts b/src/devices/livolo.ts index a799b5c13745b..bc1fff104bbe3 100644 --- a/src/devices/livolo.ts +++ b/src/devices/livolo.ts @@ -43,7 +43,7 @@ const definitions: DefinitionWithExtend[] = [ if (['start', 'deviceAnnounce'].includes(type)) { await poll(device); if (!globalStore.hasValue(device, 'interval')) { - const interval = setInterval(async () => await poll(device), 300 * 1000); + const interval = setInterval(async () => poll(device), 300 * 1000); globalStore.putValue(device, 'interval', interval); } } @@ -271,7 +271,7 @@ const definitions: DefinitionWithExtend[] = [ if (['start', 'deviceAnnounce'].includes(type)) { await poll(device); if (!globalStore.hasValue(device, 'interval')) { - const interval = setInterval(async () => await poll(device), 10 * 1000); + const interval = setInterval(async () => poll(device), 10 * 1000); globalStore.putValue(device, 'interval', interval); } } @@ -312,7 +312,7 @@ const definitions: DefinitionWithExtend[] = [ if (['start', 'deviceAnnounce'].includes(type)) { await poll(device); if (!globalStore.hasValue(device, 'interval')) { - const interval = setInterval(async () => await poll(device), 60 * 1000); + const interval = setInterval(async () => poll(device), 60 * 1000); globalStore.putValue(device, 'interval', interval); } } @@ -357,7 +357,7 @@ const definitions: DefinitionWithExtend[] = [ if (['start', 'deviceAnnounce'].includes(type)) { await poll(device); if (!globalStore.hasValue(device, 'interval')) { - const interval = setInterval(async () => await poll(device), 300 * 1000); + const interval = setInterval(async () => poll(device), 300 * 1000); globalStore.putValue(device, 'interval', interval); } } diff --git a/src/devices/sunricher.ts b/src/devices/sunricher.ts index 7e4a7b20c4653..326381da29579 100644 --- a/src/devices/sunricher.ts +++ b/src/devices/sunricher.ts @@ -598,7 +598,7 @@ const definitions: DefinitionWithExtend[] = [ const endpoint = device.getEndpoint(1); const hours24 = 1000 * 60 * 60 * 24; // Device does not ask for the time with binding, therefore we write the time every 24 hours - const interval = setInterval(async () => await syncTime(endpoint), hours24); + const interval = setInterval(async () => syncTime(endpoint), hours24); globalStore.putValue(device, 'time', interval); } }, diff --git a/src/devices/tuya.ts b/src/devices/tuya.ts index 280572ac9e356..af3c9a3dc0615 100644 --- a/src/devices/tuya.ts +++ b/src/devices/tuya.ts @@ -401,7 +401,7 @@ const tzLocal = { } return {state: libColor.syncColorState(newState, meta.state, entity, meta.options) as KeyValue}; } else { - return await tz.light_color.convertSet(entity, key, value, meta); + return tz.light_color.convertSet(entity, key, value, meta); } }, convertGet: tz.light_color.convertGet, diff --git a/src/lib/legacy.ts b/src/lib/legacy.ts index c3026afe4342a..23122218b280e 100644 --- a/src/lib/legacy.ts +++ b/src/lib/legacy.ts @@ -180,31 +180,31 @@ function dpValueFromBitmap(dp: number, bitmapBuffer: any) { // Return `seq` - transaction ID for handling concrete response async function sendDataPoint(entity: Zh.Endpoint | Zh.Group, dpValue: any, cmd?: string, seq: number = undefined) { - return await sendDataPoints(entity, [dpValue], cmd, seq); + return sendDataPoints(entity, [dpValue], cmd, seq); } async function sendDataPointValue(entity: Zh.Endpoint | Zh.Group, dp: number, value: any, cmd?: string, seq: number = undefined) { - return await sendDataPoints(entity, [dpValueFromIntValue(dp, value)], cmd, seq); + return sendDataPoints(entity, [dpValueFromIntValue(dp, value)], cmd, seq); } async function sendDataPointBool(entity: Zh.Endpoint | Zh.Group, dp: number, value: boolean | number, cmd?: string, seq: number = undefined) { - return await sendDataPoints(entity, [dpValueFromBool(dp, value)], cmd, seq); + return sendDataPoints(entity, [dpValueFromBool(dp, value)], cmd, seq); } async function sendDataPointEnum(entity: Zh.Endpoint | Zh.Group, dp: number, value: number, cmd?: string, seq: number = undefined) { - return await sendDataPoints(entity, [dpValueFromEnum(dp, value)], cmd, seq); + return sendDataPoints(entity, [dpValueFromEnum(dp, value)], cmd, seq); } async function sendDataPointRaw(entity: Zh.Endpoint | Zh.Group, dp: number, value: any, cmd?: string, seq: number = undefined) { - return await sendDataPoints(entity, [dpValueFromRaw(dp, value)], cmd, seq); + return sendDataPoints(entity, [dpValueFromRaw(dp, value)], cmd, seq); } async function sendDataPointBitmap(entity: Zh.Endpoint | Zh.Group, dp: number, value: any, cmd?: string, seq: number = undefined) { - return await sendDataPoints(entity, [dpValueFromBitmap(dp, value)], cmd, seq); + return sendDataPoints(entity, [dpValueFromBitmap(dp, value)], cmd, seq); } async function sendDataPointStringBuffer(entity: Zh.Endpoint | Zh.Group, dp: number, value: any, cmd?: string, seq: number = undefined) { - return await sendDataPoints(entity, [dpValueFromStringBuffer(dp, value)], cmd, seq); + return sendDataPoints(entity, [dpValueFromStringBuffer(dp, value)], cmd, seq); } function convertRawToCycleTimer(value: any) { diff --git a/src/lib/lumi.ts b/src/lib/lumi.ts index 83927001a1be8..9d09bd6b10267 100644 --- a/src/lib/lumi.ts +++ b/src/lib/lumi.ts @@ -1865,7 +1865,7 @@ export const lumiModernExtend = { cluster: 'manuSpecificLumi', type: ['attributeReport', 'readResponse'], convert: async (model, msg, publish, options, meta) => { - return await numericAttributes2Payload(msg, meta, model, options, msg.data); + return numericAttributes2Payload(msg, meta, model, options, msg.data); }, }, ]; @@ -2238,7 +2238,7 @@ export const fromZigbee = { cluster: 'genBasic', type: ['attributeReport', 'readResponse'], convert: async (model, msg, publish, options, meta) => { - return await numericAttributes2Payload(msg, meta, model, options, msg.data); + return numericAttributes2Payload(msg, meta, model, options, msg.data); }, } satisfies Fz.Converter, lumi_basic_raw: { @@ -2257,7 +2257,7 @@ export const fromZigbee = { cluster: 'manuSpecificLumi', type: ['attributeReport', 'readResponse'], convert: async (model, msg, publish, options, meta) => { - return await numericAttributes2Payload(msg, meta, model, options, msg.data); + return numericAttributes2Payload(msg, meta, model, options, msg.data); }, } satisfies Fz.Converter, lumi_co2: { diff --git a/src/lib/ota/common.ts b/src/lib/ota/common.ts index 9e8a622e4239b..1de8077c326c2 100644 --- a/src/lib/ota/common.ts +++ b/src/lib/ota/common.ts @@ -154,7 +154,7 @@ export async function getFirmwareFile(image: KeyValueAny): Promise<{data: Buffer // First try to download firmware file with the URL provided if (isValidUrl(urlOrName)) { logger.debug(`Downloading firmware image from '${urlOrName}'`, NS); - return await getAxios().get(urlOrName, {responseType: 'arraybuffer'}); + return getAxios().get(urlOrName, {responseType: 'arraybuffer'}); } logger.debug(`Try to read firmware image from local file '${urlOrName}'`, NS); diff --git a/src/lib/philips.ts b/src/lib/philips.ts index 2cd894fcdb804..42fabd6502f49 100644 --- a/src/lib/philips.ts +++ b/src/lib/philips.ts @@ -128,7 +128,7 @@ export const philipsTz = { if (Object.keys(hueEffects).includes(value.toLowerCase())) { await entity.command('manuSpecificPhilips2', 'multiColor', {data: Buffer.from(utils.getFromLookup(value, hueEffects), 'hex')}); } else { - return await tz.effect.convertSet(entity, key, value, meta); + return tz.effect.convertSet(entity, key, value, meta); } }, } satisfies Tz.Converter, diff --git a/src/lib/tuya.ts b/src/lib/tuya.ts index 7fb9b1e361f24..89a578864a36f 100644 --- a/src/lib/tuya.ts +++ b/src/lib/tuya.ts @@ -278,27 +278,27 @@ function dpValueFromBitmap(dp: number, bitmapBuffer: number) { } export async function sendDataPointValue(entity: Zh.Group | Zh.Endpoint, dp: number, value: number, cmd?: string, seq?: number) { - return await sendDataPoints(entity, [dpValueFromNumberValue(dp, value)], cmd, seq); + return sendDataPoints(entity, [dpValueFromNumberValue(dp, value)], cmd, seq); } export async function sendDataPointBool(entity: Zh.Group | Zh.Endpoint, dp: number, value: boolean, cmd?: string, seq?: number) { - return await sendDataPoints(entity, [dpValueFromBool(dp, value)], cmd, seq); + return sendDataPoints(entity, [dpValueFromBool(dp, value)], cmd, seq); } export async function sendDataPointEnum(entity: Zh.Group | Zh.Endpoint, dp: number, value: number, cmd?: string, seq?: number) { - return await sendDataPoints(entity, [dpValueFromEnum(dp, value)], cmd, seq); + return sendDataPoints(entity, [dpValueFromEnum(dp, value)], cmd, seq); } export async function sendDataPointRaw(entity: Zh.Group | Zh.Endpoint, dp: number, value: number[], cmd?: string, seq?: number) { - return await sendDataPoints(entity, [dpValueFromRaw(dp, value)], cmd, seq); + return sendDataPoints(entity, [dpValueFromRaw(dp, value)], cmd, seq); } export async function sendDataPointBitmap(entity: Zh.Group | Zh.Endpoint, dp: number, value: number, cmd?: string, seq?: number) { - return await sendDataPoints(entity, [dpValueFromBitmap(dp, value)], cmd, seq); + return sendDataPoints(entity, [dpValueFromBitmap(dp, value)], cmd, seq); } export async function sendDataPointStringBuffer(entity: Zh.Group | Zh.Endpoint, dp: number, value: string, cmd?: string, seq?: number) { - return await sendDataPoints(entity, [dpValueFromString(dp, value)], cmd, seq); + return sendDataPoints(entity, [dpValueFromString(dp, value)], cmd, seq); } const tuyaExposes = { From 361bf0c35529d00832eee3a395981594bc37067e Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Sun, 8 Sep 2024 22:32:59 +0200 Subject: [PATCH 05/12] @typescript-eslint/await-thenable --- eslint.config.mjs | 2 +- src/converters/fromZigbee.ts | 26 +++++++++++++------------- src/devices/bituo_technik.ts | 4 ++-- src/devices/tuya.ts | 4 ++-- src/lib/lumi.ts | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 5bca856225b1c..9a61d943338ec 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -14,7 +14,7 @@ export default tseslint.config( }, }, rules: { - '@typescript-eslint/await-thenable': 'off', // TODO error + '@typescript-eslint/await-thenable': 'error', '@typescript-eslint/ban-ts-comment': 'off', // TODO error '@typescript-eslint/explicit-function-return-type': 'off', // TODO error '@typescript-eslint/no-explicit-any': 'error', diff --git a/src/converters/fromZigbee.ts b/src/converters/fromZigbee.ts index 114ad0d72109f..5de2e6b052724 100644 --- a/src/converters/fromZigbee.ts +++ b/src/converters/fromZigbee.ts @@ -4957,7 +4957,7 @@ const converters2 = { cluster: 'ssIasAce', type: 'commandArm', convert: async (model, msg, publish, options, meta) => { - const payload = await converters1.command_arm.convert(model, msg, publish, options, meta); + const payload = converters1.command_arm.convert(model, msg, publish, options, meta); if (!payload) return; payload.action_transaction = msg.meta.zclTransactionSequenceNumber; return payload; @@ -4967,7 +4967,7 @@ const converters2 = { cluster: 'seMetering', type: ['attributeReport', 'readResponse'], convert: async (model, msg, publish, options, meta) => { - const result = await converters1.metering.convert(model, msg, publish, options, meta); + const result = converters1.metering.convert(model, msg, publish, options, meta); // Filter incorrect 0 energy values reported by the device: // https://github.com/Koenkk/zigbee2mqtt/issues/7852 if (result && result.energy === 0) { @@ -4983,7 +4983,7 @@ const converters2 = { cluster: 'seMetering', type: ['attributeReport', 'readResponse'], convert: async (model, msg, publish, options, meta) => { - const result = await converters1.metering.convert(model, msg, publish, options, meta); + const result = converters1.metering.convert(model, msg, publish, options, meta); if (result && result.hasOwnProperty('power')) { result.power /= 1000; } @@ -4994,8 +4994,8 @@ const converters2 = { cluster: 'genOnOff', type: 'commandOn', convert: async (model, msg, publish, options, meta) => { - const payload1 = await converters1.checkin_presence.convert(model, msg, publish, options, meta); - const payload2 = await converters1.command_on.convert(model, msg, publish, options, meta); + const payload1 = converters1.checkin_presence.convert(model, msg, publish, options, meta); + const payload2 = converters1.command_on.convert(model, msg, publish, options, meta); return {...payload1, ...payload2}; }, } satisfies Fz.Converter, @@ -5037,7 +5037,7 @@ const converters2 = { cluster: 'hvacThermostat', type: ['attributeReport', 'readResponse'], convert: async (model, msg, publish, options, meta) => { - const result = await converters1.thermostat.convert(model, msg, publish, options, meta); + const result = converters1.thermostat.convert(model, msg, publish, options, meta); if (result && msg.data['StelproSystemMode'] === 5) { // 'Eco' mode is translated into 'auto' here result.system_mode = constants.thermostatSystemModes[1]; @@ -5052,7 +5052,7 @@ const converters2 = { cluster: 'hvacThermostat', type: ['attributeReport', 'readResponse'], convert: async (model, msg, publish, options, meta) => { - const result = await converters1.thermostat.convert(model, msg, publish, options, meta); + const result = converters1.thermostat.convert(model, msg, publish, options, meta); if (result) { // ViessMann TRVs report piHeatingDemand from 0-5 @@ -5089,7 +5089,7 @@ const converters2 = { cluster: 'hvacThermostat', type: ['attributeReport', 'readResponse'], convert: async (model, msg, publish, options, meta) => { - const result = await converters1.thermostat.convert(model, msg, publish, options, meta); + const result = converters1.thermostat.convert(model, msg, publish, options, meta); if (result) { if (typeof msg.data[0x4003] == 'number') { result.current_heating_setpoint = precisionRound(msg.data[0x4003], 2) / 100; @@ -5162,7 +5162,7 @@ const converters2 = { const sidelookup: KeyValueAny = {5: 'right', 7: 'right', 40: 'left', 56: 'left'}; if (sidelookup[value]) { msg.data.occupancy = 1; - const payload = (await converters1.occupancy_with_timeout.convert(model, msg, publish, options, meta)) as KeyValueAny; + const payload = converters1.occupancy_with_timeout.convert(model, msg, publish, options, meta) as KeyValueAny; if (payload) { payload.action_side = sidelookup[value]; payload.side = sidelookup[value]; /* legacy: remove this line (replaced by action_side) */ @@ -5180,7 +5180,7 @@ const converters2 = { let result: KeyValueAny = {}; const data = msg.data; if (data && data.hasOwnProperty('zoneStatus')) { - const result1 = await converters1.ias_occupancy_alarm_1_report.convert(model, msg, publish, options, meta); + const result1 = converters1.ias_occupancy_alarm_1_report.convert(model, msg, publish, options, meta); result = {...result1}; } if (data && data.hasOwnProperty('currentZoneSensitivityLevel')) { @@ -5198,7 +5198,7 @@ const converters2 = { cluster: 'lightingBallastCfg', type: ['attributeReport', 'readResponse'], convert: async (model, msg, publish, options, meta) => { - const result = await converters1.lighting_ballast_configuration.convert(model, msg, publish, options, meta); + const result = converters1.lighting_ballast_configuration.convert(model, msg, publish, options, meta); const lookup: KeyValueAny = {1: 'RC', 2: 'RL'}; if (result && msg.data.hasOwnProperty(0xe000)) { result.dimmer_mode = lookup[msg.data[0xe000]]; @@ -5210,7 +5210,7 @@ const converters2 = { cluster: 'lightingBallastCfg', type: ['attributeReport', 'readResponse'], convert: async (model, msg, publish, options, meta) => { - const result = await converters1.lighting_ballast_configuration.convert(model, msg, publish, options, meta); + const result = converters1.lighting_ballast_configuration.convert(model, msg, publish, options, meta); if (result && msg.data.hasOwnProperty('wiserControlMode')) { result.dimmer_mode = constants.wiserDimmerControlMode[msg.data['wiserControlMode']]; } @@ -5221,7 +5221,7 @@ const converters2 = { cluster: 'hvacThermostat', type: ['attributeReport', 'readResponse'], convert: async (model, msg, publish, options, meta) => { - const result = await converters1.thermostat.convert(model, msg, publish, options, meta); + const result = converters1.thermostat.convert(model, msg, publish, options, meta); if (result) { if (msg.data.hasOwnProperty(0xe010)) { diff --git a/src/devices/bituo_technik.ts b/src/devices/bituo_technik.ts index eaffc29bbf558..ed0b95ba4c088 100644 --- a/src/devices/bituo_technik.ts +++ b/src/devices/bituo_technik.ts @@ -31,7 +31,7 @@ const definitions: DefinitionWithExtend[] = [ // {change: 0} Ensure that energy and produced energy report parameters correctly during initialization instead of showing null await reporting.currentSummDelivered(endpoint, {change: 0}); await reporting.currentSummReceived(endpoint, {change: 0}); - await endpoint.saveClusterAttributeKeyValue('haElectricalMeasurement', { + endpoint.saveClusterAttributeKeyValue('haElectricalMeasurement', { acPowerMultiplier: 1, acPowerDivisor: 1, }); @@ -74,7 +74,7 @@ const definitions: DefinitionWithExtend[] = [ // {change: 0} Ensure that energy and produced energy report parameters correctly during initialization instead of showing null await reporting.currentSummDelivered(endpoint, {change: 0}); await reporting.currentSummReceived(endpoint, {change: 0}); - await endpoint.saveClusterAttributeKeyValue('haElectricalMeasurement', { + endpoint.saveClusterAttributeKeyValue('haElectricalMeasurement', { acPowerMultiplier: 1, acPowerDivisor: 1, }); diff --git a/src/devices/tuya.ts b/src/devices/tuya.ts index af3c9a3dc0615..6c272d9e633e0 100644 --- a/src/devices/tuya.ts +++ b/src/devices/tuya.ts @@ -538,7 +538,7 @@ const fzLocal = { TS0222_humidity: { ...fz.humidity, convert: async (model, msg, publish, options, meta) => { - const result = await fz.humidity.convert(model, msg, publish, options, meta); + const result = fz.humidity.convert(model, msg, publish, options, meta); if (result) result.humidity *= 10; return result; }, @@ -603,7 +603,7 @@ const fzLocal = { TS011F_electrical_measurement: { ...fz.electrical_measurement, convert: async (model, msg, publish, options, meta) => { - const result = (await fz.electrical_measurement.convert(model, msg, publish, options, meta)) ?? {}; + const result = fz.electrical_measurement.convert(model, msg, publish, options, meta) ?? {}; const lookup: KeyValueString = {power: 'activePower', current: 'rmsCurrent', voltage: 'rmsVoltage'}; // Wait 5 seconds before reporting a 0 value as this could be an invalid measurement. diff --git a/src/lib/lumi.ts b/src/lib/lumi.ts index 9d09bd6b10267..86414d6746ee9 100644 --- a/src/lib/lumi.ts +++ b/src/lib/lumi.ts @@ -2540,7 +2540,7 @@ export const fromZigbee = { cluster: 'msPressureMeasurement', type: ['attributeReport', 'readResponse'], convert: async (model, msg, publish, options, meta) => { - const result = await fz.pressure.convert(model, msg, publish, options, meta); + const result = fz.pressure.convert(model, msg, publish, options, meta); if (result && result.pressure > 500 && result.pressure < 2000) { return result; } From a0f863eee8f3f9396e8c9f7e528cae5f5850a7fb Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Sun, 8 Sep 2024 22:52:03 +0200 Subject: [PATCH 06/12] @typescript-eslint/no-unused-vars --- eslint.config.mjs | 2 +- src/converters/toZigbee.ts | 8 ++++---- src/devices/alecto.ts | 1 - src/devices/avatto.ts | 1 - src/devices/bitron.ts | 2 +- src/devices/blaupunkt.ts | 2 +- src/devices/busch_jaeger.ts | 1 - src/devices/centralite.ts | 2 +- src/devices/custom_devices_diy.ts | 6 +++--- src/devices/danfoss.ts | 4 ++-- src/devices/develco.ts | 4 ++-- src/devices/ewelink.ts | 2 +- src/devices/gledopto.ts | 2 +- src/devices/gmmts.ts | 8 ++++---- src/devices/hive.ts | 2 +- src/devices/legrand.ts | 4 ++-- src/devices/lidl.ts | 4 ++-- src/devices/lifecontrol.ts | 2 +- src/devices/livolo.ts | 2 +- src/devices/lixee.ts | 6 +++--- src/devices/lumi.ts | 4 ++-- src/devices/mercator.ts | 4 ++-- src/devices/moes.ts | 2 +- src/devices/namron.ts | 2 +- src/devices/owon.ts | 1 - src/devices/sinope.ts | 32 ++++++++++++++--------------- src/devices/smartthings.ts | 2 +- src/devices/sunricher.ts | 4 ++-- src/devices/third_reality.ts | 2 +- src/devices/tuya.ts | 20 +++++++++--------- src/devices/ubisys.ts | 2 +- src/devices/yale.ts | 6 +++--- src/devices/zemismart.ts | 2 +- src/lib/develco.ts | 16 +++------------ src/lib/legacy.ts | 2 +- src/lib/light.ts | 2 +- src/lib/lumi.ts | 10 +++++---- src/lib/ota/common.ts | 2 +- src/lib/tuya.ts | 34 +++---------------------------- src/lib/utils.ts | 6 +++--- 40 files changed, 90 insertions(+), 130 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 9a61d943338ec..bb22f62299d9d 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -18,7 +18,7 @@ export default tseslint.config( '@typescript-eslint/ban-ts-comment': 'off', // TODO error '@typescript-eslint/explicit-function-return-type': 'off', // TODO error '@typescript-eslint/no-explicit-any': 'error', - '@typescript-eslint/no-unused-vars': 'off', // TODO error + '@typescript-eslint/no-unused-vars': ['error', {args: 'none'}], 'array-bracket-spacing': ['error', 'never'], 'no-return-await': 'error', 'object-curly-spacing': ['error', 'never'], diff --git a/src/converters/toZigbee.ts b/src/converters/toZigbee.ts index 9d94e8e8df9a2..64051eab2d5d9 100644 --- a/src/converters/toZigbee.ts +++ b/src/converters/toZigbee.ts @@ -659,7 +659,7 @@ const converters2 = { if (typeof value === 'string') { try { value = JSON.parse(value); - } catch (e) { + } catch { throw new Error('Payload is not valid JSON'); } } @@ -778,7 +778,7 @@ const converters2 = { for (const attribute of ['onOffTransitionTime', 'onTransitionTime', 'offTransitionTime', 'startUpCurrentLevel', 'onLevel', 'options']) { try { await entity.read('genLevelCtrl', [attribute]); - } catch (ex) { + } catch { // continue regardless of error, all these are optional in ZCL } } @@ -827,7 +827,7 @@ const converters2 = { try { // @ts-expect-error result = {...result, ...(await entity.read('lightingBallastCfg', [utils.toCamelCase(attrName)]))}; - } catch (ex) { + } catch { // continue regardless of error } } @@ -1119,7 +1119,7 @@ const converters2 = { // @ts-expect-error onLevel = attributeRead['onLevel']; } - } catch (e) { + } catch { // OnLevel not supported } } diff --git a/src/devices/alecto.ts b/src/devices/alecto.ts index 76b246d0ba1fb..993837cea5e75 100644 --- a/src/devices/alecto.ts +++ b/src/devices/alecto.ts @@ -1,5 +1,4 @@ import fz from '../converters/fromZigbee'; -import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import {DefinitionWithExtend} from '../lib/types'; diff --git a/src/devices/avatto.ts b/src/devices/avatto.ts index 5706c42c76bac..7c170d1fd612a 100644 --- a/src/devices/avatto.ts +++ b/src/devices/avatto.ts @@ -3,7 +3,6 @@ import * as tuya from '../lib/tuya'; import {DefinitionWithExtend} from '../lib/types'; const e = exposes.presets; -const ea = exposes.access; const definitions: DefinitionWithExtend[] = [ { diff --git a/src/devices/bitron.ts b/src/devices/bitron.ts index e1268df572dbc..78031c6b144c4 100644 --- a/src/devices/bitron.ts +++ b/src/devices/bitron.ts @@ -184,7 +184,7 @@ const definitions: DefinitionWithExtend[] = [ await reporting.currentSummDelivered(endpoint); try { await reporting.currentSummReceived(endpoint); - } catch (error) { + } catch { /* fails for some: https://github.com/Koenkk/zigbee2mqtt/issues/13258 */ } endpoint.saveClusterAttributeKeyValue('seMetering', {divisor: 10000, multiplier: 1}); diff --git a/src/devices/blaupunkt.ts b/src/devices/blaupunkt.ts index ec1bf1b3afb80..a612c1fc72b38 100644 --- a/src/devices/blaupunkt.ts +++ b/src/devices/blaupunkt.ts @@ -20,7 +20,7 @@ const definitions: DefinitionWithExtend[] = [ await reporting.bind(endpoint, coordinatorEndpoint, ['genLevelCtrl']); try { await reporting.brightness(endpoint); - } catch (e) { + } catch { // Some version don't support this: https://github.com/Koenkk/zigbee2mqtt/issues/4246 } }, diff --git a/src/devices/busch_jaeger.ts b/src/devices/busch_jaeger.ts index 55cd484ba07e3..7fc2e48c4a95c 100644 --- a/src/devices/busch_jaeger.ts +++ b/src/devices/busch_jaeger.ts @@ -4,7 +4,6 @@ import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import {onOff} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; -import * as globalStore from '../lib/store'; import {DefinitionWithExtend} from '../lib/types'; import * as utils from '../lib/utils'; diff --git a/src/devices/centralite.ts b/src/devices/centralite.ts index f32bc7a3d4c93..d52bb3d3f46a0 100644 --- a/src/devices/centralite.ts +++ b/src/devices/centralite.ts @@ -129,7 +129,7 @@ const definitions: DefinitionWithExtend[] = [ await reporting.onOff(endpoint); try { await reporting.readEletricalMeasurementMultiplierDivisors(endpoint); - } catch (exception) { + } catch { // For some this fails so set manually // https://github.com/Koenkk/zigbee2mqtt/issues/3575 endpoint.saveClusterAttributeKeyValue('haElectricalMeasurement', { diff --git a/src/devices/custom_devices_diy.ts b/src/devices/custom_devices_diy.ts index f6f5074acefc7..6885599facd09 100644 --- a/src/devices/custom_devices_diy.ts +++ b/src/devices/custom_devices_diy.ts @@ -574,7 +574,7 @@ const definitions: DefinitionWithExtend[] = [ ptvoSetMetaOption(device, 'device_config', deviceConfig); device.save(); } - } catch (err) { + } catch { /* do nothing */ } } @@ -871,7 +871,7 @@ const definitions: DefinitionWithExtend[] = [ await endpoint.read('hvacThermostat', [0x0010, 0x0011, 0x0102, 0x0103, 0x0104, 0x0105]); await endpoint.read('msTemperatureMeasurement', [0x0010]); await endpoint.read('msRelativeHumidity', [0x0010]); - } catch (e) { + } catch { /* backward compatibility */ } }, @@ -1085,7 +1085,7 @@ const definitions: DefinitionWithExtend[] = [ await endpoint.read('hvacThermostat', [0x0010, 0x0011, 0x0102, 0x0103, 0x0104, 0x0105, 0x0107]); await endpoint.read('msTemperatureMeasurement', [0x0010]); await endpoint.read('msRelativeHumidity', [0x0010]); - } catch (e) { + } catch { /* backward compatibility */ } }, diff --git a/src/devices/danfoss.ts b/src/devices/danfoss.ts index 5e913d0e22228..7baf1e69e1819 100644 --- a/src/devices/danfoss.ts +++ b/src/devices/danfoss.ts @@ -296,7 +296,7 @@ const definitions: DefinitionWithExtend[] = [ ], options, ); - } catch (e) { + } catch { /* not supported by all */ } @@ -322,7 +322,7 @@ const definitions: DefinitionWithExtend[] = [ ], options, ); - } catch (e) { + } catch { /* not supported by all https://github.com/Koenkk/zigbee2mqtt/issues/11872 */ } diff --git a/src/devices/develco.ts b/src/devices/develco.ts index e622135b8e5d0..b222fbc165c1c 100644 --- a/src/devices/develco.ts +++ b/src/devices/develco.ts @@ -10,7 +10,7 @@ import {battery, humidity, illuminance} from '../lib/modernExtend'; import * as ota from '../lib/ota'; import * as reporting from '../lib/reporting'; import * as globalStore from '../lib/store'; -import {DefinitionWithExtend, Fz, KeyValue, Tz, Zh} from '../lib/types'; +import {DefinitionWithExtend, Fz, KeyValue, Tz} from '../lib/types'; import * as utils from '../lib/utils'; const e = exposes.presets; @@ -537,7 +537,7 @@ const definitions: DefinitionWithExtend[] = [ for (const cluster of ['ssIasZone', 'ssIasWd', 'genBasic', 'genBinaryInput']) { try { await endpoint.bind(cluster, coordinatorEndpoint); - } catch (error) { + } catch { logger.debug(`Failed to bind '${cluster}'`, NS); } } diff --git a/src/devices/ewelink.ts b/src/devices/ewelink.ts index 8185f5c4f529c..1efe1a4fdc86a 100644 --- a/src/devices/ewelink.ts +++ b/src/devices/ewelink.ts @@ -51,7 +51,7 @@ const definitions: DefinitionWithExtend[] = [ configure: async (device, coordinatorEndpoint) => { try { await device.getEndpoint(1).bind('genOnOff', coordinatorEndpoint); - } catch (error) { + } catch { // This might fail because there are some repeaters which advertise to support genOnOff but don't support it. // https://github.com/Koenkk/zigbee2mqtt/issues/19865 logger.debug('Failed to bind genOnOff for SA-003-Zigbee', NS); diff --git a/src/devices/gledopto.ts b/src/devices/gledopto.ts index df53eabd90ca8..ba7bc80b68a8a 100644 --- a/src/devices/gledopto.ts +++ b/src/devices/gledopto.ts @@ -144,7 +144,7 @@ function gledoptoOnOff(args?: OnOffArgs) { const interval = setInterval(async () => { try { await device.endpoints[0].read('genOnOff', ['onOff']); - } catch (error) { + } catch { // Do nothing } }, 5000); diff --git a/src/devices/gmmts.ts b/src/devices/gmmts.ts index 591a9fb3d0473..7df8b199b9c6e 100644 --- a/src/devices/gmmts.ts +++ b/src/devices/gmmts.ts @@ -2001,7 +2001,7 @@ const definitions: DefinitionWithExtend[] = [ try { endpoint = device.getEndpoint(1); - } catch (error) { + } catch { logger.warning('Exposes: No endpoint', 'TICMeter'); } @@ -2304,7 +2304,7 @@ const definitions: DefinitionWithExtend[] = [ const interval = setInterval(async () => { try { await poll(endpoint, device); - } catch (error) { + } catch { /* Do nothing*/ } }, seconds * 1000); @@ -2312,7 +2312,7 @@ const definitions: DefinitionWithExtend[] = [ globalStore.putValue(device, 'refresh_rate', seconds); try { await poll(endpoint, device); - } catch (e) { + } catch { // Do nothing } } else { @@ -2324,7 +2324,7 @@ const definitions: DefinitionWithExtend[] = [ const interval = setInterval(async () => { try { await poll(endpoint, device); - } catch (error) { + } catch { /* Do nothing*/ } }, seconds * 1000); diff --git a/src/devices/hive.ts b/src/devices/hive.ts index bef379528c437..adcc1b20985b0 100644 --- a/src/devices/hive.ts +++ b/src/devices/hive.ts @@ -701,7 +701,7 @@ const definitions: DefinitionWithExtend[] = [ async () => { try { await device.endpoints[0].read('genBasic', ['zclVersion']); - } catch (error) { + } catch { // Do nothing } }, diff --git a/src/devices/legrand.ts b/src/devices/legrand.ts index 42af6814a83f7..ea56834e80cb6 100644 --- a/src/devices/legrand.ts +++ b/src/devices/legrand.ts @@ -378,7 +378,7 @@ const definitions: DefinitionWithExtend[] = [ await reporting.activePower(endpoint); try { await reporting.apparentPower(endpoint); - } catch (e) { + } catch { // Some version/firmware don't seem to support this. // https://github.com/Koenkk/zigbee2mqtt/issues/16732 } @@ -481,7 +481,7 @@ const definitions: DefinitionWithExtend[] = [ try { await reporting.apparentPower(endpoint); await endpoint.read('haElectricalMeasurement', ['apparentPower']); - } catch (e) { + } catch { // Some version/firmware don't seem to support this. } // Read configuration values that are not sent periodically. diff --git a/src/devices/lidl.ts b/src/devices/lidl.ts index 1e1b8c1b0b3fb..4be8b9a104654 100644 --- a/src/devices/lidl.ts +++ b/src/devices/lidl.ts @@ -261,7 +261,7 @@ const definitions: DefinitionWithExtend[] = [ await endpoint.read('genOnOff', ['tuyaOperationMode']); try { await endpoint.read(0xe001, [0xd011]); - } catch (err) { + } catch { /* do nothing */ } await endpoint.read('genPowerCfg', ['batteryVoltage', 'batteryPercentageRemaining']); @@ -404,7 +404,7 @@ const definitions: DefinitionWithExtend[] = [ try { await tuya.sendDataPointBool(endpoint, 109, false); await tuya.sendDataPointBool(endpoint, 108, false); - } catch (e) { + } catch { // ignore, just prevent any crashes } } diff --git a/src/devices/lifecontrol.ts b/src/devices/lifecontrol.ts index d58a63b773f2c..3211dbcdc557e 100644 --- a/src/devices/lifecontrol.ts +++ b/src/devices/lifecontrol.ts @@ -61,7 +61,7 @@ function electricityMeterPoll(): ModernExtend { try { await endpoint.read('haElectricalMeasurement', ['rmsVoltage', 'rmsCurrent', 'activePower']); await endpoint.read('seMetering', ['currentSummDelivered', 'multiplier', 'divisor']); - } catch (error) { + } catch { // Do nothing } }, 10 * 1000); // Every 10 seconds diff --git a/src/devices/livolo.ts b/src/devices/livolo.ts index bc1fff104bbe3..4b7f355102160 100644 --- a/src/devices/livolo.ts +++ b/src/devices/livolo.ts @@ -12,7 +12,7 @@ const poll = async (device: Zh.Device) => { const endpoint = device.getEndpoint(6); const options = {transactionSequenceNumber: 0, srcEndpoint: 8, disableResponse: true, disableRecovery: true}; await endpoint.command('genOnOff', 'toggle', {}, options); - } catch (error) { + } catch { // device is lost, need to permit join } }; diff --git a/src/devices/lixee.ts b/src/devices/lixee.ts index f3e4479b7b6d2..ddf8d7df354a5 100644 --- a/src/devices/lixee.ts +++ b/src/devices/lixee.ts @@ -1647,7 +1647,7 @@ function getCurrentConfig(device: Zh.Device, options: KeyValue) { lMode.raiseError; // raise if undefined // @ts-expect-error return ((lMode >> bitLinkyMode) & 1) == 1 ? valueTrue : valueFalse; - } catch (err) { + } catch { logger.warning(`Was not able to detect the Linky ` + targetOption + `. Default to ` + valueDefault, NS); return valueDefault; // default value in the worst case } @@ -1680,7 +1680,7 @@ function getCurrentConfig(device: Zh.Device, options: KeyValue) { lixAtts.raiseIfEmpty; // @ts-expect-error currentTarf = fzLocal.lixee_private_fz.convert({}, {data: lixAtts}).current_tarif; - } catch (error) { + } catch { logger.warning(`Not able to detect the current tarif. Not filtering any expose...`, NS); } } @@ -1903,7 +1903,7 @@ const definitions: DefinitionWithExtend[] = [ } } } - } catch (error) { + } catch { /* Do nothing*/ } setTimer(); diff --git a/src/devices/lumi.ts b/src/devices/lumi.ts index 953969c6311d7..5f2384ce2227b 100644 --- a/src/devices/lumi.ts +++ b/src/devices/lumi.ts @@ -328,7 +328,7 @@ const definitions: DefinitionWithExtend[] = [ try { const endpoint = device.endpoints[1]; await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff', 'genPowerCfg']); - } catch (error) { + } catch { // fails for some but device works as expected: https://github.com/Koenkk/zigbee2mqtt/issues/9136 } }, @@ -2135,7 +2135,7 @@ const definitions: DefinitionWithExtend[] = [ const interval = setInterval(async () => { try { await switchEndpoint.read('genDeviceTempCfg', ['currentTemperature']); - } catch (error) { + } catch { // Do nothing } }, 1800000); diff --git a/src/devices/mercator.ts b/src/devices/mercator.ts index d0630faca9f3c..c82dec5ca2f4e 100644 --- a/src/devices/mercator.ts +++ b/src/devices/mercator.ts @@ -39,7 +39,7 @@ const definitions: DefinitionWithExtend[] = [ await reporting.bind(endpoint, coordinatorEndpoint, ['genPowerCfg']); try { await reporting.batteryPercentageRemaining(endpoint); - } catch (error) { + } catch { /* Fails for some https://github.com/Koenkk/zigbee2mqtt/issues/13708*/ } }, @@ -68,7 +68,7 @@ const definitions: DefinitionWithExtend[] = [ await reporting.bind(endpoint, coordinatorEndpoint, ['genPowerCfg']); await reporting.batteryPercentageRemaining(endpoint); await reporting.batteryVoltage(endpoint); - } catch (error) { + } catch { /* Fails for some*/ } }, diff --git a/src/devices/moes.ts b/src/devices/moes.ts index db1cf58e688f4..797022f9850ef 100644 --- a/src/devices/moes.ts +++ b/src/devices/moes.ts @@ -552,7 +552,7 @@ const definitions: DefinitionWithExtend[] = [ await endpoint.read('genOnOff', ['tuyaOperationMode']); try { await endpoint.read(0xe001, [0xd011]); - } catch (err) { + } catch { /* do nothing */ } await endpoint.read('genPowerCfg', ['batteryVoltage', 'batteryPercentageRemaining']); diff --git a/src/devices/namron.ts b/src/devices/namron.ts index fc9cf07204eb1..72e12e2f4cd1a 100644 --- a/src/devices/namron.ts +++ b/src/devices/namron.ts @@ -622,7 +622,7 @@ const definitions: DefinitionWithExtend[] = [ const time = Math.round((new Date().getTime() - constants.OneJanuary2000) / 1000 + new Date().getTimezoneOffset() * -1 * 60); const values = {time: time}; await endpoint.write('genTime', values); - } catch (error) { + } catch { /* Do nothing*/ } }, hours24); diff --git a/src/devices/owon.ts b/src/devices/owon.ts index 5ecfaa1e03fb1..3725f6fdcef81 100644 --- a/src/devices/owon.ts +++ b/src/devices/owon.ts @@ -5,7 +5,6 @@ import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; import {battery, iasZoneAlarm} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; -import * as tuya from '../lib/tuya'; import {DefinitionWithExtend, Fz, KeyValue} from '../lib/types'; const e = exposes.presets; diff --git a/src/devices/sinope.ts b/src/devices/sinope.ts index 5694b64bc85b7..44ca17cd5e1d8 100644 --- a/src/devices/sinope.ts +++ b/src/devices/sinope.ts @@ -716,7 +716,7 @@ const definitions: DefinitionWithExtend[] = [ ]); try { await reporting.thermostatSystemMode(endpoint); - } catch (error) { + } catch { /* Not all support this */ } @@ -726,7 +726,7 @@ const definitions: DefinitionWithExtend[] = [ try { await endpoint.read('haElectricalMeasurement', ['acPowerMultiplier', 'acPowerDivisor']); await reporting.activePower(endpoint, {min: 10, max: 305, change: 1}); // divider 1: 1W - } catch (error) { + } catch { endpoint.saveClusterAttributeKeyValue('haElectricalMeasurement', {acPowerMultiplier: 1, acPowerDivisor: 1}); } await reporting.rmsCurrent(endpoint, {min: 10, max: 306, change: 100}); // divider 1000: 0.1Arms @@ -841,7 +841,7 @@ const definitions: DefinitionWithExtend[] = [ ]); try { await reporting.thermostatSystemMode(endpoint); - } catch (error) { + } catch { /* Not all support this */ } @@ -851,7 +851,7 @@ const definitions: DefinitionWithExtend[] = [ try { await endpoint.read('haElectricalMeasurement', ['acPowerMultiplier', 'acPowerDivisor']); await reporting.activePower(endpoint, {min: 10, max: 305, change: 1}); // divider 1: 1W - } catch (error) { + } catch { endpoint.saveClusterAttributeKeyValue('haElectricalMeasurement', {acPowerMultiplier: 1, acPowerDivisor: 1}); } await reporting.rmsCurrent(endpoint, {min: 10, max: 306, change: 100}); // divider 1000: 0.1Arms @@ -984,7 +984,7 @@ const definitions: DefinitionWithExtend[] = [ await reporting.thermostatRunningState(endpoint, {min: 1, max: 0xffff}); try { await reporting.thermostatUnoccupiedHeatingSetpoint(endpoint); - } catch (error) { + } catch { /* Do nothing */ } }, @@ -1115,7 +1115,7 @@ const definitions: DefinitionWithExtend[] = [ await reporting.thermostatRunningState(endpoint, {min: 1, max: 0xffff}); try { await reporting.thermostatUnoccupiedHeatingSetpoint(endpoint); - } catch (error) { + } catch { /* Do nothing */ } }, @@ -1223,36 +1223,36 @@ const definitions: DefinitionWithExtend[] = [ await reporting.thermostatOccupiedHeatingSetpoint(endpoint); try { await reporting.readMeteringMultiplierDivisor(endpoint); - } catch (error) { + } catch { /* Do nothing*/ } try { await reporting.currentSummDelivered(endpoint, {min: 10, max: 303, change: [1, 1]}); - } catch (error) { + } catch { /* Do nothing*/ } try { await endpoint.read('haElectricalMeasurement', ['acPowerMultiplier', 'acPowerDivisor']); await reporting.activePower(endpoint, {min: 10, max: 305, change: 1}); // divider 1: 1W - } catch (error) { + } catch { endpoint.saveClusterAttributeKeyValue('haElectricalMeasurement', {acPowerMultiplier: 1, acPowerDivisor: 1}); } try { await endpoint.read('haElectricalMeasurement', ['acCurrentMultiplier', 'acCurrentDivisor']); await reporting.rmsCurrent(endpoint, {min: 10, max: 306, change: 100}); // divider 1000: 0.1Arms - } catch (error) { + } catch { /* Do nothing*/ } try { await endpoint.read('haElectricalMeasurement', ['acVoltageMultiplier', 'acVoltageDivisor']); await reporting.rmsVoltage(endpoint, {min: 10, max: 307, change: 5}); // divider 10: 0.5Vrms - } catch (error) { + } catch { /* Do nothing*/ } try { await reporting.thermostatKeypadLockMode(endpoint); - } catch (error) { + } catch { // Not all support this: https://github.com/Koenkk/zigbee2mqtt/issues/3760 } @@ -1414,7 +1414,7 @@ const definitions: DefinitionWithExtend[] = [ try { await reporting.thermostatSystemMode(endpoint); - } catch (error) { + } catch { /* Not all support this */ } @@ -1589,7 +1589,7 @@ const definitions: DefinitionWithExtend[] = [ try { await reporting.readMeteringMultiplierDivisor(endpoint); await reporting.currentSummDelivered(endpoint, {min: 10, max: 300, change: [0, 10]}); - } catch (error) { + } catch { /* Do nothing*/ } const payload = [ @@ -1869,12 +1869,12 @@ const definitions: DefinitionWithExtend[] = [ await reporting.brightness(endpoint); // valve position try { await reporting.batteryVoltage(endpoint); - } catch (error) { + } catch { /* Do Nothing */ } try { await reporting.batteryAlarmState(endpoint); - } catch (error) { + } catch { /* Do Nothing */ } }, diff --git a/src/devices/smartthings.ts b/src/devices/smartthings.ts index dd8aa0c882606..651fc37e2d74d 100644 --- a/src/devices/smartthings.ts +++ b/src/devices/smartthings.ts @@ -169,7 +169,7 @@ const definitions: DefinitionWithExtend[] = [ try { // https://github.com/Koenkk/zigbee2mqtt/issues/11706 await reporting.readEletricalMeasurementMultiplierDivisors(endpoint); - } catch (error) { + } catch { /* Fails for some*/ } await reporting.activePower(endpoint); diff --git a/src/devices/sunricher.ts b/src/devices/sunricher.ts index 326381da29579..063dc156e5301 100644 --- a/src/devices/sunricher.ts +++ b/src/devices/sunricher.ts @@ -68,7 +68,7 @@ async function syncTime(endpoint: Zh.Endpoint) { const time = Math.round((new Date().getTime() - constants.OneJanuary2000) / 1000 + new Date().getTimezoneOffset() * -1 * 60); const values = {time: time}; await endpoint.write('genTime', values); - } catch (error) { + } catch { /* Do nothing*/ } } @@ -623,7 +623,7 @@ const definitions: DefinitionWithExtend[] = [ await reporting.thermostatUnoccupiedHeatingSetpoint(endpoint); try { await reporting.thermostatKeypadLockMode(endpoint); - } catch (error) { + } catch { // Fails for some // https://github.com/Koenkk/zigbee2mqtt/issues/15025 logger.debug(`Failed to setup keypadLockout reporting`, NS); diff --git a/src/devices/third_reality.ts b/src/devices/third_reality.ts index 7d9739907888f..09136e70505f3 100644 --- a/src/devices/third_reality.ts +++ b/src/devices/third_reality.ts @@ -165,7 +165,7 @@ const definitions: DefinitionWithExtend[] = [ await reporting.currentPositionLiftPercentage(endpoint); try { await reporting.batteryPercentageRemaining(endpoint); - } catch (error) { + } catch { /* Fails for some*/ } }, diff --git a/src/devices/tuya.ts b/src/devices/tuya.ts index 6c272d9e633e0..52376eba8089d 100644 --- a/src/devices/tuya.ts +++ b/src/devices/tuya.ts @@ -900,7 +900,7 @@ const definitions: DefinitionWithExtend[] = [ await reporting.bind(endpoint, coordinatorEndpoint, ['genPowerCfg']); await reporting.batteryPercentageRemaining(endpoint); await reporting.batteryVoltage(endpoint); - } catch (error) { + } catch { /* Fails for some*/ } }, @@ -1760,7 +1760,7 @@ const definitions: DefinitionWithExtend[] = [ try { await reporting.batteryPercentageRemaining(endpoint); await reporting.batteryVoltage(endpoint); - } catch (error) { + } catch { /* Fails for some https://github.com/Koenkk/zigbee2mqtt/issues/13708 */ } }, @@ -3263,7 +3263,7 @@ const definitions: DefinitionWithExtend[] = [ await endpoint.read('genOnOff', ['tuyaOperationMode']); try { await endpoint.read(0xe001, [0xd011]); - } catch (err) { + } catch { /* do nothing */ } await endpoint.read('genPowerCfg', ['batteryVoltage', 'batteryPercentageRemaining']); @@ -3324,7 +3324,7 @@ const definitions: DefinitionWithExtend[] = [ await endpoint.read('genOnOff', ['tuyaOperationMode']); try { await endpoint.read(0xe001, [0xd011]); - } catch (err) { + } catch { /* do nothing */ } await endpoint.read('genPowerCfg', ['batteryVoltage', 'batteryPercentageRemaining']); @@ -5081,7 +5081,7 @@ const definitions: DefinitionWithExtend[] = [ await reporting.rmsVoltage(endpoint, {change: 5}); await reporting.rmsCurrent(endpoint, {change: 50}); await reporting.activePower(endpoint, {change: 10}); - } catch (error) { + } catch { /* fails for some https://github.com/Koenkk/zigbee2mqtt/issues/11179 and https://github.com/Koenkk/zigbee2mqtt/issues/16864 */ } @@ -5951,7 +5951,7 @@ const definitions: DefinitionWithExtend[] = [ const endpoint = device.getEndpoint(ID); await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff']); } - } catch (e) { + } catch { // Fails for some: https://github.com/Koenkk/zigbee2mqtt/issues/4872 } device.powerSource = 'Mains (single phase)'; @@ -5983,7 +5983,7 @@ const definitions: DefinitionWithExtend[] = [ const endpoint = device.getEndpoint(ID); await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff']); } - } catch (e) { + } catch { // Fails for some: https://github.com/Koenkk/zigbee2mqtt/issues/4872 } device.powerSource = 'Mains (single phase)'; @@ -6013,7 +6013,7 @@ const definitions: DefinitionWithExtend[] = [ const endpoint = device.getEndpoint(ID); await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff']); } - } catch (e) { + } catch { // Fails for some: https://github.com/Koenkk/zigbee2mqtt/issues/4872 } device.powerSource = 'Mains (single phase)'; @@ -6937,7 +6937,7 @@ const definitions: DefinitionWithExtend[] = [ await endpoint.read('genOnOff', ['tuyaOperationMode']); try { await endpoint.read(0xe001, [0xd011]); - } catch (err) { + } catch { /* do nothing */ } await endpoint.read('genPowerCfg', ['batteryVoltage', 'batteryPercentageRemaining']); @@ -7032,7 +7032,7 @@ const definitions: DefinitionWithExtend[] = [ await endpoint.read('genOnOff', ['tuyaOperationMode']); try { await endpoint.read(0xe001, [0xd011]); - } catch (err) { + } catch { /* do nothing */ } await endpoint.read('genPowerCfg', ['batteryVoltage', 'batteryPercentageRemaining']); diff --git a/src/devices/ubisys.ts b/src/devices/ubisys.ts index 5af18d611f1b6..87e2c79890fc3 100644 --- a/src/devices/ubisys.ts +++ b/src/devices/ubisys.ts @@ -34,7 +34,7 @@ const ubisysOnEventReadCurrentSummDelivered = async function (type: OnEventType, if (data.type === 'attributeReport' && data.cluster === 'seMetering') { try { await data.endpoint.read('seMetering', ['currentSummDelivered']); - } catch (error) { + } catch { /* Do nothing*/ } } diff --git a/src/devices/yale.ts b/src/devices/yale.ts index c7af4d5375fb5..15f1072c40741 100644 --- a/src/devices/yale.ts +++ b/src/devices/yale.ts @@ -47,7 +47,7 @@ const lockExtend = (meta = {}, lockStateOptions: Reporting.Override | false = nu await reporting.batteryPercentageRemaining(endpoint); try { await reporting.batteryAlarmState(endpoint); - } catch (e) { + } catch { // Fails for some: https://github.com/Koenkk/zigbee-herdsman-converters/pull/5414 } }, @@ -99,7 +99,7 @@ const fzLocal = { // We need to read the lock attributes as these are not reported by the device try { await msg.endpoint.read('manuSpecificAssaDoorLock', ['batteryLevel']); - } catch (error) { + } catch { logger.warning(`Failed to read lock attributes`, NS); } return result; @@ -203,7 +203,7 @@ const fzLocal = { // We need to read the lock state as the alarm code is unknown try { await msg.endpoint.read('closuresDoorLock', ['lockState']); - } catch (error) { + } catch { logger.warning(`Failed to read lock state`, NS); } } else { diff --git a/src/devices/zemismart.ts b/src/devices/zemismart.ts index 4e43079631e07..6fcc8846ef57e 100644 --- a/src/devices/zemismart.ts +++ b/src/devices/zemismart.ts @@ -2,7 +2,7 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; import * as legacy from '../lib/legacy'; -import {battery, deviceEndpoints, forcePowerSource, identify, light, onOff} from '../lib/modernExtend'; +import {deviceEndpoints, forcePowerSource, identify, light, onOff} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import * as tuya from '../lib/tuya'; import {DefinitionWithExtend} from '../lib/types'; diff --git a/src/lib/develco.ts b/src/lib/develco.ts index e7afd82a9130e..5732aa7b25f30 100644 --- a/src/lib/develco.ts +++ b/src/lib/develco.ts @@ -1,19 +1,9 @@ import {Zcl} from 'zigbee-herdsman'; import {presets as e, access as ea} from './exposes'; -import {logger} from './logger'; -import { - deviceAddCustomCluster, - deviceTemperature, - numeric, - NumericArgs, - ScaleFunction, - setupConfigureForReporting, - temperature, -} from './modernExtend'; -import {Configure, Fz, ModernExtend, Tz} from './types'; +import {deviceAddCustomCluster, deviceTemperature, numeric, NumericArgs, temperature} from './modernExtend'; +import {Configure, Fz, ModernExtend} from './types'; -const NS = 'zhc:develco'; const manufacturerOptions = {manufacturerCode: Zcl.ManufacturerCode.DEVELCO}; export const develcoModernExtend = { @@ -62,7 +52,7 @@ export const develcoModernExtend = { } device.save(); - } catch (error) { + } catch { /* catch timeouts of sleeping devices */ } break; diff --git a/src/lib/legacy.ts b/src/lib/legacy.ts index 23122218b280e..f89d39725c1fa 100644 --- a/src/lib/legacy.ts +++ b/src/lib/legacy.ts @@ -4443,7 +4443,7 @@ const fromZigbee1 = { convert: (model, msg, publish, options, meta) => { const separateWhite = model.meta && model.meta.separateWhite; const result: KeyValueAny = {}; - for (const [i, dpValue] of msg.data.dpValues.entries()) { + for (const dpValue of msg.data.dpValues.values()) { const dp = dpValue.dp; const value = getDataValue(dpValue); if (dp === dataPoints.state) { diff --git a/src/lib/light.ts b/src/lib/light.ts index 10c5f9f83350b..75d8a5601c229 100644 --- a/src/lib/light.ts +++ b/src/lib/light.ts @@ -101,7 +101,7 @@ export async function configure(device: Zh.Device, coordinatorEndpoint: Zh.Endpo if (readColorTempMinMaxAttribute) { await readColorTempMinMax(endpoint); } - } catch (e) { + } catch { /* Fails for some, e.g. https://github.com/Koenkk/zigbee2mqtt/issues/5717 */ } } diff --git a/src/lib/lumi.ts b/src/lib/lumi.ts index 86414d6746ee9..9a1b4bc8d8b3d 100644 --- a/src/lib/lumi.ts +++ b/src/lib/lumi.ts @@ -32,7 +32,6 @@ import { getKey, getOptions, hasAlreadyProcessedMessage, - isEndpoint, isLegacyEnabled, isObject, isString, @@ -619,7 +618,7 @@ export const numericAttributes2Payload = async (msg: Fz.Message, meta: Fz.Meta, await callback(); payload.operation_mode = newMode; globalStore.putValue(meta.device, 'opModeSwitchTask', null); - } catch (error) { + } catch { // do nothing when callback fails } } else { @@ -1803,7 +1802,10 @@ export const lumiModernExtend = { try { await endpoint.bind(b.cluster.name, b.target); } catch (error) { - logger.debug(`Failed to re-bind ${b.cluster.name} from ${b.target} for ${msg.device.ieeeAddr}.`, NS); + logger.debug( + `Failed to re-bind ${b.cluster.name} from ${b.target} for ${msg.device.ieeeAddr} (${error})`, + NS, + ); } } @@ -1818,7 +1820,7 @@ export const lumiModernExtend = { reportableChange: c.reportableChange, }, ]); - } catch (error) { + } catch { logger.debug( `Failed to re-setup reporting of ${c.cluster.name}/${c.attribute.name} for ${msg.device.ieeeAddr}.`, NS, diff --git a/src/lib/ota/common.ts b/src/lib/ota/common.ts index 1de8077c326c2..7971429ec9ed3 100644 --- a/src/lib/ota/common.ts +++ b/src/lib/ota/common.ts @@ -394,7 +394,7 @@ async function requestOTA(endpoint: Zh.Endpoint): Promise<[transNum: number, Ota const response = await queryNextImageRequest.promise; return [response.header.transactionSequenceNumber, response.payload as Ota.ImageInfo]; - } catch (e) { + } catch { queryNextImageRequest.cancel(); throw new Error(`Device didn't respond to OTA request`); diff --git a/src/lib/tuya.ts b/src/lib/tuya.ts index 89a578864a36f..5130d2f480308 100644 --- a/src/lib/tuya.ts +++ b/src/lib/tuya.ts @@ -96,35 +96,10 @@ export function onEvent(args?: { payload: [...convertDecimalValueTo4ByteHexArray(utcTime), ...convertDecimalValueTo4ByteHexArray(localTime)], }; await endpoint.command('manuSpecificTuya', 'mcuSyncTime', payload, {}); - } catch (error) { + } catch { /* handle error to prevent crash */ } } - - // Some devices require a dataQuery on deviceAnnounce, otherwise they don't report any data - if (args.queryOnDeviceAnnounce && type === 'deviceAnnounce') { - await endpoint.command('manuSpecificTuya', 'dataQuery', {}); - } - - if (args.queryIntervalSeconds) { - if (type === 'stop') { - clearTimeout(globalStore.getValue(device, 'query_interval')); - globalStore.clearValue(device, 'query_interval'); - } else if (!globalStore.hasValue(device, 'query_interval')) { - const setTimer = () => { - const timer = setTimeout(async () => { - try { - await endpoint.command('manuSpecificTuya', 'dataQuery', {}); - } catch (error) { - /* Do nothing*/ - } - setTimer(); - }, args.queryIntervalSeconds * 1000); - globalStore.putValue(device, 'query_interval', timer); - }; - setTimer(); - } - } }; } @@ -201,7 +176,7 @@ export async function onEventSetTime(type: OnEventType, data: KeyValue, device: payload: [...convertDecimalValueTo4ByteHexArray(utcTime), ...convertDecimalValueTo4ByteHexArray(localTime)], }; await endpoint.command('manuSpecificTuya', 'mcuSyncTime', payload, {}); - } catch (error) { + } catch { // endpoint.command can throw an error which needs to // be caught or the zigbee-herdsman may crash // Debug message is handled in the zigbee-herdsman @@ -234,7 +209,7 @@ export async function onEventSetLocalTime(type: OnEventType, data: KeyValue, dev payload: [...convertDecimalValueTo4ByteHexArray(utcTime), ...convertDecimalValueTo4ByteHexArray(localTime)], }; await endpoint.command('manuSpecificTuya', 'mcuSyncTime', payload, {}); - } catch (error) { + } catch { // endpoint.command can throw an error which needs to // be caught or the zigbee-herdsman may crash // Debug message is handled in the zigbee-herdsman @@ -1309,9 +1284,6 @@ const tuyaTz = { inchingSwitch: { key: ['inching_control_set'], convertSet: async (entity, key, value: KeyValue, meta) => { - const inchingControl = 'inching_control'; - const inchingTime = 'inching_time'; - const result = {}; const inching = valueConverter.inchingSwitch.to(value); const payload = {payload: inching}; const endpoint = meta.device.getEndpoint(1); diff --git a/src/lib/utils.ts b/src/lib/utils.ts index d2233d57bb7a6..be1d376c09589 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,6 +1,6 @@ import {Zcl} from 'zigbee-herdsman'; -import {Feature, Light, Numeric} from './exposes'; +import {Light, Numeric} from './exposes'; import {logger} from './logger'; import * as globalStore from './store'; import { @@ -51,7 +51,7 @@ export function onEventPoll( const timer = setTimeout(async () => { try { await poll(); - } catch (error) { + } catch { /* Do nothing*/ } setTimer(); @@ -195,7 +195,7 @@ export function calibrateAndPrecisionRoundOptions(number: number, options: KeyVa return precisionRound(number, precision); } -export function toPercentage(value: number, min: number, max: number, log = false) { +export function toPercentage(value: number, min: number, max: number) { if (value > max) { value = max; } else if (value < min) { From 9cf1183031651d88f699af1e97cd40fb1745668c Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Sun, 8 Sep 2024 22:56:41 +0200 Subject: [PATCH 07/12] @typescript-eslint/ban-ts-comment --- eslint.config.mjs | 2 +- scripts/modernExtendRefactor.ts | 12 +- src/converters/fromZigbee.ts | 2 +- src/converters/toZigbee.ts | 44 +++---- src/devices/datek.ts | 2 +- src/devices/inovelli.ts | 34 +++--- src/devices/kmpcil.ts | 2 +- src/devices/lidl.ts | 20 ++-- src/devices/lixee.ts | 26 ++--- src/devices/niko.ts | 6 +- src/devices/perenio.ts | 4 +- src/devices/saswell.ts | 2 +- src/devices/schneider_electric.ts | 2 +- src/devices/sinope.ts | 18 +-- src/devices/tuya.ts | 4 +- src/devices/ubisys.ts | 10 +- src/devices/wirenboard.ts | 4 +- src/index.ts | 8 +- src/lib/color.ts | 4 +- src/lib/configureKey.ts | 4 +- src/lib/exposes.ts | 2 +- src/lib/legacy.ts | 187 +++++++++++++++--------------- src/lib/lumi.ts | 64 +++++----- src/lib/modernExtend.ts | 12 +- src/lib/ota/inovelli.ts | 6 +- src/lib/ota/salus.ts | 2 +- src/lib/philips.ts | 8 +- src/lib/reporting.ts | 6 +- src/lib/tuya.ts | 6 +- src/lib/utils.ts | 14 +-- test/utils.ts | 12 +- 31 files changed, 262 insertions(+), 267 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index bb22f62299d9d..7ccf86428a66f 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -15,7 +15,7 @@ export default tseslint.config( }, rules: { '@typescript-eslint/await-thenable': 'error', - '@typescript-eslint/ban-ts-comment': 'off', // TODO error + '@typescript-eslint/ban-ts-comment': 'error', '@typescript-eslint/explicit-function-return-type': 'off', // TODO error '@typescript-eslint/no-explicit-any': 'error', '@typescript-eslint/no-unused-vars': ['error', {args: 'none'}], diff --git a/scripts/modernExtendRefactor.ts b/scripts/modernExtendRefactor.ts index dfb36cb1d0114..f9b4da654a274 100644 --- a/scripts/modernExtendRefactor.ts +++ b/scripts/modernExtendRefactor.ts @@ -60,10 +60,10 @@ project.getSourceFiles().forEach((sourceFile) => { const evalOpts = Object.entries(eval(`(${opts})`)); for (const [key, value] of evalOpts) { if (key === 'colorTempRange') { - // @ts-expect-error + // @ts-expect-error ignore newOpts.colorTemp = {...newOpts.colorTemp, range: value}; } else if (key === 'disableColorTempStartup') { - // @ts-expect-error + // @ts-expect-error ignore newOpts.colorTemp = {...newOpts.colorTemp, startup: !value}; } else if (key === 'disablePowerOnBehavior') { newOpts.powerOnBehavior = !value; @@ -72,10 +72,10 @@ project.getSourceFiles().forEach((sourceFile) => { } else if (key === 'disableHueEffects') { newOpts.hueEffect = !value; } else if (key === 'supportsHueAndSaturation' || key === 'preferHueAndSaturation') { - // @ts-expect-error + // @ts-expect-error ignore newOpts.color = {...newOpts.color, modes: evalOpts.preferHueAndSaturation ? ['hs', 'xy'] : ['xy', 'hs']}; } else if (key === 'extraEffects') { - // @ts-expect-error + // @ts-expect-error ignore newOpts.gradient = {...newOpts.gradient, extraEffects: value}; } else if (key === 'noConfigure') { // ignore @@ -89,10 +89,10 @@ project.getSourceFiles().forEach((sourceFile) => { // if (key === 'turnsOffAtBrightness1') { // newOpts.turnsOffAtBrightness1 = value; // } else if (key === 'applyRedFix') { - // // @ts-expect-error + // // @ts-expect-error ignore // newOpts.color = {...newOpts.color, applyRedFix: value}; // } else if (key === 'supportsEnhancedHue') { - // // @ts-expect-error + // // @ts-expect-error ignore // newOpts.color = {...newOpts.color, enhancedHue: value}; // } else if (key === 'multiEndpoint' || key === 'disableDefaultResponse') { // // ignore diff --git a/src/converters/fromZigbee.ts b/src/converters/fromZigbee.ts index 5de2e6b052724..1e4001bb5f90e 100644 --- a/src/converters/fromZigbee.ts +++ b/src/converters/fromZigbee.ts @@ -2357,7 +2357,7 @@ const converters1 = { convert: (model, msg, publish, options, meta) => { const dp = msg.data[10]; const defaults = {motor_direction: 'FORWARD', motor_speed: 40}; - // @ts-expect-error + // @ts-expect-error ignore if ((msg.data[0] === 0x7a) & (msg.data[1] === 0xd1)) { const reportType = msg.data[12]; switch (dp) { diff --git a/src/converters/toZigbee.ts b/src/converters/toZigbee.ts index 64051eab2d5d9..e6a848efb4bbf 100644 --- a/src/converters/toZigbee.ts +++ b/src/converters/toZigbee.ts @@ -105,7 +105,7 @@ const converters1 = { } else { zclData.hue = utils.mapNumberRange(hsvCorrected.hue, 0, 360, 0, 254); } - // @ts-expect-error + // @ts-expect-error ignore zclData.direction = value.direction || 0; } @@ -115,7 +115,7 @@ const converters1 = { if (hsv.value !== null) { // fallthrough to genLevelCtrl - // @ts-expect-error + // @ts-expect-error ignore value.brightness = utils.mapNumberRange(hsvCorrected.value, 0, 100, 0, 254); } @@ -140,7 +140,7 @@ const converters1 = { await entity.command( 'genLevelCtrl', 'moveToLevelWithOnOff', - // @ts-expect-error + // @ts-expect-error ignore {level: Number(value.brightness), transtime: utils.getTransition(entity, key, meta).time}, utils.getOptions(meta.mapped, entity), ); @@ -385,7 +385,7 @@ const converters2 = { } }, convertGet: async (entity, key, meta) => { - // @ts-expect-error + // @ts-expect-error ignore const user = meta && meta.message && meta.message.pin_code ? meta.message.pin_code.user : undefined; if (user === undefined) { const max = utils.getMetaValue(entity, meta.mapped, 'pinCodeCount'); @@ -437,7 +437,7 @@ const converters2 = { ); }, convertGet: async (entity, key, meta) => { - // @ts-expect-error + // @ts-expect-error ignore const user = meta && meta.message && meta.message.user_status ? meta.message.user_status.user : undefined; const pinCodeCount = utils.getMetaValue(entity, meta.mapped, 'pinCodeCount'); if (user === undefined) { @@ -500,17 +500,17 @@ const converters2 = { const strobeLevel = {low: 0, medium: 1, high: 2, very_high: 3}; const values = { - // @ts-expect-error + // @ts-expect-error ignore mode: value.mode || 'emergency', - // @ts-expect-error + // @ts-expect-error ignore level: value.level || 'medium', - // @ts-expect-error + // @ts-expect-error ignore strobe: value.hasOwnProperty('strobe') ? value.strobe : true, - // @ts-expect-error + // @ts-expect-error ignore duration: value.hasOwnProperty('duration') ? value.duration : 10, - // @ts-expect-error + // @ts-expect-error ignore strobeDutyCycle: value.hasOwnProperty('strobe_duty_cycle') ? value.strobe_duty_cycle * 10 : 0, - // @ts-expect-error + // @ts-expect-error ignore strobeLevel: value.hasOwnProperty('strobe_level') ? utils.getFromLookup(value.strobe_level, strobeLevel) : 1, }; @@ -825,7 +825,7 @@ const converters2 = { 'lamp_burn_hours_trip_point', ]) { try { - // @ts-expect-error + // @ts-expect-error ignore result = {...result, ...(await entity.read('lightingBallastCfg', [utils.toCamelCase(attrName)]))}; } catch { // continue regardless of error @@ -1116,7 +1116,7 @@ const converters2 = { try { const attributeRead = await entity.read('genLevelCtrl', ['onLevel']); if (attributeRead !== undefined) { - // @ts-expect-error + // @ts-expect-error ignore onLevel = attributeRead['onLevel']; } } catch { @@ -2784,9 +2784,9 @@ const converters2 = { const zclData = { brightness: globalStore.getValue(entity, 'brightness') || 100, - // @ts-expect-error + // @ts-expect-error ignore hue: utils.mapNumberRange(meta.state.color.h, 0, 360, 0, 254) || 100, - // @ts-expect-error + // @ts-expect-error ignore saturation: utils.mapNumberRange(meta.state.color.s, 0, 100, 0, 254) || 100, transtime: 0, }; @@ -3368,7 +3368,7 @@ const converters2 = { let value = utils.getFromLookup(rawValue, lookup, Number(rawValue)); if (key == 'sensors_type') { - // @ts-expect-error + // @ts-expect-error ignore value = utils.getFromLookup(rawValue, sensorsTypeLookup, Number(rawValue)); } @@ -3437,7 +3437,7 @@ const converters2 = { const modeOpenLookup = {never: '0', once: '1', always: '2', drop: '3'}; let value = utils.getFromLookup(rawValue, lookup, Number(rawValue)); if (key == 'mode') { - // @ts-expect-error + // @ts-expect-error ignore value = utils.getFromLookup(rawValue, modeOpenLookup, Number(rawValue)); } const payloads: KeyValueAny = { @@ -3506,7 +3506,7 @@ const converters2 = { const options = { // Don't send a manufacturerCode (otherwise set in herdsman): // https://github.com/Koenkk/zigbee-herdsman-converters/pull/2827 - // @ts-expect-error + // @ts-expect-error ignore manufacturerCode: null, ...utils.getOptions(meta.mapped, entity), }; @@ -3563,11 +3563,11 @@ const converters2 = { utils.saveSceneState(member, sceneid, groupid, meta.membersState[member.getDevice().ieeeAddr], scenename); } } - // @ts-expect-error + // @ts-expect-error ignore } else if (response.status === 0) { utils.saveSceneState(entity, sceneid, groupid, meta.state, scenename); } else { - // @ts-expect-error + // @ts-expect-error ignore throw new Error(`Scene add not successful ('${Zcl.Status[response.status]}')`); } logger.info('Successfully stored scene', NS); @@ -3798,11 +3798,11 @@ const converters2 = { utils.deleteSceneState(member, sceneid, groupid); } } - // @ts-expect-error + // @ts-expect-error ignore } else if (response.status === 0) { utils.deleteSceneState(entity, sceneid, groupid); } else { - // @ts-expect-error + // @ts-expect-error ignore throw new Error(`Scene remove not successful ('${Zcl.Status[response.status]}')`); } logger.info('Successfully removed scene', NS); diff --git a/src/devices/datek.ts b/src/devices/datek.ts index 9eb7a29dfabee..b493d118cf5ea 100644 --- a/src/devices/datek.ts +++ b/src/devices/datek.ts @@ -130,7 +130,7 @@ const definitions: DefinitionWithExtend[] = [ attribute: {ID: 0x4000, type: 0x10}, }, ]; - // @ts-expect-error + // @ts-expect-error ignore await endpoint.configureReporting('ssIasZone', payload, options); await endpoint.read('ssIasZone', ['iasCieAddr', 'zoneState', 'zoneId']); await endpoint.read('msOccupancySensing', ['pirOToUDelay']); diff --git a/src/devices/inovelli.ts b/src/devices/inovelli.ts index 2b17f7979589e..d3b4c6e890227 100644 --- a/src/devices/inovelli.ts +++ b/src/devices/inovelli.ts @@ -273,7 +273,7 @@ const attributesToExposeList = (ATTRIBUTES: {[s: string]: Attribute}, exposesLis .binary( key, ATTRIBUTES[key].readOnly ? ea.STATE_GET : ea.ALL, - // @ts-expect-error + // @ts-expect-error ignore ATTRIBUTES[key].values.Enabled, ATTRIBUTES[key].values.Disabled, ) @@ -1256,7 +1256,7 @@ const tzLocal = { [ATTRIBUTES[key].ID]: { value: ATTRIBUTES[key].displayType === 'enum' - ? // @ts-expect-error + ? // @ts-expect-error ignore ATTRIBUTES[key].values[value] : value, type: ATTRIBUTES[key].dataType, @@ -1311,13 +1311,13 @@ const tzLocal = { 'manuSpecificInovelli', 'ledEffect', { - // @ts-expect-error + // @ts-expect-error ignore effect: ledEffects[values.effect], - // @ts-expect-error + // @ts-expect-error ignore color: Math.min(Math.max(0, values.color), 255), - // @ts-expect-error + // @ts-expect-error ignore level: Math.min(Math.max(0, values.level), 100), - // @ts-expect-error + // @ts-expect-error ignore duration: Math.min(Math.max(0, values.duration), 255), }, {disableResponse: true, disableDefaultResponse: true}, @@ -1332,15 +1332,15 @@ const tzLocal = { 'manuSpecificInovelli', 'individualLedEffect', { - // @ts-expect-error + // @ts-expect-error ignore led: Math.min(Math.max(0, parseInt(values.led)), 7), - // @ts-expect-error + // @ts-expect-error ignore effect: individualLedEffects[values.effect], - // @ts-expect-error + // @ts-expect-error ignore color: Math.min(Math.max(0, values.color), 255), - // @ts-expect-error + // @ts-expect-error ignore level: Math.min(Math.max(0, values.level), 100), - // @ts-expect-error + // @ts-expect-error ignore duration: Math.min(Math.max(0, values.duration), 255), }, {disableResponse: true, disableDefaultResponse: true}, @@ -1359,7 +1359,7 @@ const tzLocal = { const transition = utils.getTransition(entity, 'brightness', meta); const turnsOffAtBrightness1 = utils.getMetaValue(entity, meta.mapped, 'turnsOffAtBrightness1', 'allEqual', false); let state = message.hasOwnProperty('state') - ? // @ts-expect-error + ? // @ts-expect-error ignore message.state.toLowerCase() : undefined; let brightness = undefined; @@ -1403,7 +1403,7 @@ const tzLocal = { const payload = {level, transtime: transition.time}; await entity.command('genLevelCtrl', 'moveToLevelWithOnOff', payload, utils.getOptions(meta.mapped, entity)); const result = {state: {state: state.toUpperCase()}}; - // @ts-expect-error + // @ts-expect-error ignore if (state === 'on') result.state.brightness = level; return result; } else { @@ -1415,10 +1415,10 @@ const tzLocal = { } const result = await inovelliOnOffConvertSet(entity, 'state', state, meta); - // @ts-expect-error + // @ts-expect-error ignore result.readAfterWriteTime = 0; if (result.state && result.state.state === 'ON' && meta.state.brightness === 0) { - // @ts-expect-error + // @ts-expect-error ignore result.state.brightness = 1; } @@ -1450,7 +1450,7 @@ const tzLocal = { }, readAfterWriteTime: transition.time === 0 - ? // @ts-expect-error + ? // @ts-expect-error ignore defaultTransitionTime.rampRateOnToOffRemote * 100 : transition.time * 100, // need on speed }; @@ -1693,7 +1693,7 @@ const tzLocal = { * fallback to if a transition is not specified by passing 0xffff */ const inovelliOnOffConvertSet = async (entity: Zh.Endpoint | Zh.Group, key: string, value: unknown, meta: Tz.Meta) => { - // @ts-expect-error + // @ts-expect-error ignore const state = meta.message.hasOwnProperty('state') ? meta.message.state.toLowerCase() : null; utils.validateValue(state, ['toggle', 'off', 'on']); diff --git a/src/devices/kmpcil.ts b/src/devices/kmpcil.ts index a7532cfc5c03e..40ac10051235c 100644 --- a/src/devices/kmpcil.ts +++ b/src/devices/kmpcil.ts @@ -69,7 +69,7 @@ const kmpcilConverters = { if (msg.data.hasOwnProperty('batteryVoltage')) { payload.voltage = msg.data['batteryVoltage'] * 100; if (model.meta && model.meta.battery && model.meta.battery.voltageToPercentage) { - // @ts-expect-error + // @ts-expect-error ignore payload.battery = utils.batteryVoltageToPercentage(payload.voltage, model.meta.battery.voltageToPercentage); } } diff --git a/src/devices/lidl.ts b/src/devices/lidl.ts index 4be8b9a104654..759fff8053880 100644 --- a/src/devices/lidl.ts +++ b/src/devices/lidl.ts @@ -51,19 +51,19 @@ const valueConverterLocal = { const now = new Date(); const timeslot = [1, 2, 3, 4, 5, 6] .map((slotNumber) => utils.getObjectProperty(meta.state, `schedule_slot_${slotNumber}`, {})) - // @ts-expect-error + // @ts-expect-error ignore .find((ts) => ts.state === 'ON' && ts.start_hour === now.getHours() && ts.start_minute === now.getMinutes() && ts.timer > 0); if (timeslot) { - // @ts-expect-error + // @ts-expect-error ignore const iterationDuration = timeslot.timer + timeslot.pause; // automatic watering detected globalStore.putValue(meta.device, 'watering_timer_active_time_slot', { timeslot_start_timestamp: now.getTime(), // end of last watering excluding last pause - // @ts-expect-error + // @ts-expect-error ignore timeslot_end_timestamp: now.getTime() + (timeslot.iterations * iterationDuration - timeslot.pause) * 60 * 1000, - // @ts-expect-error + // @ts-expect-error ignore timer: timeslot.timer, iteration_inverval: null, // will be set in the next step iteration_start_timestamp: 0, // will be set in the next step @@ -79,7 +79,7 @@ const valueConverterLocal = { // time slot execution is already completed Date.now() > ts.timeslot_end_timestamp - 5000 || // scheduling was interrupted by turning watering on manually - // @ts-expect-error + // @ts-expect-error ignore (result.state === 'ON' && result.state != meta.state.state && meta.state.time_left > 0) ) { // reporting is no longer necessary @@ -145,11 +145,11 @@ const valueConverterLocal = { to: (value: KeyValue, meta: Tz.Meta) => { // map each day to ON/OFF and use current state as default to allow partial updates const dayValues = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'] - // @ts-expect-error + // @ts-expect-error ignore .map((dayName) => utils.getObjectProperty(value, dayName, utils.getObjectProperty(meta.state.schedule_weekday, dayName, 'OFF'))); const scheduleValue = dayValues.reduce((dayConfig, value, index) => { - // @ts-expect-error + // @ts-expect-error ignore return dayConfig | (value === 'ON' ? 1 << index : 0); }, 0); @@ -189,7 +189,7 @@ const valueConverterLocal = { if (iterations > 1 && pauseInMin === 0) throw new Error(`Pause value must be at least 1 minute when using multiple iterations`); return [ - // @ts-expect-error + // @ts-expect-error ignore state === 'ON' ? 1 : 0, // time slot enabled or not startHour, // start hour startMinute, // start minute @@ -392,10 +392,10 @@ const definitions: DefinitionWithExtend[] = [ fromZigbee: [fz.ignore_basic_report, fz.ignore_tuya_set_time, fz.ignore_onoff_report, tuya.fz.datapoints], toZigbee: [tuya.tz.datapoints], onEvent: async (type, data, device) => { - // @ts-expect-error + // @ts-expect-error ignore await tuya.onEventSetLocalTime(type, data, device); - // @ts-expect-error + // @ts-expect-error ignore if (type === 'deviceInterview' && data.status === 'successful') { // dirty hack: reset frost guard & frost alarm to get the initial state // wait 10 seconds to ensure configure is done diff --git a/src/devices/lixee.ts b/src/devices/lixee.ts index ddf8d7df354a5..982be1c7a398d 100644 --- a/src/devices/lixee.ts +++ b/src/devices/lixee.ts @@ -194,7 +194,7 @@ const fzLocal = { case 'activeEnergyOutD02': case 'activeEnergyOutD03': case 'activeEnergyOutD04': - // @ts-expect-error + // @ts-expect-error ignore val = utils.precisionRound(val / 1000, kWh_p); // from Wh to kWh break; case 'relais': { @@ -414,7 +414,7 @@ const fzLocal = { case 'currentTier8SummDelivered': case 'currentTier9SummDelivered': case 'currentTier10SummDelivered': - // @ts-expect-error + // @ts-expect-error ignore result[at_snake] = utils.precisionRound(((val[0] << 32) + val[1]) / 1000, kWh_p); // Wh to kWh break; } @@ -423,10 +423,10 @@ const fzLocal = { // TODO: Check if all tarifs which doesn't publish "currentSummDelivered" use just Tier1 & Tier2 if ( result['current_summ_delivered'] == 0 && - // @ts-expect-error + // @ts-expect-error ignore (result['current_tier1_summ_delivered'] > 0 || result['current_tier2_summ_delivered'] > 0) ) { - // @ts-expect-error + // @ts-expect-error ignore result['current_summ_delivered'] = result['current_tier1_summ_delivered'] + result['current_tier2_summ_delivered']; } return result; @@ -1629,7 +1629,7 @@ function getCurrentConfig(device: Zh.Device, options: KeyValue) { } catch (error) { logger.debug(error, NS); } - // @ts-expect-error + // @ts-expect-error ignore function getConfig(targetOption, bitLinkyMode, valueTrue, valueFalse) { const valueDefault = valueFalse; if (options && options.hasOwnProperty(targetOption) && options[targetOption] != 'auto') { @@ -1642,10 +1642,10 @@ function getCurrentConfig(device: Zh.Device, options: KeyValue) { let lMode; try { lMode = endpoint.clusters[clustersDef._0xFF66].attributes['linkyMode']; - // @ts-expect-error + // @ts-expect-error ignore // eslint-disable-next-line @typescript-eslint/no-unused-expressions lMode.raiseError; // raise if undefined - // @ts-expect-error + // @ts-expect-error ignore return ((lMode >> bitLinkyMode) & 1) == 1 ? valueTrue : valueFalse; } catch { logger.warning(`Was not able to detect the Linky ` + targetOption + `. Default to ` + valueDefault, NS); @@ -1678,7 +1678,7 @@ function getCurrentConfig(device: Zh.Device, options: KeyValue) { const lixAtts = endpoint.clusters[clustersDef._0xFF66].attributes; // eslint-disable-next-line @typescript-eslint/no-unused-expressions lixAtts.raiseIfEmpty; - // @ts-expect-error + // @ts-expect-error ignore currentTarf = fzLocal.lixee_private_fz.convert({}, {data: lixAtts}).current_tarif; } catch { logger.warning(`Not able to detect the current tarif. Not filtering any expose...`, NS); @@ -1697,7 +1697,7 @@ function getCurrentConfig(device: Zh.Device, options: KeyValue) { case linkyMode == linkyModeDef.legacy && tarifsDef.histo_EJP.currentTarf: myExpose = myExpose.filter((a) => !tarifsDef.histo_EJP.excluded.includes(a.exposes.name)); break; - // @ts-expect-error + // @ts-expect-error ignore case linkyMode == linkyModeDef.legacy && currentTarf && currentTarf.startsWith(tarifsDef.histo_BBR.currentTarf): myExpose = myExpose.filter((a) => !tarifsDef.histo_BBR.excluded.includes(a.exposes.name)); break; @@ -1731,10 +1731,10 @@ function getCurrentConfig(device: Zh.Device, options: KeyValue) { // Filter exposed attributes with user whitelist if (options && options.hasOwnProperty('tic_command_whitelist')) { - // @ts-expect-error + // @ts-expect-error ignore const tic_commands_str = options['tic_command_whitelist'].toUpperCase(); if (tic_commands_str !== 'ALL') { - // @ts-expect-error + // @ts-expect-error ignore const tic_commands = tic_commands_str.split(',').map((a) => a.trim()); myExpose = myExpose.filter((a) => tic_commands.includes(a.exposes.name)); } @@ -1844,7 +1844,7 @@ const definitions: DefinitionWithExtend[] = [ }; // Override reportings if (e.hasOwnProperty('report')) { - // @ts-expect-error + // @ts-expect-error ignore params = {...params, ...e.report}; } configReportings.push( @@ -1885,7 +1885,7 @@ const definitions: DefinitionWithExtend[] = [ for (const key in clustersDef) { if (Object.hasOwnProperty.call(clustersDef, key)) { - // @ts-expect-error + // @ts-expect-error ignore const cluster = clustersDef[key]; const targ = currentExposes.filter((e) => e.cluster == cluster).map((e) => e.att); if (targ.length) { diff --git a/src/devices/niko.ts b/src/devices/niko.ts index 50812429dad0a..8a788b916269e 100644 --- a/src/devices/niko.ts +++ b/src/devices/niko.ts @@ -104,16 +104,16 @@ const local = { // this seems to brick the device and it will need to be rejoined utils.assertEndpoint(entity); const operationModeLookup = {control_relay: 0x02, decoupled: 0x01}; - // @ts-expect-error + // @ts-expect-error ignore if (!operationModeLookup.hasOwnProperty(value)) { throw new Error(`operation_mode was called with an invalid value (${value})`); } else { await utils.enforceEndpoint(entity, key, meta).write( 'manuSpecificNiko1', - // @ts-expect-error + // @ts-expect-error ignore {switchOperationMode: operationModeLookup[value]}, ); - // @ts-expect-error + // @ts-expect-error ignore return {state: {operation_mode: value.toLowerCase()}}; } }, diff --git a/src/devices/perenio.ts b/src/devices/perenio.ts index 34d1b383504ff..98bcb2843faa6 100644 --- a/src/devices/perenio.ts +++ b/src/devices/perenio.ts @@ -85,7 +85,7 @@ const fzPerenio = { 2: 'previous', }; if (msg.data.hasOwnProperty(0)) { - // @ts-expect-error + // @ts-expect-error ignore result['default_on_off_state'] = powerOnStateLookup[msg.data[0]]; } if (msg.data.hasOwnProperty(1)) { @@ -198,7 +198,7 @@ const tzPerenio = { on_off_mod: { key: ['state', 'on_time', 'off_wait_time'], convertSet: async (entity, key, value, meta) => { - // @ts-expect-error + // @ts-expect-error ignore const state = meta.message.hasOwnProperty('state') ? meta.message.state.toLowerCase() : null; utils.validateValue(state, ['toggle', 'off', 'on']); const alarmVoltageMin = meta.state[`alarm_voltage_min${meta.endpoint_name ? `_${meta.endpoint_name}` : ''}`]; diff --git a/src/devices/saswell.ts b/src/devices/saswell.ts index 669a8f391fa9f..35b6effc83b5e 100644 --- a/src/devices/saswell.ts +++ b/src/devices/saswell.ts @@ -51,7 +51,7 @@ const definitions: DefinitionWithExtend[] = [ legacy.tz.saswell_thermostat_anti_scaling, legacy.tz.tuya_thermostat_weekly_schedule, ], - // @ts-expect-error + // @ts-expect-error ignore onEvent: (type, data, device) => !['_TZE200_c88teujp'].includes(device.manufacturerName) && tuya.onEventSetTime(type, data, device), meta: { thermostat: { diff --git a/src/devices/schneider_electric.ts b/src/devices/schneider_electric.ts index bf39d05327362..ffe72f2aceaec 100644 --- a/src/devices/schneider_electric.ts +++ b/src/devices/schneider_electric.ts @@ -461,7 +461,7 @@ const fzLocal = { if (rxAfterTx) { // Send Schneider specific ACK to make PowerTag happy - // @ts-expect-error + // @ts-expect-error ignore const networkParameters = await msg.device.constructor.adapter.getNetworkParameters(); const payload = { options: 0b000, diff --git a/src/devices/sinope.ts b/src/devices/sinope.ts index 44ca17cd5e1d8..461f55deb374e 100644 --- a/src/devices/sinope.ts +++ b/src/devices/sinope.ts @@ -34,7 +34,7 @@ const fzLocal = { type: ['attributeReport', 'readResponse'], options: [exposes.options.legacy()], convert: (model, msg, publish, options, meta) => { - // @ts-expect-error + // @ts-expect-error ignore delete msg['running_state']; const result: KeyValue = {}; const occupancyLookup = {0: 'unoccupied', 1: 'occupied'}; @@ -373,7 +373,7 @@ const tzLocal = { } const lookup = {ambiant: 1, floor: 2}; value = value.toLowerCase(); - // @ts-expect-error + // @ts-expect-error ignore if (lookup.hasOwnProperty(value)) { await entity.write('manuSpecificSinope', {floorControlMode: utils.getFromLookup(value, lookup)}); } @@ -387,9 +387,9 @@ const tzLocal = { // TH1300ZB and TH1400ZB specific key: ['ambiant_max_heat_setpoint'], convertSet: async (entity, key, value, meta) => { - // @ts-expect-error + // @ts-expect-error ignore if ((value >= 5 && value <= 36) || value == 'off') { - // @ts-expect-error + // @ts-expect-error ignore await entity.write('manuSpecificSinope', {ambiantMaxHeatSetpointLimit: value == 'off' ? -32768 : value * 100}); return {readAfterWriteTime: 250, state: {ambiant_max_heat_setpoint: value}}; } @@ -402,9 +402,9 @@ const tzLocal = { // TH1300ZB and TH1400ZB specific key: ['floor_min_heat_setpoint'], convertSet: async (entity, key, value, meta) => { - // @ts-expect-error + // @ts-expect-error ignore if ((value >= 5 && value <= 34) || value == 'off') { - // @ts-expect-error + // @ts-expect-error ignore await entity.write('manuSpecificSinope', {floorMinHeatSetpointLimit: value == 'off' ? -32768 : value * 100}); return {readAfterWriteTime: 250, state: {floor_min_heat_setpoint: value}}; } @@ -417,9 +417,9 @@ const tzLocal = { // TH1300ZB and TH1400ZB specific key: ['floor_max_heat_setpoint'], convertSet: async (entity, key, value, meta) => { - // @ts-expect-error + // @ts-expect-error ignore if ((value >= 7 && value <= 36) || value == 'off') { - // @ts-expect-error + // @ts-expect-error ignore await entity.write('manuSpecificSinope', {floorMaxHeatSetpointLimit: value == 'off' ? -32768 : value * 100}); return {readAfterWriteTime: 250, state: {floor_max_heat_setpoint: value}}; } @@ -437,7 +437,7 @@ const tzLocal = { } const lookup = {'10k': 0, '12k': 1}; value = value.toLowerCase(); - // @ts-expect-error + // @ts-expect-error ignore if (lookup.hasOwnProperty(value)) { await entity.write('manuSpecificSinope', {temperatureSensor: utils.getFromLookup(value, lookup)}); } diff --git a/src/devices/tuya.ts b/src/devices/tuya.ts index 52376eba8089d..f3020658328b3 100644 --- a/src/devices/tuya.ts +++ b/src/devices/tuya.ts @@ -322,9 +322,9 @@ const tzLocal = { // Load current state or defaults const newSettings = { brightness: meta.state.brightness ?? 254, // full brightness - // @ts-expect-error + // @ts-expect-error ignore hue: (meta.state.color ?? {}).hue ?? 0, // red - // @ts-expect-error + // @ts-expect-error ignore saturation: (meta.state.color ?? {}).saturation ?? 100, // full saturation }; diff --git a/src/devices/ubisys.ts b/src/devices/ubisys.ts index 87e2c79890fc3..0b59b8dc9b2ee 100644 --- a/src/devices/ubisys.ts +++ b/src/devices/ubisys.ts @@ -26,7 +26,7 @@ const manufacturerOptions = { * https://github.com/Koenkk/zigbee-herdsman/issues/52 */ ubisys: {manufacturerCode: Zcl.ManufacturerCode.UBISYS_TECHNOLOGIES_GMBH}, - // @ts-expect-error + // @ts-expect-error ignore ubisysNull: {manufacturerCode: null}, }; @@ -136,7 +136,7 @@ const ubisys = { do { await sleepSeconds(2); const response = await entity.read('closuresWindowCovering', ['operationalStatus']); - // @ts-expect-error + // @ts-expect-error ignore operationalStatus = response.operationalStatus; } while (operationalStatus != 0); await sleepSeconds(2); @@ -167,7 +167,7 @@ const ubisys = { const stepsPerSecond = value.steps_per_second || 50; const hasCalibrate = value.hasOwnProperty('calibrate'); // cancel any running calibration - // @ts-expect-error + // @ts-expect-error ignore let mode = (await entity.read('closuresWindowCovering', ['windowCoveringMode'])).windowCoveringMode; const modeCalibrationBitMask = 0x02; if (mode & modeCalibrationBitMask) { @@ -177,7 +177,7 @@ const ubisys = { // delay a bit if reconfiguring basic configuration attributes await writeAttrFromJson('windowCoveringType', undefined, undefined, 2); await writeAttrFromJson('configStatus', undefined, undefined, 2); - // @ts-expect-error + // @ts-expect-error ignore if (await writeAttrFromJson('windowCoveringMode', undefined, undefined, 2)) { mode = value['windowCoveringMode']; } @@ -527,7 +527,7 @@ const ubisys = { const templates = Array.isArray(value.input_action_templates) ? value.input_action_templates : [value.input_action_templates]; let resultingInputActions: unknown[] = []; for (const template of templates) { - // @ts-expect-error + // @ts-expect-error ignore const templateType = templateTypes[template.type]; if (!templateType) { throw new Error( diff --git a/src/devices/wirenboard.ts b/src/devices/wirenboard.ts index 8cc000e91187b..2890760db03aa 100644 --- a/src/devices/wirenboard.ts +++ b/src/devices/wirenboard.ts @@ -128,7 +128,7 @@ const tzLocal = { reservedBits: 0, direction: 0, writeUndiv: false, - // @ts-expect-error + // @ts-expect-error ignore transactionSequenceNumber: null, }; @@ -404,7 +404,7 @@ const sprutModernExtend = { reservedBits: 0, direction: 0, writeUndiv: false, - // @ts-expect-error + // @ts-expect-error ignore transactionSequenceNumber: null, }; diff --git a/src/index.ts b/src/index.ts index 306d3f7ed6c01..b683d309c1066 100644 --- a/src/index.ts +++ b/src/index.ts @@ -102,13 +102,13 @@ const converterRequiredFields = { function validateDefinition(definition: Definition) { for (const [field, expectedType] of Object.entries(converterRequiredFields)) { - // @ts-expect-error + // @ts-expect-error ignore assert.notStrictEqual(null, definition[field], `Converter field ${field} is null`); - // @ts-expect-error + // @ts-expect-error ignore assert.notStrictEqual(undefined, definition[field], `Converter field ${field} is undefined`); - // @ts-expect-error + // @ts-expect-error ignore const msg = `Converter field ${field} expected type doenst match to ${definition[field]}`; - // @ts-expect-error + // @ts-expect-error ignore assert.strictEqual(definition[field].constructor.name, expectedType, msg); } assert.ok(Array.isArray(definition.exposes) || typeof definition.exposes === 'function', 'Exposes incorrect'); diff --git a/src/lib/color.ts b/src/lib/color.ts index 0f3304080d5b9..48d03d702606a 100644 --- a/src/lib/color.ts +++ b/src/lib/color.ts @@ -519,7 +519,7 @@ class ColorHSV { static correctHue(hue: number, meta: Tz.Meta): number { const {options} = meta; if (options.hasOwnProperty('hue_correction')) { - // @ts-expect-error + // @ts-expect-error ignore return this.interpolateHue(hue, options.hue_correction); } else { return hue; @@ -557,7 +557,7 @@ export class Color { * @param xy - ColorXY instance */ constructor(hsv: ColorHSV, rgb: ColorRGB, xy: ColorXY) { - // @ts-expect-error + // @ts-expect-error ignore if ((hsv !== null) + (rgb !== null) + (xy !== null) != 1) { throw new Error('Color object should have exactly only one of hsv, rgb or xy properties'); } else if (hsv !== null) { diff --git a/src/lib/configureKey.ts b/src/lib/configureKey.ts index 6223cd961a9ac..bae1afa3f5304 100644 --- a/src/lib/configureKey.ts +++ b/src/lib/configureKey.ts @@ -21,7 +21,7 @@ export function getConfigureKey(definition: Definition) { } // Prevent unnecessary recalculation of the hash - // @ts-expect-error + // @ts-expect-error ignore if (definition.configure in lookup) return lookup[definition.configure]; const body = definition.configure.toString().replace(/\s/g, ''); @@ -37,7 +37,7 @@ export function getConfigureKey(definition: Definition) { * if the hash dind't change. */ const configureKey = legacyKey in legacyKeys ? legacyKeys[legacyKey] : hash; - // @ts-expect-error + // @ts-expect-error ignore lookup[definition.configure] = configureKey; return configureKey; } diff --git a/src/lib/exposes.ts b/src/lib/exposes.ts index 7a7ef27914a7a..1ee5d2c938fc9 100644 --- a/src/lib/exposes.ts +++ b/src/lib/exposes.ts @@ -451,7 +451,7 @@ export class Light extends Base { .withDescription('Color temperature of this light'); if (process.env.ZHC_TEST) { - // @ts-ignore + // @ts-expect-error ignore feature._colorTempRangeProvided = rangeProvided; } diff --git a/src/lib/legacy.ts b/src/lib/legacy.ts index f89d39725c1fa..29dbfdc59c710 100644 --- a/src/lib/legacy.ts +++ b/src/lib/legacy.ts @@ -231,10 +231,10 @@ function convertRawToCycleTimer(value: any) { weekdays = 'once'; } let minsincemidnight: any = value[4] * 256 + value[5]; - // @ts-ignore + // @ts-expect-error ignore starttime = String(parseInt(minsincemidnight / 60)).padStart(2, '0') + ':' + String(minsincemidnight % 60).padStart(2, '0'); minsincemidnight = value[6] * 256 + value[7]; - // @ts-ignore + // @ts-expect-error ignore endtime = String(parseInt(minsincemidnight / 60)).padStart(2, '0') + ':' + String(minsincemidnight % 60).padStart(2, '0'); irrigationDuration = value[8] * 256 + value[9]; pauseDuration = value[10] * 256 + value[11]; @@ -467,7 +467,7 @@ function convertRawToTimer(value: any) { if (value.length > 12) { timernr = value[1]; const minsincemidnight = value[2] * 256 + value[3]; - // @ts-ignore + // @ts-expect-error ignore starttime = String(parseInt(minsincemidnight / 60)).padStart(2, '0') + ':' + String(minsincemidnight % 60).padStart(2, '0'); duration = value[4] * 256 + value[5]; if (value[6] > 0) { @@ -1539,7 +1539,7 @@ const fromZigbee1 = { break; } case 1: // report state - // @ts-ignore + // @ts-expect-error ignore result.state = {0: 'OPEN', 1: 'STOP', 2: 'CLOSE'}[value]; break; case dataPoints.motorDirection: // reverse direction @@ -1549,7 +1549,7 @@ const fromZigbee1 = { result.cycle_time = value; break; case 101: // model - // @ts-ignore + // @ts-expect-error ignore result.motor_type = { 0: '', 1: 'AM0/6-28R-Sm', @@ -1563,11 +1563,11 @@ const fromZigbee1 = { result.cycle_count = value; break; case 103: // set or clear bottom limit - // @ts-ignore + // @ts-expect-error ignore result.bottom_limit = {0: 'SET', 1: 'CLEAR'}[value]; break; case 104: // set or clear top limit - // @ts-ignore + // @ts-expect-error ignore result.top_limit = {0: 'SET', 1: 'CLEAR'}[value]; break; case 109: // active power @@ -1579,7 +1579,7 @@ const fromZigbee1 = { case 116: // report confirmation break; case 121: // running state - // @ts-ignore + // @ts-expect-error ignore result.motor_state = {0: 'OPENING', 1: 'STOPPED', 2: 'CLOSING'}[value]; result.running = value !== 1 ? true : false; break; @@ -1809,7 +1809,7 @@ const fromZigbee1 = { cluster: 'manuSpecificTuya', type: ['commandDataResponse', 'commandDataReport'], convert: (model, msg, publish, options, meta) => { - // @ts-ignore + // @ts-expect-error ignore const modelConverters = giexFzModelConverters[model.model] || {}; for (const dpValue of msg.data.dpValues) { const value = getDataValue(dpValue); @@ -1852,14 +1852,14 @@ const fromZigbee1 = { const value = getDataValue(dpValue); switch (dp) { case dataPoints.alectoSmokeState: - // @ts-ignore + // @ts-expect-error ignore return {smoke_state: {0: 'alarm', 1: 'normal'}[value]}; case dataPoints.alectoSmokeValue: return {smoke_value: value}; case dataPoints.alectoSelfChecking: return {self_checking: value}; case dataPoints.alectoCheckingResult: - // @ts-ignore + // @ts-expect-error ignore return {checking_result: {0: 'checking', 1: 'check_success', 2: 'check_failure', 3: 'others'}[value]}; case dataPoints.alectoSmokeTest: return {smoke_test: value}; @@ -1868,7 +1868,7 @@ const fromZigbee1 = { case dataPoints.alectoBatteryPercentage: return {battery: value}; case dataPoints.alectoBatteryState: - // @ts-ignore + // @ts-expect-error ignore return {battery_state: {0: 'low', 1: 'middle', 2: 'high'}[value]}; case dataPoints.alectoSilence: return {silence: value}; @@ -3023,22 +3023,21 @@ const fromZigbee1 = { const ctrl = msg.data['ctrlSeqeOfOper']; if (typeof ctrl == 'number' && thermostatControlSequenceOfOperations.hasOwnProperty(ctrl)) { result[postfixWithEndpointName('control_sequence_of_operation', msg, model)] = - // @ts-ignore + // @ts-expect-error ignore thermostatControlSequenceOfOperations[ctrl]; } const smode = msg.data['systemMode']; if (typeof smode == 'number' && thermostatSystemModes.hasOwnProperty(smode)) { - // @ts-ignore + // @ts-expect-error ignore result[postfixWithEndpointName('system_mode', msg, model)] = thermostatSystemModes[smode]; } const rmode = msg.data['runningMode']; if (typeof rmode == 'number' && thermostatSystemModes.hasOwnProperty(rmode)) { - // @ts-ignore + // @ts-expect-error ignore result[postfixWithEndpointName('running_mode', msg, model)] = thermostatSystemModes[rmode]; } const state = msg.data['runningState']; if (typeof state == 'number' && constants.thermostatRunningStates.hasOwnProperty(state)) { - // @ts-ignore result[postfixWithEndpointName('running_state', msg, model)] = constants.thermostatRunningStates[state]; } if (typeof msg.data['pIHeatingDemand'] == 'number') { @@ -3414,7 +3413,7 @@ const fromZigbee1 = { ), ); fromZigbeeStore[deviceID].delayedTimer = null; - // @ts-expect-error + // @ts-expect-error ignore }, multiplePressTimeout * 1000); } else { const pressDuration = @@ -3595,7 +3594,7 @@ const fromZigbee1 = { const presetLookup = {0: 'programming', 1: 'manual', 2: 'temporary_manual', 3: 'holiday'}; switch (dp) { case dataPoints.moesSsystemMode: - // @ts-ignore + // @ts-expect-error ignore return {preset: presetLookup[value], system_mode: 'heat'}; case dataPoints.moesSheatingSetpoint: return {current_heating_setpoint: value}; @@ -3625,7 +3624,7 @@ const fromZigbee1 = { // local_temperature is now stale: the valve does not report the re-calibrated value until an actual temperature change // so update local_temperature by subtracting the old calibration and adding the new one ...(meta && meta.state && meta.state.local_temperature != null && meta.state.local_temperature_calibration != null - ? // @ts-expect-error + ? // @ts-expect-error ignore {local_temperature: meta.state.local_temperature + (value - meta.state.local_temperature_calibration)} : {}), }; @@ -3746,7 +3745,7 @@ const fromZigbee1 = { case dataPoints.connecteTempFloor: return {external_temperature: value}; case dataPoints.connecteSensorType: - // @ts-ignore + // @ts-expect-error ignore return {sensor: {0: 'internal', 1: 'external', 2: 'both'}[value]}; case dataPoints.connecteHysteresis: return {hysteresis: value}; @@ -4067,7 +4066,7 @@ const fromZigbee1 = { ret.away_mode = ret.preset == 'away' ? 'ON' : 'OFF'; // Away is special HA mode const presetToSystemMode = utils.getMetaValue(msg.endpoint, model, 'tuyaThermostatPresetToSystemMode', null, {}); if (value in presetToSystemMode) { - // @ts-expect-error + // @ts-expect-error ignore ret.system_mode = presetToSystemMode[value]; } } else { @@ -4139,7 +4138,7 @@ const fromZigbee1 = { let result = null; switch (dp) { case dataPoints.state: - // @ts-ignore + // @ts-expect-error ignore result = {occupancy: {1: true, 0: false}[value]}; break; case dataPoints.msReferenceLuminance: @@ -4152,7 +4151,7 @@ const fromZigbee1 = { result = {v_sensitivity: msLookups.VSensitivity[value]}; break; case dataPoints.msLedStatus: - // @ts-ignore + // @ts-expect-error ignore result = {led_status: {1: 'OFF', 0: 'ON'}[value]}; break; case dataPoints.msVacancyDelay: @@ -4260,11 +4259,11 @@ const fromZigbee1 = { } break; case dataPoints.tvWindowDetection: - // @ts-ignore + // @ts-expect-error ignore result = {window_detection: {1: true, 0: false}[value]}; break; case dataPoints.tvFrostDetection: - // @ts-ignore + // @ts-expect-error ignore result = {frost_detection: {1: true, 0: false}[value]}; break; case dataPoints.tvHeatingSetpoint: @@ -4284,7 +4283,7 @@ const fromZigbee1 = { result = {battery: value}; break; case dataPoints.tvChildLock: - // @ts-ignore + // @ts-expect-error ignore result = {child_lock: {1: 'LOCK', 0: 'UNLOCK'}[value]}; break; case dataPoints.tvErrorStatus: @@ -4598,7 +4597,7 @@ const fromZigbee1 = { let result = null; switch (dp) { case dataPoints.tshpsPresenceState: - // @ts-ignore + // @ts-expect-error ignore result = {presence: {0: false, 1: true}[value]}; break; case dataPoints.tshpscSensitivity: @@ -4650,11 +4649,11 @@ const fromZigbee1 = { result.battery = value; break; case dataPoints.lmsSensitivity: - // @ts-ignore + // @ts-expect-error ignore result.sensitivity = {'0': 'low', '1': 'medium', '2': 'high'}[value]; break; case dataPoints.lmsKeepTime: - // @ts-ignore + // @ts-expect-error ignore result.keep_time = {'0': '10', '1': '30', '2': '60', '3': '120'}[value]; break; case dataPoints.lmsIlluminance: @@ -4684,19 +4683,18 @@ const fromZigbee1 = { break; } case dataPoints.state: - // @ts-ignore + // @ts-expect-error ignore result = {state: {0: 'OPEN', 1: 'STOP', 2: 'CLOSE'}[value], running: {0: true, 1: false, 2: true}[value]}; break; case dataPoints.moesCoverBacklight: - // @ts-ignore result = {backlight: value ? 'ON' : 'OFF'}; break; case dataPoints.moesCoverCalibration: - // @ts-ignore + // @ts-expect-error ignore result = {calibration: {0: 'ON', 1: 'OFF'}[value]}; break; case dataPoints.moesCoverMotorReversal: - // @ts-ignore + // @ts-expect-error ignore result = {motor_reversal: {0: 'OFF', 1: 'ON'}[value]}; break; default: @@ -4719,7 +4717,7 @@ const fromZigbee1 = { return {humidity: value / (['_TZE200_bjawzodf', '_TZE200_zl1kmjqx'].includes(meta.device.manufacturerName) ? 10 : 1)}; case dataPoints.tthBatteryLevel: return { - // @ts-ignore + // @ts-expect-error ignore battery_level: {0: 'low', 1: 'middle', 2: 'high'}[value], battery_low: value === 0 ? true : false, }; @@ -4749,7 +4747,7 @@ const fromZigbee1 = { result.battery = value; break; case dataPoints.nousTempUnitConvert: - // @ts-ignore + // @ts-expect-error ignore result.temperature_unit_convert = {0x00: 'celsius', 0x01: 'fahrenheit'}[value]; break; case dataPoints.nousMaxTemp: @@ -4765,11 +4763,11 @@ const fromZigbee1 = { result.min_humidity = value; break; case dataPoints.nousTempAlarm: - // @ts-ignore + // @ts-expect-error ignore result.temperature_alarm = {0x00: 'lower_alarm', 0x01: 'upper_alarm', 0x02: 'canceled'}[value]; break; case dataPoints.nousHumiAlarm: - // @ts-ignore + // @ts-expect-error ignore result.humidity_alarm = {0x00: 'lower_alarm', 0x01: 'upper_alarm', 0x02: 'canceled'}[value]; break; case dataPoints.nousTempSensitivity: @@ -4923,15 +4921,15 @@ const fromZigbee1 = { case dataPoints.hyLocalTemp: // 0x027F MCU reporting room temperature return {local_temperature: (value / 10).toFixed(1)}; case dataPoints.hySensor: // Sensor type - // @ts-ignore + // @ts-expect-error ignore return {sensor_type: {0: 'internal', 1: 'external', 2: 'both'}[value]}; case dataPoints.hyPowerOnBehavior: // 0x0475 State after power on - // @ts-ignore + // @ts-expect-error ignore return {power_on_behavior: {0: 'restore', 1: 'off', 2: 'on'}[value]}; case dataPoints.hyWeekFormat: // 0x0476 Week select 0 - 5 days, 1 - 6 days, 2 - 7 days return {week: thermostatWeekFormat[value]}; case dataPoints.hyMode: // 0x0480 mode - // @ts-ignore + // @ts-expect-error ignore return {system_mode: {0: 'manual', 1: 'auto', 2: 'away'}[value]}; case dataPoints.hyAlarm: // [16] [0] return {alarm: value > 0 ? true : false}; @@ -4952,7 +4950,7 @@ const fromZigbee1 = { return {occupancy: value > 0 ? true : false}; case 102: return { - // @ts-ignore + // @ts-expect-error ignore power_type: {0: 'battery_full', 1: 'battery_high', 2: 'battery_medium', 3: 'battery_low', 4: 'usb'}[value], battery_low: value === 3, }; @@ -4977,7 +4975,7 @@ const fromZigbee1 = { case 112: return {unknown_112: value ? 'ON' : 'OFF'}; case dataPoints.neoTempHumidityAlarm: - // @ts-ignore + // @ts-expect-error ignore return {alarm: {0: 'over_temperature', 1: 'over_humidity', 2: 'below_min_temperature', 3: 'below_min_humdity', 4: 'off'}[value]}; default: // Unknown code logger.debug(`Unrecognized DP #${dp}: ${JSON.stringify(dpValue)}`, 'zhc:legacy:fz:neo_nas_pd07'); @@ -5016,7 +5014,7 @@ const fromZigbee1 = { return {humidity_max: value}; case dataPoints.neoPowerType: // 0x0465 [4] return { - // @ts-ignore + // @ts-expect-error ignore power_type: {0: 'battery_full', 1: 'battery_high', 2: 'battery_medium', 3: 'battery_low', 4: 'usb'}[value], battery_low: value === 3, }; @@ -5025,7 +5023,7 @@ const fromZigbee1 = { case dataPoints.neoUnknown3: // 0x0473 [0] break; case dataPoints.neoVolume: // 0x0474 [0]/[1]/[2] Volume 0-max, 2-low - // @ts-ignore + // @ts-expect-error ignore return {volume: {2: 'low', 1: 'medium', 0: 'high'}[value]}; default: // Unknown code logger.debug(`Unrecognized DP #${dp}: ${JSON.stringify(dpValue)}`, 'zhc:legacy:fz:neo_t_h_alarm'); @@ -5050,7 +5048,7 @@ const fromZigbee1 = { case dataPoints.neoAOMelody: // 0x21 [5] Melody return {melody: value}; case dataPoints.neoAOVolume: // 0x5 [0]/[1]/[2] Volume 0-low, 2-max - // @ts-ignore + // @ts-expect-error ignore return {volume: {0: 'low', 1: 'medium', 2: 'high'}[value]}; default: // Unknown code logger.debug(`Unrecognized DP #${dp}: ${JSON.stringify(msg.data)}`, 'zhc:legacy:fz:neo_alarm'); @@ -5066,18 +5064,18 @@ const fromZigbee1 = { const value = getDataValue(dpValue); switch (dp) { case dataPoints.fantemPowerSupplyMode: - // @ts-ignore + // @ts-expect-error ignore return {power_supply_mode: {0: 'unknown', 1: 'no_neutral', 2: 'with_neutral'}[value]}; case dataPoints.fantemExtSwitchType: - // @ts-ignore + // @ts-expect-error ignore return {switch_type: {0: 'unknown', 1: 'toggle', 2: 'momentary', 3: 'rotary', 4: 'auto_config'}[value]}; case dataPoints.fantemLoadDetectionMode: - // @ts-ignore + // @ts-expect-error ignore return {load_detection_mode: {0: 'none', 1: 'first_power_on', 2: 'every_power_on'}[value]}; case dataPoints.fantemExtSwitchStatus: return {switch_status: value}; case dataPoints.fantemControlMode: - // @ts-ignore + // @ts-expect-error ignore return {control_mode: {0: 'ext_switch', 1: 'remote', 2: 'both'}[value]}; case 111: // Value 0 is received after each device power-on. No idea what it means. @@ -5085,10 +5083,10 @@ const fromZigbee1 = { case dataPoints.fantemLoadType: // Not sure if 0 is 'resistive' and 2 is 'resistive_inductive'. // If you see 'unknown', pls. check with Tuya gateway and app and update with label shown in Tuya app. - // @ts-ignore + // @ts-expect-error ignore return {load_type: {0: 'unknown', 1: 'resistive_capacitive', 2: 'unknown', 3: 'detecting'}[value]}; case dataPoints.fantemLoadDimmable: - // @ts-ignore + // @ts-expect-error ignore return {load_dimmable: {0: 'unknown', 1: 'dimmable', 2: 'not_dimmable'}[value]}; default: logger.debug(`Unrecognized DP|Value [${dp}|${value}][${JSON.stringify(dpValue)}]`, 'zhc:legacy:fz:zb006x_settings'); @@ -5527,7 +5525,6 @@ const fromZigbee1 = { return { // Same as in hvacThermostat:getWeeklyScheduleRsp hvacThermostat:setWeeklySchedule cluster format weekly_schedule: { - // @ts-ignore days: [constants.thermostatDayOfWeek[dayOfWeek]], transitions: dataToTransitions(value, maxTransitions, dataOffset), }, @@ -5675,7 +5672,6 @@ const fromZigbee2 = { options: [exposes.options.legacy()], convert: (model, msg, publish, options, meta) => { if (!utils.isLegacyEnabled(options)) { - // @ts-ignore return fromZigbee1.tuya_thermostat_weekly_schedule_2.convert(model, msg, publish, options, meta); } @@ -5741,7 +5737,6 @@ const toZigbee1 = { SA12IZL_alarm: { key: ['alarm'], convertSet: async (entity, key, value: any, meta) => { - // @ts-ignore await sendDataPointEnum(entity, 20, value ? 0 : 1); }, } satisfies Tz.Converter, @@ -5870,12 +5865,12 @@ const toZigbee2 = { break; } case 'top_limit': { - // @ts-ignore + // @ts-expect-error ignore await sendDataPointEnum(entity, 104, {SET: 0, CLEAR: 1}[value]); break; } case 'bottom_limit': { - // @ts-ignore + // @ts-expect-error ignore await sendDataPointEnum(entity, 103, {SET: 0, CLEAR: 1}[value]); break; } @@ -6161,7 +6156,7 @@ const toZigbee2 = { if (value.hasOwnProperty(attrName)) { v = value[attrName]; } else if (meta.state.hasOwnProperty(attrName)) { - // @ts-expect-error + // @ts-expect-error ignore v = meta.state[attrName]; } switch (attrName) { @@ -6218,7 +6213,7 @@ const toZigbee2 = { if (value.hasOwnProperty(attrName)) { v = value[attrName]; } else if (meta.state.hasOwnProperty(attrName)) { - // @ts-expect-error + // @ts-expect-error ignore v = meta.state[attrName]; } if (v < 0.5 || v > 29.5) v = 17; @@ -6230,7 +6225,7 @@ const toZigbee2 = { if (value.hasOwnProperty(attrName)) { h = value[attrName]; } else if (meta.state.hasOwnProperty(attrName)) { - // @ts-expect-error + // @ts-expect-error ignore h = meta.state[attrName]; } // minute @@ -6239,7 +6234,7 @@ const toZigbee2 = { if (value.hasOwnProperty(attrName)) { m = value[attrName]; } else if (meta.state.hasOwnProperty(attrName)) { - // @ts-expect-error + // @ts-expect-error ignore m = meta.state[attrName]; } let rt = h * 4 + m / 15; @@ -6310,7 +6305,7 @@ const toZigbee2 = { key: ['trigger'], convertSet: async (entity, key, value, meta) => { const state = meta.message.hasOwnProperty('trigger') ? meta.message.trigger : true; - // @ts-expect-error + // @ts-expect-error ignore await sendDataPointBool(entity, dataPoints.garageDoorTrigger, state); return {state: {trigger: state}}; }, @@ -6337,7 +6332,7 @@ const toZigbee2 = { await sendDataPointBool(entity, dataPoints.connecteChildLock, value === 'LOCK'); break; case 'local_temperature_calibration': - // @ts-ignore + // @ts-expect-error ignore if (value < 0) value = 0xffffffff + value + 1; await sendDataPointValue(entity, dataPoints.connecteTempCalibration, value); break; @@ -6346,7 +6341,7 @@ const toZigbee2 = { await sendDataPointValue(entity, dataPoints.connecteHysteresis, value); break; case 'max_temperature_protection': - // @ts-ignore + // @ts-expect-error ignore await sendDataPointValue(entity, dataPoints.connecteMaxProtectTemp, Math.round(value)); break; case 'current_heating_setpoint': @@ -6356,7 +6351,7 @@ const toZigbee2 = { await sendDataPointEnum( entity, dataPoints.connecteSensorType, - // @ts-ignore + // @ts-expect-error ignore {internal: 0, external: 1, both: 2}[value], ); break; @@ -6494,7 +6489,7 @@ const toZigbee2 = { /* Merge modified value into existing state and send all over in one go */ const newProgram = { - // @ts-expect-error + // @ts-expect-error ignore ...meta.state.program, ...value, }; @@ -6656,7 +6651,7 @@ const toZigbee2 = { await sendDataPointEnum( entity, dataPoints.moesSwitchPowerOnBehavior, - // @ts-expect-error + // @ts-expect-error ignore utils.getKey(moesSwitch.powerOnBehavior, value), ); break; @@ -6664,7 +6659,7 @@ const toZigbee2 = { await sendDataPointEnum( entity, dataPoints.moesSwitchIndicateLight, - // @ts-expect-error + // @ts-expect-error ignore utils.getKey(moesSwitch.indicateLight, value), ); break; @@ -6956,15 +6951,15 @@ const toZigbee2 = { key: ['weekly_schedule'], convertSet: async (entity, key, value, meta) => { const thermostatMeta = utils.getMetaValue(entity, meta.mapped, 'thermostat'); - // @ts-expect-error + // @ts-expect-error ignore const maxTransitions = thermostatMeta.weeklyScheduleMaxTransitions; - // @ts-expect-error + // @ts-expect-error ignore const supportedModes = thermostatMeta.weeklyScheduleSupportedModes; - // @ts-expect-error + // @ts-expect-error ignore const firstDayDpId = thermostatMeta.weeklyScheduleFirstDayDpId; let conversion = 'generic'; if (thermostatMeta.hasOwnProperty('weeklyScheduleConversion')) { - // @ts-expect-error + // @ts-expect-error ignore conversion = thermostatMeta.weeklyScheduleConversion; } @@ -7070,7 +7065,7 @@ const toZigbee2 = { convertSet: async (entity, key, value, meta) => { const modeId = utils.getKey(utils.getMetaValue(entity, meta.mapped, 'tuyaThermostatSystemMode'), value, null, Number); if (modeId !== null) { - // @ts-expect-error + // @ts-expect-error ignore await sendDataPointEnum(entity, dataPoints.mode, parseInt(modeId)); } else { throw new Error(`TRV system mode ${value} is not recognized.`); @@ -7082,7 +7077,7 @@ const toZigbee2 = { convertSet: async (entity, key, value, meta) => { const presetId = utils.getKey(utils.getMetaValue(entity, meta.mapped, 'tuyaThermostatPreset'), value, null, Number); if (presetId !== null) { - // @ts-expect-error + // @ts-expect-error ignore await sendDataPointEnum(entity, dataPoints.mode, parseInt(presetId)); } else { throw new Error(`TRV preset ${value} is not recognized.`); @@ -7093,13 +7088,13 @@ const toZigbee2 = { key: ['away_mode'], convertSet: async (entity, key, value, meta) => { // HA has special behavior for the away mode - // @ts-expect-error + // @ts-expect-error ignore const awayPresetId = utils.getKey(utils.getMetaValue(entity, meta.mapped, 'tuyaThermostatPreset'), 'away', null, Number); const schedulePresetId = utils.getKey( utils.getMetaValue(entity, meta.mapped, 'tuyaThermostatPreset'), 'schedule', null, - // @ts-expect-error + // @ts-expect-error ignore Number, ); if (awayPresetId !== null) { @@ -7119,7 +7114,7 @@ const toZigbee2 = { convertSet: async (entity, key, value, meta) => { const modeId = utils.getKey(fanModes, value, null, Number); if (modeId !== null) { - // @ts-expect-error + // @ts-expect-error ignore await sendDataPointEnum(entity, dataPoints.fanMode, parseInt(modeId)); } else { throw new Error(`TRV fan mode ${value} is not recognized.`); @@ -7131,7 +7126,7 @@ const toZigbee2 = { convertSet: async (entity, key, value, meta) => { const modeId = utils.getKey(fanModes, value, null, Number); if (modeId !== null) { - // @ts-expect-error + // @ts-expect-error ignore await sendDataPointEnum(entity, dataPoints.bacFanMode, parseInt(modeId)); } else { throw new Error(`TRV fan mode ${value} is not recognized.`); @@ -7189,7 +7184,7 @@ const toZigbee2 = { convertSet: async (entity, key, value, meta) => { const modeId = utils.getKey(thermostatForceMode, value, null, Number); if (modeId !== null) { - // @ts-expect-error + // @ts-expect-error ignore await sendDataPointEnum(entity, dataPoints.forceMode, parseInt(modeId)); } else { throw new Error(`TRV force mode ${value} is not recognized.`); @@ -7201,7 +7196,7 @@ const toZigbee2 = { convertSet: async (entity, key, value, meta) => { const modeId = utils.getKey(utils.getMetaValue(entity, meta.mapped, 'tuyaThermostatSystemMode'), value, null, Number); if (modeId !== null) { - // @ts-expect-error + // @ts-expect-error ignore await sendDataPointEnum(entity, dataPoints.forceMode, parseInt(modeId)); } else { throw new Error(`TRV system mode ${value} is not recognized.`); @@ -7365,7 +7360,7 @@ const toZigbee2 = { await sendDataPointEnum( entity, dataPoints.neoVolume, - // @ts-ignore + // @ts-expect-error ignore {low: 2, medium: 1, high: 0}[value], ); break; @@ -7409,7 +7404,7 @@ const toZigbee2 = { await sendDataPointEnum( entity, dataPoints.neoAOVolume, - // @ts-ignore + // @ts-expect-error ignore {low: 0, medium: 1, high: 2}[value], ); break; @@ -7584,9 +7579,9 @@ const toZigbee2 = { data = data.concat(convertStringToHexArray(speedString)); let colors = value.colors; - // @ts-expect-error + // @ts-expect-error ignore if (!colors && meta.state && meta.state.effect && meta.state.effect.colors) { - // @ts-expect-error + // @ts-expect-error ignore colors = meta.state.effect.colors; } @@ -7814,7 +7809,7 @@ const toZigbee2 = { await sendDataPointEnum( entity, dataPoints.hySensor, - // @ts-ignore + // @ts-expect-error ignore {internal: 0, external: 1, both: 2}[value], ); break; @@ -7822,7 +7817,7 @@ const toZigbee2 = { await sendDataPointEnum( entity, dataPoints.hyPowerOnBehavior, - // @ts-ignore + // @ts-expect-error ignore {restore: 0, off: 1, on: 2}[value], ); break; @@ -7833,7 +7828,7 @@ const toZigbee2 = { await sendDataPointEnum( entity, dataPoints.hyMode, - // @ts-ignore + // @ts-expect-error ignore {manual: 0, auto: 1, away: 2}[value], ); break; @@ -7882,11 +7877,11 @@ const toZigbee2 = { await sendDataPointBool(entity, dataPoints.fantemReportingEnable, value, 'sendData'); break; case 'sensitivity': - // @ts-ignore + // @ts-expect-error ignore await entity.write('ssIasZone', {currentZoneSensitivityLevel: {low: 0, medium: 1, high: 2}[value]}); break; case 'keep_time': - // @ts-ignore + // @ts-expect-error ignore await entity.write('ssIasZone', {61441: {value: {'0': 0, '30': 1, '60': 2, '120': 3, '240': 4, '480': 5}[value], type: 0x20}}); break; default: // Unknown key @@ -7902,7 +7897,7 @@ const toZigbee2 = { await sendDataPointEnum( entity, dataPoints.fantemExtSwitchType, - // @ts-expect-error + // @ts-expect-error ignore {unknown: 0, toggle: 1, momentary: 2, rotary: 3, auto_config: 4}[value], 'sendData', ); @@ -7911,13 +7906,13 @@ const toZigbee2 = { await sendDataPointEnum( entity, dataPoints.fantemLoadDetectionMode, - // @ts-expect-error + // @ts-expect-error ignore {none: 0, first_power_on: 1, every_power_on: 2}[value], 'sendData', ); break; case 'control_mode': - // @ts-expect-error + // @ts-expect-error ignore await sendDataPointEnum(entity, dataPoints.fantemControlMode, {ext_switch: 0, remote: 1, both: 2}[value], 'sendData'); break; default: // Unknown key @@ -7936,7 +7931,7 @@ const toZigbee2 = { await sendDataPointEnum(entity, dataPoints.msVSensitivity, utils.getKey(msLookups.VSensitivity, value)); break; case 'led_status': - // @ts-ignore + // @ts-expect-error ignore await sendDataPointEnum(entity, dataPoints.msLedStatus, {on: 0, off: 1}[value.toLowerCase()]); break; case 'vacancy_delay': @@ -8111,7 +8106,7 @@ const toZigbee2 = { cool: 250, coolest: colorTempMin, }; - // @ts-ignore + // @ts-expect-error ignore if (typeof value === 'string' && isNaN(value)) { const presetName = value.toLowerCase(); if (presetName in preset) { @@ -8291,11 +8286,11 @@ const toZigbee2 = { convertSet: async (entity, key, value, meta) => { switch (key) { case 'sensitivity': - // @ts-ignore + // @ts-expect-error ignore await sendDataPointEnum(entity, dataPoints.lmsSensitivity, {low: 0, medium: 1, high: 2}[value]); break; case 'keep_time': - // @ts-ignore + // @ts-expect-error ignore await sendDataPointEnum(entity, dataPoints.lmsKeepTime, {'10': 0, '30': 1, '60': 2, '120': 3}[value]); break; default: // Unknown key @@ -8329,7 +8324,7 @@ const toZigbee2 = { } break; case 'state': { - // @ts-ignore + // @ts-expect-error ignore const state = {OPEN: 0, STOP: 1, CLOSE: 2}[value.toUpperCase()]; await sendDataPointEnum(entity, dataPoints.state, state); break; diff --git a/src/lib/lumi.ts b/src/lib/lumi.ts index 9a1b4bc8d8b3d..0dea92d4b2f4d 100644 --- a/src/lib/lumi.ts +++ b/src/lib/lumi.ts @@ -346,7 +346,7 @@ export const numericAttributes2Payload = async (msg: Fz.Message, meta: Fz.Meta, } else if (['WSDCGQ01LM', 'WSDCGQ11LM', 'WSDCGQ12LM', 'VOCKQJK11LM'].includes(model.model)) { // https://github.com/Koenkk/zigbee2mqtt/issues/798 // Sometimes the sensor publishes non-realistic vales, filter these - // @ts-expect-error + // @ts-expect-error ignore const temperature = parseFloat(value) / 100.0; if (temperature > -65 && temperature < 65) { payload.temperature = temperature; @@ -414,7 +414,7 @@ export const numericAttributes2Payload = async (msg: Fz.Message, meta: Fz.Meta, } else if (['WSDCGQ01LM', 'WSDCGQ11LM', 'WSDCGQ12LM', 'VOCKQJK11LM'].includes(model.model)) { // https://github.com/Koenkk/zigbee2mqtt/issues/798 // Sometimes the sensor publishes non-realistic vales, filter these - // @ts-expect-error + // @ts-expect-error ignore const humidity = parseFloat(value) / 100.0; if (humidity >= 0 && humidity <= 100) { payload.humidity = humidity; @@ -792,7 +792,7 @@ export const numericAttributes2Payload = async (msg: Fz.Message, meta: Fz.Meta, payload.hand_open = !value; } else { // next values update only when curtain finished initial setup and knows current position - // @ts-expect-error + // @ts-expect-error ignore payload.options = {...payload.options, reverse_direction: value[2] == '\u0001', hand_open: value[5] == '\u0000'}; } break; @@ -889,7 +889,7 @@ export const numericAttributes2Payload = async (msg: Fz.Message, meta: Fz.Meta, break; case '65281': { - // @ts-expect-error + // @ts-expect-error ignore const payload65281 = await numericAttributes2Payload(msg, meta, model, options, value); payload = {...payload, ...payload65281}; } @@ -898,13 +898,13 @@ export const numericAttributes2Payload = async (msg: Fz.Message, meta: Fz.Meta, // This is a a complete structure with attributes, like element 0 for state, element 1 for voltage... // At this moment we only extract what we are sure, for example, position 0 seems to be always 1 for a // occupancy sensor, so we ignore it at this moment - // @ts-expect-error + // @ts-expect-error ignore payload.voltage = value[1].elmVal; if (model.meta && model.meta.battery && model.meta.battery.voltageToPercentage) { assertNumber(payload.voltage); payload.battery = batteryVoltageToPercentage(payload.voltage, model.meta.battery.voltageToPercentage); } - // @ts-expect-error + // @ts-expect-error ignore payload.power_outage_count = value[4].elmVal - 1; break; case 'mode': @@ -1133,7 +1133,7 @@ function writeDaySelection(buffer: Buffer, offset: number, selectedDays: Day[]) const bitMap = dayNames.reduce((repeat, dayName, index) => { const isDaySelected = selectedDays.includes(dayName); - // @ts-expect-error + // @ts-expect-error ignore return repeat | (isDaySelected << (index + 1)); }, 0); @@ -1411,7 +1411,7 @@ export const trv = { stringifiedScheduleFragments.forEach((fragment, index) => { if (index === 0) { - // @ts-expect-error + // @ts-expect-error ignore schedule.days.push(...fragment.split(stringifiedScheduleValueSeparator)); } else { const entryFragments = fragment.split(stringifiedScheduleValueSeparator); @@ -2558,16 +2558,16 @@ export const fromZigbee = { Object.entries(msg.data).forEach(([key, value]) => { switch (parseInt(key)) { case 0xfff1: { - // @ts-expect-error + // @ts-expect-error ignore if (value.length < 8) { logger.debug(`Cannot handle ${value}, frame too small`, 'zhc:lumi:feeder'); return; } - // @ts-expect-error + // @ts-expect-error ignore const attr = value.slice(3, 7); - // @ts-expect-error + // @ts-expect-error ignore const len = value.slice(7, 8).readUInt8(); - // @ts-expect-error + // @ts-expect-error ignore const val = value.slice(8, 8 + len); switch (attr.readInt32BE()) { case 0x04150055: // feeding @@ -2655,7 +2655,7 @@ export const fromZigbee = { result['system_mode'] = getFromLookup(value, {1: 'heat', 0: 'off'}); break; case 0x0272: - // @ts-expect-error + // @ts-expect-error ignore Object.assign(result, trv.decodePreset(value)); break; case 0x0273: @@ -2687,7 +2687,7 @@ export const fromZigbee = { result['valve_alarm'] = getFromLookup(value, {1: true, 0: false}); break; case 247: { - // @ts-expect-error + // @ts-expect-error ignore const heartbeat = trv.decodeHeartbeat(meta, model, value); logger.debug(`${model.model}: Processed heartbeat message into payload ${JSON.stringify(heartbeat)}`, 'zhc:lumi:trv'); @@ -2698,7 +2698,7 @@ export const fromZigbee = { // This is not reflected in the frontend unless the device is reconfigured // or the whole service restarted. // See https://github.com/Koenkk/zigbee-herdsman-converters/pull/5363#discussion_r1081477047 - // @ts-expect-error + // @ts-expect-error ignore meta.device.softwareBuildID = heartbeat.firmware_version; delete heartbeat.firmware_version; } @@ -2758,9 +2758,9 @@ export const fromZigbee = { } const [regionIdRaw, eventTypeCodeRaw] = value; - // @ts-expect-error + // @ts-expect-error ignore const regionId = parseInt(regionIdRaw, 10); - // @ts-expect-error + // @ts-expect-error ignore const eventTypeCode = parseInt(eventTypeCodeRaw, 10); if (Number.isNaN(regionId)) { @@ -3718,11 +3718,11 @@ export const toZigbee = { key: ['feed', 'schedule', 'led_indicator', 'child_lock', 'mode', 'serving_size', 'portion_weight'], convertSet: async (entity, key, value, meta) => { const sendAttr = async (attrCode: number, value: number, length: number) => { - // @ts-expect-error + // @ts-expect-error ignore entity.sendSeq = ((entity.sendSeq || 0) + 1) % 256; - // @ts-expect-error + // @ts-expect-error ignore const val = Buffer.from([0x00, 0x02, entity.sendSeq, 0, 0, 0, 0, 0]); - // @ts-expect-error + // @ts-expect-error ignore entity.sendSeq += 1; val.writeInt32BE(attrCode, 3); val.writeUInt8(length, 7); @@ -3738,7 +3738,7 @@ export const toZigbee = { v.writeUInt32BE(value); break; default: - // @ts-expect-error + // @ts-expect-error ignore v = value; } await entity.write('manuSpecificLumi', {0xfff1: {value: Buffer.concat([val, v]), type: 0x41}}, {manufacturerCode: manufacturerCode}); @@ -3749,13 +3749,13 @@ export const toZigbee = { break; case 'schedule': { const schedule: string[] = []; - // @ts-expect-error + // @ts-expect-error ignore value.forEach((item) => { const schedItem = Buffer.from([getKey(feederDaysLookup, item.days, 0x7f), item.hour, item.minute, item.size, 0]); schedule.push(schedItem.toString('hex')); }); const val = Buffer.concat([Buffer.from(schedule.join(',')), Buffer.from([0])]); - // @ts-expect-error + // @ts-expect-error ignore await sendAttr(0x080008c8, val, val.length); break; } @@ -3769,11 +3769,11 @@ export const toZigbee = { await sendAttr(0x04180055, getFromLookup(value, {manual: 0, schedule: 1}), 1); break; case 'serving_size': - // @ts-expect-error + // @ts-expect-error ignore await sendAttr(0x0e5c0055, value, 4); break; case 'portion_weight': - // @ts-expect-error + // @ts-expect-error ignore await sendAttr(0x0e5f0055, value, 4); break; default: // Unknown key @@ -3989,7 +3989,7 @@ export const toZigbee = { ); break; case 'schedule_settings': { - // @ts-expect-error + // @ts-expect-error ignore const schedule = trv.parseSchedule(value); trv.validateSchedule(schedule); const buffer = trv.encodeSchedule(schedule); @@ -4094,7 +4094,7 @@ export const toZigbee = { if (!commandWrapper.isSuccess) { logger.warning( - // @ts-expect-error + // @ts-expect-error ignore `Encountered an error (${commandWrapper.error.reason}) while parsing configuration commands (input: ${JSON.stringify(value)})`, NS, ); @@ -4274,7 +4274,7 @@ export const toZigbee = { const lookup = {rgbw: 3, dual_ct: 1}; assertString(value, key); value = value.toLowerCase(); - // @ts-expect-error + // @ts-expect-error ignore if (['rgbw'].includes(value)) { await entity.write('manuSpecificLumi', {0x0509: {value: getFromLookup(value, lookup), type: 0x23}}, manufacturerOptions.lumi); await entity.write('manuSpecificLumi', {0x050f: {value: 1, type: 0x23}}, manufacturerOptions.lumi); @@ -5125,7 +5125,7 @@ export const toZigbee = { payload.push(...value.switch_1_text.split('').map((c: string) => c.charCodeAt(0))); statearr.switch_1_text = value.switch_1_text; } else { - // @ts-expect-error + // @ts-expect-error ignore payload.push(...''.text.split('').map((c) => c.charCodeAt(0))); statearr.switch_1_text = ''; } @@ -5147,7 +5147,7 @@ export const toZigbee = { payload.push(...value.switch_2_text.split('').map((c: string) => c.charCodeAt(0))); statearr.switch_2_text = value.switch_2_text; } else { - // @ts-expect-error + // @ts-expect-error ignore payload.push(...''.text.split('').map((c) => c.charCodeAt(0))); statearr.switch_2_text = ''; } @@ -5169,7 +5169,7 @@ export const toZigbee = { payload.push(...value.switch_3_text.split('').map((c: string) => c.charCodeAt(0))); statearr.switch_3_text = value.switch_3_text; } else { - // @ts-expect-error + // @ts-expect-error ignore payload.push(...''.text.split('').map((c) => c.charCodeAt(0))); statearr.switch_3_text = ''; } @@ -5210,7 +5210,7 @@ export const legacyFromZigbee = { legacyFromZigbeeStore[key].long_timer = setTimeout(() => { legacyFromZigbeeStore[key].long = false; }, 4000); // After 4000 milliseconds of not receiving long_release we assume it will not happen. - // @ts-expect-error + // @ts-expect-error ignore }, options.long_timeout || 1000); // After 1000 milliseconds of not releasing we assume long click. } else if (state === 1) { if (legacyFromZigbeeStore[key].long) { diff --git a/src/lib/modernExtend.ts b/src/lib/modernExtend.ts index 4964c5e157835..c6e94ca4ca176 100644 --- a/src/lib/modernExtend.ts +++ b/src/lib/modernExtend.ts @@ -1564,17 +1564,17 @@ export function iasWarning(args?: IasWarningArgs): ModernExtend { key: ['warning'], convertSet: async (entity, key, value, meta) => { const values = { - // @ts-expect-error + // @ts-expect-error ignore mode: value.mode || 'emergency', - // @ts-expect-error + // @ts-expect-error ignore level: value.level || 'medium', - // @ts-expect-error + // @ts-expect-error ignore strobe: value.hasOwnProperty('strobe') ? value.strobe : true, - // @ts-expect-error + // @ts-expect-error ignore duration: value.hasOwnProperty('duration') ? value.duration : 10, - // @ts-expect-error + // @ts-expect-error ignore strobeDutyCycle: value.hasOwnProperty('strobe_duty_cycle') ? value.strobe_duty_cycle * 10 : 0, - // @ts-expect-error + // @ts-expect-error ignore strobeLevel: value.hasOwnProperty('strobe_level') ? utils.getFromLookup(value.strobe_level, strobeLevel) : 1, }; diff --git a/src/lib/ota/inovelli.ts b/src/lib/ota/inovelli.ts index 118f8b90e758d..fa5d62a89fd8a 100644 --- a/src/lib/ota/inovelli.ts +++ b/src/lib/ota/inovelli.ts @@ -32,9 +32,9 @@ export async function getImageMeta(current: Ota.ImageInfo, device: Zh.Device): P .sort((a: KeyValueAny, b: KeyValueAny) => { const aRadix = a.version.match(/[A-F]/) ? 16 : 10; const bRadix = b.version.match(/[A-F]/) ? 16 : 10; - // @ts-expect-error + // @ts-expect-error ignore const aVersion = parseFloat(a.version, aRadix); - // @ts-expect-error + // @ts-expect-error ignore const bVersion = parseFloat(b.version, bRadix); // doesn't matter which order they are in if (aVersion < bVersion) { @@ -55,7 +55,7 @@ export async function getImageMeta(current: Ota.ImageInfo, device: Zh.Device): P // version in the firmware removes the zero padding and support hex versioning return { - // @ts-expect-error + // @ts-expect-error ignore fileVersion: parseFloat(image.version, image.version.match(/[A-F]/) ? 16 : 10), url: image.firmware, }; diff --git a/src/lib/ota/salus.ts b/src/lib/ota/salus.ts index 49eb1e5f9eb0d..13b8f21cef129 100644 --- a/src/lib/ota/salus.ts +++ b/src/lib/ota/salus.ts @@ -73,7 +73,7 @@ async function downloadImage(meta: KeyValueAny) { const files = await untar(download.data); - // @ts-expect-error + // @ts-expect-error ignore const imageFile = files.find((file) => file.headers.name.endsWith('.ota')); return imageFile; diff --git a/src/lib/philips.ts b/src/lib/philips.ts index 42fabd6502f49..e02275b4b426b 100644 --- a/src/lib/philips.ts +++ b/src/lib/philips.ts @@ -111,7 +111,7 @@ export const philipsTz = { return { key: ['gradient'], convertSet: async (entity, key, value, meta) => { - // @ts-expect-error + // @ts-expect-error ignore const scene = encodeGradientColors(value, opts); const payload = {data: Buffer.from(scene, 'hex')}; await entity.command('manuSpecificPhilips2', 'multiColor', payload); @@ -187,7 +187,7 @@ export const philipsTz = { await entity.write('lightingColorCtrl', {0x0004: {value: 0xffff, type: 0x21}}, manufacturerOptions); } } else if (meta.message.hasOwnProperty('hue_power_on_color')) { - // @ts-expect-error + // @ts-expect-error ignore const colorXY = libColor.ColorRGB.fromHex(meta.message.hue_power_on_color).toXY(); const xy = {x: utils.mapNumberRange(colorXY.x, 0, 1, 0, 65535), y: utils.mapNumberRange(colorXY.y, 0, 1, 0, 65535)}; value = xy; @@ -381,7 +381,7 @@ export const philipsFz = { // simulated brightness if (options.simulated_brightness) { const opts = options.simulated_brightness; - // @ts-expect-error + // @ts-expect-error ignore const deltaOpts = typeof opts === 'object' && opts.hasOwnProperty('delta') ? opts.delta : 35; const delta = direction === 'right' ? deltaOpts : deltaOpts * -1; const brightness = globalStore.getValue(msg.endpoint, 'brightness', 255) + delta; @@ -538,7 +538,7 @@ function decodeGradientColors(input: string, opts: KeyValue) { // Effect mode const effect = input.slice(0, 4); - // @ts-expect-error + // @ts-expect-error ignore const name = knownEffects[effect] || `unknown_${effect}`; return { color_mode: 'xy', diff --git a/src/lib/reporting.ts b/src/lib/reporting.ts index 91e9d2ab445f8..9a65a18a60f3b 100644 --- a/src/lib/reporting.ts +++ b/src/lib/reporting.ts @@ -14,7 +14,7 @@ export function payload(attribute: string | number, min: number, max: number, ch if (overrides) { if (overrides.hasOwnProperty('min')) payload.minimumReportInterval = overrides.min; if (overrides.hasOwnProperty('max')) payload.maximumReportInterval = overrides.max; - // @ts-expect-error + // @ts-expect-error ignore if (overrides.hasOwnProperty('change')) payload.reportableChange = overrides.change; } @@ -124,12 +124,12 @@ export const instantaneousDemand = async (endpoint: Zh.Endpoint, overrides?: Rep await endpoint.configureReporting('seMetering', p); }; export const currentSummDelivered = async (endpoint: Zh.Endpoint, overrides?: Reporting.Override) => { - // @ts-expect-error + // @ts-expect-error ignore const p = payload('currentSummDelivered', 5, repInterval.HOUR, [1, 1], overrides); await endpoint.configureReporting('seMetering', p); }; export const currentSummReceived = async (endpoint: Zh.Endpoint, overrides?: Reporting.Override) => { - // @ts-expect-error + // @ts-expect-error ignore const p = payload('currentSummReceived', 5, repInterval.HOUR, [1, 1], overrides); await endpoint.configureReporting('seMetering', p); }; diff --git a/src/lib/tuya.ts b/src/lib/tuya.ts index 5130d2f480308..fecfc5b22b61a 100644 --- a/src/lib/tuya.ts +++ b/src/lib/tuya.ts @@ -703,7 +703,7 @@ export const valueConverter = { }, to: (v: string) => { const numberPattern = /\d+/g; - // @ts-ignore + // @ts-expect-error ignore return v.match(numberPattern).join([]).toString(); }, }, @@ -813,7 +813,7 @@ export const valueConverter = { ':' + String(parseInt(v[index + 1])).padStart(2, '0') + '/' + - // @ts-ignore + // @ts-expect-error ignore (parseFloat((v[index + 2] << 8) + v[index + 3]) / 10.0).toFixed(1), ); } @@ -1242,7 +1242,7 @@ const tuyaTz = { if (countdown !== undefined) { // OnTime is a 16bit register and so might very well work up to 0xFFFF seconds but // the Tuya documentation says that the maximum is 43200 (so 12 hours). - // @ts-expect-error + // @ts-expect-error ignore if (!Number.isInteger(countdown) || countdown < 0 || countdown > 12 * 3600) { throw new Error('countdown must be an integer between 1 and 43200 (12 hours) or 0 to cancel'); } diff --git a/src/lib/utils.ts b/src/lib/utils.ts index be1d376c09589..f1b4140583f32 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -224,7 +224,7 @@ export function postfixWithEndpointName(value: string, msg: Fz.Message, definiti // Prevent breaking change https://github.com/Koenkk/zigbee2mqtt/issues/13451 if (!meta) { logger.warning(`No meta passed to postfixWithEndpointName, update your external converter!`, NS); - // @ts-expect-error + // @ts-expect-error ignore meta = {device: null}; } @@ -245,7 +245,7 @@ export function postfixWithEndpointName(value: string, msg: Fz.Message, definiti export function enforceEndpoint(entity: Zh.Endpoint, key: string, meta: Tz.Meta) { const multiEndpointEnforce = getMetaValue(entity, meta.mapped, 'multiEndpointEnforce', 'allEqual', []); if (multiEndpointEnforce && multiEndpointEnforce.hasOwnProperty(key)) { - // @ts-expect-error + // @ts-expect-error ignore const endpoint = entity.getDevice().getEndpoint(multiEndpointEnforce[key]); if (endpoint) return endpoint; } @@ -254,7 +254,7 @@ export function enforceEndpoint(entity: Zh.Endpoint, key: string, meta: Tz.Meta) export function getKey(object: {[s: string]: T} | {[s: number]: T}, value: T, fallback?: T, convertTo?: (v: unknown) => T) { for (const key in object) { - // @ts-expect-error + // @ts-expect-error ignore if (object[key] === value) { return convertTo ? convertTo(key) : key; } @@ -386,7 +386,7 @@ export function toSnakeCase(value: string | KeyValueAny) { for (const key of Object.keys(value)) { const keySnakeCase = toSnakeCase(key); if (key !== keySnakeCase) { - // @ts-expect-error + // @ts-expect-error ignore value[keySnakeCase] = value[key]; delete value[key]; } @@ -405,7 +405,7 @@ export function toCamelCase(value: KeyValueAny | string) { for (const key of Object.keys(value)) { const keyCamelCase = toCamelCase(key); if (key !== keyCamelCase) { - // @ts-expect-error + // @ts-expect-error ignore value[keyCamelCase] = value[key]; delete value[key]; } @@ -504,7 +504,7 @@ export function getMetaValues(definitions: Definition | Definition[], entity: Zh if (definition && definition.meta) { for (const key of Object.keys(definition.meta)) { if (allowed == null || allowed.includes(key)) { - // @ts-expect-error + // @ts-expect-error ignore const value = definition.meta[key]; if (typeof value === 'function') { if (isEndpoint(entity)) { @@ -628,7 +628,7 @@ export function assertNumber(value: unknown, property?: string): asserts value i export function toNumber(value: unknown, property?: string): number { property = property ? `'${property}'` : 'Value'; - // @ts-ignore + // @ts-expect-error ignore const result = parseFloat(value); if (Number.isNaN(result)) { throw new Error(`${property} is not a number, got ${typeof value} (${value.toString()})`); diff --git a/test/utils.ts b/test/utils.ts index 8198d66c3efad..69176bd3cd186 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -20,7 +20,7 @@ export function reportingItem(attribute: string, min: number, max: number, chang export function mockDevice(args: {modelID: string; manufacturerID?: number; manufacturerName?: string; endpoints: MockEndpointArgs[]}): Zh.Device { const ieeeAddr = '0x12345678'; const device: Zh.Device = { - // @ts-expect-error + // @ts-expect-error ignore constructor: {name: 'Device'}, ieeeAddr, save: jest.fn(), @@ -28,7 +28,7 @@ export function mockDevice(args: {modelID: string; manufacturerID?: number; manu }; const endpoints = args.endpoints.map((e) => mockEndpoint(e, device)); - // @ts-expect-error + // @ts-expect-error ignore device.endpoints = endpoints; device.getEndpoint = (ID: number) => { const endpoint = endpoints.find((e) => e.ID === ID); @@ -50,7 +50,7 @@ function mockEndpoint(args: MockEndpointArgs, device: Zh.Device | undefined): Zh const outputClusters = (args.outputClusters ?? []).map((c) => getCluster(c).ID); return { ID: args?.ID ?? 1, - // @ts-expect-error + // @ts-expect-error ignore constructor: {name: 'Endpoint'}, bind: jest.fn(), configureReporting: jest.fn(), @@ -58,9 +58,9 @@ function mockEndpoint(args: MockEndpointArgs, device: Zh.Device | undefined): Zh getDevice: () => device, inputClusters, outputClusters, - // @ts-expect-error + // @ts-expect-error ignore getInputClusters: () => inputClusters.map((c) => getCluster(c)), - // @ts-expect-error + // @ts-expect-error ignore getOutputClusters: () => outputClusters.map((c) => getCluster(c)), supportsInputCluster: (key) => !!inputClusters.find((ID) => ID === getCluster(key).ID), saveClusterAttributeKeyValue: jest.fn().mockImplementation((cluster, values) => (attributes[cluster] = {...attributes[cluster], ...values})), @@ -143,7 +143,7 @@ export async function assertDefintion(args: AssertDefinitionArgs) { } if (definition.endpoint) { - // @ts-expect-error + // @ts-expect-error ignore expect(definition.endpoint()).toStrictEqual(args.endpoints); } } From e389bbdcb1693c4c9edadfa3dbdfc0ebbc26c6b3 Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Mon, 9 Sep 2024 22:19:28 +0200 Subject: [PATCH 08/12] ignore @typescript-eslint/explicit-function-return-type --- eslint.config.mjs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 7ccf86428a66f..c122c961df316 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -16,7 +16,8 @@ export default tseslint.config( rules: { '@typescript-eslint/await-thenable': 'error', '@typescript-eslint/ban-ts-comment': 'error', - '@typescript-eslint/explicit-function-return-type': 'off', // TODO error + // Not enabled for now, gives 3.6k errors which require manual fixing. + // '@typescript-eslint/explicit-function-return-type': 'error', '@typescript-eslint/no-explicit-any': 'error', '@typescript-eslint/no-unused-vars': ['error', {args: 'none'}], 'array-bracket-spacing': ['error', 'never'], From cbefc0f1b89251ab26adb8cf85fcd37592781aaf Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Mon, 9 Sep 2024 23:20:00 +0200 Subject: [PATCH 09/12] no-prototype-builtins --- eslint.config.mjs | 1 - src/converters/fromZigbee.ts | 670 +++++++++++++++--------------- src/converters/toZigbee.ts | 105 +++-- src/devices/bitron.ts | 12 +- src/devices/bosch.ts | 50 +-- src/devices/centralite.ts | 4 +- src/devices/ctm.ts | 124 +++--- src/devices/custom_devices_diy.ts | 12 +- src/devices/develco.ts | 29 +- src/devices/gledopto.ts | 2 +- src/devices/gmmts.ts | 38 +- src/devices/inovelli.ts | 49 +-- src/devices/kmpcil.ts | 8 +- src/devices/led_trading.ts | 8 +- src/devices/leviton.ts | 2 +- src/devices/linptech.ts | 10 +- src/devices/lixee.ts | 17 +- src/devices/lumi.ts | 4 +- src/devices/lytko.ts | 12 +- src/devices/namron.ts | 10 +- src/devices/niko.ts | 14 +- src/devices/nue_3a.ts | 4 +- src/devices/owon.ts | 50 +-- src/devices/perenio.ts | 36 +- src/devices/schneider_electric.ts | 40 +- src/devices/shinasystem.ts | 2 +- src/devices/siglis.ts | 2 +- src/devices/sinope.ts | 106 +++-- src/devices/sonoff.ts | 4 +- src/devices/stelpro.ts | 4 +- src/devices/sunricher.ts | 6 +- src/devices/tuya.ts | 8 +- src/devices/ubisys.ts | 34 +- src/devices/wirenboard.ts | 14 +- src/devices/woolley.ts | 2 +- src/devices/xyzroe.ts | 12 +- src/lib/color.ts | 93 ++--- src/lib/develco.ts | 8 +- src/lib/ikea.ts | 20 +- src/lib/legacy.ts | 65 ++- src/lib/legrand.ts | 8 +- src/lib/light.ts | 8 +- src/lib/lumi.ts | 108 +++-- src/lib/modernExtend.ts | 18 +- src/lib/ota/zigbeeOTA.ts | 8 +- src/lib/philips.ts | 16 +- src/lib/reporting.ts | 6 +- src/lib/store.ts | 4 +- src/lib/tuya.ts | 41 +- src/lib/ubisys.ts | 2 +- src/lib/utils.ts | 34 +- test/index.test.js | 2 +- 52 files changed, 954 insertions(+), 992 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index c122c961df316..d18724fb43e23 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -24,7 +24,6 @@ export default tseslint.config( 'no-return-await': 'error', 'object-curly-spacing': ['error', 'never'], '@typescript-eslint/no-floating-promises': 'error', - 'no-prototype-builtins': 'off', // TODO remove (error by default) }, }, { diff --git a/src/converters/fromZigbee.ts b/src/converters/fromZigbee.ts index 1e4001bb5f90e..a487d7a538b26 100644 --- a/src/converters/fromZigbee.ts +++ b/src/converters/fromZigbee.ts @@ -29,7 +29,7 @@ const converters1 = { cluster: 'hvacFanCtrl', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('fanMode')) { + if (msg.data.fanMode !== undefined) { const key = getKey(constants.fanMode, msg.data.fanMode); return {fan_mode: key, fan_state: key === 'off' ? 'OFF' : 'ON'}; } @@ -41,58 +41,58 @@ const converters1 = { convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; const dontMapPIHeatingDemand = model.meta && model.meta.thermostat && model.meta.thermostat.dontMapPIHeatingDemand; - if (msg.data.hasOwnProperty('localTemp')) { + if (msg.data.localTemp !== undefined) { const value = precisionRound(msg.data['localTemp'], 2) / 100; if (value >= -273.15) { result[postfixWithEndpointName('local_temperature', msg, model, meta)] = value; } } - if (msg.data.hasOwnProperty('localTemperatureCalibration')) { + if (msg.data.localTemperatureCalibration !== undefined) { result[postfixWithEndpointName('local_temperature_calibration', msg, model, meta)] = precisionRound(msg.data['localTemperatureCalibration'], 2) / 10; } - if (msg.data.hasOwnProperty('outdoorTemp')) { + if (msg.data.outdoorTemp !== undefined) { const value = precisionRound(msg.data['outdoorTemp'], 2) / 100; if (value >= -273.15) { result[postfixWithEndpointName('outdoor_temperature', msg, model, meta)] = value; } } - if (msg.data.hasOwnProperty('occupancy')) { + if (msg.data.occupancy !== undefined) { result[postfixWithEndpointName('occupancy', msg, model, meta)] = msg.data.occupancy % 2 > 0; } - if (msg.data.hasOwnProperty('occupiedHeatingSetpoint')) { + if (msg.data.occupiedHeatingSetpoint !== undefined) { const value = precisionRound(msg.data['occupiedHeatingSetpoint'], 2) / 100; // Stelpro will return -325.65 when set to off, value is not realistic anyway if (value >= -273.15) { result[postfixWithEndpointName('occupied_heating_setpoint', msg, model, meta)] = value; } } - if (msg.data.hasOwnProperty('unoccupiedHeatingSetpoint')) { + if (msg.data.unoccupiedHeatingSetpoint !== undefined) { result[postfixWithEndpointName('unoccupied_heating_setpoint', msg, model, meta)] = precisionRound(msg.data['unoccupiedHeatingSetpoint'], 2) / 100; } - if (msg.data.hasOwnProperty('occupiedCoolingSetpoint')) { + if (msg.data.occupiedCoolingSetpoint !== undefined) { result[postfixWithEndpointName('occupied_cooling_setpoint', msg, model, meta)] = precisionRound(msg.data['occupiedCoolingSetpoint'], 2) / 100; } - if (msg.data.hasOwnProperty('unoccupiedCoolingSetpoint')) { + if (msg.data.unoccupiedCoolingSetpoint !== undefined) { result[postfixWithEndpointName('unoccupied_cooling_setpoint', msg, model, meta)] = precisionRound(msg.data['unoccupiedCoolingSetpoint'], 2) / 100; } - if (msg.data.hasOwnProperty('setpointChangeAmount')) { + if (msg.data.setpointChangeAmount !== undefined) { result[postfixWithEndpointName('setpoint_change_amount', msg, model, meta)] = msg.data['setpointChangeAmount'] / 100; } - if (msg.data.hasOwnProperty('setpointChangeSource')) { + if (msg.data.setpointChangeSource !== undefined) { const lookup: KeyValueAny = {0: 'manual', 1: 'schedule', 2: 'externally'}; result[postfixWithEndpointName('setpoint_change_source', msg, model, meta)] = lookup[msg.data['setpointChangeSource']]; } - if (msg.data.hasOwnProperty('setpointChangeSourceTimeStamp')) { + if (msg.data.setpointChangeSourceTimeStamp !== undefined) { const date = new Date(2000, 0, 1); date.setSeconds(msg.data['setpointChangeSourceTimeStamp']); const value = toLocalISOString(date); result[postfixWithEndpointName('setpoint_change_source_timestamp', msg, model, meta)] = value; } - if (msg.data.hasOwnProperty('remoteSensing')) { + if (msg.data.remoteSensing !== undefined) { const value = msg.data['remoteSensing']; result[postfixWithEndpointName('remote_sensing', msg, model, meta)] = { local_temperature: (value & 1) > 0 ? 'remotely' : 'internally', @@ -100,24 +100,24 @@ const converters1 = { occupancy: (value & (1 << 2)) > 0 ? 'remotely' : 'internally', }; } - if (msg.data.hasOwnProperty('ctrlSeqeOfOper')) { + if (msg.data.ctrlSeqeOfOper !== undefined) { result[postfixWithEndpointName('control_sequence_of_operation', msg, model, meta)] = constants.thermostatControlSequenceOfOperations[msg.data['ctrlSeqeOfOper']]; } - if (msg.data.hasOwnProperty('programingOperMode')) { + if (msg.data.programingOperMode !== undefined) { result[postfixWithEndpointName('programming_operation_mode', msg, model, meta)] = constants.thermostatProgrammingOperationModes[msg.data['programingOperMode']]; } - if (msg.data.hasOwnProperty('systemMode')) { + if (msg.data.systemMode !== undefined) { result[postfixWithEndpointName('system_mode', msg, model, meta)] = constants.thermostatSystemModes[msg.data['systemMode']]; } - if (msg.data.hasOwnProperty('runningMode')) { + if (msg.data.runningMode !== undefined) { result[postfixWithEndpointName('running_mode', msg, model, meta)] = constants.thermostatRunningMode[msg.data['runningMode']]; } - if (msg.data.hasOwnProperty('runningState')) { + if (msg.data.runningState !== undefined) { result[postfixWithEndpointName('running_state', msg, model, meta)] = constants.thermostatRunningStates[msg.data['runningState']]; } - if (msg.data.hasOwnProperty('pIHeatingDemand')) { + if (msg.data.pIHeatingDemand !== undefined) { result[postfixWithEndpointName('pi_heating_demand', msg, model, meta)] = mapNumberRange( msg.data['pIHeatingDemand'], 0, @@ -126,7 +126,7 @@ const converters1 = { 100, ); } - if (msg.data.hasOwnProperty('pICoolingDemand')) { + if (msg.data.pICoolingDemand !== undefined) { // we assume the behavior is consistent for pIHeatingDemand + pICoolingDemand for the same vendor result[postfixWithEndpointName('pi_cooling_demand', msg, model, meta)] = mapNumberRange( msg.data['pICoolingDemand'], @@ -136,55 +136,55 @@ const converters1 = { 100, ); } - if (msg.data.hasOwnProperty('tempSetpointHold')) { + if (msg.data.tempSetpointHold !== undefined) { result[postfixWithEndpointName('temperature_setpoint_hold', msg, model, meta)] = msg.data['tempSetpointHold'] == 1; } - if (msg.data.hasOwnProperty('tempSetpointHoldDuration')) { + if (msg.data.tempSetpointHoldDuration !== undefined) { result[postfixWithEndpointName('temperature_setpoint_hold_duration', msg, model, meta)] = msg.data['tempSetpointHoldDuration']; } - if (msg.data.hasOwnProperty('minHeatSetpointLimit')) { + if (msg.data.minHeatSetpointLimit !== undefined) { const value = precisionRound(msg.data['minHeatSetpointLimit'], 2) / 100; if (value >= -273.15) { result[postfixWithEndpointName('min_heat_setpoint_limit', msg, model, meta)] = value; } } - if (msg.data.hasOwnProperty('maxHeatSetpointLimit')) { + if (msg.data.maxHeatSetpointLimit !== undefined) { const value = precisionRound(msg.data['maxHeatSetpointLimit'], 2) / 100; if (value >= -273.15) { result[postfixWithEndpointName('max_heat_setpoint_limit', msg, model, meta)] = value; } } - if (msg.data.hasOwnProperty('absMinHeatSetpointLimit')) { + if (msg.data.absMinHeatSetpointLimit !== undefined) { const value = precisionRound(msg.data['absMinHeatSetpointLimit'], 2) / 100; if (value >= -273.15) { result[postfixWithEndpointName('abs_min_heat_setpoint_limit', msg, model, meta)] = value; } } - if (msg.data.hasOwnProperty('absMaxHeatSetpointLimit')) { + if (msg.data.absMaxHeatSetpointLimit !== undefined) { const value = precisionRound(msg.data['absMaxHeatSetpointLimit'], 2) / 100; if (value >= -273.15) { result[postfixWithEndpointName('abs_max_heat_setpoint_limit', msg, model, meta)] = value; } } - if (msg.data.hasOwnProperty('absMinCoolSetpointLimit')) { + if (msg.data.absMinCoolSetpointLimit !== undefined) { const value = precisionRound(msg.data['absMinCoolSetpointLimit'], 2) / 100; if (value >= -273.15) { result[postfixWithEndpointName('abs_min_cool_setpoint_limit', msg, model, meta)] = value; } } - if (msg.data.hasOwnProperty('absMaxCoolSetpointLimit')) { + if (msg.data.absMaxCoolSetpointLimit !== undefined) { const value = precisionRound(msg.data['absMaxCoolSetpointLimit'], 2) / 100; if (value >= -273.15) { result[postfixWithEndpointName('abs_max_cool_setpoint_limit', msg, model, meta)] = value; } } - if (msg.data.hasOwnProperty('minSetpointDeadBand')) { + if (msg.data.minSetpointDeadBand !== undefined) { const value = precisionRound(msg.data['minSetpointDeadBand'], 2) / 100; if (value >= -273.15) { result[postfixWithEndpointName('min_setpoint_dead_band', msg, model, meta)] = value; } } - if (msg.data.hasOwnProperty('acLouverPosition')) { + if (msg.data.acLouverPosition !== undefined) { result[postfixWithEndpointName('ac_louver_position', msg, model, meta)] = constants.thermostatAcLouverPositions[msg.data['acLouverPosition']]; } @@ -205,10 +205,10 @@ const converters1 = { const transitions = []; for (const transition of msg.data.transitions) { const entry: KeyValueAny = {time: transition.transitionTime}; - if (transition.hasOwnProperty('heatSetpoint')) { + if (transition.heatSetpoint !== undefined) { entry['heating_setpoint'] = transition['heatSetpoint'] / 100; } - if (transition.hasOwnProperty('coolSetpoint')) { + if (transition.coolSetpoint !== undefined) { entry['cooling_setpoint'] = transition['coolSetpoint'] / 100; } transitions.push(entry); @@ -222,15 +222,17 @@ const converters1 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty('keypadLockout')) { - result.keypad_lockout = constants.keypadLockoutMode.hasOwnProperty(msg.data['keypadLockout']) - ? constants.keypadLockoutMode[msg.data['keypadLockout']] - : msg.data['keypadLockout']; - } - if (msg.data.hasOwnProperty('tempDisplayMode')) { - result.temperature_display_mode = constants.temperatureDisplayMode.hasOwnProperty(msg.data['tempDisplayMode']) - ? constants.temperatureDisplayMode[msg.data['tempDisplayMode']] - : msg.data['tempDisplayMode']; + if (msg.data.keypadLockout !== undefined) { + result.keypad_lockout = + constants.keypadLockoutMode[msg.data['keypadLockout']] !== undefined + ? constants.keypadLockoutMode[msg.data['keypadLockout']] + : msg.data['keypadLockout']; + } + if (msg.data.tempDisplayMode !== undefined) { + result.temperature_display_mode = + constants.temperatureDisplayMode[msg.data['tempDisplayMode']] !== undefined + ? constants.temperatureDisplayMode[msg.data['tempDisplayMode']] + : msg.data['tempDisplayMode']; } return result; }, @@ -292,21 +294,21 @@ const converters1 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty('lockState')) { + if (msg.data.lockState !== undefined) { result.state = msg.data.lockState == 1 ? 'LOCK' : 'UNLOCK'; const lookup = ['not_fully_locked', 'locked', 'unlocked']; result.lock_state = lookup[msg.data['lockState']]; } - if (msg.data.hasOwnProperty('autoRelockTime')) { + if (msg.data.autoRelockTime !== undefined) { result.auto_relock_time = msg.data.autoRelockTime; } - if (msg.data.hasOwnProperty('soundVolume')) { + if (msg.data.soundVolume !== undefined) { result.sound_volume = constants.lockSoundVolume[msg.data.soundVolume]; } - if (msg.data.hasOwnProperty('doorState')) { + if (msg.data.doorState !== undefined) { const lookup: KeyValueAny = { 0: 'open', 1: 'closed', @@ -378,7 +380,7 @@ const converters1 = { // returned by the device and are instead calculating it ourselves. if ( model.meta?.battery?.voltageToPercentage == null && - msg.data.hasOwnProperty('batteryPercentageRemaining') && + msg.data.batteryPercentageRemaining !== undefined && msg.data['batteryPercentageRemaining'] < 255 ) { // Some devices do not comply to the ZCL and report a @@ -389,7 +391,7 @@ const converters1 = { payload.battery = precisionRound(percentage, 2); } - if (msg.data.hasOwnProperty('batteryVoltage') && msg.data['batteryVoltage'] < 255) { + if (msg.data.batteryVoltage !== undefined && msg.data['batteryVoltage'] < 255) { // Deprecated: voltage is = mV now but should be V payload.voltage = msg.data['batteryVoltage'] * 100; @@ -398,7 +400,7 @@ const converters1 = { } } - if (msg.data.hasOwnProperty('batteryAlarmState')) { + if (msg.data.batteryAlarmState !== undefined) { const battery1Low = (msg.data.batteryAlarmState & (1 << 0) || msg.data.batteryAlarmState & (1 << 1) || @@ -424,7 +426,7 @@ const converters1 = { cluster: 'msTemperatureMeasurement', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('measuredValue')) { + if (msg.data.measuredValue !== undefined) { const temperature = parseFloat(msg.data['measuredValue']) / 100.0; const property = postfixWithEndpointName('temperature', msg, model, meta); return {[property]: temperature}; @@ -435,7 +437,7 @@ const converters1 = { cluster: 'genDeviceTempCfg', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('currentTemperature')) { + if (msg.data.currentTemperature !== undefined) { const value = parseInt(msg.data['currentTemperature']); return {device_temperature: value}; } @@ -460,7 +462,7 @@ const converters1 = { cluster: 'pm25Measurement', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('measuredValue')) { + if (msg.data.measuredValue !== undefined) { return {pm25: msg.data['measuredValue']}; } }, @@ -471,7 +473,7 @@ const converters1 = { convert: (model, msg, publish, options, meta) => { const flow = parseFloat(msg.data['measuredValue']) / 10.0; const property = postfixWithEndpointName('flow', msg, model, meta); - if (msg.data.hasOwnProperty('measuredValue')) { + if (msg.data.measuredValue !== undefined) { return {[property]: flow}; } }, @@ -499,7 +501,7 @@ const converters1 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { let pressure = 0; - if (msg.data.hasOwnProperty('scaledValue')) { + if (msg.data.scaledValue !== undefined) { const scale = msg.endpoint.getClusterAttributeValue('msPressureMeasurement', 'scale') as number; pressure = msg.data['scaledValue'] / Math.pow(10, scale) / 100.0; // convert to hPa } else { @@ -521,7 +523,7 @@ const converters1 = { type: ['attributeReport', 'readResponse'], options: [exposes.options.no_occupancy_since_false()], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('occupancy')) { + if (msg.data.occupancy !== undefined) { const payload = {occupancy: msg.data.occupancy % 2 > 0}; utils.noOccupancySince(msg.endpoint, options, publish, payload.occupancy ? 'stop' : 'start'); return payload; @@ -544,7 +546,7 @@ const converters1 = { // The occupancy sensor only sends a message when motion detected. // Therefore we need to publish the no_motion detected by ourselves. - const timeout = options && options.hasOwnProperty('occupancy_timeout') ? Number(options.occupancy_timeout) : 90; + const timeout = options && options.occupancy_timeout !== undefined ? Number(options.occupancy_timeout) : 90; // Stop existing timers because motion is detected and set a new one. clearTimeout(globalStore.getValue(msg.endpoint, 'occupancy_timer', null)); @@ -566,7 +568,7 @@ const converters1 = { cluster: 'msOccupancySensing', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('pirOToUDelay')) { + if (msg.data.pirOToUDelay !== undefined) { return {occupancy_timeout: msg.data.pirOToUDelay}; } }, @@ -575,7 +577,7 @@ const converters1 = { cluster: 'genLevelCtrl', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('currentLevel')) { + if (msg.data.currentLevel !== undefined) { const property = postfixWithEndpointName('brightness', msg, model, meta); return {[property]: msg.data['currentLevel']}; } @@ -588,13 +590,13 @@ const converters1 = { const result: KeyValueAny = {level_config: {}}; // onOffTransitionTime - range 0x0000 to 0xffff - optional - if (msg.data.hasOwnProperty('onOffTransitionTime') && msg.data['onOffTransitionTime'] !== undefined) { + if (msg.data.onOffTransitionTime !== undefined && msg.data['onOffTransitionTime'] !== undefined) { result.level_config.on_off_transition_time = Number(msg.data['onOffTransitionTime']); } // onTransitionTime - range 0x0000 to 0xffff - optional // 0xffff = use onOffTransitionTime - if (msg.data.hasOwnProperty('onTransitionTime') && msg.data['onTransitionTime'] !== undefined) { + if (msg.data.onTransitionTime !== undefined && msg.data['onTransitionTime'] !== undefined) { result.level_config.on_transition_time = Number(msg.data['onTransitionTime']); if (result.level_config.on_transition_time == 65535) { result.level_config.on_transition_time = 'disabled'; @@ -603,7 +605,7 @@ const converters1 = { // offTransitionTime - range 0x0000 to 0xffff - optional // 0xffff = use onOffTransitionTime - if (msg.data.hasOwnProperty('offTransitionTime') && msg.data['offTransitionTime'] !== undefined) { + if (msg.data.offTransitionTime !== undefined && msg.data['offTransitionTime'] !== undefined) { result.level_config.off_transition_time = Number(msg.data['offTransitionTime']); if (result.level_config.off_transition_time == 65535) { result.level_config.off_transition_time = 'disabled'; @@ -613,7 +615,7 @@ const converters1 = { // startUpCurrentLevel - range 0x00 to 0xff - optional // 0x00 = return to minimum supported level // 0xff - return to previous previous - if (msg.data.hasOwnProperty('startUpCurrentLevel') && msg.data['startUpCurrentLevel'] !== undefined) { + if (msg.data.startUpCurrentLevel !== undefined && msg.data['startUpCurrentLevel'] !== undefined) { result.level_config.current_level_startup = Number(msg.data['startUpCurrentLevel']); if (result.level_config.current_level_startup == 255) { result.level_config.current_level_startup = 'previous'; @@ -625,7 +627,7 @@ const converters1 = { // onLevel - range 0x00 to 0xff - optional // Any value outside of MinLevel to MaxLevel, including 0xff and 0x00, is interpreted as "previous". - if (msg.data.hasOwnProperty('onLevel') && msg.data['onLevel'] !== undefined) { + if (msg.data.onLevel !== undefined && msg.data['onLevel'] !== undefined) { result.level_config.on_level = Number(msg.data['onLevel']); if (result.level_config.on_level === 255) { result.level_config.on_level = 'previous'; @@ -637,7 +639,7 @@ const converters1 = { // when 1, CurrentLevel can be changed while the device is off. // bit 1: CoupleColorTempToLevel - when 1, changes to level also change color temperature. // (What this means is not defined, but it's most likely to be "dim to warm".) - if (msg.data.hasOwnProperty('options') && msg.data['options'] !== undefined) { + if (msg.data.options !== undefined && msg.data['options'] !== undefined) { result.level_config.execute_if_off = !!(Number(msg.data['options']) & 1); } @@ -653,47 +655,48 @@ const converters1 = { convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty('colorTemperature')) { + if (msg.data.colorTemperature !== undefined) { result.color_temp = msg.data['colorTemperature']; } - if (msg.data.hasOwnProperty('startUpColorTemperature')) { + if (msg.data.startUpColorTemperature !== undefined) { result.color_temp_startup = msg.data['startUpColorTemperature']; } - if (msg.data.hasOwnProperty('colorMode')) { - result.color_mode = constants.colorModeLookup.hasOwnProperty(msg.data['colorMode']) - ? constants.colorModeLookup[msg.data['colorMode']] - : msg.data['colorMode']; + if (msg.data.colorMode !== undefined) { + result.color_mode = + constants.colorModeLookup[msg.data['colorMode']] !== undefined + ? constants.colorModeLookup[msg.data['colorMode']] + : msg.data['colorMode']; } if ( - msg.data.hasOwnProperty('currentX') || - msg.data.hasOwnProperty('currentY') || - msg.data.hasOwnProperty('currentSaturation') || - msg.data.hasOwnProperty('currentHue') || - msg.data.hasOwnProperty('enhancedCurrentHue') + msg.data.currentX !== undefined || + msg.data.currentY !== undefined || + msg.data.currentSaturation !== undefined || + msg.data.currentHue !== undefined || + msg.data.enhancedCurrentHue !== undefined ) { result.color = {}; - if (msg.data.hasOwnProperty('currentX')) { + if (msg.data.currentX !== undefined) { result.color.x = mapNumberRange(msg.data['currentX'], 0, 65535, 0, 1, 4); } - if (msg.data.hasOwnProperty('currentY')) { + if (msg.data.currentY !== undefined) { result.color.y = mapNumberRange(msg.data['currentY'], 0, 65535, 0, 1, 4); } - if (msg.data.hasOwnProperty('currentSaturation')) { + if (msg.data.currentSaturation !== undefined) { result.color.saturation = mapNumberRange(msg.data['currentSaturation'], 0, 254, 0, 100); } - if (msg.data.hasOwnProperty('currentHue')) { + if (msg.data.currentHue !== undefined) { result.color.hue = mapNumberRange(msg.data['currentHue'], 0, 254, 0, 360, 0); } - if (msg.data.hasOwnProperty('enhancedCurrentHue')) { + if (msg.data.enhancedCurrentHue !== undefined) { result.color.hue = mapNumberRange(msg.data['enhancedCurrentHue'], 0, 65535, 0, 360, 1); } } - if (msg.data.hasOwnProperty('options')) { + if (msg.data.options !== undefined) { /* * Bit | Value & Summary * -------------------------- @@ -741,7 +744,7 @@ const converters1 = { const divisor = msg.endpoint.getClusterAttributeValue('seMetering', 'divisor') as number; const factor = multiplier && divisor ? multiplier / divisor : null; - if (msg.data.hasOwnProperty('instantaneousDemand')) { + if (msg.data.instantaneousDemand !== undefined) { let power = msg.data['instantaneousDemand']; if (factor != null) { power = power * factor * 1000; // kWh to Watt @@ -750,14 +753,14 @@ const converters1 = { payload[property] = power; } - if (factor != null && (msg.data.hasOwnProperty('currentSummDelivered') || msg.data.hasOwnProperty('currentSummReceived'))) { - if (msg.data.hasOwnProperty('currentSummDelivered')) { + if (factor != null && (msg.data.currentSummDelivered !== undefined || msg.data.currentSummReceived !== undefined)) { + if (msg.data.currentSummDelivered !== undefined) { const data = msg.data['currentSummDelivered']; const value = (parseInt(data[0]) << 32) + parseInt(data[1]); const property = postfixWithEndpointName('energy', msg, model, meta); payload[property] = value * factor; } - if (msg.data.hasOwnProperty('currentSummReceived')) { + if (msg.data.currentSummReceived !== undefined) { const data = msg.data['currentSummReceived']; const value = (parseInt(data[0]) << 32) + parseInt(data[1]); const property = postfixWithEndpointName('produced_energy', msg, model, meta); @@ -808,22 +811,22 @@ const converters1 = { const payload: KeyValueAny = {}; for (const entry of lookup) { - if (msg.data.hasOwnProperty(entry.key)) { + if (msg.data[entry.key] !== undefined) { const factor = getFactor(entry.factor); const property = postfixWithEndpointName(entry.name, msg, model, meta); const value = msg.data[entry.key] * factor; payload[property] = value; } } - if (msg.data.hasOwnProperty('powerFactor')) { + if (msg.data.powerFactor !== undefined) { const property = postfixWithEndpointName('power_factor', msg, model, meta); payload[property] = precisionRound(msg.data['powerFactor'] / 100, 2); } - if (msg.data.hasOwnProperty('powerFactorPhB')) { + if (msg.data.powerFactorPhB !== undefined) { const property = postfixWithEndpointName('power_factor_phase_b', msg, model, meta); payload[property] = precisionRound(msg.data['powerFactorPhB'] / 100, 2); } - if (msg.data.hasOwnProperty('powerFactorPhC')) { + if (msg.data.powerFactorPhC !== undefined) { const property = postfixWithEndpointName('power_factor_phase_c', msg, model, meta); payload[property] = precisionRound(msg.data['powerFactorPhC'] / 100, 2); } @@ -835,7 +838,7 @@ const converters1 = { type: ['attributeReport', 'readResponse'], options: [exposes.options.state_action()], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('onOff')) { + if (msg.data.onOff !== undefined) { const payload: KeyValueAny = {}; const property = postfixWithEndpointName('state', msg, model, meta); const state = msg.data['onOff'] === 1 ? 'ON' : 'OFF'; @@ -855,9 +858,9 @@ const converters1 = { // This converted is need instead of `fz.on_off` when no meta: {multiEndpoint: true} can be defined for this device // but it is needed for the `state`. E.g. when a switch has 3 channels (state_l1, state_l2, state_l3) but // has combined power measurements (power, energy)) - if (msg.data.hasOwnProperty('onOff')) { + if (msg.data.onOff !== undefined) { const payload: KeyValueAny = {}; - const endpointName = model.hasOwnProperty('endpoint') ? utils.getKey(model.endpoint(meta.device), msg.endpoint.ID) : msg.endpoint.ID; + const endpointName = model.endpoint !== undefined ? utils.getKey(model.endpoint(meta.device), msg.endpoint.ID) : msg.endpoint.ID; const state = msg.data['onOff'] === 1 ? 'ON' : 'OFF'; payload[`state_${endpointName}`] = state; if (options && options.state_action) { @@ -875,7 +878,7 @@ const converters1 = { // Device sends multiple messages with the same transactionSequenceNumber, // prevent that multiple messages get send. // https://github.com/Koenkk/zigbee2mqtt/issues/3687 - if (msg.data.hasOwnProperty('onOff') && !hasAlreadyProcessedMessage(msg, model)) { + if (msg.data.onOff !== undefined && !hasAlreadyProcessedMessage(msg, model)) { const payload: KeyValueAny = {}; const property = postfixWithEndpointName('state', msg, model, meta); const state = msg.data['onOff'] === 1 ? 'ON' : 'OFF'; @@ -892,7 +895,7 @@ const converters1 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const lookup: KeyValueAny = {0: 'off', 1: 'on', 2: 'toggle', 255: 'previous'}; - if (msg.data.hasOwnProperty('startUpOnOff')) { + if (msg.data.startUpOnOff !== undefined) { const property = postfixWithEndpointName('power_on_behavior', msg, model, meta); return {[property]: lookup[msg.data['startUpOnOff']]}; } @@ -968,7 +971,7 @@ const converters1 = { convert: (model, msg, publish, options, meta) => { const zoneStatus = msg.data.zonestatus; - const timeout = options && options.hasOwnProperty('vibration_timeout') ? Number(options.vibration_timeout) : 90; + const timeout = options && options.vibration_timeout !== undefined ? Number(options.vibration_timeout) : 90; // Stop existing timers because vibration is detected and set a new one. globalStore.getValue(msg.endpoint, 'timers', []).forEach((t: NodeJS.Timeout) => clearTimeout(t)); @@ -1162,7 +1165,7 @@ const converters1 = { options: [exposes.options.occupancy_timeout()], convert: (model, msg, publish, options, meta) => { const zoneStatus = msg.data.zonestatus; - const timeout = options && options.hasOwnProperty('occupancy_timeout') ? Number(options.occupancy_timeout) : 90; + const timeout = options && options.occupancy_timeout !== undefined ? Number(options.occupancy_timeout) : 90; clearTimeout(globalStore.getValue(msg.endpoint, 'timer')); @@ -1330,8 +1333,8 @@ const converters1 = { if (options.simulated_brightness) { const opts: KeyValueAny = options.simulated_brightness; - const deltaOpts = typeof opts === 'object' && opts.hasOwnProperty('delta') ? opts.delta : 20; - const intervalOpts = typeof opts === 'object' && opts.hasOwnProperty('interval') ? opts.interval : 200; + const deltaOpts = typeof opts === 'object' && opts.delta !== undefined ? opts.delta : 20; + const intervalOpts = typeof opts === 'object' && opts.interval !== undefined ? opts.interval : 200; globalStore.putValue(msg.endpoint, 'simulated_brightness_direction', direction); if (globalStore.getValue(msg.endpoint, 'simulated_brightness_timer') === undefined) { @@ -1421,7 +1424,7 @@ const converters1 = { action_step_size: msg.data.stepsize, }; - if (msg.data.hasOwnProperty('transtime')) { + if (msg.data.transtime !== undefined) { payload.action_transition_time = msg.data.transtime / 100; } @@ -1642,7 +1645,7 @@ const converters1 = { const metaInvert = model.meta && model.meta.coverInverted; const invert = metaInvert ? !options.invert_cover : options.invert_cover; const coverStateFromTilt = model.meta && model.meta.coverStateFromTilt; - if (msg.data.hasOwnProperty('currentPositionLiftPercentage') && msg.data['currentPositionLiftPercentage'] <= 100) { + if (msg.data.currentPositionLiftPercentage !== undefined && msg.data['currentPositionLiftPercentage'] <= 100) { const value = msg.data['currentPositionLiftPercentage']; result[postfixWithEndpointName('position', msg, model, meta)] = invert ? value : 100 - value; if (!coverStateFromTilt) { @@ -1655,7 +1658,7 @@ const converters1 = { : 'OPEN'; } } - if (msg.data.hasOwnProperty('currentPositionTiltPercentage') && msg.data['currentPositionTiltPercentage'] <= 100) { + if (msg.data.currentPositionTiltPercentage !== undefined && msg.data['currentPositionTiltPercentage'] <= 100) { const value = msg.data['currentPositionTiltPercentage']; result[postfixWithEndpointName('tilt', msg, model, meta)] = invert ? value : 100 - value; if (coverStateFromTilt) { @@ -1668,7 +1671,7 @@ const converters1 = { : 'CLOSE'; } } - if (msg.data.hasOwnProperty('windowCoveringMode')) { + if (msg.data.windowCoveringMode !== undefined) { result[postfixWithEndpointName('cover_mode', msg, model, meta)] = { reversed: (msg.data.windowCoveringMode & (1 << 0)) > 0, calibration: (msg.data.windowCoveringMode & (1 << 1)) > 0, @@ -1695,7 +1698,7 @@ const converters1 = { cluster: 'genOnOff', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('onOff')) { + if (msg.data.onOff !== undefined) { return {state: msg.data['onOff'] === 1 ? 'OPEN' : 'CLOSE'}; } }, @@ -1715,49 +1718,49 @@ const converters1 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty('ballastStatus')) { + if (msg.data.ballastStatus !== undefined) { const ballastStatus = msg.data.ballastStatus; result['ballast_status_non_operational'] = ballastStatus & 1 ? true : false; result['ballast_status_lamp_failure'] = ballastStatus & 2 ? true : false; } - if (msg.data.hasOwnProperty('minLevel')) { + if (msg.data.minLevel !== undefined) { result['ballast_minimum_level'] = msg.data.minLevel; } - if (msg.data.hasOwnProperty('maxLevel')) { + if (msg.data.maxLevel !== undefined) { result['ballast_maximum_level'] = msg.data.maxLevel; } - if (msg.data.hasOwnProperty('powerOnLevel')) { + if (msg.data.powerOnLevel !== undefined) { result['ballast_power_on_level'] = msg.data.powerOnLevel; } - if (msg.data.hasOwnProperty('powerOnFadeTime')) { + if (msg.data.powerOnFadeTime !== undefined) { result['ballast_power_on_fade_time'] = msg.data.powerOnFadeTime; } - if (msg.data.hasOwnProperty('intrinsicBallastFactor')) { + if (msg.data.intrinsicBallastFactor !== undefined) { result['ballast_intrinsic_ballast_factor'] = msg.data.intrinsicBallastFactor; } - if (msg.data.hasOwnProperty('ballastFactorAdjustment')) { + if (msg.data.ballastFactorAdjustment !== undefined) { result['ballast_ballast_factor_adjustment'] = msg.data.ballastFactorAdjustment; } - if (msg.data.hasOwnProperty('lampQuantity')) { + if (msg.data.lampQuantity !== undefined) { result['ballast_lamp_quantity'] = msg.data.lampQuantity; } - if (msg.data.hasOwnProperty('lampType')) { + if (msg.data.lampType !== undefined) { result['ballast_lamp_type'] = msg.data.lampType; } - if (msg.data.hasOwnProperty('lampManufacturer')) { + if (msg.data.lampManufacturer !== undefined) { result['ballast_lamp_manufacturer'] = msg.data.lampManufacturer; } - if (msg.data.hasOwnProperty('lampRatedHours')) { + if (msg.data.lampRatedHours !== undefined) { result['ballast_lamp_rated_hours'] = msg.data.lampRatedHours; } - if (msg.data.hasOwnProperty('lampBurnHours')) { + if (msg.data.lampBurnHours !== undefined) { result['ballast_lamp_burn_hours'] = msg.data.lampBurnHours; } - if (msg.data.hasOwnProperty('lampAlarmMode')) { + if (msg.data.lampAlarmMode !== undefined) { const lampAlarmMode = msg.data.lampAlarmMode; result['ballast_lamp_alarm_lamp_burn_hours'] = lampAlarmMode & 1 ? true : false; } - if (msg.data.hasOwnProperty('lampBurnHoursTripPoint')) { + if (msg.data.lampBurnHoursTripPoint !== undefined) { result['ballast_lamp_burn_hours_trip_point'] = msg.data.lampBurnHoursTripPoint; } return result; @@ -1768,7 +1771,7 @@ const converters1 = { type: ['commandCheckin'], options: [exposes.options.presence_timeout()], convert: (model, msg, publish, options, meta) => { - const useOptionsTimeout = options && options.hasOwnProperty('presence_timeout'); + const useOptionsTimeout = options && options.presence_timeout !== undefined; const timeout = useOptionsTimeout ? Number(options.presence_timeout) : 100; // 100 seconds by default // Stop existing timer because presence is detected and set a new one. @@ -1799,7 +1802,7 @@ const converters1 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty('maxDuration')) result['max_duration'] = msg.data.maxDuration; + if (msg.data.maxDuration !== undefined) result['max_duration'] = msg.data.maxDuration; return result; }, } satisfies Fz.Converter, @@ -1808,7 +1811,7 @@ const converters1 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const payload: KeyValueAny = {}; - if (msg.data.hasOwnProperty('powerSource')) { + if (msg.data.powerSource !== undefined) { const value = msg.data['powerSource']; const lookup: KeyValueAny = { 0: 'unknown', @@ -1840,66 +1843,66 @@ const converters1 = { convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; const data = msg.data; - if (data.hasOwnProperty(0x1000)) { + if (data[0x1000] !== undefined) { // Display brightness const lookup: KeyValueAny = {0: 'low', 1: 'mid', 2: 'high'}; result.lcd_brightness = lookup[data[0x1000]]; } - if (data.hasOwnProperty(0x1001)) { + if (data[0x1001] !== undefined) { // Button vibration level const lookup: KeyValueAny = {0: 'off', 1: 'low', 2: 'high'}; result.button_vibration_level = lookup[data[0x1001]]; } - if (data.hasOwnProperty(0x1002)) { + if (data[0x1002] !== undefined) { // Floor sensor type const lookup: KeyValueAny = {1: '10k', 2: '15k', 3: '50k', 4: '100k', 5: '12k'}; result.floor_sensor_type = lookup[data[0x1002]]; } - if (data.hasOwnProperty(0x1003)) { + if (data[0x1003] !== undefined) { // Sensor const lookup: KeyValueAny = {0: 'air', 1: 'floor', 2: 'both'}; result.sensor = lookup[data[0x1003]]; } - if (data.hasOwnProperty(0x1004)) { + if (data[0x1004] !== undefined) { // PowerUpStatus const lookup: KeyValueAny = {0: 'default', 1: 'last_status'}; result.powerup_status = lookup[data[0x1004]]; } - if (data.hasOwnProperty(0x1005)) { + if (data[0x1005] !== undefined) { // FloorSensorCalibration result.floor_sensor_calibration = precisionRound(data[0x1005], 2) / 10; } - if (data.hasOwnProperty(0x1006)) { + if (data[0x1006] !== undefined) { // DryTime result.dry_time = data[0x1006]; } - if (data.hasOwnProperty(0x1007)) { + if (data[0x1007] !== undefined) { // ModeAfterDry const lookup: KeyValueAny = {0: 'off', 1: 'manual', 2: 'auto', 3: 'away'}; result.mode_after_dry = lookup[data[0x1007]]; } - if (data.hasOwnProperty(0x1008)) { + if (data[0x1008] !== undefined) { // TemperatureDisplay const lookup: KeyValueAny = {0: 'room', 1: 'floor'}; result.temperature_display = lookup[data[0x1008]]; } - if (data.hasOwnProperty(0x1009)) { + if (data[0x1009] !== undefined) { // WindowOpenCheck result.window_open_check = data[0x1009] / 2; } - if (data.hasOwnProperty(0x100a)) { + if (data[0x100a] !== undefined) { // Hysterersis result.hysterersis = precisionRound(data[0x100a], 2) / 10; } - if (data.hasOwnProperty(0x100b)) { + if (data[0x100b] !== undefined) { // DisplayAutoOffEnable result.display_auto_off_enabled = data[0x100b] ? 'enabled' : 'disabled'; } - if (data.hasOwnProperty(0x2001)) { + if (data[0x2001] !== undefined) { // AlarmAirTempOverValue result.alarm_airtemp_overvalue = data[0x2001]; } - if (data.hasOwnProperty(0x2002)) { + if (data[0x2002] !== undefined) { // Away Mode Set result.away_mode = data[0x2002] ? 'ON' : 'OFF'; } @@ -1912,7 +1915,7 @@ const converters1 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty('keypadLockout')) { + if (msg.data.keypadLockout !== undefined) { // Set as child lock instead as keypadlockout result.child_lock = msg.data['keypadLockout'] === 0 ? 'UNLOCK' : 'LOCK'; } @@ -1926,27 +1929,27 @@ const converters1 = { const result: KeyValueAny = {}; const data = msg.data; - if (data.hasOwnProperty('elkoDisplayText')) { + if (data.elkoDisplayText !== undefined) { // Display text result.display_text = data['elkoDisplayText']; } - if (data.hasOwnProperty('elkoPowerStatus')) { + if (data.elkoPowerStatus !== undefined) { // Power status result.system_mode = data['elkoPowerStatus'] ? 'heat' : 'off'; } - if (data.hasOwnProperty('elkoExternalTemp')) { + if (data.elkoExternalTemp !== undefined) { // External temp (floor) result.floor_temp = utils.precisionRound(data['elkoExternalTemp'], 2) / 100; } - if (data.hasOwnProperty('elkoRelayState')) { + if (data.elkoRelayState !== undefined) { // Relay state result.running_state = data['elkoRelayState'] ? 'heat' : 'idle'; } - if (data.hasOwnProperty('elkoCalibration')) { + if (data.elkoCalibration !== undefined) { // Calibration result.local_temperature_calibration = precisionRound(data['elkoCalibration'], 2) / 10; } @@ -1973,23 +1976,23 @@ const converters1 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty('alarm_temperature_max')) { + if (msg.data.alarm_temperature_max !== undefined) { result.alarm_temperature_max = msg.data['alarm_temperature_max']; } - if (msg.data.hasOwnProperty('alarm_temperature_min')) { + if (msg.data.alarm_temperature_min !== undefined) { result.alarm_temperature_min = msg.data['alarm_temperature_min']; } - if (msg.data.hasOwnProperty('alarm_humidity_max')) { + if (msg.data.alarm_humidity_max !== undefined) { result.alarm_humidity_max = msg.data['alarm_humidity_max']; } - if (msg.data.hasOwnProperty('alarm_humidity_min')) { + if (msg.data.alarm_humidity_min !== undefined) { result.alarm_humidity_min = msg.data['alarm_humidity_min']; } - if (msg.data.hasOwnProperty('alarm_humidity')) { + if (msg.data.alarm_humidity !== undefined) { const sensorAlarmLookup: KeyValueAny = {'0': 'below_min_humdity', '1': 'over_humidity', '2': 'off'}; result.alarm_humidity = sensorAlarmLookup[msg.data['alarm_humidity']]; } - if (msg.data.hasOwnProperty('alarm_temperature')) { + if (msg.data.alarm_temperature !== undefined) { const sensorAlarmLookup: KeyValueAny = {'0': 'below_min_temperature', '1': 'over_temperature', '2': 'off'}; result.alarm_temperature = sensorAlarmLookup[msg.data['alarm_temperature']]; } @@ -2003,16 +2006,16 @@ const converters1 = { convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty('colorTemperature')) { + if (msg.data.colorTemperature !== undefined) { const value = Number(msg.data['colorTemperature']); result.color_temp = mapNumberRange(value, 0, 255, 500, 153); } - if (msg.data.hasOwnProperty('tuyaBrightness')) { + if (msg.data.tuyaBrightness !== undefined) { result.brightness = msg.data['tuyaBrightness']; } - if (msg.data.hasOwnProperty('tuyaRgbMode')) { + if (msg.data.tuyaRgbMode !== undefined) { if (msg.data['tuyaRgbMode'] === 1) { result.color_mode = constants.colorModeLookup[0]; } else { @@ -2022,12 +2025,12 @@ const converters1 = { result.color = {}; - if (msg.data.hasOwnProperty('currentHue')) { + if (msg.data.currentHue !== undefined) { result.color.hue = mapNumberRange(msg.data['currentHue'], 0, 254, 0, 360); result.color.h = result.color.hue; } - if (msg.data.hasOwnProperty('currentSaturation')) { + if (msg.data.currentSaturation !== undefined) { result.color.saturation = mapNumberRange(msg.data['currentSaturation'], 0, 254, 0, 100); result.color.s = result.color.saturation; } @@ -2162,11 +2165,11 @@ const converters1 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty('maxDuration')) result['duration'] = msg.data.maxDuration; - if (msg.data.hasOwnProperty('2')) { + if (msg.data.maxDuration !== undefined) result['duration'] = msg.data.maxDuration; + if (msg.data['2'] !== undefined) { result['volume'] = mapNumberRange(msg.data['2'], 100, 10, 0, 100); } - if (msg.data.hasOwnProperty('61440')) { + if (msg.data['61440'] !== undefined) { result['alarm'] = msg.data['61440'] == 0 ? false : true; } return result; @@ -2177,11 +2180,11 @@ const converters1 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty('moesCalibrationTime')) { + if (msg.data.moesCalibrationTime !== undefined) { const value = parseFloat(msg.data['moesCalibrationTime']) / 100; result[postfixWithEndpointName('calibration_time', msg, model, meta)] = value; } - if (msg.data.hasOwnProperty('tuyaMotorReversal')) { + if (msg.data.tuyaMotorReversal !== undefined) { const value = msg.data['tuyaMotorReversal']; const reversalLookup: KeyValueAny = {0: 'OFF', 1: 'ON'}; result[postfixWithEndpointName('motor_reversal', msg, model, meta)] = reversalLookup[value]; @@ -2194,22 +2197,22 @@ const converters1 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty('tuyaMovingState')) { + if (msg.data.tuyaMovingState !== undefined) { const value = msg.data['tuyaMovingState']; const movingLookup: KeyValueAny = {0: 'UP', 1: 'STOP', 2: 'DOWN'}; result[postfixWithEndpointName('moving', msg, model, meta)] = movingLookup[value]; } - if (msg.data.hasOwnProperty('tuyaCalibration')) { + if (msg.data.tuyaCalibration !== undefined) { const value = msg.data['tuyaCalibration']; const calibrationLookup: KeyValueAny = {0: 'ON', 1: 'OFF'}; result[postfixWithEndpointName('calibration', msg, model, meta)] = calibrationLookup[value]; } - if (msg.data.hasOwnProperty('tuyaMotorReversal')) { + if (msg.data.tuyaMotorReversal !== undefined) { const value = msg.data['tuyaMotorReversal']; const reversalLookup: KeyValueAny = {0: 'OFF', 1: 'ON'}; result[postfixWithEndpointName('motor_reversal', msg, model, meta)] = reversalLookup[value]; } - if (msg.data.hasOwnProperty('moesCalibrationTime')) { + if (msg.data.moesCalibrationTime !== undefined) { const value = parseFloat(msg.data['moesCalibrationTime']) / 10.0; result[postfixWithEndpointName('calibration_time', msg, model, meta)] = value; } @@ -2624,7 +2627,7 @@ const converters1 = { const cluster = 'genLevelCtrl'; if (endpoint && (endpoint.supportsInputCluster(cluster) || endpoint.supportsOutputCluster(cluster))) { payload['brightness_' + name] = msg.data['presentValue']; - } else if (msg.data.hasOwnProperty('description')) { + } else if (msg.data.description !== undefined) { const data1 = msg.data['description']; if (data1) { const data2 = data1.split(','); @@ -2711,7 +2714,7 @@ const converters1 = { type: ['readResponse', 'attributeReport'], convert: (model, msg, publish, options, meta) => { const payload: KeyValueAny = {}; - if (msg.data.hasOwnProperty('mainsVoltage')) { + if (msg.data.mainsVoltage !== undefined) { payload.voltage = msg.data['mainsVoltage']; if (model.meta && model.meta.battery && model.meta.battery.voltageToPercentage) { @@ -2780,62 +2783,62 @@ const converters1 = { convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; // typo on property name to stick with zcl definition - if (msg.data.hasOwnProperty('inletTempreature')) { + if (msg.data.inletTempreature !== undefined) { result.inlet_temperature = precisionRound(msg.data['inletTempreature'], 2); result.inletTemperature = result.inlet_temperature; // deprecated } - if (msg.data.hasOwnProperty('status')) { + if (msg.data.status !== undefined) { result.status = precisionRound(msg.data['status'], 2); } - if (msg.data.hasOwnProperty('8192')) { + if (msg.data['8192'] !== undefined) { result.line_frequency = precisionRound(parseFloat(msg.data['8192']) / 100.0, 2); result.linefrequency = result.line_frequency; // deprecated } - if (msg.data.hasOwnProperty('8193')) { + if (msg.data['8193'] !== undefined) { result.power = precisionRound(msg.data['8193'], 2); } - if (msg.data.hasOwnProperty('8196')) { + if (msg.data['8196'] !== undefined) { result.voltage = precisionRound(msg.data['8196'], 2); } - if (msg.data.hasOwnProperty('8213')) { + if (msg.data['8213'] !== undefined) { result.voltage = precisionRound(msg.data['8213'], 2); } - if (msg.data.hasOwnProperty('8199')) { + if (msg.data['8199'] !== undefined) { result.current = precisionRound(msg.data['8199'], 2); } - if (msg.data.hasOwnProperty('8216')) { + if (msg.data['8216'] !== undefined) { result.current = precisionRound(msg.data['8216'], 2); } - if (msg.data.hasOwnProperty('8202')) { + if (msg.data['8202'] !== undefined) { result.reactive_power = precisionRound(msg.data['8202'], 2); result.reactivepower = result.reactive_power; // deprecated } - if (msg.data.hasOwnProperty('12288')) { + if (msg.data['12288'] !== undefined) { result.energy_consumed = precisionRound(msg.data['12288'], 2); // deprecated result.energyconsumed = result.energy_consumed; // deprecated result.energy = result.energy_consumed; } - if (msg.data.hasOwnProperty('12291')) { + if (msg.data['12291'] !== undefined) { result.energy_produced = precisionRound(msg.data['12291'], 2); result.energyproduced = result.energy_produced; // deprecated } - if (msg.data.hasOwnProperty('12294')) { + if (msg.data['12294'] !== undefined) { result.reactive_summation = precisionRound(msg.data['12294'], 2); result.reactivesummation = result.reactive_summation; // deprecated } - if (msg.data.hasOwnProperty('16408')) { + if (msg.data['16408'] !== undefined) { result.measure_serial = precisionRound(msg.data['16408'], 2); result.measureserial = result.measure_serial; // deprecated } @@ -2848,54 +2851,52 @@ const converters1 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty('danfossWindowOpenFeatureEnable')) { + if (msg.data.danfossWindowOpenFeatureEnable !== undefined) { result[postfixWithEndpointName('window_open_feature', msg, model, meta)] = msg.data['danfossWindowOpenFeatureEnable'] === 1; } - if (msg.data.hasOwnProperty('danfossWindowOpenInternal')) { - result[postfixWithEndpointName('window_open_internal', msg, model, meta)] = constants.danfossWindowOpen.hasOwnProperty( - msg.data['danfossWindowOpenInternal'], - ) - ? constants.danfossWindowOpen[msg.data['danfossWindowOpenInternal']] - : msg.data['danfossWindowOpenInternal']; + if (msg.data.danfossWindowOpenInternal !== undefined) { + result[postfixWithEndpointName('window_open_internal', msg, model, meta)] = + constants.danfossWindowOpen[msg.data['danfossWindowOpenInternal']] !== undefined + ? constants.danfossWindowOpen[msg.data['danfossWindowOpenInternal']] + : msg.data['danfossWindowOpenInternal']; } - if (msg.data.hasOwnProperty('danfossWindowOpenExternal')) { + if (msg.data.danfossWindowOpenExternal !== undefined) { result[postfixWithEndpointName('window_open_external', msg, model, meta)] = msg.data['danfossWindowOpenExternal'] === 1; } - if (msg.data.hasOwnProperty('danfossDayOfWeek')) { - result[postfixWithEndpointName('day_of_week', msg, model, meta)] = constants.thermostatDayOfWeek.hasOwnProperty( - msg.data['danfossDayOfWeek'], - ) - ? constants.thermostatDayOfWeek[msg.data['danfossDayOfWeek']] - : msg.data['danfossDayOfWeek']; + if (msg.data.danfossDayOfWeek !== undefined) { + result[postfixWithEndpointName('day_of_week', msg, model, meta)] = + constants.thermostatDayOfWeek[msg.data['danfossDayOfWeek']] !== undefined + ? constants.thermostatDayOfWeek[msg.data['danfossDayOfWeek']] + : msg.data['danfossDayOfWeek']; } - if (msg.data.hasOwnProperty('danfossTriggerTime')) { + if (msg.data.danfossTriggerTime !== undefined) { result[postfixWithEndpointName('trigger_time', msg, model, meta)] = msg.data['danfossTriggerTime']; } - if (msg.data.hasOwnProperty('danfossMountedModeActive')) { + if (msg.data.danfossMountedModeActive !== undefined) { result[postfixWithEndpointName('mounted_mode_active', msg, model, meta)] = msg.data['danfossMountedModeActive'] === 1; } - if (msg.data.hasOwnProperty('danfossMountedModeControl')) { + if (msg.data.danfossMountedModeControl !== undefined) { result[postfixWithEndpointName('mounted_mode_control', msg, model, meta)] = msg.data['danfossMountedModeControl'] === 1; } - if (msg.data.hasOwnProperty('danfossThermostatOrientation')) { + if (msg.data.danfossThermostatOrientation !== undefined) { result[postfixWithEndpointName('thermostat_vertical_orientation', msg, model, meta)] = msg.data['danfossThermostatOrientation'] === 1; } - if (msg.data.hasOwnProperty('danfossExternalMeasuredRoomSensor')) { + if (msg.data.danfossExternalMeasuredRoomSensor !== undefined) { result[postfixWithEndpointName('external_measured_room_sensor', msg, model, meta)] = msg.data['danfossExternalMeasuredRoomSensor']; } - if (msg.data.hasOwnProperty('danfossRadiatorCovered')) { + if (msg.data.danfossRadiatorCovered !== undefined) { result[postfixWithEndpointName('radiator_covered', msg, model, meta)] = msg.data['danfossRadiatorCovered'] === 1; } - if (msg.data.hasOwnProperty('danfossViewingDirection')) { + if (msg.data.danfossViewingDirection !== undefined) { result[postfixWithEndpointName('viewing_direction', msg, model, meta)] = msg.data['danfossViewingDirection'] === 1; } - if (msg.data.hasOwnProperty('danfossAlgorithmScaleFactor')) { + if (msg.data.danfossAlgorithmScaleFactor !== undefined) { result[postfixWithEndpointName('algorithm_scale_factor', msg, model, meta)] = msg.data['danfossAlgorithmScaleFactor']; } - if (msg.data.hasOwnProperty('danfossHeatAvailable')) { + if (msg.data.danfossHeatAvailable !== undefined) { result[postfixWithEndpointName('heat_available', msg, model, meta)] = msg.data['danfossHeatAvailable'] === 1; } - if (msg.data.hasOwnProperty('danfossHeatRequired')) { + if (msg.data.danfossHeatRequired !== undefined) { if (msg.data['danfossHeatRequired'] === 1) { result[postfixWithEndpointName('heat_required', msg, model, meta)] = true; result[postfixWithEndpointName('running_state', msg, model, meta)] = 'heat'; @@ -2904,41 +2905,40 @@ const converters1 = { result[postfixWithEndpointName('running_state', msg, model, meta)] = 'idle'; } } - if (msg.data.hasOwnProperty('danfossLoadBalancingEnable')) { + if (msg.data.danfossLoadBalancingEnable !== undefined) { result[postfixWithEndpointName('load_balancing_enable', msg, model, meta)] = msg.data['danfossLoadBalancingEnable'] === 1; } - if (msg.data.hasOwnProperty('danfossLoadRoomMean')) { + if (msg.data.danfossLoadRoomMean !== undefined) { result[postfixWithEndpointName('load_room_mean', msg, model, meta)] = msg.data['danfossLoadRoomMean']; } - if (msg.data.hasOwnProperty('danfossLoadEstimate')) { + if (msg.data.danfossLoadEstimate !== undefined) { result[postfixWithEndpointName('load_estimate', msg, model, meta)] = msg.data['danfossLoadEstimate']; } - if (msg.data.hasOwnProperty('danfossPreheatStatus')) { + if (msg.data.danfossPreheatStatus !== undefined) { result[postfixWithEndpointName('preheat_status', msg, model, meta)] = msg.data['danfossPreheatStatus'] === 1; } - if (msg.data.hasOwnProperty('danfossAdaptionRunStatus')) { + if (msg.data.danfossAdaptionRunStatus !== undefined) { result[postfixWithEndpointName('adaptation_run_status', msg, model, meta)] = constants.danfossAdaptionRunStatus[msg.data['danfossAdaptionRunStatus']]; } - if (msg.data.hasOwnProperty('danfossAdaptionRunSettings')) { + if (msg.data.danfossAdaptionRunSettings !== undefined) { result[postfixWithEndpointName('adaptation_run_settings', msg, model, meta)] = msg.data['danfossAdaptionRunSettings'] === 1; } - if (msg.data.hasOwnProperty('danfossAdaptionRunControl')) { + if (msg.data.danfossAdaptionRunControl !== undefined) { result[postfixWithEndpointName('adaptation_run_control', msg, model, meta)] = constants.danfossAdaptionRunControl[msg.data['danfossAdaptionRunControl']]; } - if (msg.data.hasOwnProperty('danfossRegulationSetpointOffset')) { + if (msg.data.danfossRegulationSetpointOffset !== undefined) { result[postfixWithEndpointName('regulation_setpoint_offset', msg, model, meta)] = msg.data['danfossRegulationSetpointOffset']; } // Danfoss Icon Converters - if (msg.data.hasOwnProperty('danfossRoomStatusCode')) { - result[postfixWithEndpointName('room_status_code', msg, model, meta)] = constants.danfossRoomStatusCode.hasOwnProperty( - msg.data['danfossRoomStatusCode'], - ) - ? constants.danfossRoomStatusCode[msg.data['danfossRoomStatusCode']] - : msg.data['danfossRoomStatusCode']; - } - if (msg.data.hasOwnProperty('danfossOutputStatus')) { + if (msg.data.danfossRoomStatusCode !== undefined) { + result[postfixWithEndpointName('room_status_code', msg, model, meta)] = + constants.danfossRoomStatusCode[msg.data['danfossRoomStatusCode']] !== undefined + ? constants.danfossRoomStatusCode[msg.data['danfossRoomStatusCode']] + : msg.data['danfossRoomStatusCode']; + } + if (msg.data.danfossOutputStatus !== undefined) { if (msg.data['danfossOutputStatus'] === 1) { result[postfixWithEndpointName('output_status', msg, model, meta)] = 'active'; result[postfixWithEndpointName('running_state', msg, model, meta)] = 'heat'; @@ -2955,7 +2955,7 @@ const converters1 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty('occupiedHeatingSetpoint')) { + if (msg.data.occupiedHeatingSetpoint !== undefined) { result[postfixWithEndpointName('occupied_heating_setpoint_scheduled', msg, model, meta)] = precisionRound(msg.data['occupiedHeatingSetpoint'], 2) / 100; } @@ -2967,20 +2967,19 @@ const converters1 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty('danfossRoomFloorSensorMode')) { - result[postfixWithEndpointName('room_floor_sensor_mode', msg, model, meta)] = constants.danfossRoomFloorSensorMode.hasOwnProperty( - msg.data['danfossRoomFloorSensorMode'], - ) - ? constants.danfossRoomFloorSensorMode[msg.data['danfossRoomFloorSensorMode']] - : msg.data['danfossRoomFloorSensorMode']; - } - if (msg.data.hasOwnProperty('danfossFloorMinSetpoint')) { + if (msg.data.danfossRoomFloorSensorMode !== undefined) { + result[postfixWithEndpointName('room_floor_sensor_mode', msg, model, meta)] = + constants.danfossRoomFloorSensorMode[msg.data['danfossRoomFloorSensorMode']] !== undefined + ? constants.danfossRoomFloorSensorMode[msg.data['danfossRoomFloorSensorMode']] + : msg.data['danfossRoomFloorSensorMode']; + } + if (msg.data.danfossFloorMinSetpoint !== undefined) { const value = precisionRound(msg.data['danfossFloorMinSetpoint'], 2) / 100; if (value >= -273.15) { result[postfixWithEndpointName('floor_min_setpoint', msg, model, meta)] = value; } } - if (msg.data.hasOwnProperty('danfossFloorMaxSetpoint')) { + if (msg.data.danfossFloorMaxSetpoint !== undefined) { const value = precisionRound(msg.data['danfossFloorMaxSetpoint'], 2) / 100; if (value >= -273.15) { result[postfixWithEndpointName('floor_max_setpoint', msg, model, meta)] = value; @@ -2994,7 +2993,7 @@ const converters1 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty('batteryPercentageRemaining')) { + if (msg.data.batteryPercentageRemaining !== undefined) { // Some devices do not comply to the ZCL and report a // batteryPercentageRemaining of 100 when the battery is full (should be 200). const dontDividePercentage = model.meta && model.meta.battery && model.meta.battery.dontDividePercentage; @@ -3011,26 +3010,23 @@ const converters1 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty('danfossSystemStatusCode')) { - result[postfixWithEndpointName('system_status_code', msg, model, meta)] = constants.danfossSystemStatusCode.hasOwnProperty( - msg.data['danfossSystemStatusCode'], - ) - ? constants.danfossSystemStatusCode[msg.data['danfossSystemStatusCode']] - : msg.data['danfossSystemStatusCode']; - } - if (msg.data.hasOwnProperty('danfossSystemStatusWater')) { - result[postfixWithEndpointName('system_status_water', msg, model, meta)] = constants.danfossSystemStatusWater.hasOwnProperty( - msg.data['danfossSystemStatusWater'], - ) - ? constants.danfossSystemStatusWater[msg.data['danfossSystemStatusWater']] - : msg.data['danfossSystemStatusWater']; - } - if (msg.data.hasOwnProperty('danfossMultimasterRole')) { - result[postfixWithEndpointName('multimaster_role', msg, model, meta)] = constants.danfossMultimasterRole.hasOwnProperty( - msg.data['danfossMultimasterRole'], - ) - ? constants.danfossMultimasterRole[msg.data['danfossMultimasterRole']] - : msg.data['danfossMultimasterRole']; + if (msg.data.danfossSystemStatusCode !== undefined) { + result[postfixWithEndpointName('system_status_code', msg, model, meta)] = + constants.danfossSystemStatusCode[msg.data['danfossSystemStatusCode']] !== undefined + ? constants.danfossSystemStatusCode[msg.data['danfossSystemStatusCode']] + : msg.data['danfossSystemStatusCode']; + } + if (msg.data.danfossSystemStatusWater !== undefined) { + result[postfixWithEndpointName('system_status_water', msg, model, meta)] = + constants.danfossSystemStatusWater[msg.data['danfossSystemStatusWater']] !== undefined + ? constants.danfossSystemStatusWater[msg.data['danfossSystemStatusWater']] + : msg.data['danfossSystemStatusWater']; + } + if (msg.data.danfossMultimasterRole !== undefined) { + result[postfixWithEndpointName('multimaster_role', msg, model, meta)] = + constants.danfossMultimasterRole[msg.data['danfossMultimasterRole']] !== undefined + ? constants.danfossMultimasterRole[msg.data['danfossMultimasterRole']] + : msg.data['danfossMultimasterRole']; } return result; }, @@ -3040,19 +3036,17 @@ const converters1 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty('keypadLockout')) { - result[postfixWithEndpointName('keypad_lockout', msg, model, meta)] = constants.keypadLockoutMode.hasOwnProperty( - msg.data['keypadLockout'], - ) - ? constants.keypadLockoutMode[msg.data['keypadLockout']] - : msg.data['keypadLockout']; - } - if (msg.data.hasOwnProperty('tempDisplayMode')) { - result[postfixWithEndpointName('temperature_display_mode', msg, model, meta)] = constants.temperatureDisplayMode.hasOwnProperty( - msg.data['tempDisplayMode'], - ) - ? constants.temperatureDisplayMode[msg.data['tempDisplayMode']] - : msg.data['tempDisplayMode']; + if (msg.data.keypadLockout !== undefined) { + result[postfixWithEndpointName('keypad_lockout', msg, model, meta)] = + constants.keypadLockoutMode[msg.data['keypadLockout']] !== undefined + ? constants.keypadLockoutMode[msg.data['keypadLockout']] + : msg.data['keypadLockout']; + } + if (msg.data.tempDisplayMode !== undefined) { + result[postfixWithEndpointName('temperature_display_mode', msg, model, meta)] = + constants.temperatureDisplayMode[msg.data['tempDisplayMode']] !== undefined + ? constants.temperatureDisplayMode[msg.data['tempDisplayMode']] + : msg.data['tempDisplayMode']; } return result; }, @@ -3166,7 +3160,7 @@ const converters1 = { cluster: 'genLevelCtrl', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('currentLevel')) { + if (msg.data.currentLevel !== undefined) { // Ignore brightness = 0, which only happens when state is OFF if (Number(msg.data['currentLevel']) > 0) { return {brightness: msg.data['currentLevel']}; @@ -3239,7 +3233,7 @@ const converters1 = { 0x22: 'press_energy_bar', }; - const action = lookup.hasOwnProperty(commandID) ? lookup[commandID] : `unknown_${commandID}`; + const action = lookup[commandID] !== undefined ? lookup[commandID] : `unknown_${commandID}`; return {action}; }, } satisfies Fz.Converter, @@ -3285,7 +3279,7 @@ const converters1 = { 0x53: 'tilt', }; - if (!lookup.hasOwnProperty(commandID)) { + if (lookup[commandID] === undefined) { logger.error(`PTM 215ZE: missing command '${commandID}'`, NS); } else { return {action: lookup[commandID]}; @@ -3326,7 +3320,7 @@ const converters1 = { }; const ID = `${commandID}_${msg.data.commandFrame.raw?.slice(0, 1).join('_') ?? ''}`; - if (!lookup.hasOwnProperty(ID)) { + if (lookup[ID] === undefined) { logger.error(`PTM 216Z: missing command '${ID}'`, NS); } else { return {action: lookup[ID]}; @@ -3381,7 +3375,7 @@ const converters1 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const payload: KeyValueAny = {}; - if (msg.data.hasOwnProperty('acceleration')) payload.moving = msg.data['acceleration'] === 1; + if (msg.data.acceleration !== undefined) payload.moving = msg.data['acceleration'] === 1; // https://github.com/SmartThingsCommunity/SmartThingsPublic/blob/master/devicetypes/smartthings/smartsense-multi-sensor.src/smartsense-multi-sensor.groovy#L222 /* @@ -3391,9 +3385,9 @@ const converters1 = { xyzResults.y = y xyzResults.z = -x */ - if (msg.data.hasOwnProperty('z_axis')) payload.x_axis = msg.data['z_axis']; - if (msg.data.hasOwnProperty('y_axis')) payload.y_axis = msg.data['y_axis']; - if (msg.data.hasOwnProperty('x_axis')) payload.z_axis = -msg.data['x_axis']; + if (msg.data.z_axis !== undefined) payload.x_axis = msg.data['z_axis']; + if (msg.data.y_axis !== undefined) payload.y_axis = msg.data['y_axis']; + if (msg.data.x_axis !== undefined) payload.z_axis = -msg.data['x_axis']; return payload; }, @@ -3523,16 +3517,16 @@ const converters1 = { // 0xf000 = 61440 // This attribute returns usually 2 when power is over the defined threshold. - if (msg.data.hasOwnProperty('61440')) { + if (msg.data['61440'] !== undefined) { payload.power_alarm_active_value = msg.data['61440']; payload.power_alarm_active = payload.power_alarm_active_value > 0; } // 0xf001 = 61441 - if (msg.data.hasOwnProperty('61441')) { + if (msg.data['61441'] !== undefined) { payload.power_alarm_enabled = msg.data['61441']; } // 0xf002 = 61442, wh = watt hour - if (msg.data.hasOwnProperty('61442')) { + if (msg.data['61442'] !== undefined) { payload.power_alarm_wh_threshold = msg.data['61442']; } return payload; @@ -3560,7 +3554,7 @@ const converters1 = { 0x35: 'up', 0x36: 'down', // 600087l }; - if (!lookup.hasOwnProperty(commandID)) { + if (lookup[commandID] === undefined) { logger.error(`Legrand GreenPower: missing command '${commandID}'`, NS); } else { return {action: lookup[commandID]}; @@ -3621,7 +3615,7 @@ const converters1 = { cluster: 'msPressureMeasurement', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - const pressure = msg.data.hasOwnProperty('measuredValue') ? msg.data.measuredValue : parseFloat(msg.data['32']) / 1000.0; + const pressure = msg.data.measuredValue !== undefined ? msg.data.measuredValue : parseFloat(msg.data['32']) / 1000.0; return {pressure}; }, } satisfies Fz.Converter, @@ -3758,14 +3752,14 @@ const converters1 = { // https://github.com/Koenkk/zigbee-herdsman-converters/pull/1336 // Need to add time_close and time_open in your configuration.yaml after friendly_name (and set your time) - if (options.hasOwnProperty('time_close') && options.hasOwnProperty('time_open')) { + if (options.time_close !== undefined && options.time_open !== undefined) { if (!globalStore.hasValue(msg.endpoint, 'position')) { globalStore.putValue(msg.endpoint, 'position', {lastPreviousAction: -1, CurrentPosition: -1, since: false}); } const entry = globalStore.getValue(msg.endpoint, 'position'); // ignore if first action is middle and ignore action middle if previous action is middle - if (msg.data.hasOwnProperty('currentPositionLiftPercentage') && msg.data['currentPositionLiftPercentage'] == 50) { + if (msg.data.currentPositionLiftPercentage !== undefined && msg.data['currentPositionLiftPercentage'] == 50) { if ((entry.CurrentPosition == -1 && entry.lastPreviousAction == -1) || entry.lastPreviousAction == 50) { logger.warning(`ZMCSW032D ignore action`, NS); return; @@ -3778,7 +3772,7 @@ const converters1 = { entry.since = Date.now(); entry.lastPreviousAction = msg.data['currentPositionLiftPercentage']; - if (msg.data.hasOwnProperty('currentPositionLiftPercentage') && msg.data['currentPositionLiftPercentage'] == 50) { + if (msg.data.currentPositionLiftPercentage !== undefined && msg.data['currentPositionLiftPercentage'] == 50) { if (deltaTimeSec < timeCoverSetMiddle || deltaTimeSec > timeCoverSetMiddle) { if (lastPreviousAction == 100) { // Open @@ -3795,7 +3789,7 @@ const converters1 = { } entry.CurrentPosition = currentPosition; - if (msg.data.hasOwnProperty('currentPositionLiftPercentage') && msg.data['currentPositionLiftPercentage'] !== 50) { + if (msg.data.currentPositionLiftPercentage !== undefined && msg.data['currentPositionLiftPercentage'] !== 50) { // position cast float to int result.position = currentPosition | 0; } else { @@ -3810,7 +3804,7 @@ const converters1 = { result.position = options.invert_cover ? 100 - result.position : result.position; } else { // Previous solution without time_close and time_open - if (msg.data.hasOwnProperty('currentPositionLiftPercentage') && msg.data['currentPositionLiftPercentage'] !== 50) { + if (msg.data.currentPositionLiftPercentage !== undefined && msg.data['currentPositionLiftPercentage'] !== 50) { const liftPercentage = msg.data['currentPositionLiftPercentage']; result.position = liftPercentage; result.position = options.invert_cover ? 100 - result.position : result.position; @@ -3828,7 +3822,7 @@ const converters1 = { type: 'commandArrivalSensorNotify', options: [exposes.options.presence_timeout()], convert: (model, msg, publish, options, meta) => { - const useOptionsTimeout = options && options.hasOwnProperty('presence_timeout'); + const useOptionsTimeout = options && options.presence_timeout !== undefined; const timeout = useOptionsTimeout ? Number(options.presence_timeout) : 100; // 100 seconds by default // Stop existing timer because motion is detected and set a new one. @@ -3845,7 +3839,7 @@ const converters1 = { type: ['attributeReport', 'readResponse'], options: [exposes.options.presence_timeout()], convert: (model, msg, publish, options, meta) => { - const useOptionsTimeout = options && options.hasOwnProperty('presence_timeout'); + const useOptionsTimeout = options && options.presence_timeout !== undefined; const timeout = useOptionsTimeout ? Number(options.presence_timeout) : 100; // 100 seconds by default // Stop existing timer because motion is detected and set a new one. @@ -3868,7 +3862,7 @@ const converters1 = { commandGoOut: 'go_out', commandRepast: 'repast', }; - if (lookup.hasOwnProperty(msg.type)) return {action: lookup[msg.type]}; + if (lookup[msg.type] !== undefined) return {action: lookup[msg.type]}; }, } satisfies Fz.Converter, javis_lock_report: { @@ -3937,22 +3931,22 @@ const converters1 = { type: 'readResponse', convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty(0xf001)) { + if (msg.data[0xf001] !== undefined) { result.led_feedback = ['OFF', 'ON'][msg.data[0xf001]]; } - if (msg.data.hasOwnProperty(0xf002)) { + if (msg.data[0xf002] !== undefined) { result.buzzer_feedback = ['OFF', 'ON'][msg.data[0xf002]]; } - if (msg.data.hasOwnProperty(0xf000)) { + if (msg.data[0xf000] !== undefined) { result.sensitivity = msg.data[0xf000]; } - if (msg.data.hasOwnProperty(0xf003)) { + if (msg.data[0xf003] !== undefined) { result.sensors_count = msg.data[0xf003]; } - if (msg.data.hasOwnProperty(0xf004)) { + if (msg.data[0xf004] !== undefined) { result.sensors_type = ['СБМ-20/СТС-5/BOI-33', 'СБМ-19/СТС-6', 'Others'][msg.data[0xf004]]; } - if (msg.data.hasOwnProperty(0xf005)) { + if (msg.data[0xf005] !== undefined) { result.alert_threshold = msg.data[0xf005]; } return result; @@ -3963,16 +3957,16 @@ const converters1 = { type: 'readResponse', convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty(0x0203)) { + if (msg.data[0x0203] !== undefined) { result.led_feedback = ['OFF', 'ON'][msg.data[0x0203]]; } - if (msg.data.hasOwnProperty(0x0202)) { + if (msg.data[0x0202] !== undefined) { result.enable_abc = ['OFF', 'ON'][msg.data[0x0202]]; } - if (msg.data.hasOwnProperty(0x0204)) { + if (msg.data[0x0204] !== undefined) { result.threshold1 = msg.data[0x0204]; } - if (msg.data.hasOwnProperty(0x0205)) { + if (msg.data[0x0205] !== undefined) { result.threshold2 = msg.data[0x0205]; } return result; @@ -3983,7 +3977,7 @@ const converters1 = { type: 'readResponse', convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty(0x0210)) { + if (msg.data[0x0210] !== undefined) { result.temperature_offset = msg.data[0x0210]; } return result; @@ -3994,7 +3988,7 @@ const converters1 = { type: 'readResponse', convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty(0x0210)) { + if (msg.data[0x0210] !== undefined) { result.pressure_offset = msg.data[0x0210]; } return result; @@ -4005,7 +3999,7 @@ const converters1 = { type: 'readResponse', convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty(0x0210)) { + if (msg.data[0x0210] !== undefined) { result.humidity_offset = msg.data[0x0210]; } return result; @@ -4016,28 +4010,28 @@ const converters1 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty(0x0050)) { + if (msg.data[0x0050] !== undefined) { result.state = ['idle', 'ring', 'talk', 'open', 'drop'][msg.data[0x0050]]; } - if (msg.data.hasOwnProperty(0x0051)) { + if (msg.data[0x0051] !== undefined) { result.mode = ['never', 'once', 'always', 'drop'][msg.data[0x0051]]; } - if (msg.data.hasOwnProperty(0x0052)) { + if (msg.data[0x0052] !== undefined) { result.sound = ['OFF', 'ON'][msg.data[0x0052]]; } - if (msg.data.hasOwnProperty(0x0053)) { + if (msg.data[0x0053] !== undefined) { result.time_ring = msg.data[0x0053]; } - if (msg.data.hasOwnProperty(0x0054)) { + if (msg.data[0x0054] !== undefined) { result.time_talk = msg.data[0x0054]; } - if (msg.data.hasOwnProperty(0x0055)) { + if (msg.data[0x0055] !== undefined) { result.time_open = msg.data[0x0055]; } - if (msg.data.hasOwnProperty(0x0057)) { + if (msg.data[0x0057] !== undefined) { result.time_bell = msg.data[0x0057]; } - if (msg.data.hasOwnProperty(0x0056)) { + if (msg.data[0x0056] !== undefined) { result.time_report = msg.data[0x0056]; } return result; @@ -4098,7 +4092,7 @@ const converters1 = { cluster: 'msOccupancySensing', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('48')) { + if (msg.data['48'] !== undefined) { const lookup: KeyValueAny = ['low', 'medium', 'high', 'very_high', 'max']; return {motion_sensitivity: lookup[msg.data['48']]}; } @@ -4108,7 +4102,7 @@ const converters1 = { cluster: 'genBasic', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('51')) { + if (msg.data['51'] !== undefined) { return {led_indication: msg.data['51'] === 1}; } }, @@ -4117,7 +4111,7 @@ const converters1 = { cluster: 'genBasic', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('52')) { + if (msg.data['52'] !== undefined) { const values = ['single_rocker', 'single_push_button', 'dual_rocker', 'dual_push_button']; return {device_mode: values[msg.data['52']]}; } @@ -4311,7 +4305,7 @@ const converters1 = { // simulated brightness if (options.simulated_brightness && (button === 'down' || button === 'up') && type !== 'release') { const opts: KeyValueAny = options.simulated_brightness; - const deltaOpts = typeof opts === 'object' && opts.hasOwnProperty('delta') ? opts.delta : 35; + const deltaOpts = typeof opts === 'object' && opts.delta !== undefined ? opts.delta : 35; const delta = button === 'up' ? deltaOpts : deltaOpts * -1; const brightness = globalStore.getValue(msg.endpoint, 'brightness', 255) + delta; payload.brightness = numberWithinRange(brightness, 0, 255); @@ -4341,7 +4335,7 @@ const converters1 = { 0x64: 'press_1_and_2', 0x65: 'release_1_and_2', }; - if (!lookup.hasOwnProperty(commandID)) { + if (lookup[commandID] === undefined) { logger.error(`Hue Tap: missing command '${commandID}'`, NS); } else { return {action: lookup[commandID]}; @@ -4354,11 +4348,11 @@ const converters1 = { convert: (model, msg, publish, options, meta) => { const property = 0x8001; - if (msg.data.hasOwnProperty(property)) { + if (msg.data[property] !== undefined) { const dict: KeyValueNumberString = {0x00: 'off', 0x01: 'on_off', 0x02: 'off_on'}; const value = msg.data[property]; - if (dict.hasOwnProperty(value)) { + if (dict[value] !== undefined) { return {[postfixWithEndpointName('indicator_mode', msg, model, meta)]: dict[value]}; } } @@ -4393,11 +4387,11 @@ const converters1 = { const data = msg.data; const senslookup: KeyValueAny = {'0': 'low', '1': 'medium', '2': 'high'}; const keeptimelookup: KeyValueAny = {'0': 0, '1': 30, '2': 60, '3': 120, '4': 240, '5': 480}; - if (data && data.hasOwnProperty('currentZoneSensitivityLevel')) { + if (data && data.currentZoneSensitivityLevel !== undefined) { const value = data.currentZoneSensitivityLevel; return {sensitivity: senslookup[value]}; } - if (data && data.hasOwnProperty('61441')) { + if (data && data['61441'] !== undefined) { const value = data['61441']; return {keep_time: keeptimelookup[value]}; } @@ -4612,7 +4606,7 @@ const converters1 = { cluster: 'genOnOff', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('tuyaOperationMode')) { + if (msg.data.tuyaOperationMode !== undefined) { const value = msg.data['tuyaOperationMode']; const lookup: KeyValueAny = {0: 'command', 1: 'event'}; return {operation_mode: lookup[value]}; @@ -4627,7 +4621,7 @@ const converters1 = { if (hasAlreadyProcessedMessage(msg, model, msg.data.frameCounter, `${msg.device.ieeeAddr}_${commandID}`)) return; if (commandID === 224) return; const lookup: KeyValueAny = {0x21: 'press_on', 0x20: 'press_off', 0x34: 'release', 0x35: 'hold_on', 0x36: 'hold_off'}; - if (!lookup.hasOwnProperty(commandID)) { + if (lookup[commandID] === undefined) { logger.error(`Sunricher: missing command '${commandID}'`, NS); } else { return {action: lookup[commandID]}; @@ -4650,7 +4644,7 @@ const converters1 = { 0x36: 'hold_low', 0x34: 'release', }; - if (!lookup.hasOwnProperty(commandID)) { + if (lookup[commandID] === undefined) { logger.error(`Sunricher: missing command '${commandID}'`, NS); } else { return {action: lookup[commandID]}; @@ -4705,7 +4699,7 @@ const converters1 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty('hwVersion')) result['hw_version'] = msg.data.hwVersion; + if (msg.data.hwVersion !== undefined) result['hw_version'] = msg.data.hwVersion; return result; }, } satisfies Fz.Converter, @@ -4984,7 +4978,7 @@ const converters2 = { type: ['attributeReport', 'readResponse'], convert: async (model, msg, publish, options, meta) => { const result = converters1.metering.convert(model, msg, publish, options, meta); - if (result && result.hasOwnProperty('power')) { + if (result && result.power !== undefined) { result.power /= 1000; } return result; @@ -5018,11 +5012,11 @@ const converters2 = { // https://github.com/Koenkk/zigbee-herdsman-converters/issues/915 const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty('instantaneousDemand')) { + if (msg.data.instantaneousDemand !== undefined) { result.power = msg.data['instantaneousDemand']; } // Summation is reported in Watthours - if (msg.data.hasOwnProperty('currentSummDelivered')) { + if (msg.data.currentSummDelivered !== undefined) { const data = msg.data['currentSummDelivered']; const value = (parseInt(data[0]) << 32) + parseInt(data[1]); result.energy = value / 1000.0; @@ -5042,7 +5036,7 @@ const converters2 = { // 'Eco' mode is translated into 'auto' here result.system_mode = constants.thermostatSystemModes[1]; } - if (result && msg.data.hasOwnProperty('pIHeatingDemand')) { + if (result && msg.data.pIHeatingDemand !== undefined) { result.running_state = msg.data['pIHeatingDemand'] >= 10 ? 'heat' : 'idle'; } return result; @@ -5065,19 +5059,19 @@ const converters2 = { // 0-2, 5: unknown // 3: window open (OO on display, no heating) // 4: window open (OO on display, heating) - if (msg.data.hasOwnProperty('viessmannWindowOpenInternal')) { + if (msg.data.viessmannWindowOpenInternal !== undefined) { result.window_open = msg.data['viessmannWindowOpenInternal'] == 3 || msg.data['viessmannWindowOpenInternal'] == 4; } // viessmannWindowOpenForce (rw, bool) - if (msg.data.hasOwnProperty('viessmannWindowOpenForce')) { + if (msg.data.viessmannWindowOpenForce !== undefined) { result.window_open_force = msg.data['viessmannWindowOpenForce'] == 1; } // viessmannAssemblyMode (ro, bool) // 0: TRV installed // 1: TRV ready to install (-- on display) - if (msg.data.hasOwnProperty('viessmannAssemblyMode')) { + if (msg.data.viessmannAssemblyMode !== undefined) { result.assembly_mode = msg.data['viessmannAssemblyMode'] == 1; } } @@ -5120,7 +5114,7 @@ const converters2 = { if (typeof msg.data[0x4001] == 'number') { result.valve_position = msg.data[0x4001]; } - if (msg.data.hasOwnProperty('pIHeatingDemand')) { + if (msg.data.pIHeatingDemand !== undefined) { result.running_state = msg.data['pIHeatingDemand'] >= 10 ? 'heat' : 'idle'; } } @@ -5179,15 +5173,15 @@ const converters2 = { convert: async (model, msg, publish, options, meta) => { let result: KeyValueAny = {}; const data = msg.data; - if (data && data.hasOwnProperty('zoneStatus')) { + if (data && data.zoneStatus !== undefined) { const result1 = converters1.ias_occupancy_alarm_1_report.convert(model, msg, publish, options, meta); result = {...result1}; } - if (data && data.hasOwnProperty('currentZoneSensitivityLevel')) { + if (data && data.currentZoneSensitivityLevel !== undefined) { const senslookup: KeyValueAny = {'0': 'low', '1': 'medium', '2': 'high'}; result.sensitivity = senslookup[data.currentZoneSensitivityLevel]; } - if (data && data.hasOwnProperty('61441')) { + if (data && data['61441'] !== undefined) { const keeptimelookup: KeyValueAny = {'0': 30, '1': 60, '2': 120}; result.keep_time = keeptimelookup[data['61441']]; } @@ -5200,7 +5194,7 @@ const converters2 = { convert: async (model, msg, publish, options, meta) => { const result = converters1.lighting_ballast_configuration.convert(model, msg, publish, options, meta); const lookup: KeyValueAny = {1: 'RC', 2: 'RL'}; - if (result && msg.data.hasOwnProperty(0xe000)) { + if (result && msg.data[0xe000] !== undefined) { result.dimmer_mode = lookup[msg.data[0xe000]]; } return result; @@ -5211,7 +5205,7 @@ const converters2 = { type: ['attributeReport', 'readResponse'], convert: async (model, msg, publish, options, meta) => { const result = converters1.lighting_ballast_configuration.convert(model, msg, publish, options, meta); - if (result && msg.data.hasOwnProperty('wiserControlMode')) { + if (result && msg.data.wiserControlMode !== undefined) { result.dimmer_mode = constants.wiserDimmerControlMode[msg.data['wiserControlMode']]; } return result; @@ -5224,26 +5218,26 @@ const converters2 = { const result = converters1.thermostat.convert(model, msg, publish, options, meta); if (result) { - if (msg.data.hasOwnProperty(0xe010)) { + if (msg.data[0xe010] !== undefined) { // wiserSmartZoneMode const lookup: KeyValueAny = {1: 'manual', 2: 'schedule', 3: 'energy_saver', 6: 'holiday'}; result['zone_mode'] = lookup[msg.data[0xe010]]; } - if (msg.data.hasOwnProperty(0xe011)) { + if (msg.data[0xe011] !== undefined) { // wiserSmartHactConfig const lookup: KeyValueAny = {0x00: 'unconfigured', 0x80: 'setpoint_switch', 0x82: 'setpoint_fip', 0x83: 'fip_fip'}; result['hact_config'] = lookup[msg.data[0xe011]]; } - if (msg.data.hasOwnProperty(0xe020)) { + if (msg.data[0xe020] !== undefined) { // wiserSmartCurrentFilPiloteMode const lookup: KeyValueAny = {0: 'comfort', 1: 'comfort_-1', 2: 'comfort_-2', 3: 'energy_saving', 4: 'frost_protection', 5: 'off'}; result['fip_setting'] = lookup[msg.data[0xe020]]; } - if (msg.data.hasOwnProperty(0xe030)) { + if (msg.data[0xe030] !== undefined) { // wiserSmartValvePosition result['pi_heating_demand'] = msg.data[0xe030]; } - if (msg.data.hasOwnProperty(0xe031)) { + if (msg.data[0xe031] !== undefined) { // wiserSmartValveCalibrationStatus const lookup: KeyValueAny = {0: 'ongoing', 1: 'successful', 2: 'uncalibrated', 3: 'failed_e1', 4: 'failed_e2', 5: 'failed_e3'}; result['valve_calibration_status'] = lookup[msg.data[0xe031]]; @@ -5252,8 +5246,8 @@ const converters2 = { // force an update of the value if it doesn't match the current existing value if ( meta.device.modelID === 'EH-ZB-VACT' && - msg.data.hasOwnProperty('occupiedHeatingSetpoint') && - meta.state.hasOwnProperty('occupied_heating_setpoint') + msg.data.occupiedHeatingSetpoint !== undefined && + meta.state.occupied_heating_setpoint !== undefined ) { if (result.occupied_heating_setpoint != meta.state.occupied_heating_setpoint) { const lookup: KeyValueAny = {manual: 1, schedule: 2, energy_saver: 3, holiday: 6}; @@ -5307,13 +5301,13 @@ const converters2 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty('64515')) { + if (msg.data['64515'] !== undefined) { result['min_brightness'] = utils.mapNumberRange(msg.data['64515'], 0, 1000, 1, 255); } - if (msg.data.hasOwnProperty('64516')) { + if (msg.data['64516'] !== undefined) { result['max_brightness'] = utils.mapNumberRange(msg.data['64516'], 0, 1000, 1, 255); } - if (msg.data.hasOwnProperty('61440')) { + if (msg.data['61440'] !== undefined) { const propertyName = utils.postfixWithEndpointName('brightness', msg, model, meta); result[propertyName] = utils.mapNumberRange(msg.data['61440'], 0, 1000, 0, 255); } @@ -5325,7 +5319,7 @@ const converters2 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty('64514')) { + if (msg.data['64514'] !== undefined) { const lookup: KeyValue = {0: 'led', 1: 'incandescent', 2: 'halogen'}; result['light_type'] = lookup[msg.data['64514']]; } @@ -5337,7 +5331,7 @@ const converters2 = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty('64514')) { + if (msg.data['64514'] !== undefined) { const lookup: KeyValue = {0: 'momentary', 1: 'toggle', 2: 'state'}; const propertyName = utils.postfixWithEndpointName('switch_type', msg, model, meta); result[propertyName] = lookup[msg.data['64514']]; diff --git a/src/converters/toZigbee.ts b/src/converters/toZigbee.ts index e6a848efb4bbf..0e2d5f566b7cf 100644 --- a/src/converters/toZigbee.ts +++ b/src/converters/toZigbee.ts @@ -32,9 +32,9 @@ const converters1 = { const state = utils.isString(meta.message.state) ? meta.message.state.toLowerCase() : null; utils.validateValue(state, ['toggle', 'off', 'on']); - if (state === 'on' && (meta.message.hasOwnProperty('on_time') || meta.message.hasOwnProperty('off_wait_time'))) { - const onTime = meta.message.hasOwnProperty('on_time') ? meta.message.on_time : 0; - const offWaitTime = meta.message.hasOwnProperty('off_wait_time') ? meta.message.off_wait_time : 0; + if (state === 'on' && (meta.message.on_time !== undefined || meta.message.off_wait_time !== undefined)) { + const onTime = meta.message.on_time !== undefined ? meta.message.on_time : 0; + const offWaitTime = meta.message.off_wait_time !== undefined ? meta.message.off_wait_time : 0; if (typeof onTime !== 'number') { throw Error('The on_time value must be a number!'); @@ -136,11 +136,10 @@ const converters1 = { } } - if (value.hasOwnProperty('brightness')) { + if (utils.isObject(value) && value.brightness !== undefined) { await entity.command( 'genLevelCtrl', 'moveToLevelWithOnOff', - // @ts-expect-error ignore {level: Number(value.brightness), transtime: utils.getTransition(entity, key, meta).time}, utils.getOptions(meta.mapped, entity), ); @@ -196,9 +195,9 @@ const converters2 = { key: ['read'], convertSet: async (entity, key, value, meta) => { utils.assertObject(value, key); - const result = await entity.read(value.cluster, value.attributes, value.hasOwnProperty('options') ? value.options : {}); + const result = await entity.read(value.cluster, value.attributes, value.options !== undefined ? value.options : {}); logger.info(`Read result of '${value.cluster}': ${JSON.stringify(result)}`, NS); - if (value.hasOwnProperty('state_property')) { + if (value.state_property !== undefined) { return {state: {[value.state_property]: result}}; } }, @@ -208,7 +207,7 @@ const converters2 = { convertSet: async (entity, key, value, meta) => { utils.assertObject(value, key); const options = utils.getOptions(meta.mapped, entity); - if (value.hasOwnProperty('options')) { + if (value.options !== undefined) { Object.assign(options, value.options); } await entity.write(value.cluster, value.payload, options); @@ -220,7 +219,7 @@ const converters2 = { convertSet: async (entity, key, value, meta) => { utils.assertObject(value, key); const options = utils.getOptions(meta.mapped, entity); - await entity.command(value.cluster, value.command, value.hasOwnProperty('payload') ? value.payload : {}, options); + await entity.command(value.cluster, value.command, value.payload !== undefined ? value.payload : {}, options); logger.info(`Invoked '${value.cluster}.${value.command}' with payload '${JSON.stringify(value.payload)}'`, NS); }, } satisfies Tz.Converter, @@ -243,9 +242,9 @@ const converters2 = { key: ['zclcommand'], convertSet: async (entity, key, value, meta) => { utils.assertObject(value, key); - const payload = value.hasOwnProperty('payload') ? value.payload : {}; + const payload = value.payload !== undefined ? value.payload : {}; utils.assertEndpoint(entity); - await entity.zclCommand(value.cluster, value.command, payload, value.hasOwnProperty('options') ? value.options : {}); + await entity.zclCommand(value.cluster, value.command, payload, value.options !== undefined ? value.options : {}); logger.info(`Invoked ZCL command ${value.cluster}.${value.command} with payload '${JSON.stringify(payload)}'`, NS); }, } satisfies Tz.Converter, @@ -255,7 +254,7 @@ const converters2 = { utils.assertEndpoint(entity); utils.assertObject(value, key); if (Array.isArray(meta.mapped)) throw new Error(`Not supported for groups`); - const isNotification = value.hasOwnProperty('transaction'); + const isNotification = value.transaction !== undefined; const modeSrc = isNotification ? constants.armNotification : constants.armMode; const mode = utils.getKey(modeSrc, value.mode, undefined, Number); if (mode === undefined) { @@ -316,7 +315,7 @@ const converters2 = { key: ['color_options'], convertSet: async (entity, key, value, meta) => { utils.assertObject(value, key); - const options = value.hasOwnProperty('execute_if_off') && value.execute_if_off ? 1 : 0; + const options = value.execute_if_off !== undefined && value.execute_if_off ? 1 : 0; await entity.write('lightingColorCtrl', {options}, utils.getOptions(meta.mapped, entity)); return {state: {color_options: value}}; }, @@ -364,7 +363,7 @@ const converters2 = { utils.assertObject(value, key); const user = value.user; const userType = value.user_type || 'unrestricted'; - const userEnabled = value.hasOwnProperty('user_enabled') ? value.user_enabled : true; + const userEnabled = value.user_enabled !== undefined ? value.user_enabled : true; const pinCode = value.pin_code; if (isNaN(user)) throw new Error('user must be numbers'); const pinCodeCount = utils.getMetaValue(entity, meta.mapped, 'pinCodeCount'); @@ -505,13 +504,13 @@ const converters2 = { // @ts-expect-error ignore level: value.level || 'medium', // @ts-expect-error ignore - strobe: value.hasOwnProperty('strobe') ? value.strobe : true, + strobe: value.strobe !== undefined ? value.strobe : true, // @ts-expect-error ignore - duration: value.hasOwnProperty('duration') ? value.duration : 10, + duration: value.duration !== undefined ? value.duration : 10, // @ts-expect-error ignore - strobeDutyCycle: value.hasOwnProperty('strobe_duty_cycle') ? value.strobe_duty_cycle * 10 : 0, + strobeDutyCycle: value.strobe_duty_cycle !== undefined ? value.strobe_duty_cycle * 10 : 0, // @ts-expect-error ignore - strobeLevel: value.hasOwnProperty('strobe_level') ? utils.getFromLookup(value.strobe_level, strobeLevel) : 1, + strobeLevel: value.strobe_level !== undefined ? utils.getFromLookup(value.strobe_level, strobeLevel) : 1, }; let info; @@ -572,7 +571,7 @@ const converters2 = { const values = { state: value.state, level: value.level || 'very_high', - strobe: value.hasOwnProperty('strobe') ? value.strobe : false, + strobe: value.strobe !== undefined ? value.strobe : false, }; const info = utils.getFromLookup(values.state, state) + ((values.strobe ? 1 : 0) << 4) + (utils.getFromLookup(values.level, level) << 6); await entity.command('ssIasWd', 'squawk', {squawkinfo: info}, utils.getOptions(meta.mapped, entity)); @@ -666,7 +665,7 @@ const converters2 = { utils.assertObject(value, key); // onOffTransitionTime - range 0x0000 to 0xffff - optional - if (value.hasOwnProperty('on_off_transition_time')) { + if (value.on_off_transition_time !== undefined) { let onOffTransitionTimeValue = Number(value.on_off_transition_time); if (onOffTransitionTimeValue > 65535) onOffTransitionTimeValue = 65535; if (onOffTransitionTimeValue < 0) onOffTransitionTimeValue = 0; @@ -677,7 +676,7 @@ const converters2 = { // onTransitionTime - range 0x0000 to 0xffff - optional // 0xffff = use onOffTransitionTime - if (value.hasOwnProperty('on_transition_time')) { + if (value.on_transition_time !== undefined) { let onTransitionTimeValue = value.on_transition_time; if (typeof onTransitionTimeValue === 'string' && onTransitionTimeValue.toLowerCase() == 'disabled') { onTransitionTimeValue = 65535; @@ -698,7 +697,7 @@ const converters2 = { // offTransitionTime - range 0x0000 to 0xffff - optional // 0xffff = use onOffTransitionTime - if (value.hasOwnProperty('off_transition_time')) { + if (value.off_transition_time !== undefined) { let offTransitionTimeValue = value.off_transition_time; if (typeof offTransitionTimeValue === 'string' && offTransitionTimeValue.toLowerCase() == 'disabled') { offTransitionTimeValue = 65535; @@ -720,7 +719,7 @@ const converters2 = { // startUpCurrentLevel - range 0x00 to 0xff - optional // 0x00 = return to minimum supported level // 0xff = return to previous previous - if (value.hasOwnProperty('current_level_startup')) { + if (value.current_level_startup !== undefined) { let startUpCurrentLevelValue = value.current_level_startup; if (typeof startUpCurrentLevelValue === 'string' && startUpCurrentLevelValue.toLowerCase() == 'previous') { startUpCurrentLevelValue = 255; @@ -746,7 +745,7 @@ const converters2 = { // onLevel - range 0x00 to 0xff - optional // Any value outside of MinLevel to MaxLevel, including 0xff and 0x00, is interpreted as "previous". - if (value.hasOwnProperty('on_level')) { + if (value.on_level !== undefined) { let onLevel = value.on_level; if (typeof onLevel === 'string' && onLevel.toLowerCase() == 'previous') { onLevel = 255; @@ -764,7 +763,7 @@ const converters2 = { // when 1, CurrentLevel can be changed while the device is off. // bit 1: CoupleColorTempToLevel - when 1, changes to level also change color temperature. // (What this means is not defined, but it's most likely to be "dim to warm".) - if (value.hasOwnProperty('execute_if_off')) { + if (value.execute_if_off !== undefined) { const executeIfOffValue = !!value.execute_if_off; await entity.write('genLevelCtrl', {options: executeIfOffValue ? 1 : 0}, utils.getOptions(meta.mapped, entity)); Object.assign(state, {execute_if_off: executeIfOffValue}); @@ -850,7 +849,7 @@ const converters2 = { const payload = {stepmode: mode, stepsize: Math.abs(value), transtime: transition}; await entity.command('genLevelCtrl', command, payload, utils.getOptions(meta.mapped, entity)); - if (meta.state.hasOwnProperty('brightness')) { + if (meta.state.brightness !== undefined) { utils.assertNumber(meta.state.brightness); let brightness = onOff || meta.state.state === 'ON' ? meta.state.brightness + value : meta.state.brightness; if (value === 0) { @@ -950,7 +949,7 @@ const converters2 = { const stop = (val: string) => ['stop', 'release', '0'].some((el) => val.includes(el)); const up = (val: string) => ['1', 'up'].some((el) => val.includes(el)); const arr = [value.toString()]; - const moverate = meta.message.hasOwnProperty('rate') ? Number(meta.message.rate) : 55; + const moverate = meta.message.rate !== undefined ? Number(meta.message.rate) : 55; payload.rate = moverate; if (arr.filter(stop).length) { payload.movemode = 0; @@ -1047,11 +1046,11 @@ const converters2 = { const {message} = meta; const transition = utils.getTransition(entity, 'brightness', meta); const turnsOffAtBrightness1 = utils.getMetaValue(entity, meta.mapped, 'turnsOffAtBrightness1', 'allEqual', false); - let state = message.hasOwnProperty('state') ? (typeof message.state === 'string' ? message.state.toLowerCase() : null) : undefined; + let state = message.state !== undefined ? (typeof message.state === 'string' ? message.state.toLowerCase() : null) : undefined; let brightness = undefined; - if (message.hasOwnProperty('brightness')) { + if (message.brightness !== undefined) { brightness = Number(message.brightness); - } else if (message.hasOwnProperty('brightness_percent')) { + } else if (message.brightness_percent !== undefined) { brightness = utils.mapNumberRange(Number(message.brightness_percent), 0, 100, 0, 255); } @@ -1093,7 +1092,7 @@ const converters2 = { logger.debug(`Supressing OFF transition since entity has noOffTransition=true`, NS); brightness = undefined; } - if (meta.state.hasOwnProperty('brightness') && meta.state.state === 'ON') { + if (meta.state.brightness !== undefined && meta.state.state === 'ON') { // The light's current level gets clobbered in two cases: // 1. when 'Off' has a transition, in which case it is really 'MoveToLevelWithOnOff' // https://github.com/Koenkk/zigbee-herdsman-converters/issues/1073 @@ -1340,10 +1339,10 @@ const converters2 = { // transform transition payload values if needed for (const elem of payload.transitions) { // update payload.mode if needed - if (elem.hasOwnProperty('heatSetpoint') && !payload.mode.includes('heat')) { + if (elem.heatSetpoint !== undefined && !payload.mode.includes('heat')) { payload.mode.push('heat'); } - if (elem.hasOwnProperty('coolSetpoint') && !payload.mode.includes('cool')) { + if (elem.coolSetpoint !== undefined && !payload.mode.includes('cool')) { payload.mode.push('cool'); } @@ -1367,7 +1366,7 @@ const converters2 = { elem['transitionTime'] = timeHour + timeMinute; } } else if (typeof elem['transitionTime'] === 'object') { - if (!elem['transitionTime'].hasOwnProperty('hour') || !elem['transitionTime'].hasOwnProperty('minute')) { + if (elem['transitionTime'].hour === undefined || elem['transitionTime'].minute === undefined) { throw new Error( 'weekly_schedule: expected 24h time object (e.g. {"hour": 19, "minute": 30}), ' + `but got '${JSON.stringify(elem['transitionTime'])}'!`, @@ -1403,7 +1402,7 @@ const converters2 = { let dayofweek = 0; for (let d of payload.dayofweek) { if (typeof d === 'object') { - if (!d.hasOwnProperty('day')) { + if (d.day === undefined) { throw new Error( 'weekly_schedule: expected dayofweek to be string or {"day": "str"}, ' + `but got '${JSON.stringify(d)}'!`, ); @@ -2141,7 +2140,7 @@ const converters2 = { transactionSequenceNumber: 0xe9, }; - if (value.hasOwnProperty('motor_direction')) { + if (value.motor_direction !== undefined) { let direction; switch (value.motor_direction) { case 'FORWARD': @@ -2159,7 +2158,7 @@ const converters2 = { await entity.write('genPowerCfg', payload, options); } - if (value.hasOwnProperty('motor_speed')) { + if (value.motor_speed !== undefined) { if (value.motor_speed < 20 || value.motor_speed > 40) { throw new Error('livolo_cover_options: Motor speed is out of range (20-40)'); } @@ -2220,7 +2219,7 @@ const converters2 = { utils.assertString(value, key); utils.validateValue(value, ['toggle', 'off', 'on']); if (value === 'toggle') { - if (!meta.state.hasOwnProperty('state')) { + if (meta.state.state === undefined) { throw new Error('Cannot toggle, state not known yet'); } else { const payload = {0x0055: {value: meta.state.state === 'OFF' ? 0x01 : 0x00, type: 0x10}}; @@ -2547,7 +2546,7 @@ const converters2 = { key: ['position', 'tilt'], convertSet: async (entity, key, value, meta) => { utils.assertNumber(value, key); - if (meta.options.hasOwnProperty('time_close') && meta.options.hasOwnProperty('time_open')) { + if (meta.options.time_close !== undefined && meta.options.time_open !== undefined) { const sleepSeconds = async (s: number) => { return new Promise((resolve) => setTimeout(resolve, s * 1000)); }; @@ -2733,8 +2732,8 @@ const converters2 = { if ( key === 'brightness' && meta.state.color_mode == constants.colorModeLookup[2] && - !meta.message.hasOwnProperty('color') && - !meta.message.hasOwnProperty('color_temp') + meta.message.color === undefined && + meta.message.color_temp === undefined ) { const zclData = {level: Number(value), transtime: 0}; @@ -2815,7 +2814,7 @@ const converters2 = { } } - if (meta.message.hasOwnProperty('color')) { + if (meta.message.color !== undefined) { if (utils.isObject(meta.message.color)) { if (meta.message.color.h) { zclData.hue = utils.mapNumberRange(meta.message.color.h, 0, 360, 0, 254); @@ -3583,10 +3582,10 @@ const converters2 = { await entity.command('genScenes', 'recall', {groupid, sceneid}, utils.getOptions(meta.mapped, entity)); const addColorMode = (newState: KeyValueAny) => { - if (newState.hasOwnProperty('color_temp')) { + if (newState.color_temp !== undefined) { newState.color_mode = constants.colorModeLookup[2]; - } else if (newState.hasOwnProperty('color')) { - if (newState.color.hasOwnProperty('x')) { + } else if (newState.color !== undefined) { + if (newState.color.x !== undefined) { newState.color_mode = constants.colorModeLookup[1]; } else { newState.color_mode = constants.colorModeLookup[0]; @@ -3602,7 +3601,7 @@ const converters2 = { let recalledState = utils.getSceneState(member, sceneid, groupid); if (recalledState) { // add color_mode if saved state does not contain it - if (!recalledState.hasOwnProperty('color_mode')) { + if (recalledState.color_mode === undefined) { recalledState = addColorMode(recalledState); } @@ -3619,7 +3618,7 @@ const converters2 = { let recalledState = utils.getSceneState(entity, sceneid, groupid); if (recalledState) { // add color_mode if saved state does not contain it - if (!recalledState.hasOwnProperty('color_mode')) { + if (recalledState.color_mode === undefined) { recalledState = addColorMode(recalledState); } @@ -3835,7 +3834,7 @@ const converters2 = { const isGroup = utils.isGroup(entity); const sceneid = value.ID; const scenename = value.name; - const groupid = isGroup ? entity.groupID : value.hasOwnProperty('group_id') ? value.group_id : 0; + const groupid = isGroup ? entity.groupID : value.group_id !== undefined ? value.group_id : 0; if (isGroup) { if (meta.membersState) { @@ -4364,7 +4363,7 @@ const converters3 = { const deviceState = meta.state || {}; const message = meta.message; const state = utils.isString(message.state) ? message.state.toLowerCase() : null; - const hasBrightness = message.hasOwnProperty('brightness') || message.hasOwnProperty('brightness_percent'); + const hasBrightness = message.brightness !== undefined || message.brightness_percent !== undefined; // Add brightness if command is 'on' and we can restore previous value if (state === 'on' && !hasBrightness && utils.isNumber(deviceState.brightness) && deviceState.brightness > 0) { @@ -4433,9 +4432,9 @@ const converters3 = { const message = meta.message; let brightness = undefined; - if (message.hasOwnProperty('brightness')) { + if (message.brightness !== undefined) { brightness = Number(message.brightness); - } else if (message.hasOwnProperty('brightness_percent')) brightness = Math.round(Number(message.brightness_percent) * 2.55); + } else if (message.brightness_percent !== undefined) brightness = Math.round(Number(message.brightness_percent) * 2.55); if (brightness !== undefined && brightness === 0) { message.state = 'off'; @@ -4483,9 +4482,9 @@ const converters3 = { key: ['state', 'brightness'], convertSet: async (entity, key, value, meta) => { const {message, state} = meta; - if (message.state === 'OFF' || (message.hasOwnProperty('state') && !message.hasOwnProperty('brightness'))) { + if (message.state === 'OFF' || (message.state !== undefined && message.brightness === undefined)) { return converters1.on_off.convertSet(entity, key, value, meta); - } else if (message.hasOwnProperty('brightness')) { + } else if (message.brightness !== undefined) { // set brightness if (state.state === 'OFF') { await entity.command('genOnOff', 'on', {}, utils.getOptions(meta.mapped, entity)); diff --git a/src/devices/bitron.ts b/src/devices/bitron.ts index 78031c6b144c4..125038d98e968 100644 --- a/src/devices/bitron.ts +++ b/src/devices/bitron.ts @@ -21,13 +21,13 @@ const bitron = { convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty('fourNoksHysteresisHigh')) { - if (!result.hasOwnProperty('hysteresis')) result.hysteresis = {}; + if (msg.data.fourNoksHysteresisHigh !== undefined) { + if (result.hysteresis === undefined) result.hysteresis = {}; result.hysteresis.high = msg.data.fourNoksHysteresisHigh; } - if (msg.data.hasOwnProperty('fourNoksHysteresisLow')) { - if (!result.hasOwnProperty('hysteresis')) result.hysteresis = {}; + if (msg.data.fourNoksHysteresisLow !== undefined) { + if (result.hysteresis === undefined) result.hysteresis = {}; result.hysteresis.low = msg.data.fourNoksHysteresisLow; } @@ -40,12 +40,12 @@ const bitron = { key: ['hysteresis', 'hysteresis'], convertSet: async (entity, key, value: KeyValueAny, meta) => { const result: KeyValueAny = {state: {hysteresis: {}}}; - if (value.hasOwnProperty('high')) { + if (value.high !== undefined) { await entity.write('hvacThermostat', {fourNoksHysteresisHigh: value.high}, manufacturerOptions); result.state.hysteresis.high = value.high; } - if (value.hasOwnProperty('low')) { + if (value.low !== undefined) { await entity.write('hvacThermostat', {fourNoksHysteresisLow: value.low}, manufacturerOptions); result.state.hysteresis.low = value.low; } diff --git a/src/devices/bosch.ts b/src/devices/bosch.ts index 36839666d6dbe..d80c5102c08b1 100644 --- a/src/devices/bosch.ts +++ b/src/devices/bosch.ts @@ -245,7 +245,7 @@ const boschExtend = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty('valveAdaptStatus')) { + if (msg.data.valveAdaptStatus !== undefined) { if (msg.data['valveAdaptStatus'] === adaptationStatus.calibration_in_progress) { result.valve_adapt_process = true; } else { @@ -292,7 +292,7 @@ const boschExtend = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty('heatingDemand')) { + if (msg.data.heatingDemand !== undefined) { const demand = msg.data['heatingDemand'] as number; result.pi_heating_demand = demand; result.running_state = demand > 0 ? 'heat' : 'idle'; @@ -367,7 +367,7 @@ const boschExtend = { cluster: 'ssIasZone', type: ['commandStatusChangeNotification', 'attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('zoneStatus') || msg.data.hasOwnProperty('zonestatus')) { + if (msg.data.zoneStatus !== undefined || msg.data.zonestatus !== undefined) { const zoneStatus = msg.type === 'commandStatusChangeNotification' ? msg.data.zonestatus : msg.data.zoneStatus; const lookup: KeyValue = {0x00: 'none', 0x01: 'single', 0x02: 'long'}; const result: KeyValue = { @@ -418,7 +418,7 @@ const boschExtend = { cluster: 'ssIasZone', type: ['commandStatusChangeNotification', 'attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('zoneStatus') || msg.data.hasOwnProperty('zonestatus')) { + if (msg.data.zoneStatus !== undefined || msg.data.zonestatus !== undefined) { const zoneStatus = msg.type === 'commandStatusChangeNotification' ? msg.data.zonestatus : msg.data.zoneStatus; return { smoke: (zoneStatus & 1) > 0, @@ -586,7 +586,7 @@ const boschExtend = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty('sensitivity')) { + if (msg.data.sensitivity !== undefined) { result.sensitivity = Object.keys(smokeSensitivity)[msg.data['sensitivity']]; } return result; @@ -597,13 +597,13 @@ const boschExtend = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty('humidity')) { + if (msg.data.humidity !== undefined) { const humidity = utils.toNumber(msg.data['humidity']) / 100.0; if (utils.isInRange(0, 100, humidity)) { result.humidity = humidity; } } - if (msg.data.hasOwnProperty('airpurity')) { + if (msg.data.airpurity !== undefined) { const iaq = utils.toNumber(msg.data['airpurity']); result.aqi = iaq; let factorVoc = 6; @@ -627,13 +627,13 @@ const boschExtend = { result.voc = iaq * factorVoc; result.co2 = iaq * factorCo2 + 400; } - if (msg.data.hasOwnProperty('temperature')) { + if (msg.data.temperature !== undefined) { result.temperature = utils.toNumber(msg.data['temperature']) / 100.0; } - if (msg.data.hasOwnProperty('illuminance_lux')) { + if (msg.data.illuminance_lux !== undefined) { result.illuminance_lux = utils.precisionRound(msg.data['illuminance_lux'] / 2, 2); } - if (msg.data.hasOwnProperty('battery')) { + if (msg.data.battery !== undefined) { result.battery = utils.precisionRound(msg.data['battery'] / 2, 2); } return result; @@ -644,7 +644,7 @@ const boschExtend = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty('pre_alarm')) { + if (msg.data.pre_alarm !== undefined) { result.pre_alarm = Object.keys(stateOffOn)[msg.data['pre_alarm']]; } return result; @@ -655,7 +655,7 @@ const boschExtend = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty('heartbeat')) { + if (msg.data.heartbeat !== undefined) { result.heartbeat = Object.keys(stateOffOn)[msg.data['heartbeat']]; } return result; @@ -674,7 +674,7 @@ const boschExtend = { 0x00200081: 'fire', 0x00200040: 'silenced', }; - if (msg.data.hasOwnProperty('alarm_status')) { + if (msg.data.alarm_status !== undefined) { result.self_test = (msg.data['alarm_status'] & (1 << 24)) > 0; result.smoke = (msg.data['alarm_status'] & (1 << 7)) > 0; result.siren_state = lookup[msg.data['alarm_status']]; @@ -804,7 +804,7 @@ const boschExtend = { convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; const data = msg.data; - if (data.hasOwnProperty('deviceMode')) { + if (data.deviceMode !== undefined) { result.device_mode = Object.keys(stateDeviceMode).find((key) => stateDeviceMode[key] === msg.data['deviceMode']); const deviceMode = msg.data['deviceMode']; if (deviceMode !== meta.device.meta.deviceMode) { @@ -812,26 +812,26 @@ const boschExtend = { meta.deviceExposesChanged(); } } - if (data.hasOwnProperty('switchType')) { + if (data.switchType !== undefined) { result.switch_type = Object.keys(stateSwitchType).find((key) => stateSwitchType[key] === msg.data['switchType']); } - if (data.hasOwnProperty('calibrationOpeningTime')) { + if (data.calibrationOpeningTime !== undefined) { result.calibration_opening_time = msg.data['calibrationOpeningTime'] / 10; } - if (data.hasOwnProperty('calibrationClosingTime')) { + if (data.calibrationClosingTime !== undefined) { result.calibration_closing_time = msg.data['calibrationClosingTime'] / 10; } - if (data.hasOwnProperty('calibrationButtonHoldTime')) { + if (data.calibrationButtonHoldTime !== undefined) { result.calibration_button_hold_time = msg.data['calibrationButtonHoldTime'] / 10; } - if (data.hasOwnProperty('calibrationMotorStartDelay')) { + if (data.calibrationMotorStartDelay !== undefined) { result.calibration_motor_start_delay = msg.data['calibrationMotorStartDelay'] / 10; } - if (data.hasOwnProperty('childLock')) { + if (data.childLock !== undefined) { const property = utils.postfixWithEndpointName('child_lock', msg, model, meta); result[property] = msg.data['childLock'] === 1 ? 'ON' : 'OFF'; } - if (data.hasOwnProperty('motorState')) { + if (data.motorState !== undefined) { result.motor_state = Object.keys(stateMotor).find((key) => stateMotor[key] === msg.data['motorState']); } return result; @@ -1033,13 +1033,13 @@ const tzLocal = { bhius_config: { key: Object.keys(buttonMap), convertGet: async (entity, key, meta) => { - if (!buttonMap.hasOwnProperty(key)) { + if (buttonMap[key] === undefined) { throw new Error(`Unknown key ${key}`); } await entity.read('boschSpecific', [buttonMap[key as keyof typeof buttonMap]], manufacturerOptions); }, convertSet: async (entity, key, value, meta) => { - if (!buttonMap.hasOwnProperty(key)) { + if (buttonMap[key] === undefined) { return; } @@ -1068,7 +1068,7 @@ const fzLocal = { const longPress = msg.data.readUInt8(5); const duration = msg.data.readUInt16LE(6); let buffer; - if (options.hasOwnProperty('led_response')) { + if (options.led_response !== undefined) { buffer = Buffer.from(options.led_response as string, 'hex'); if (buffer.length !== 9) { logger.error(`Invalid length of led_response: ${buffer.length} (should be 9)`, NS); @@ -1104,7 +1104,7 @@ const fzLocal = { convert: async (model, msg, publish, options, meta) => { const result: {[key: number | string]: string} = {}; for (const id of Object.values(buttonMap)) { - if (msg.data.hasOwnProperty(id)) { + if (msg.data[id] !== undefined) { result[Object.keys(buttonMap).find((key) => buttonMap[key] === id)] = msg.data[id].toString('hex'); } } diff --git a/src/devices/centralite.ts b/src/devices/centralite.ts index d52bb3d3f46a0..31d3ae0cd643e 100644 --- a/src/devices/centralite.ts +++ b/src/devices/centralite.ts @@ -17,7 +17,7 @@ const fzLocal = { cluster: 'hvacThermostat', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('runningState')) { + if (msg.data.runningState !== undefined) { if (msg.data['runningState'] == 1) { msg.data['runningState'] = 0; } else if (msg.data['runningState'] == 5) { @@ -28,7 +28,7 @@ const fzLocal = { msg.data['runningState'] = 9; } } - if (msg.data.hasOwnProperty('ctrlSeqeOfOper')) { + if (msg.data.ctrlSeqeOfOper !== undefined) { if (msg.data['ctrlSeqeOfOper'] == 6) { msg.data['ctrlSeqeOfOper'] = 4; } diff --git a/src/devices/ctm.ts b/src/devices/ctm.ts index 235137a5867eb..2d77712d63a5d 100644 --- a/src/devices/ctm.ts +++ b/src/devices/ctm.ts @@ -20,7 +20,7 @@ const fzLocal = { convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; const data = msg.data; - if (data.hasOwnProperty('onOff')) { + if (data.onOff !== undefined) { result.device_enabled = data['onOff'] ? 'ON' : 'OFF'; } @@ -33,7 +33,7 @@ const fzLocal = { convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; const data = msg.data; - if (data.hasOwnProperty(0x2200)) { + if (data[0x2200] !== undefined) { const deviceModeLookup = {0: 'astro_clock', 1: 'timer', 2: 'daily_timer', 3: 'weekly_timer'}; result.device_mode = utils.getFromLookup(data[0x2200], deviceModeLookup); } @@ -47,7 +47,7 @@ const fzLocal = { convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; const data = msg.data; - if (data.hasOwnProperty(0x2201)) { + if (data[0x2201] !== undefined) { result.device_enabled = data[0x2201] ? 'ON' : 'OFF'; } @@ -60,7 +60,7 @@ const fzLocal = { convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; const data = msg.data; - if (data.hasOwnProperty(0x2202)) { + if (data[0x2202] !== undefined) { result.child_lock = data[0x2202] ? 'locked' : 'unlocked'; } @@ -73,7 +73,7 @@ const fzLocal = { convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; const data = msg.data; - if (data.hasOwnProperty(0x5000)) { + if (data[0x5000] !== undefined) { result.current_flag = data[0x5000]; } @@ -86,7 +86,7 @@ const fzLocal = { convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; const data = msg.data; - if (data.hasOwnProperty(0x5001)) { + if (data[0x5001] !== undefined) { result.state = data[0x5001] ? 'ON' : 'OFF'; } @@ -99,23 +99,23 @@ const fzLocal = { convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; const data = msg.data; - if (data.hasOwnProperty(0x0401)) { + if (data[0x0401] !== undefined) { // Load result.load = data[0x0401]; } - if (data.hasOwnProperty('elkoLoad')) { + if (data.elkoLoad !== undefined) { // Load result.load = data['elkoLoad']; } - if (data.hasOwnProperty(0x0402)) { + if (data[0x0402] !== undefined) { // Display text result.display_text = data[0x0402]; } - if (data.hasOwnProperty('elkoDisplayText')) { + if (data.elkoDisplayText !== undefined) { // Display text result.display_text = data['elkoDisplayText']; } - if (data.hasOwnProperty(0x0403)) { + if (data[0x0403] !== undefined) { // Sensor const sensorModeLookup = { 0: 'air', @@ -128,7 +128,7 @@ const fzLocal = { }; result.sensor = utils.getFromLookup(data[0x0403], sensorModeLookup); } - if (data.hasOwnProperty('elkoSensor')) { + if (data.elkoSensor !== undefined) { // Sensor const sensorModeLookup = { 0: 'air', @@ -141,123 +141,123 @@ const fzLocal = { }; result.sensor = utils.getFromLookup(data['elkoSensor'], sensorModeLookup); } - if (data.hasOwnProperty(0x0405)) { + if (data[0x0405] !== undefined) { // Regulator mode result.regulator_mode = data[0x0405] ? 'regulator' : 'thermostat'; } - if (data.hasOwnProperty('elkoRegulatorMode')) { + if (data.elkoRegulatorMode !== undefined) { // Regulator mode result.regulator_mode = data['elkoRegulatorMode'] ? 'regulator' : 'thermostat'; } - if (data.hasOwnProperty(0x0406)) { + if (data[0x0406] !== undefined) { // Power status result.power_status = data[0x0406] ? 'ON' : 'OFF'; } - if (data.hasOwnProperty('elkoPowerStatus')) { + if (data.elkoPowerStatus !== undefined) { // Power status result.power_status = data['elkoPowerStatus'] ? 'ON' : 'OFF'; } - if (data.hasOwnProperty(0x0408)) { + if (data[0x0408] !== undefined) { // Mean power result.mean_power = data[0x0408]; } - if (data.hasOwnProperty('elkoMeanPower')) { + if (data.elkoMeanPower !== undefined) { // Mean power result.mean_power = data['elkoMeanPower']; } - if (data.hasOwnProperty(0x0409)) { + if (data[0x0409] !== undefined) { // Floor temp result.floor_temp = utils.precisionRound(data[0x0409], 2) / 100; } - if (data.hasOwnProperty('elkoExternalTemp')) { + if (data.elkoExternalTemp !== undefined) { // External temp (floor) result.floor_temp = utils.precisionRound(data['elkoExternalTemp'], 2) / 100; } - if (data.hasOwnProperty(0x0411)) { + if (data[0x0411] !== undefined) { // Night switching result.night_switching = data[0x0411] ? 'ON' : 'OFF'; } - if (data.hasOwnProperty('elkoNightSwitching')) { + if (data.elkoNightSwitching !== undefined) { // Night switching result.night_switching = data['elkoNightSwitching'] ? 'ON' : 'OFF'; } - if (data.hasOwnProperty(0x0412)) { + if (data[0x0412] !== undefined) { // Frost guard result.frost_guard = data[0x0412] ? 'ON' : 'OFF'; } - if (data.hasOwnProperty('elkoFrostGuard')) { + if (data.elkoFrostGuard !== undefined) { // Frost guard result.frost_guard = data['elkoFrostGuard'] ? 'ON' : 'OFF'; } - if (data.hasOwnProperty(0x0413)) { + if (data[0x0413] !== undefined) { // Child lock result.child_lock = data[0x0413] ? 'LOCK' : 'UNLOCK'; } - if (data.hasOwnProperty('elkoChildLock')) { + if (data.elkoChildLock !== undefined) { // Child lock result.child_lock = data['elkoChildLock'] ? 'LOCK' : 'UNLOCK'; } - if (data.hasOwnProperty(0x0414)) { + if (data[0x0414] !== undefined) { // Max floor temp result.max_floor_temp = data[0x0414]; } - if (data.hasOwnProperty('elkoMaxFloorTemp')) { + if (data.elkoMaxFloorTemp !== undefined) { // Max floor temp result.max_floor_temp = data['elkoMaxFloorTemp']; } - if (data.hasOwnProperty(0x0415)) { + if (data[0x0415] !== undefined) { // Running_state result.running_state = data[0x0415] ? 'heat' : 'idle'; } - if (data.hasOwnProperty('elkoRelayState')) { + if (data.elkoRelayState !== undefined) { // Running_state result.running_state = data['elkoRelayState'] ? 'heat' : 'idle'; } - if (data.hasOwnProperty(0x0420)) { + if (data[0x0420] !== undefined) { // Regulator setpoint result.regulator_setpoint = data[0x0420]; } - if (data.hasOwnProperty(0x0421)) { + if (data[0x0421] !== undefined) { // Regulation mode const regulationModeLookup = {0: 'thermostat', 1: 'regulator', 2: 'zzilent'}; result.regulation_mode = utils.getFromLookup(data[0x0421], regulationModeLookup); } - if (data.hasOwnProperty(0x0422)) { + if (data[0x0422] !== undefined) { // Operation mode const presetLookup = {0: 'off', 1: 'away', 2: 'sleep', 3: 'home'}; const systemModeLookup = {0: 'off', 1: 'off', 2: 'off', 3: 'heat'}; result.preset = utils.getFromLookup(data[0x0422], presetLookup); result.system_mode = utils.getFromLookup(data[0x0422], systemModeLookup); } - if (data.hasOwnProperty(0x0423)) { + if (data[0x0423] !== undefined) { // Maximum floor temp guard result.max_floor_guard = data[0x0423] ? 'ON' : 'OFF'; } - if (data.hasOwnProperty(0x0424)) { + if (data[0x0424] !== undefined) { // Weekly timer enabled result.weekly_timer = data[0x0424] ? 'ON' : 'OFF'; } - if (data.hasOwnProperty(0x0425)) { + if (data[0x0425] !== undefined) { // Frost guard setpoint result.frost_guard_setpoint = data[0x0425]; } - if (data.hasOwnProperty(0x0426)) { + if (data[0x0426] !== undefined) { // External temperature result.external_temp = utils.precisionRound(data[0x0426], 2) / 100; } - if (data.hasOwnProperty(0x0428)) { + if (data[0x0428] !== undefined) { // External sensor source result.exteral_sensor_source = data[0x0428]; } - if (data.hasOwnProperty(0x0429)) { + if (data[0x0429] !== undefined) { // Current air temperature result.air_temp = utils.precisionRound(data[0x0429], 2) / 100; } - if (data.hasOwnProperty(0x0424)) { + if (data[0x0424] !== undefined) { // Floor Sensor Error result.floor_sensor_error = data[0x042b] ? 'error' : 'ok'; } - if (data.hasOwnProperty(0x0424)) { + if (data[0x0424] !== undefined) { // External Air Sensor Error result.exteral_sensor_error = data[0x042c] ? 'error' : 'ok'; } @@ -271,7 +271,7 @@ const fzLocal = { convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; const data = msg.data; - if (data.hasOwnProperty(0x0000)) { + if (data[0x0000] !== undefined) { result.group_id = data[0x0000]; } @@ -284,7 +284,7 @@ const fzLocal = { convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; const data = msg.data; - if (data.hasOwnProperty(0x0001)) { + if (data[0x0001] !== undefined) { // Alarm status const alarmStatusLookup = { 0: 'ok', @@ -297,31 +297,31 @@ const fzLocal = { }; result.alarm_status = utils.getFromLookup(data[0x0001], alarmStatusLookup); } - if (data.hasOwnProperty(0x0002)) { + if (data[0x0002] !== undefined) { // Change battery result.battery_low = data[0x0002] ? true : false; } - if (data.hasOwnProperty(0x0003)) { + if (data[0x0003] !== undefined) { // Stove temperature result.stove_temperature = data[0x0003]; } - if (data.hasOwnProperty(0x0004)) { + if (data[0x0004] !== undefined) { // Ambient temperature result.ambient_temperature = data[0x0004]; } - if (data.hasOwnProperty(0x0005)) { + if (data[0x0005] !== undefined) { // Active result.active = data[0x0005] ? true : false; } - if (data.hasOwnProperty(0x0006)) { + if (data[0x0006] !== undefined) { // Runtime result.runtime = data[0x0006]; } - if (data.hasOwnProperty(0x0007)) { + if (data[0x0007] !== undefined) { // Runtime timeout result.runtime_timeout = data[0x0007]; } - if (data.hasOwnProperty(0x0008)) { + if (data[0x0008] !== undefined) { // Reset reason const resetReasonLookup = { 0: 'unknown', @@ -335,56 +335,56 @@ const fzLocal = { }; result.reset_reason = utils.getFromLookup(data[0x0008], resetReasonLookup); } - if (data.hasOwnProperty(0x0009)) { + if (data[0x0009] !== undefined) { // Dip switch result.dip_switch = data[0x0009]; } - if (data.hasOwnProperty(0x000a)) { + if (data[0x000a] !== undefined) { // Software version result.sw_version = data[0x000a]; } - if (data.hasOwnProperty(0x000b)) { + if (data[0x000b] !== undefined) { // Hardware version result.hw_version = data[0x000b]; } - if (data.hasOwnProperty(0x000c)) { + if (data[0x000c] !== undefined) { // Bootloader version result.bootloader_version = data[0x000c]; } - if (data.hasOwnProperty(0x000d)) { + if (data[0x000d] !== undefined) { // Model const modelLookup = {0: 'unknown', 1: '1_8', 2: 'infinity', 3: 'hybrid', 4: 'tak', 0xff: 'unknown'}; result.model = utils.getFromLookup(data[0x000d], modelLookup); } - if (data.hasOwnProperty(0x0010)) { + if (data[0x0010] !== undefined) { // Relay address result.relay_address = data[0x0010]; } - if (data.hasOwnProperty(0x0100)) { + if (data[0x0100] !== undefined) { // Relay current flag const currentFlagLookup = {0: 'false', 1: 'true', 0xff: 'unknown'}; result.current_flag = utils.getFromLookup(data[0x0100], currentFlagLookup); } - if (data.hasOwnProperty(0x0101)) { + if (data[0x0101] !== undefined) { // Relay current result.relay_current = data[0x0101]; } - if (data.hasOwnProperty(0x0102)) { + if (data[0x0102] !== undefined) { // Relay status const relayStatusLookup = {0: 'off', 1: 'on', 2: 'not_present', 0xff: 'unknown'}; result.relay_status = utils.getFromLookup(data[0x0102], relayStatusLookup); } - if (data.hasOwnProperty(0x0103)) { + if (data[0x0103] !== undefined) { // Relay external button const relayStatusLookup = {0: 'not_clicked', 1: 'clicked', 0xff: 'unknown'}; result.external_button = utils.getFromLookup(data[0x0103], relayStatusLookup); } - if (data.hasOwnProperty(0x0104)) { + if (data[0x0104] !== undefined) { // Relay alarm const relayAlarmLookup = {0: 'ok', 1: 'no_communication', 2: 'over_current', 3: 'over_temperature', 0xff: 'unknown'}; result.relay_alarm = utils.getFromLookup(data[0x0104], relayAlarmLookup); } - if (data.hasOwnProperty(0x0105)) { + if (data[0x0105] !== undefined) { // Alarm status (from relay) const relayAlarmStatusLookup = { 0: 'ok', diff --git a/src/devices/custom_devices_diy.ts b/src/devices/custom_devices_diy.ts index 6885599facd09..cf5fbec3e91ab 100644 --- a/src/devices/custom_devices_diy.ts +++ b/src/devices/custom_devices_diy.ts @@ -89,7 +89,7 @@ const fzLocal = { // Sometimes the sensor publishes non-realistic vales, it should only publish message // in the 0 - 100 range, don't produce messages beyond these values. if (humidity >= 0 && humidity <= 100) { - const multiEndpoint = model.meta && model.meta.hasOwnProperty('multiEndpoint') && model.meta.multiEndpoint; + const multiEndpoint = model.meta && model.meta.multiEndpoint !== undefined && model.meta.multiEndpoint; const property = multiEndpoint ? postfixWithEndpointName('humidity', msg, model, meta) : 'humidity'; return {[property]: humidity}; } @@ -103,7 +103,7 @@ const fzLocal = { // DEPRECATED: only return lux here (change illuminance_lux -> illuminance) const illuminance = msg.data['measuredValue']; const illuminanceLux = illuminance === 0 ? 0 : Math.pow(10, (illuminance - 1) / 10000); - const multiEndpoint = model.meta && model.meta.hasOwnProperty('multiEndpoint') && model.meta.multiEndpoint; + const multiEndpoint = model.meta && model.meta.multiEndpoint !== undefined && model.meta.multiEndpoint; const property1 = multiEndpoint ? postfixWithEndpointName('illuminance', msg, model, meta) : 'illuminance'; const property2 = multiEndpoint ? postfixWithEndpointName('illuminance_lux', msg, model, meta) : 'illuminance_lux'; return {[property1]: illuminance, [property2]: illuminanceLux}; @@ -115,13 +115,13 @@ const fzLocal = { convert: (model, msg, publish, options, meta) => { // multi-endpoint version based on the stastard onverter 'fz.pressure' let pressure = 0; - if (msg.data.hasOwnProperty('scaledValue')) { + if (msg.data.scaledValue !== undefined) { const scale = msg.endpoint.getClusterAttributeValue('msPressureMeasurement', 'scale') as number; pressure = msg.data['scaledValue'] / Math.pow(10, scale) / 100.0; // convert to hPa } else { pressure = parseFloat(msg.data['measuredValue']); } - const multiEndpoint = model.meta && model.meta.hasOwnProperty('multiEndpoint') && model.meta.multiEndpoint; + const multiEndpoint = model.meta && model.meta.multiEndpoint !== undefined && model.meta.multiEndpoint; const property = multiEndpoint ? postfixWithEndpointName('pressure', msg, model, meta) : 'pressure'; return {[property]: pressure}; }, @@ -371,7 +371,7 @@ const definitions: DefinitionWithExtend[] = [ } for (const endpoint of device.endpoints) { - if (allEndpoints.hasOwnProperty(endpoint.ID)) { + if (allEndpoints[endpoint.ID] !== undefined) { continue; } epConfig = endpoint.ID.toString(); @@ -394,7 +394,7 @@ const definitions: DefinitionWithExtend[] = [ let valueId = valueConfigItems[0] ? valueConfigItems[0] : ''; let valueDescription = valueConfigItems[1] ? valueConfigItems[1] : ''; let valueUnit = valueConfigItems[2] !== undefined ? valueConfigItems[2] : ''; - if (!exposeDeviceOptions.hasOwnProperty(epName)) { + if (exposeDeviceOptions[epName] === undefined) { exposeDeviceOptions[epName] = {}; } const exposeEpOptions: KeyValueAny = exposeDeviceOptions[epName]; diff --git a/src/devices/develco.ts b/src/devices/develco.ts index b222fbc165c1c..2d217f76d5eba 100644 --- a/src/devices/develco.ts +++ b/src/devices/develco.ts @@ -51,10 +51,10 @@ const develco = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty('totalActivePower') && msg.data['totalActivePower'] !== -0x80000000) { + if (msg.data.totalActivePower !== undefined && msg.data['totalActivePower'] !== -0x80000000) { result[utils.postfixWithEndpointName('power', msg, model, meta)] = msg.data['totalActivePower']; } - if (msg.data.hasOwnProperty('totalReactivePower') && msg.data['totalReactivePower'] !== -0x80000000) { + if (msg.data.totalReactivePower !== undefined && msg.data['totalReactivePower'] !== -0x80000000) { result[utils.postfixWithEndpointName('power_reactive', msg, model, meta)] = msg.data['totalReactivePower']; } return result; @@ -73,7 +73,7 @@ const develco = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty('develcoPulseConfiguration')) { + if (msg.data.develcoPulseConfiguration !== undefined) { result[utils.postfixWithEndpointName('pulse_configuration', msg, model, meta)] = msg.data['develcoPulseConfiguration']; } @@ -85,14 +85,13 @@ const develco = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty('develcoInterfaceMode')) { - result[utils.postfixWithEndpointName('interface_mode', msg, model, meta)] = constants.develcoInterfaceMode.hasOwnProperty( - msg.data['develcoInterfaceMode'], - ) - ? constants.develcoInterfaceMode[msg.data['develcoInterfaceMode']] - : msg.data['develcoInterfaceMode']; + if (msg.data.develcoInterfaceMode !== undefined) { + result[utils.postfixWithEndpointName('interface_mode', msg, model, meta)] = + constants.develcoInterfaceMode[msg.data['develcoInterfaceMode']] !== undefined + ? constants.develcoInterfaceMode[msg.data['develcoInterfaceMode']] + : msg.data['develcoInterfaceMode']; } - if (msg.data.hasOwnProperty('status')) { + if (msg.data.status !== undefined) { result['battery_low'] = (msg.data.status & 2) > 0; result['check_meter'] = (msg.data.status & 1) > 0; } @@ -105,11 +104,11 @@ const develco = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty('reliability')) { + if (msg.data.reliability !== undefined) { const lookup = {0: 'no_fault_detected', 7: 'unreliable_other', 8: 'process_error'}; result.reliability = utils.getFromLookup(msg.data['reliability'], lookup); } - if (msg.data.hasOwnProperty('statusFlags')) { + if (msg.data.statusFlags !== undefined) { result.fault = msg.data['statusFlags'] === 1; } return result; @@ -121,7 +120,7 @@ const develco = { convert: (model, msg, publish, options, meta) => { const state: KeyValue = {}; - if (msg.data.hasOwnProperty('develcoLedControl')) { + if (msg.data.develcoLedControl !== undefined) { state['led_control'] = utils.getFromLookup(msg.data['develcoLedControl'], develcoLedControlMap); } @@ -134,7 +133,7 @@ const develco = { convert: (model, msg, publish, options, meta) => { const state: KeyValue = {}; - if (msg.data.hasOwnProperty('develcoAlarmOffDelay')) { + if (msg.data.develcoAlarmOffDelay !== undefined) { state['occupancy_timeout'] = msg.data['develcoAlarmOffDelay']; } @@ -146,7 +145,7 @@ const develco = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty('presentValue')) { + if (msg.data.presentValue !== undefined) { const value = msg.data['presentValue']; result[utils.postfixWithEndpointName('input', msg, model, meta)] = value == 1; } diff --git a/src/devices/gledopto.ts b/src/devices/gledopto.ts index ba7bc80b68a8a..daa35e70e9b9c 100644 --- a/src/devices/gledopto.ts +++ b/src/devices/gledopto.ts @@ -95,7 +95,7 @@ const tzLocal = { if (key == 'color') { const result = await tzLocal1.gledopto_light_color.convertSet(entity, key, value, meta); utils.assertObject(result); - if (result.state && result.state.color.hasOwnProperty('x') && result.state.color.hasOwnProperty('y')) { + if (result.state && result.state.color.x !== undefined && result.state.color.y !== undefined) { result.state.color_temp = Math.round(libColor.ColorXY.fromObject(result.state.color).toMireds()); } diff --git a/src/devices/gmmts.ts b/src/devices/gmmts.ts index 7df8b199b9c6e..c235a92c22686 100644 --- a/src/devices/gmmts.ts +++ b/src/devices/gmmts.ts @@ -2005,26 +2005,26 @@ const definitions: DefinitionWithExtend[] = [ logger.warning('Exposes: No endpoint', 'TICMeter'); } - if (endpoint != null && endpoint.hasOwnProperty('clusters') && endpoint.clusters[CLUSTER_TIC] != undefined) { - if (endpoint.clusters[CLUSTER_TIC].hasOwnProperty('attributes') && endpoint.clusters[CLUSTER_TIC].attributes != undefined) { + if (endpoint != null && endpoint.clusters !== undefined && endpoint.clusters[CLUSTER_TIC] != undefined) { + if (endpoint.clusters[CLUSTER_TIC].attributes !== undefined && endpoint.clusters[CLUSTER_TIC].attributes != undefined) { const attr = endpoint.clusters[CLUSTER_TIC].attributes; if (globalStore.getValue(device, 'tic_mode') == undefined) { - if (attr.hasOwnProperty('ticMode') && attr.ticMode != null) { + if (attr.ticMode !== undefined && attr.ticMode != null) { logger.debug(`Load ticMode: ${attr.ticMode}`, 'TICMeter'); globalStore.putValue(device, 'tic_mode', modeTICEnum[Number(attr.ticMode)]); } } if (globalStore.getValue(device, 'elec_mode') == undefined) { - if (attr.hasOwnProperty('elecMode') && attr.elecMode != null) { + if (attr.elecMode !== undefined && attr.elecMode != null) { logger.debug(`Load elecMode: ${attr.elecMode}`, 'TICMeter'); globalStore.putValue(device, 'elec_mode', modeElecEnum[Number(attr.elecMode)]); } } if (globalStore.getValue(device, 'contract_type') == undefined) { - if (attr.hasOwnProperty('contractType') && attr.contractType != null) { + if (attr.contractType !== undefined && attr.contractType != null) { let string = attr.contractType; if (Buffer.isBuffer(string)) { string = string.toString(); @@ -2034,14 +2034,14 @@ const definitions: DefinitionWithExtend[] = [ } } - if (attr.hasOwnProperty('powerInjected') && attr.powerInjected != null) { + if (attr.powerInjected !== undefined && attr.powerInjected != null) { logger.debug(`Load powerInjected: ${attr.powerInjected}`, 'TICMeter'); globalStore.putValue(device, 'producer', 'ON'); } } } - if (options && options.hasOwnProperty('contract_type') && options.contract_type != 'AUTO') { + if (options && options.contract_type !== undefined && options.contract_type != 'AUTO') { currentContract = String(options.contract_type); logger.debug(`contract: ${currentContract}`, 'TICMeter'); } else { @@ -2053,7 +2053,7 @@ const definitions: DefinitionWithExtend[] = [ } } - if (options && options.hasOwnProperty('linky_elec') && options.linky_elec != 'AUTO') { + if (options && options.linky_elec !== undefined && options.linky_elec != 'AUTO') { currentElec = String(options.linky_elec); logger.debug(`Manual elec: ${currentElec}`, 'TICMeter'); } else { @@ -2065,7 +2065,7 @@ const definitions: DefinitionWithExtend[] = [ } } - if (options && options.hasOwnProperty('tic_mode') && options.tic_mode != 'AUTO') { + if (options && options.tic_mode !== undefined && options.tic_mode != 'AUTO') { currentTIC = String(options.tic_mode); logger.debug(`Manual tic: ${currentTIC}`, 'TICMeter'); } else { @@ -2077,7 +2077,7 @@ const definitions: DefinitionWithExtend[] = [ } } - if (options && options.hasOwnProperty('producer') && options.producer != 'AUTO') { + if (options && options.producer !== undefined && options.producer != 'AUTO') { currentProducer = String(options.producer); logger.debug(`Manual producer: ${currentProducer}`, 'TICMeter'); } else { @@ -2088,7 +2088,7 @@ const definitions: DefinitionWithExtend[] = [ } } - if (options && options.hasOwnProperty('translation')) { + if (options && options.translation !== undefined) { translation = String(options.translation); } else { translation = TRANSLATION_FR; @@ -2105,7 +2105,7 @@ const definitions: DefinitionWithExtend[] = [ let elecOK = false; let ticOK = false; let producerOK = true; - if (item.hasOwnProperty('contract')) { + if (item.contract !== undefined) { if (item['contract'] == currentContract || item['contract'] == C.ANY) { contractOK = true; } @@ -2113,7 +2113,7 @@ const definitions: DefinitionWithExtend[] = [ logger.warning(`No contract for ${item.name}`, 'TICMeter'); } - if (item.hasOwnProperty('elec')) { + if (item.elec !== undefined) { if (item['elec'] == currentElec || item['elec'] == E.ANY) { elecOK = true; } @@ -2121,7 +2121,7 @@ const definitions: DefinitionWithExtend[] = [ logger.warning(`No elec for ${item.name}`, 'TICMeter'); } - if (item.hasOwnProperty('tic')) { + if (item.tic !== undefined) { if (item['tic'] == currentTIC || item['tic'] == T.ANY) { ticOK = true; } @@ -2129,7 +2129,7 @@ const definitions: DefinitionWithExtend[] = [ logger.warning(`No tic for ${item.name}`, 'TICMeter'); } - if (item.hasOwnProperty('prod')) { + if (item.prod !== undefined) { if (item['prod'] == true && currentProducer == 'OFF') { producerOK = false; } @@ -2177,7 +2177,7 @@ const definitions: DefinitionWithExtend[] = [ }); logger.debug(`Exposes ${exposes.length} attributes`, 'TICMeter'); - if (options.hasOwnProperty('translation')) { + if (options.translation !== undefined) { switch (options.translation) { case TRANSLATION_FR: for (let i = 0; i < ticmeterOptions.length; i++) { @@ -2275,16 +2275,16 @@ const definitions: DefinitionWithExtend[] = [ const intervalDefined = globalStore.hasValue(device, 'interval'); if (data.data) { - if (data.data.hasOwnProperty('ticMode')) { + if (data.data.ticMode !== undefined) { const ticMode = modeTICEnum[data.data.ticMode]; globalStore.putValue(device, 'tic_mode', ticMode); // settings.changeEntityOptions(device, { tic_mode: ticMode }); } - if (data.data.hasOwnProperty('elecMode')) { + if (data.data.elecMode !== undefined) { const elecMode = modeElecEnum[data.data.elecMode]; globalStore.putValue(device, 'elec_mode', elecMode); } - if (data.data.hasOwnProperty('contractType')) { + if (data.data.contractType !== undefined) { let contractType; if (Buffer.isBuffer(data.data.contractType)) { contractType = data.data.contractType.toString(); diff --git a/src/devices/inovelli.ts b/src/devices/inovelli.ts index d3b4c6e890227..af7e98a642507 100644 --- a/src/devices/inovelli.ts +++ b/src/devices/inovelli.ts @@ -1358,14 +1358,15 @@ const tzLocal = { const {message} = meta; const transition = utils.getTransition(entity, 'brightness', meta); const turnsOffAtBrightness1 = utils.getMetaValue(entity, meta.mapped, 'turnsOffAtBrightness1', 'allEqual', false); - let state = message.hasOwnProperty('state') - ? // @ts-expect-error ignore - message.state.toLowerCase() - : undefined; + let state = + message.state !== undefined + ? // @ts-expect-error ignore + message.state.toLowerCase() + : undefined; let brightness = undefined; - if (message.hasOwnProperty('brightness')) { + if (message.brightness !== undefined) { brightness = Number(message.brightness); - } else if (message.hasOwnProperty('brightness_percent')) { + } else if (message.brightness_percent !== undefined) { brightness = utils.mapNumberRange(Number(message.brightness_percent), 0, 100, 0, 255); } @@ -1409,7 +1410,7 @@ const tzLocal = { } else { // Store brightness where the bulb was turned off with as we need it when the bulb is turned on // with transition. - if (meta.state.hasOwnProperty('brightness') && state === 'off') { + if (meta.state.brightness !== undefined && state === 'off') { globalStore.putValue(entity, 'brightness', meta.state.brightness); globalStore.putValue(entity, 'turnedOffWithTransition', true); } @@ -1490,7 +1491,7 @@ const tzLocal = { fan_state: { key: ['fan_state'], convertSet: async (entity, key, value, meta) => { - const state = meta.message.hasOwnProperty('fan_state') ? meta.message.fan_state.toString().toLowerCase() : null; + const state = meta.message.fan_state !== undefined ? meta.message.fan_state.toString().toLowerCase() : null; utils.validateValue(state, ['toggle', 'off', 'on']); await entity.command('genOnOff', state, {}, utils.getOptions(meta.mapped, entity)); @@ -1548,9 +1549,9 @@ const tzLocal = { const state = typeof meta.message.fan_state === 'string' ? meta.message.fan_state.toLowerCase() : null; utils.validateValue(state, ['toggle', 'off', 'on']); - if (state === 'on' && (meta.message.hasOwnProperty('on_time') || meta.message.hasOwnProperty('off_wait_time'))) { - const onTime = meta.message.hasOwnProperty('on_time') ? meta.message.on_time : 0; - const offWaitTime = meta.message.hasOwnProperty('off_wait_time') ? meta.message.off_wait_time : 0; + if (state === 'on' && (meta.message.on_time !== undefined || meta.message.off_wait_time !== undefined)) { + const onTime = meta.message.on_time !== undefined ? meta.message.on_time : 0; + const offWaitTime = meta.message.off_wait_time !== undefined ? meta.message.off_wait_time : 0; if (typeof onTime !== 'number') { throw Error('The on_time value must be a number!'); @@ -1694,12 +1695,12 @@ const tzLocal = { */ const inovelliOnOffConvertSet = async (entity: Zh.Endpoint | Zh.Group, key: string, value: unknown, meta: Tz.Meta) => { // @ts-expect-error ignore - const state = meta.message.hasOwnProperty('state') ? meta.message.state.toLowerCase() : null; + const state = meta.message.state !== undefined ? meta.message.state.toLowerCase() : null; utils.validateValue(state, ['toggle', 'off', 'on']); - if (state === 'on' && (meta.message.hasOwnProperty('on_time') || meta.message.hasOwnProperty('off_wait_time'))) { - const onTime = meta.message.hasOwnProperty('on_time') ? meta.message.on_time : 0; - const offWaitTime = meta.message.hasOwnProperty('off_wait_time') ? meta.message.off_wait_time : 0; + if (state === 'on' && (meta.message.on_time !== undefined || meta.message.off_wait_time !== undefined)) { + const onTime = meta.message.on_time !== undefined ? meta.message.on_time : 0; + const offWaitTime = meta.message.off_wait_time !== undefined ? meta.message.off_wait_time : 0; if (typeof onTime !== 'number') { throw Error('The on_time value must be a number!'); @@ -1710,8 +1711,8 @@ const inovelliOnOffConvertSet = async (entity: Zh.Endpoint | Zh.Group, key: stri const payload = { ctrlbits: 0, - ontime: meta.message.hasOwnProperty('on_time') ? Math.round(onTime * 10) : 0xffff, - offwaittime: meta.message.hasOwnProperty('off_wait_time') ? Math.round(offWaitTime * 10) : 0xffff, + ontime: meta.message.on_time !== undefined ? Math.round(onTime * 10) : 0xffff, + offwaittime: meta.message.off_wait_time !== undefined ? Math.round(offWaitTime * 10) : 0xffff, }; await entity.command('genOnOff', 'onWithTimedOff', payload, utils.getOptions(meta.mapped, entity)); } else { @@ -1769,7 +1770,7 @@ const fzLocal = { cluster: 'genLevelCtrl', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('currentLevel')) { + if (msg.data.currentLevel !== undefined) { const mode = intToFanMode(msg.data['currentLevel'] || 1); return { fan_mode: mode, @@ -1783,7 +1784,7 @@ const fzLocal = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { if (msg.endpoint.ID == 2) { - if (msg.data.hasOwnProperty('currentLevel')) { + if (msg.data.currentLevel !== undefined) { const mode = intToFanMode(msg.data['currentLevel'] || 1); return { fan_mode: mode, @@ -1797,7 +1798,7 @@ const fzLocal = { cluster: 'genOnOff', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('onOff')) { + if (msg.data.onOff !== undefined) { return {fan_state: msg.data['onOff'] === 1 ? 'ON' : 'OFF'}; } return msg.data; @@ -1808,7 +1809,7 @@ const fzLocal = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { if (msg.endpoint.ID == 1) { - if (msg.data.hasOwnProperty('currentLevel')) { + if (msg.data.currentLevel !== undefined) { return {brightness: msg.data['currentLevel']}; } } @@ -1831,7 +1832,7 @@ const fzLocal = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { if (msg.endpoint.ID == 2) { - if (msg.data.hasOwnProperty('breeze_mode')) { + if (msg.data.breeze_mode !== undefined) { const bitmasks = [3, 60, 192, 3840, 12288, 245760, 786432, 15728640, 50331648, 1006632960]; const raw = msg.data['breeze_mode']; const s1 = breezemodes[raw & bitmasks[0]]; @@ -1869,11 +1870,11 @@ const fzLocal = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { if (msg.endpoint.ID === 1) { - if (msg.data.hasOwnProperty('onOff')) { + if (msg.data.onOff !== undefined) { return {state: msg.data['onOff'] === 1 ? 'ON' : 'OFF'}; } } else if (msg.endpoint.ID === 2) { - if (msg.data.hasOwnProperty('onOff')) { + if (msg.data.onOff !== undefined) { return {fan_state: msg.data['onOff'] === 1 ? 'ON' : 'OFF'}; } } else { diff --git a/src/devices/kmpcil.ts b/src/devices/kmpcil.ts index 40ac10051235c..0759f3737029d 100644 --- a/src/devices/kmpcil.ts +++ b/src/devices/kmpcil.ts @@ -28,10 +28,10 @@ const kmpcilOptions = { }; function handleKmpcilPresence(model: DefinitionWithExtend, msg: Fz.Message, publish: Publish, options: KeyValue, meta: Fz.Meta): KeyValue { - const useOptionsTimeoutBattery = options && options.hasOwnProperty('presence_timeout_battery'); + const useOptionsTimeoutBattery = options && options.presence_timeout_battery !== undefined; const timeoutBattery = useOptionsTimeoutBattery ? options.presence_timeout_battery : 420; // 100 seconds by default - const useOptionsTimeoutDc = options && options.hasOwnProperty('presence_timeout_dc'); + const useOptionsTimeoutDc = options && options.presence_timeout_dc !== undefined; const timeoutDc = useOptionsTimeoutDc ? options.presence_timeout_dc : 60; const mode = meta.state ? meta.state['power_state'] : false; @@ -51,7 +51,7 @@ const kmpcilConverters = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const payload = handleKmpcilPresence(model, msg, publish, options, meta); - if (msg.data.hasOwnProperty('presentValue')) { + if (msg.data.presentValue !== undefined) { const presentValue = msg.data['presentValue']; payload.power_state = (presentValue & 0x01) > 0; payload.occupancy = (presentValue & 0x04) > 0; @@ -66,7 +66,7 @@ const kmpcilConverters = { options: [kmpcilOptions.presence_timeout_dc(), kmpcilOptions.presence_timeout_battery()], convert: (model, msg, publish, options, meta) => { const payload = handleKmpcilPresence(model, msg, publish, options, meta); - if (msg.data.hasOwnProperty('batteryVoltage')) { + if (msg.data.batteryVoltage !== undefined) { payload.voltage = msg.data['batteryVoltage'] * 100; if (model.meta && model.meta.battery && model.meta.battery.voltageToPercentage) { // @ts-expect-error ignore diff --git a/src/devices/led_trading.ts b/src/devices/led_trading.ts index 851ffd7b6a5aa..bdf48f8b50138 100644 --- a/src/devices/led_trading.ts +++ b/src/devices/led_trading.ts @@ -1,13 +1,11 @@ import fz from '../converters/fromZigbee'; import tz from '../converters/toZigbee'; import * as exposes from '../lib/exposes'; -import {logger} from '../lib/logger'; import {deviceEndpoints, light, onOff} from '../lib/modernExtend'; import * as reporting from '../lib/reporting'; import {DefinitionWithExtend, Fz} from '../lib/types'; import * as utils from '../lib/utils'; -const NS = 'zhc:led_trading'; const e = exposes.presets; const fzLocal = { @@ -28,11 +26,7 @@ const fzLocal = { 0x1d: 'hold_3', 0x1e: 'hold_4', }; - if (!lookup.hasOwnProperty(commandID)) { - logger.error(`led_trading_9133: missing command '${commandID}'`, NS); - } else { - return {action: utils.getFromLookup(commandID, lookup)}; - } + return {action: utils.getFromLookup(commandID, lookup)}; }, } satisfies Fz.Converter, }; diff --git a/src/devices/leviton.ts b/src/devices/leviton.ts index a1865c6dc0dc4..b7e7783c38c04 100644 --- a/src/devices/leviton.ts +++ b/src/devices/leviton.ts @@ -15,7 +15,7 @@ const fzLocal = { cluster: 'genLevelCtrl', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('currentLevel')) { + if (msg.data.currentLevel !== undefined) { const currentLevel = Number(msg.data['currentLevel']); const property = utils.postfixWithEndpointName('state', msg, model, meta); return {[property]: currentLevel > 0 ? 'ON' : 'OFF'}; diff --git a/src/devices/linptech.ts b/src/devices/linptech.ts index 0c06ae23d8549..b4678b2646777 100644 --- a/src/devices/linptech.ts +++ b/src/devices/linptech.ts @@ -46,19 +46,19 @@ const fzLocal = { type: ['attributeReport'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty('57354')) { + if (msg.data['57354'] !== undefined) { result['target_distance'] = msg.data['57354']; } - if (msg.data.hasOwnProperty('57355')) { + if (msg.data['57355'] !== undefined) { result['motion_detection_distance'] = msg.data['57355']; } - if (msg.data.hasOwnProperty('57348')) { + if (msg.data['57348'] !== undefined) { result['motion_detection_sensitivity'] = msg.data['57348']; } - if (msg.data.hasOwnProperty('57349')) { + if (msg.data['57349'] !== undefined) { result['static_detection_sensitivity'] = msg.data['57349']; } - if (msg.data.hasOwnProperty('57345')) { + if (msg.data['57345'] !== undefined) { result['presence_keep_time'] = msg.data['57345']; } return result; diff --git a/src/devices/lixee.ts b/src/devices/lixee.ts index 982be1c7a398d..ca22ae5b7340a 100644 --- a/src/devices/lixee.ts +++ b/src/devices/lixee.ts @@ -61,13 +61,13 @@ const fzZiPulses: Fz.Converter = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const payload: KeyValue = {}; - if (msg.data.hasOwnProperty('multiplier')) { + if (msg.data.multiplier !== undefined) { payload['multiplier'] = msg.data['multiplier']; } - if (msg.data.hasOwnProperty('divisor')) { + if (msg.data.divisor !== undefined) { payload['divisor'] = msg.data['divisor']; } - if (msg.data.hasOwnProperty('unitOfMeasure')) { + if (msg.data.unitOfMeasure !== undefined) { const val = msg.data['unitOfMeasure']; payload['unitOfMeasure'] = unitsZiPulses[val]; } @@ -179,7 +179,7 @@ const fzLocal = { .toLowerCase(); let val = msg.data[at]; if (val != null) { - if (val.hasOwnProperty('type') && val.type === 'Buffer') { + if (val.type !== undefined && val.type === 'Buffer') { val = Buffer.from(val.data); } if (Buffer.isBuffer(val)) { @@ -1632,7 +1632,7 @@ function getCurrentConfig(device: Zh.Device, options: KeyValue) { // @ts-expect-error ignore function getConfig(targetOption, bitLinkyMode, valueTrue, valueFalse) { const valueDefault = valueFalse; - if (options && options.hasOwnProperty(targetOption) && options[targetOption] != 'auto') { + if (options && options[targetOption] !== undefined && options[targetOption] != 'auto') { if (options[targetOption] === 'true' || options[targetOption] === 'false') { return options[targetOption] === 'true'; // special case for production } @@ -1671,7 +1671,7 @@ function getCurrentConfig(device: Zh.Device, options: KeyValue) { // Filter even more, based on our current tarif let currentTarf = ''; - if (options && options.hasOwnProperty('tarif') && options['tarif'] != 'auto') { + if (options && options.tarif !== undefined && options['tarif'] != 'auto') { currentTarf = Object.entries(tarifsDef).find(([k, v]) => v.fname == options['tarif'])[1].currentTarf; } else { try { @@ -1730,7 +1730,7 @@ function getCurrentConfig(device: Zh.Device, options: KeyValue) { } // Filter exposed attributes with user whitelist - if (options && options.hasOwnProperty('tic_command_whitelist')) { + if (options && options.tic_command_whitelist !== undefined) { // @ts-expect-error ignore const tic_commands_str = options['tic_command_whitelist'].toUpperCase(); if (tic_commands_str !== 'ALL') { @@ -1843,7 +1843,8 @@ const definitions: DefinitionWithExtend[] = [ change: 1, }; // Override reportings - if (e.hasOwnProperty('report')) { + // @ts-expect-error ignore + if (e.report !== undefined) { // @ts-expect-error ignore params = {...params, ...e.report}; } diff --git a/src/devices/lumi.ts b/src/devices/lumi.ts index 5f2384ce2227b..cc9bbcbc9de12 100644 --- a/src/devices/lumi.ts +++ b/src/devices/lumi.ts @@ -2441,7 +2441,7 @@ const definitions: DefinitionWithExtend[] = [ type === 'message' && data.type === 'attributeReport' && data.cluster === 'genBasic' && - data.data.hasOwnProperty('1028') && + data.data['1028'] !== undefined && data.data['1028'] == 0 ) { // Try to read the position after the motor stops, the device occasionally report wrong data right after stopping @@ -2586,7 +2586,7 @@ const definitions: DefinitionWithExtend[] = [ type === 'message' && data.type === 'attributeReport' && data.cluster === 'genMultistateOutput' && - data.data.hasOwnProperty('presentValue') && + data.data.presentValue !== undefined && data.data['presentValue'] > 1 ) { // Try to read the position after the motor stops, the device occasionally report wrong data right after stopping diff --git a/src/devices/lytko.ts b/src/devices/lytko.ts index 0966e2505c822..57d0a005c3e8f 100644 --- a/src/devices/lytko.ts +++ b/src/devices/lytko.ts @@ -23,14 +23,14 @@ const fzLocal = { const ep = getKey(model.endpoint(msg.device), msg.endpoint.ID); const result: KeyValue = {}; - if (msg.data.hasOwnProperty('minSetpointDeadBand')) { + if (msg.data.minSetpointDeadBand !== undefined) { result[postfixWithEndpointName('min_setpoint_deadband', msg, model, meta)] = precisionRound(msg.data['minSetpointDeadBand'], 2) / 10; } // sensor type - if (msg.data.hasOwnProperty('30464')) { + if (msg.data['30464'] !== undefined) { result[`sensor_type_${ep}`] = sensorTypes[toNumber(msg.data['30464'])]; } - if (msg.data.hasOwnProperty('30465')) { + if (msg.data['30465'] !== undefined) { result[postfixWithEndpointName('target_temp_first', msg, model, meta)] = msg.data['30465'] == 1; } return result; @@ -41,13 +41,13 @@ const fzLocal = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty('30464')) { + if (msg.data['30464'] !== undefined) { result[postfixWithEndpointName('brightness', msg, model, meta)] = msg.data['30464']; } - if (msg.data.hasOwnProperty('30465')) { + if (msg.data['30465'] !== undefined) { result[postfixWithEndpointName('brightness_standby', msg, model, meta)] = msg.data['30465']; } - if (msg.data.hasOwnProperty('keypadLockout')) { + if (msg.data.keypadLockout !== undefined) { result[postfixWithEndpointName('keypad_lockout', msg, model, meta)] = getFromLookup( msg.data['keypadLockout'], constants.keypadLockoutMode, diff --git a/src/devices/namron.ts b/src/devices/namron.ts index 72e12e2f4cd1a..6f688966e6eaa 100644 --- a/src/devices/namron.ts +++ b/src/devices/namron.ts @@ -24,26 +24,26 @@ const fzLocal = { convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; const data = msg.data; - if (data.hasOwnProperty(0x1000)) { + if (data[0x1000] !== undefined) { // OperateDisplayBrightnesss result.display_brightnesss = data[0x1000]; } - if (data.hasOwnProperty(0x1001)) { + if (data[0x1001] !== undefined) { // DisplayAutoOffActivation const lookup = {0: 'deactivated', 1: 'activated'}; result.display_auto_off = utils.getFromLookup(data[0x1001], lookup); } - if (data.hasOwnProperty(0x1004)) { + if (data[0x1004] !== undefined) { // PowerUpStatus const lookup = {0: 'manual', 1: 'last_state'}; result.power_up_status = utils.getFromLookup(data[0x1004], lookup); } - if (data.hasOwnProperty(0x1009)) { + if (data[0x1009] !== undefined) { // WindowOpenCheck const lookup = {0: 'enable', 1: 'disable'}; result.window_open_check = utils.getFromLookup(data[0x1009], lookup); } - if (data.hasOwnProperty(0x100a)) { + if (data[0x100a] !== undefined) { // Hysterersis result.hysterersis = utils.precisionRound(data[0x100a], 2) / 10; } diff --git a/src/devices/niko.ts b/src/devices/niko.ts index 8a788b916269e..e52f26d4f69a4 100644 --- a/src/devices/niko.ts +++ b/src/devices/niko.ts @@ -15,7 +15,7 @@ const local = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const state: KeyValue = {}; - if (msg.data.hasOwnProperty('switchOperationMode')) { + if (msg.data.switchOperationMode !== undefined) { const operationModeMap = {0x02: 'control_relay', 0x01: 'decoupled', 0x00: 'unknown'}; state['operation_mode'] = utils.getFromLookup(msg.data.switchOperationMode, operationModeMap); } @@ -28,7 +28,7 @@ const local = { convert: (model, msg, publish, options, meta) => { const state: KeyValue = {}; - if (msg.data.hasOwnProperty('switchAction')) { + if (msg.data.switchAction !== undefined) { // NOTE: a single press = two separate values reported, 16 followed by 64 // a hold/release cycle = three separate values, 16, 32, and 48 const actionMap: KeyValue = @@ -72,10 +72,10 @@ const local = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const state: KeyValue = {}; - if (msg.data.hasOwnProperty('outletLedState')) { + if (msg.data.outletLedState !== undefined) { state['led_enable'] = msg.data['outletLedState'] == 1; } - if (msg.data.hasOwnProperty('outletLedColor')) { + if (msg.data.outletLedColor !== undefined) { state['led_state'] = msg.data['outletLedColor'] == 255 ? 'ON' : 'OFF'; } return state; @@ -86,10 +86,10 @@ const local = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const state: KeyValue = {}; - if (msg.data.hasOwnProperty('outletChildLock')) { + if (msg.data.outletChildLock !== undefined) { state['child_lock'] = msg.data['outletChildLock'] == 0 ? 'LOCK' : 'UNLOCK'; } - if (msg.data.hasOwnProperty('outletLedState')) { + if (msg.data.outletLedState !== undefined) { state['led_enable'] = msg.data['outletLedState'] == 1; } return state; @@ -105,7 +105,7 @@ const local = { utils.assertEndpoint(entity); const operationModeLookup = {control_relay: 0x02, decoupled: 0x01}; // @ts-expect-error ignore - if (!operationModeLookup.hasOwnProperty(value)) { + if (operationModeLookup[value] === undefined) { throw new Error(`operation_mode was called with an invalid value (${value})`); } else { await utils.enforceEndpoint(entity, key, meta).write( diff --git a/src/devices/nue_3a.ts b/src/devices/nue_3a.ts index 41f6ebebc4654..00b7075051e2d 100644 --- a/src/devices/nue_3a.ts +++ b/src/devices/nue_3a.ts @@ -16,7 +16,7 @@ const fzLocal = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty('tuyaMovingState')) { + if (msg.data.tuyaMovingState !== undefined) { const value = msg.data['tuyaMovingState']; const movingLookup = {0: 'DOWN', 1: 'UP', 2: 'STOP'}; result.moving = utils.getFromLookup(value, movingLookup); @@ -28,7 +28,7 @@ const fzLocal = { cluster: 'genOnOff', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('onOff')) { + if (msg.data.onOff !== undefined) { return {state: msg.data['onOff'] === 1 ? 'CLOSE' : 'OPEN'}; } }, diff --git a/src/devices/owon.ts b/src/devices/owon.ts index 3725f6fdcef81..e0b3248ca5ce5 100644 --- a/src/devices/owon.ts +++ b/src/devices/owon.ts @@ -26,99 +26,99 @@ const fzLocal = { convert: (model, msg, publish, options, meta) => { const factor = 0.001; const payload: KeyValue = {}; - if (msg.data.hasOwnProperty('owonL1Energy')) { + if (msg.data.owonL1Energy !== undefined) { const data = msg.data['owonL1Energy']; const value = (parseInt(data[0]) << 32) + parseInt(data[1]); payload.energy_l1 = value * factor; } - if (msg.data.hasOwnProperty('owonL2Energy')) { + if (msg.data.owonL2Energy !== undefined) { const data = msg.data['owonL2Energy']; const value = (parseInt(data[0]) << 32) + parseInt(data[1]); payload.energy_l2 = value * factor; } - if (msg.data.hasOwnProperty('owonL3Energy')) { + if (msg.data.owonL3Energy !== undefined) { const data = msg.data['owonL3Energy']; const value = (parseInt(data[0]) << 32) + parseInt(data[1]); payload.energy_l3 = value * factor; } - if (msg.data.hasOwnProperty('owonL1ReactiveEnergy')) { + if (msg.data.owonL1ReactiveEnergy !== undefined) { const data = msg.data['owonL1ReactiveEnergy']; const value = (parseInt(data[0]) << 32) + parseInt(data[1]); payload.reactive_energy_l1 = value * factor; } - if (msg.data.hasOwnProperty('owonL2ReactiveEnergy')) { + if (msg.data.owonL2ReactiveEnergy !== undefined) { const data = msg.data['owonL2ReactiveEnergy']; const value = (parseInt(data[0]) << 32) + parseInt(data[1]); payload.reactive_energy_l2 = value * factor; } - if (msg.data.hasOwnProperty('owonL3ReactiveEnergy')) { + if (msg.data.owonL3ReactiveEnergy !== undefined) { const data = msg.data['owonL3ReactiveEnergy']; const value = (parseInt(data[0]) << 32) + parseInt(data[1]); payload.reactive_energy_l3 = value / 1000; } - if (msg.data.hasOwnProperty('owonL1PhasePower')) { + if (msg.data.owonL1PhasePower !== undefined) { payload.power_l1 = msg.data['owonL1PhasePower']; } - if (msg.data.hasOwnProperty('owonL2PhasePower')) { + if (msg.data.owonL2PhasePower !== undefined) { payload.power_l2 = msg.data['owonL2PhasePower']; } - if (msg.data.hasOwnProperty('owonL3PhasePower')) { + if (msg.data.owonL3PhasePower !== undefined) { payload.power_l3 = msg.data['owonL3PhasePower']; } - if (msg.data.hasOwnProperty('owonL1PhaseReactivePower')) { + if (msg.data.owonL1PhaseReactivePower !== undefined) { payload.reactive_power_l1 = msg.data['owonL1PhaseReactivePower']; } - if (msg.data.hasOwnProperty('owonL2PhaseReactivePower')) { + if (msg.data.owonL2PhaseReactivePower !== undefined) { payload.reactive_power_l2 = msg.data['owonL2PhaseReactivePower']; } - if (msg.data.hasOwnProperty('owonL3PhaseReactivePower')) { + if (msg.data.owonL3PhaseReactivePower !== undefined) { payload.reactive_power_l3 = msg.data['owonL3PhaseReactivePower']; } - if (msg.data.hasOwnProperty('owonL1PhaseVoltage')) { + if (msg.data.owonL1PhaseVoltage !== undefined) { payload.voltage_l1 = msg.data['owonL1PhaseVoltage'] / 10.0; } - if (msg.data.hasOwnProperty('owonL2PhaseVoltage')) { + if (msg.data.owonL2PhaseVoltage !== undefined) { payload.voltage_l2 = msg.data['owonL2PhaseVoltage'] / 10.0; } - if (msg.data.hasOwnProperty('owonL3PhaseVoltage')) { + if (msg.data.owonL3PhaseVoltage !== undefined) { payload.voltage_l3 = msg.data['owonL3PhaseVoltage'] / 10.0; } - if (msg.data.hasOwnProperty('owonL1PhaseCurrent')) { + if (msg.data.owonL1PhaseCurrent !== undefined) { payload.current_l1 = msg.data['owonL1PhaseCurrent'] * factor; } - if (msg.data.hasOwnProperty('owonL2PhaseCurrent')) { + if (msg.data.owonL2PhaseCurrent !== undefined) { payload.current_l2 = msg.data['owonL2PhaseCurrent'] * factor; } - if (msg.data.hasOwnProperty('owonL3PhaseCurrent')) { + if (msg.data.owonL3PhaseCurrent !== undefined) { payload.current_l3 = msg.data['owonL3PhaseCurrent'] * factor; } - if (msg.data.hasOwnProperty('owonFrequency')) { + if (msg.data.owonFrequency !== undefined) { payload.frequency = msg.data['owonFrequency']; } // Issue #20719 summation manufacturer attributes are not well parsed - if (msg.data.hasOwnProperty('owonReactivePowerSum') || msg.data.hasOwnProperty('8451')) { + if (msg.data.owonReactivePowerSum !== undefined || msg.data['8451'] !== undefined) { // 0x2103 -> 8451 const value = msg.data['owonReactiveEnergySum'] || msg.data['8451']; payload.power_reactive = value; } - if (msg.data.hasOwnProperty('owonCurrentSum') || msg.data.hasOwnProperty('12547')) { + if (msg.data.owonCurrentSum !== undefined || msg.data['12547'] !== undefined) { // 0x3103 -> 12547 const data = msg.data['owonCurrentSum'] || msg.data['12547'] * factor; payload.current = data; } - if (msg.data.hasOwnProperty('owonReactiveEnergySum') || msg.data.hasOwnProperty('16643')) { + if (msg.data.owonReactiveEnergySum !== undefined || msg.data['16643'] !== undefined) { // 0x4103 -> 16643 const data = msg.data['owonReactiveEnergySum'] || msg.data['16643']; const value = (parseInt(data[0]) << 32) + parseInt(data[1]); payload.reactive_energy = value * factor; } - if (msg.data.hasOwnProperty('owonL1PowerFactor')) { + if (msg.data.owonL1PowerFactor !== undefined) { payload.power_factor_l1 = msg.data['owonL1PowerFactor'] / 100; } - if (msg.data.hasOwnProperty('owonL2PowerFactor')) { + if (msg.data.owonL2PowerFactor !== undefined) { payload.power_factor_l2 = msg.data['owonL2PowerFactor'] / 100; } - if (msg.data.hasOwnProperty('owonL3PowerFactor')) { + if (msg.data.owonL3PowerFactor !== undefined) { payload.power_factor_l3 = msg.data['owonL3PowerFactor'] / 100; } diff --git a/src/devices/perenio.ts b/src/devices/perenio.ts index 98bcb2843faa6..54865d275fc3d 100644 --- a/src/devices/perenio.ts +++ b/src/devices/perenio.ts @@ -19,10 +19,10 @@ const fzPerenio = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty('lastMessageLqi')) { + if (msg.data.lastMessageLqi !== undefined) { result['last_message_lqi'] = msg.data['lastMessageLqi']; } - if (msg.data.hasOwnProperty('lastMessageRssi')) { + if (msg.data.lastMessageRssi !== undefined) { result['last_message_rssi'] = msg.data['lastMessageRssi']; } return result; @@ -40,7 +40,7 @@ const fzPerenio = { 0x00cd: 'momentary_release', 0x00dc: 'momentary_press', }; - if (msg.data.hasOwnProperty('presentValue')) { + if (msg.data.presentValue !== undefined) { const property = utils.postfixWithEndpointName('switch_type', msg, model, meta); result[property] = switchTypeLookup[msg.data['presentValue']]; } @@ -52,31 +52,31 @@ const fzPerenio = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty(2)) { + if (msg.data[2] !== undefined) { result['rms_current'] = msg.data[2]; } - if (msg.data.hasOwnProperty(3)) { + if (msg.data[3] !== undefined) { result['rms_voltage'] = msg.data[3]; } - if (msg.data.hasOwnProperty(4)) { + if (msg.data[4] !== undefined) { result['voltage_min'] = msg.data[4]; } - if (msg.data.hasOwnProperty(5)) { + if (msg.data[5] !== undefined) { result['voltage_max'] = msg.data[5]; } - if (msg.data.hasOwnProperty(10)) { + if (msg.data[10] !== undefined) { result['active_power'] = msg.data[10]; } - if (msg.data.hasOwnProperty(11)) { + if (msg.data[11] !== undefined) { result['power_max'] = msg.data[11]; } - if (msg.data.hasOwnProperty(14)) { + if (msg.data[14] !== undefined) { result['consumed_energy'] = msg.data[14]; } - if (msg.data.hasOwnProperty(15)) { + if (msg.data[15] !== undefined) { result['consumed_energy_limit'] = msg.data[15]; } - if (msg.data.hasOwnProperty(24)) { + if (msg.data[24] !== undefined) { result['rssi'] = msg.data[24]; } const powerOnStateLookup = { @@ -84,11 +84,11 @@ const fzPerenio = { 1: 'on', 2: 'previous', }; - if (msg.data.hasOwnProperty(0)) { + if (msg.data[0] !== undefined) { // @ts-expect-error ignore result['default_on_off_state'] = powerOnStateLookup[msg.data[0]]; } - if (msg.data.hasOwnProperty(1)) { + if (msg.data[1] !== undefined) { if (msg.data[1] == 0) { result['alarm_voltage_min'] = false; result['alarm_voltage_max'] = false; @@ -199,7 +199,7 @@ const tzPerenio = { key: ['state', 'on_time', 'off_wait_time'], convertSet: async (entity, key, value, meta) => { // @ts-expect-error ignore - const state = meta.message.hasOwnProperty('state') ? meta.message.state.toLowerCase() : null; + const state = meta.message.state !== undefined ? meta.message.state.toLowerCase() : null; utils.validateValue(state, ['toggle', 'off', 'on']); const alarmVoltageMin = meta.state[`alarm_voltage_min${meta.endpoint_name ? `_${meta.endpoint_name}` : ''}`]; const alarmVoltageMax = meta.state[`alarm_voltage_max${meta.endpoint_name ? `_${meta.endpoint_name}` : ''}`]; @@ -207,9 +207,9 @@ const tzPerenio = { if (alarmVoltageMin || alarmVoltageMax || alarmPowerMax) { return {state: {state: 'OFF'}}; } - if (state === 'on' && (meta.message.hasOwnProperty('on_time') || meta.message.hasOwnProperty('off_wait_time'))) { - const onTime = meta.message.hasOwnProperty('on_time') ? meta.message.on_time : 0; - const offWaitTime = meta.message.hasOwnProperty('off_wait_time') ? meta.message.off_wait_time : 0; + if (state === 'on' && (meta.message.on_time !== undefined || meta.message.off_wait_time !== undefined)) { + const onTime = meta.message.on_time !== undefined ? meta.message.on_time : 0; + const offWaitTime = meta.message.off_wait_time !== undefined ? meta.message.off_wait_time : 0; if (typeof onTime !== 'number') { throw Error('The on_time value must be a number!'); diff --git a/src/devices/schneider_electric.ts b/src/devices/schneider_electric.ts index ffe72f2aceaec..a9a4065450934 100644 --- a/src/devices/schneider_electric.ts +++ b/src/devices/schneider_electric.ts @@ -359,63 +359,63 @@ const fzLocal = { const acFrequencyDivisor = attr['acFrequencyDivisor']; const powerDivisor = attr['powerDivisor']; - if (attr.hasOwnProperty('rmsVoltage')) { + if (attr.rmsVoltage !== undefined) { ret['voltage_phase_a'] = attr['rmsVoltage'] / acVoltageDivisor; } - if (attr.hasOwnProperty('rmsVoltagePhB')) { + if (attr.rmsVoltagePhB !== undefined) { ret['voltage_phase_b'] = attr['rmsVoltagePhB'] / acVoltageDivisor; } - if (attr.hasOwnProperty('rmsVoltagePhC')) { + if (attr.rmsVoltagePhC !== undefined) { ret['voltage_phase_c'] = attr['rmsVoltagePhC'] / acVoltageDivisor; } - if (attr.hasOwnProperty('19200')) { + if (attr['19200'] !== undefined) { ret['voltage_phase_ab'] = attr['19200'] / acVoltageDivisor; } - if (attr.hasOwnProperty('19456')) { + if (attr['19456'] !== undefined) { ret['voltage_phase_bc'] = attr['19456'] / acVoltageDivisor; } - if (attr.hasOwnProperty('19712')) { + if (attr['19712'] !== undefined) { ret['voltage_phase_ca'] = attr['19712'] / acVoltageDivisor; } - if (attr.hasOwnProperty('rmsCurrent')) { + if (attr.rmsCurrent !== undefined) { ret['current_phase_a'] = attr['rmsCurrent'] / acCurrentDivisor; } - if (attr.hasOwnProperty('rmsCurrentPhB')) { + if (attr.rmsCurrentPhB !== undefined) { ret['current_phase_b'] = attr['rmsCurrentPhB'] / acCurrentDivisor; } - if (attr.hasOwnProperty('rmsCurrentPhC')) { + if (attr.rmsCurrentPhC !== undefined) { ret['current_phase_c'] = attr['rmsCurrentPhC'] / acCurrentDivisor; } - if (attr.hasOwnProperty('totalActivePower')) { + if (attr.totalActivePower !== undefined) { ret['power'] = (attr['totalActivePower'] * 1000) / powerDivisor; } - if (attr.hasOwnProperty('totalApparentPower')) { + if (attr.totalApparentPower !== undefined) { ret['power_apparent'] = (attr['totalApparentPower'] * 1000) / powerDivisor; } - if (attr.hasOwnProperty('acFrequency')) { + if (attr.acFrequency !== undefined) { ret['ac_frequency'] = attr['acFrequency'] / acFrequencyDivisor; } - if (attr.hasOwnProperty('activePower')) { + if (attr.activePower !== undefined) { ret['power_phase_a'] = (attr['activePower'] * 1000) / powerDivisor; } - if (attr.hasOwnProperty('activePowerPhB')) { + if (attr.activePowerPhB !== undefined) { ret['power_phase_b'] = (attr['activePowerPhB'] * 1000) / powerDivisor; } - if (attr.hasOwnProperty('activePowerPhC')) { + if (attr.activePowerPhC !== undefined) { ret['power_phase_c'] = (attr['activePowerPhC'] * 1000) / powerDivisor; } break; @@ -424,27 +424,27 @@ const fzLocal = { // seMetering const divisor = attr['divisor']; - if (attr.hasOwnProperty('currentSummDelivered')) { + if (attr.currentSummDelivered !== undefined) { const val = attr['currentSummDelivered']; ret['energy'] = ((parseInt(val[0]) << 32) + parseInt(val[1])) / divisor; } - if (attr.hasOwnProperty('16652')) { + if (attr['16652'] !== undefined) { const val = attr['16652']; ret['energy_phase_a'] = ((parseInt(val[0]) << 32) + parseInt(val[1])) / divisor; } - if (attr.hasOwnProperty('16908')) { + if (attr['16908'] !== undefined) { const val = attr['16908']; ret['energy_phase_b'] = ((parseInt(val[0]) << 32) + parseInt(val[1])) / divisor; } - if (attr.hasOwnProperty('17164')) { + if (attr['17164'] !== undefined) { const val = attr['17164']; ret['energy_phase_c'] = ((parseInt(val[0]) << 32) + parseInt(val[1])) / divisor; } - if (attr.hasOwnProperty('powerFactor')) { + if (attr.powerFactor !== undefined) { ret['power_factor'] = attr['powerFactor']; } diff --git a/src/devices/shinasystem.ts b/src/devices/shinasystem.ts index cda75e8931e75..0ca352f838f39 100644 --- a/src/devices/shinasystem.ts +++ b/src/devices/shinasystem.ts @@ -47,7 +47,7 @@ const fzLocal = { cluster: 'genOnOff', type: ['attributeReport', 'readResponse'], convert: async (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('onOff')) { + if (msg.data.onOff !== undefined) { const endpoint = meta.device.getEndpoint(1); await endpoint.read('genOnOff', [0x9007]); // for update : close_remain_timeout return {gas_valve_state: msg.data['onOff'] === 1 ? 'OPEN' : 'CLOSE'}; diff --git a/src/devices/siglis.ts b/src/devices/siglis.ts index bec6793d65143..c75605b7dd00e 100644 --- a/src/devices/siglis.ts +++ b/src/devices/siglis.ts @@ -91,7 +91,7 @@ const buttonEventExposes = e.action([ ]); function checkOption(device: Zh.Device, options: KeyValue, key: string) { - if (options != null && options.hasOwnProperty(key)) { + if (options != null && options[key] !== undefined) { if (options[key] === 'true') { return true; } else if (options[key] === 'false') { diff --git a/src/devices/sinope.ts b/src/devices/sinope.ts index 461f55deb374e..5c89ddeb7f009 100644 --- a/src/devices/sinope.ts +++ b/src/devices/sinope.ts @@ -40,72 +40,72 @@ const fzLocal = { const occupancyLookup = {0: 'unoccupied', 1: 'occupied'}; const cycleOutputLookup = {15: '15_sec', 300: '5_min', 600: '10_min', 900: '15_min', 1200: '20_min', 1800: '30_min', 65535: 'off'}; - if (msg.data.hasOwnProperty('1024')) { + if (msg.data['1024'] !== undefined) { result.thermostat_occupancy = utils.getFromLookup(msg.data['1024'], occupancyLookup); } - if (msg.data.hasOwnProperty('SinopeOccupancy')) { + if (msg.data.SinopeOccupancy !== undefined) { result.thermostat_occupancy = utils.getFromLookup(msg.data['SinopeOccupancy'], occupancyLookup); } - if (msg.data.hasOwnProperty('1025')) { + if (msg.data['1025'] !== undefined) { result.main_cycle_output = utils.getFromLookup(msg.data['1025'], cycleOutputLookup); } - if (msg.data.hasOwnProperty('SinopeMainCycleOutput')) { + if (msg.data.SinopeMainCycleOutput !== undefined) { result.main_cycle_output = utils.getFromLookup(msg.data['SinopeMainCycleOutput'], cycleOutputLookup); } - if (msg.data.hasOwnProperty('1026')) { + if (msg.data['1026'] !== undefined) { const lookup = {0: 'on_demand', 1: 'sensing'}; result.backlight_auto_dim = utils.getFromLookup(msg.data['1026'], lookup); } - if (msg.data.hasOwnProperty('SinopeBacklight')) { + if (msg.data.SinopeBacklight !== undefined) { const lookup = {0: 'on_demand', 1: 'sensing'}; result.backlight_auto_dim = utils.getFromLookup(msg.data['SinopeBacklight'], lookup); } - if (msg.data.hasOwnProperty('1028')) { + if (msg.data['1028'] !== undefined) { result.aux_cycle_output = utils.getFromLookup(msg.data['1028'], cycleOutputLookup); } - if (msg.data.hasOwnProperty('localTemp')) { + if (msg.data.localTemp !== undefined) { result.local_temperature = precisionRound(msg.data['localTemp'], 2) / 100; } - if (msg.data.hasOwnProperty('localTemperatureCalibration')) { + if (msg.data.localTemperatureCalibration !== undefined) { result.local_temperature_calibration = precisionRound(msg.data['localTemperatureCalibration'], 2) / 10; } - if (msg.data.hasOwnProperty('outdoorTemp')) { + if (msg.data.outdoorTemp !== undefined) { result.outdoor_temperature = precisionRound(msg.data['outdoorTemp'], 2) / 100; } - if (msg.data.hasOwnProperty('occupiedHeatingSetpoint')) { + if (msg.data.occupiedHeatingSetpoint !== undefined) { result.occupied_heating_setpoint = precisionRound(msg.data['occupiedHeatingSetpoint'], 2) / 100; } - if (msg.data.hasOwnProperty('unoccupiedHeatingSetpoint')) { + if (msg.data.unoccupiedHeatingSetpoint !== undefined) { result.unoccupied_heating_setpoint = precisionRound(msg.data['unoccupiedHeatingSetpoint'], 2) / 100; } - if (msg.data.hasOwnProperty('occupiedCoolingSetpoint')) { + if (msg.data.occupiedCoolingSetpoint !== undefined) { result.occupied_cooling_setpoint = precisionRound(msg.data['occupiedCoolingSetpoint'], 2) / 100; } - if (msg.data.hasOwnProperty('unoccupiedCoolingSetpoint')) { + if (msg.data.unoccupiedCoolingSetpoint !== undefined) { result.unoccupied_cooling_setpoint = precisionRound(msg.data['unoccupiedCoolingSetpoint'], 2) / 100; } - if (msg.data.hasOwnProperty('ctrlSeqeOfOper')) { + if (msg.data.ctrlSeqeOfOper !== undefined) { result.control_sequence_of_operation = constants.thermostatControlSequenceOfOperations[msg.data['ctrlSeqeOfOper']]; } - if (msg.data.hasOwnProperty('systemMode')) { + if (msg.data.systemMode !== undefined) { result.system_mode = constants.thermostatSystemModes[msg.data['systemMode']]; } - if (msg.data.hasOwnProperty('pIHeatingDemand')) { + if (msg.data.pIHeatingDemand !== undefined) { result.pi_heating_demand = precisionRound(msg.data['pIHeatingDemand'], 0); } - if (msg.data.hasOwnProperty('minHeatSetpointLimit')) { + if (msg.data.minHeatSetpointLimit !== undefined) { result.min_heat_setpoint_limit = precisionRound(msg.data['minHeatSetpointLimit'], 2) / 100; } - if (msg.data.hasOwnProperty('maxHeatSetpointLimit')) { + if (msg.data.maxHeatSetpointLimit !== undefined) { result.max_heat_setpoint_limit = precisionRound(msg.data['maxHeatSetpointLimit'], 2) / 100; } - if (msg.data.hasOwnProperty('absMinHeatSetpointLimit')) { + if (msg.data.absMinHeatSetpointLimit !== undefined) { result.abs_min_heat_setpoint_limit = precisionRound(msg.data['absMinHeatSetpointLimit'], 2) / 100; } - if (msg.data.hasOwnProperty('absMaxHeatSetpointLimit')) { + if (msg.data.absMaxHeatSetpointLimit !== undefined) { result.abs_max_heat_setpoint_limit = precisionRound(msg.data['absMaxHeatSetpointLimit'], 2) / 100; } - if (msg.data.hasOwnProperty('pIHeatingDemand')) { + if (msg.data.pIHeatingDemand !== undefined) { result.running_state = msg.data['pIHeatingDemand'] >= 10 ? 'heat' : 'idle'; } return result; @@ -116,7 +116,7 @@ const fzLocal = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty('presentValue')) { + if (msg.data.presentValue !== undefined) { let x = msg.data['presentValue']; if (x == -1) { result.tank_level = 0; @@ -147,84 +147,84 @@ const fzLocal = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty('GFCiStatus')) { + if (msg.data.GFCiStatus !== undefined) { const lookup = {0: 'off', 1: 'on'}; result.gfci_status = utils.getFromLookup(msg.data['GFCiStatus'], lookup); } - if (msg.data.hasOwnProperty('floorLimitStatus')) { + if (msg.data.floorLimitStatus !== undefined) { const lookup = {0: 'off', 1: 'on'}; result.floor_limit_status = utils.getFromLookup(msg.data['floorLimitStatus'], lookup); } - if (msg.data.hasOwnProperty('secondScreenBehavior')) { + if (msg.data.secondScreenBehavior !== undefined) { const lookup = {0: 'auto', 1: 'setpoint', 2: 'outdoor temp'}; result.second_display_mode = utils.getFromLookup(msg.data['secondScreenBehavior'], lookup); } - if (msg.data.hasOwnProperty('outdoorTempToDisplayTimeout')) { + if (msg.data.outdoorTempToDisplayTimeout !== undefined) { result.outdoor_temperature_timeout = msg.data['outdoorTempToDisplayTimeout']; // DEPRECATED: Use Second Display Mode or control via set outdoorTempToDisplayTimeout result.enable_outdoor_temperature = msg.data['outdoorTempToDisplayTimeout'] === 12 ? 'OFF' : 'ON'; } - if (msg.data.hasOwnProperty('outdoorTempToDisplay')) { + if (msg.data.outdoorTempToDisplay !== undefined) { result.thermostat_outdoor_temperature = precisionRound(msg.data['outdoorTempToDisplay'], 2) / 100; } - if (msg.data.hasOwnProperty('currentTimeToDisplay')) { + if (msg.data.currentTimeToDisplay !== undefined) { result.current_time_to_display = msg.data['currentTimeToDisplay']; } - if (msg.data.hasOwnProperty('floorControlMode')) { + if (msg.data.floorControlMode !== undefined) { const lookup = {1: 'ambiant', 2: 'floor'}; result.floor_control_mode = utils.getFromLookup(msg.data['floorControlMode'], lookup); } - if (msg.data.hasOwnProperty('ambiantMaxHeatSetpointLimit')) { + if (msg.data.ambiantMaxHeatSetpointLimit !== undefined) { result.ambiant_max_heat_setpoint = msg.data['ambiantMaxHeatSetpointLimit'] / 100.0; if (result.ambiant_max_heat_setpoint === -327.68) { result.ambiant_max_heat_setpoint = 'off'; } } - if (msg.data.hasOwnProperty('floorMinHeatSetpointLimit')) { + if (msg.data.floorMinHeatSetpointLimit !== undefined) { result.floor_min_heat_setpoint = msg.data['floorMinHeatSetpointLimit'] / 100.0; if (result.floor_min_heat_setpoint === -327.68) { result.floor_min_heat_setpoint = 'off'; } } - if (msg.data.hasOwnProperty('floorMaxHeatSetpointLimit')) { + if (msg.data.floorMaxHeatSetpointLimit !== undefined) { result.floor_max_heat_setpoint = msg.data['floorMaxHeatSetpointLimit'] / 100.0; if (result.floor_max_heat_setpoint === -327.68) { result.floor_max_heat_setpoint = 'off'; } } - if (msg.data.hasOwnProperty('temperatureSensor')) { + if (msg.data.temperatureSensor !== undefined) { const lookup = {0: '10k', 1: '12k'}; result.floor_temperature_sensor = utils.getFromLookup(msg.data['temperatureSensor'], lookup); } - if (msg.data.hasOwnProperty('timeFormatToDisplay')) { + if (msg.data.timeFormatToDisplay !== undefined) { const lookup = {0: '24h', 1: '12h'}; result.time_format = utils.getFromLookup(msg.data['timeFormatToDisplay'], lookup); } - if (msg.data.hasOwnProperty('connectedLoad')) { + if (msg.data.connectedLoad !== undefined) { result.connected_load = msg.data['connectedLoad']; } - if (msg.data.hasOwnProperty('auxConnectedLoad')) { + if (msg.data.auxConnectedLoad !== undefined) { result.aux_connected_load = msg.data['auxConnectedLoad']; if (result.aux_connected_load == 65535) { result.aux_connected_load = 'disabled'; } } - if (msg.data.hasOwnProperty('pumpProtection')) { + if (msg.data.pumpProtection !== undefined) { result.pump_protection = msg.data['pumpProtection'] == 1 ? 'ON' : 'OFF'; } - if (msg.data.hasOwnProperty('dimmerTimmer')) { + if (msg.data.dimmerTimmer !== undefined) { result.timer_seconds = msg.data['dimmerTimmer']; } - if (msg.data.hasOwnProperty('ledIntensityOn')) { + if (msg.data.ledIntensityOn !== undefined) { result.led_intensity_on = msg.data['ledIntensityOn']; } - if (msg.data.hasOwnProperty('ledIntensityOff')) { + if (msg.data.ledIntensityOff !== undefined) { result.led_intensity_off = msg.data['ledIntensityOff']; } - if (msg.data.hasOwnProperty('minimumBrightness')) { + if (msg.data.minimumBrightness !== undefined) { result.minimum_brightness = msg.data['minimumBrightness']; } - if (msg.data.hasOwnProperty('actionReport')) { + if (msg.data.actionReport !== undefined) { const lookup = { 1: 'up_clickdown', 2: 'up_single', @@ -237,11 +237,11 @@ const fzLocal = { }; result.action = utils.getFromLookup(msg.data['actionReport'], lookup); } - if (msg.data.hasOwnProperty('keypadLockout')) { + if (msg.data.keypadLockout !== undefined) { const lookup = {0: 'unlock', 1: 'lock'}; result.keypad_lockout = utils.getFromLookup(msg.data['keypadLockout'], lookup); } - if (msg.data.hasOwnProperty('drConfigWaterTempMin')) { + if (msg.data.drConfigWaterTempMin !== undefined) { result.low_water_temp_protection = msg.data['drConfigWaterTempMin']; } return result; @@ -374,7 +374,7 @@ const tzLocal = { const lookup = {ambiant: 1, floor: 2}; value = value.toLowerCase(); // @ts-expect-error ignore - if (lookup.hasOwnProperty(value)) { + if (lookup[value] !== undefined) { await entity.write('manuSpecificSinope', {floorControlMode: utils.getFromLookup(value, lookup)}); } return {readAfterWriteTime: 250, state: {floor_control_mode: value}}; @@ -438,7 +438,7 @@ const tzLocal = { const lookup = {'10k': 0, '12k': 1}; value = value.toLowerCase(); // @ts-expect-error ignore - if (lookup.hasOwnProperty(value)) { + if (lookup[value] !== undefined) { await entity.write('manuSpecificSinope', {temperatureSensor: utils.getFromLookup(value, lookup)}); } return {readAfterWriteTime: 250, state: {floor_temperature_sensor: value}}; @@ -450,16 +450,8 @@ const tzLocal = { time_format: { key: ['time_format'], convertSet: async (entity, key, value, meta) => { - if (typeof value !== 'string') { - return; - } - const lookup = {'24h': 0, '12h': 1}; - value = value.toLowerCase(); - utils.assertString(value); - if (lookup.hasOwnProperty(value)) { - await entity.write('manuSpecificSinope', {timeFormatToDisplay: utils.getFromLookup(value, lookup)}, manuSinope); - return {readAfterWriteTime: 250, state: {time_format: value}}; - } + await entity.write('manuSpecificSinope', {timeFormatToDisplay: utils.getFromLookup(value, {'24h': 0, '12h': 1})}, manuSinope); + return {readAfterWriteTime: 250, state: {time_format: value}}; }, convertGet: async (entity, key, meta) => { await entity.read('manuSpecificSinope', ['timeFormatToDisplay'], manuSinope); diff --git a/src/devices/sonoff.ts b/src/devices/sonoff.ts index c342f117828cc..b9c42f329c10d 100644 --- a/src/devices/sonoff.ts +++ b/src/devices/sonoff.ts @@ -42,7 +42,7 @@ const fzLocal = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty('currentLevel')) { + if (msg.data.currentLevel !== undefined) { result.light_indicator_level = msg.data['currentLevel']; } }, @@ -506,7 +506,7 @@ const sonoffExtend = { convert: (model, msg, publish, options, meta) => { const lookup: KeyValue = {edge: 0, pulse: 1, 'following(off)': 2, 'following(on)': 130}; // logger.debug(`from zigbee msg.data['externalTriggerMode'] ${msg.data['externalTriggerMode']}`, NS); - if (msg.data.hasOwnProperty('externalTriggerMode')) { + if (msg.data.externalTriggerMode !== undefined) { let switchType = 'edge'; for (const name in lookup) { if (lookup[name] === msg.data['externalTriggerMode']) { diff --git a/src/devices/stelpro.ts b/src/devices/stelpro.ts index 2c8a6449bdfa8..2488d71b667e8 100644 --- a/src/devices/stelpro.ts +++ b/src/devices/stelpro.ts @@ -13,7 +13,7 @@ const fzLocal = { cluster: 'hvacThermostat', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('16392')) { + if (msg.data['16392'] !== undefined) { return {power: msg.data['16392']}; } }, @@ -22,7 +22,7 @@ const fzLocal = { cluster: 'hvacThermostat', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('16393')) { + if (msg.data['16393'] !== undefined) { return {energy: parseFloat(msg.data['16393']) / 1000}; } }, diff --git a/src/devices/sunricher.ts b/src/devices/sunricher.ts index 063dc156e5301..621949582de65 100644 --- a/src/devices/sunricher.ts +++ b/src/devices/sunricher.ts @@ -54,11 +54,7 @@ const fzLocal = { 0x42: 'b_g_r', 0x40: 'rgb_release', }; - if (!lookup.hasOwnProperty(commandID)) { - logger.error(`Missing command '0x${commandID.toString(16)}'`, NS); - } else { - return {action: utils.getFromLookup(commandID, lookup)}; - } + return {action: utils.getFromLookup(commandID, lookup)}; }, } satisfies Fz.Converter, }; diff --git a/src/devices/tuya.ts b/src/devices/tuya.ts index f3020658328b3..d91699be62842 100644 --- a/src/devices/tuya.ts +++ b/src/devices/tuya.ts @@ -133,7 +133,7 @@ const storeLocal = { // Only publish if the set is complete otherwise discard everything. if (sign !== null && power !== null && current !== null && powerFactor !== null) { const signedPowerKey = 'signed_power_' + channel; - const signedPower = options.hasOwnProperty(signedPowerKey) ? options[signedPowerKey] : false; + const signedPower = options[signedPowerKey] !== undefined ? options[signedPowerKey] : false; if (signedPower) { result['power_' + channel] = sign * power; result['energy_flow_' + channel] = 'sign'; @@ -193,7 +193,7 @@ const convLocal = { const result = {}; priv['sign_' + channel] = v == 1 ? -1 : +1; const lateEnergyFlowKey = 'late_energy_flow_' + channel; - const lateEnergyFlow = options.hasOwnProperty(lateEnergyFlowKey) ? options[lateEnergyFlowKey] : false; + const lateEnergyFlow = options[lateEnergyFlowKey] !== undefined ? options[lateEnergyFlowKey] : false; if (lateEnergyFlow) { priv.flush(result, channel, options); } @@ -240,7 +240,7 @@ const convLocal = { const result = {}; priv['power_factor_' + channel] = v; const lateEnergyFlowKey = 'late_energy_flow_' + channel; - const lateEnergyFlow = options.hasOwnProperty(lateEnergyFlowKey) ? options[lateEnergyFlowKey] : false; + const lateEnergyFlow = options[lateEnergyFlowKey] !== undefined ? options[lateEnergyFlowKey] : false; if (!lateEnergyFlow) { priv.flush(result, channel, options); } @@ -594,7 +594,7 @@ const fzLocal = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValue = {}; - if (msg.data.hasOwnProperty('57355')) { + if (msg.data['57355'] !== undefined) { result.temperature_unit = utils.getFromLookup(msg.data['57355'], {'0': 'celsius', '1': 'fahrenheit'}); } return result; diff --git a/src/devices/ubisys.ts b/src/devices/ubisys.ts index 0b59b8dc9b2ee..9252417a1b95b 100644 --- a/src/devices/ubisys.ts +++ b/src/devices/ubisys.ts @@ -55,7 +55,7 @@ const ubisys = { cluster: 'manuSpecificUbisysDimmerSetup', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('capabilities')) { + if (msg.data.capabilities !== undefined) { const capabilities = msg.data.capabilities; const forwardPhaseControl = capabilities & 1; const reversePhaseControl = (capabilities & 2) >>> 1; @@ -70,7 +70,7 @@ const ubisys = { capabilities_overload_detection: overloadDetection ? true : false, }; } - if (msg.data.hasOwnProperty('status')) { + if (msg.data.status !== undefined) { const status = msg.data.status; const forwardPhaseControl = status & 1; const reversePhaseControl = (status & 2) >>> 1; @@ -85,7 +85,7 @@ const ubisys = { status_inductive_load: inductiveLoad ? true : false, }; } - if (msg.data.hasOwnProperty('mode')) { + if (msg.data.mode !== undefined) { const mode = msg.data.mode; const phaseControl = mode & 3; const phaseControlValues = {0: 'automatic', 1: 'forward', 2: 'reverse'}; @@ -99,7 +99,7 @@ const ubisys = { cluster: 'genLevelCtrl', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('ubisysMinimumOnLevel')) { + if (msg.data.ubisysMinimumOnLevel !== undefined) { return {minimum_on_level: msg.data.ubisysMinimumOnLevel}; } }, @@ -108,7 +108,7 @@ const ubisys = { cluster: 'manuSpecificUbisysDeviceSetup', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - const result = (meta.state.hasOwnProperty('configure_device_setup') ? meta.state.configure_device_setup : {}) as KeyValue; + const result = (meta.state.configure_device_setup !== undefined ? meta.state.configure_device_setup : {}) as KeyValue; if (msg.data['inputConfigurations'] != null) { result['input_configurations'] = msg.data['inputConfigurations']; } @@ -151,7 +151,7 @@ const ubisys = { if (jsonAttr.startsWith('ubisys')) { jsonAttr = jsonAttr.substring(6, 1).toLowerCase + jsonAttr.substring(7); } - if (value.hasOwnProperty(jsonAttr)) { + if (value[jsonAttr] !== undefined) { let attrValue = value[jsonAttr]; if (converterFunc) { attrValue = converterFunc(attrValue); @@ -165,7 +165,7 @@ const ubisys = { } }; const stepsPerSecond = value.steps_per_second || 50; - const hasCalibrate = value.hasOwnProperty('calibrate'); + const hasCalibrate = value.calibrate !== undefined; // cancel any running calibration // @ts-expect-error ignore let mode = (await entity.read('closuresWindowCovering', ['windowCoveringMode'])).windowCoveringMode; @@ -360,7 +360,7 @@ const ubisys = { logger.debug(`ubisys: using writeStructure for '${meta.options.friendly_name}'.`, NS); } - if (value.hasOwnProperty('input_configurations')) { + if (value.input_configurations !== undefined) { // example: [0, 0, 0, 0] if (useWriteStruct) { await devMgmtEp.writeStructured( @@ -387,7 +387,7 @@ const ubisys = { } } - if (value.hasOwnProperty('input_actions')) { + if (value.input_actions !== undefined) { // example (default for C4): [[0,13,1,6,0,2], [1,13,2,6,0,2], [2,13,3,6,0,2], [3,13,4,6,0,2]] if (useWriteStruct) { await devMgmtEp.writeStructured( @@ -414,7 +414,7 @@ const ubisys = { } } - if (value.hasOwnProperty('input_action_templates')) { + if (value.input_action_templates !== undefined) { const templateTypes = { // source: "ZigBee Device Physical Input Configurations Integrator’s Guide" // (can be obtained directly from ubisys upon request) @@ -536,10 +536,10 @@ const ubisys = { ); } - if (template.hasOwnProperty('input')) { + if (template.input !== undefined) { input = template.input; } - if (template.hasOwnProperty('endpoint')) { + if (template.endpoint !== undefined) { endpoint = template.endpoint; } // C4 cover endpoints only start at 5 @@ -554,16 +554,16 @@ const ubisys = { inputActions = templateType.getInputActions(input, endpoint, template); } else { // scene(s) (always single input) - if (!template.hasOwnProperty('scene_id')) { + if (template.scene_id === undefined) { throw new Error(`input_action_templates: Need an attribute 'scene_id' for '${template.type}'`); } - if (template.hasOwnProperty('group_id')) { + if (template.group_id !== undefined) { groupId = template.group_id; } inputActions = templateType.getInputActions(input, endpoint, groupId, template.scene_id); - if (template.hasOwnProperty('scene_id_2')) { - if (template.hasOwnProperty('group_id_2')) { + if (template.scene_id_2 !== undefined) { + if (template.group_id_2 !== undefined) { groupId = template.group_id_2; } inputActions = inputActions.concat(templateType.getInputActions2(input, endpoint, groupId, template.scene_id_2)); @@ -571,7 +571,7 @@ const ubisys = { } } else { // double inputs - input = template.hasOwnProperty('inputs') ? template.inputs : [input, input + 1]; + input = template.inputs !== undefined ? template.inputs : [input, input + 1]; inputActions = templateType.getInputActions(input, endpoint, template); } resultingInputActions = resultingInputActions.concat(inputActions); diff --git a/src/devices/wirenboard.ts b/src/devices/wirenboard.ts index 2890760db03aa..47424ac6ef1d0 100644 --- a/src/devices/wirenboard.ts +++ b/src/devices/wirenboard.ts @@ -33,7 +33,7 @@ const fzLocal = { cluster: 'msOccupancySensing', type: ['readResponse', 'attributeReport'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('sprutOccupancyLevel')) { + if (msg.data.sprutOccupancyLevel !== undefined) { return {occupancy_level: msg.data['sprutOccupancyLevel']}; } }, @@ -42,7 +42,7 @@ const fzLocal = { cluster: 'sprutVoc', type: ['readResponse', 'attributeReport'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('voc')) { + if (msg.data.voc !== undefined) { return {voc: msg.data['voc']}; } }, @@ -51,7 +51,7 @@ const fzLocal = { cluster: 'sprutNoise', type: ['readResponse', 'attributeReport'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('noise')) { + if (msg.data.noise !== undefined) { return {noise: msg.data['noise'].toFixed(2)}; } }, @@ -60,7 +60,7 @@ const fzLocal = { cluster: 'sprutNoise', type: ['readResponse', 'attributeReport'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('noiseDetected')) { + if (msg.data.noiseDetected !== undefined) { return {noise_detected: msg.data['noiseDetected'] === 1}; } }, @@ -97,10 +97,10 @@ const fzLocal = { cluster: 'msCO2', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('sprutCO2AutoCalibration')) { + if (msg.data.sprutCO2AutoCalibration !== undefined) { return {co2_autocalibration: switchActionValues[msg.data['sprutCO2AutoCalibration']]}; } - if (msg.data.hasOwnProperty('sprutCO2Calibration')) { + if (msg.data.sprutCO2Calibration !== undefined) { return {co2_manual_calibration: switchActionValues[msg.data['sprutCO2Calibration']]}; } }, @@ -109,7 +109,7 @@ const fzLocal = { cluster: 'msRelativeHumidity', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('sprutHeater')) { + if (msg.data.sprutHeater !== undefined) { return {th_heater: switchActionValues[msg.data['sprutHeater']]}; } }, diff --git a/src/devices/woolley.ts b/src/devices/woolley.ts index d02b2b84bc6c7..e4049841bb783 100644 --- a/src/devices/woolley.ts +++ b/src/devices/woolley.ts @@ -20,7 +20,7 @@ const fzLocal = { ]; const payload: KeyValue = {}; for (const entry of lookup) { - if (msg.data.hasOwnProperty(entry.key)) { + if (msg.data[entry.key] !== undefined) { const value = msg.data[entry.key] / 1000; payload[entry.name] = value; } diff --git a/src/devices/xyzroe.ts b/src/devices/xyzroe.ts index 44329792c3046..8298b213b9a5c 100644 --- a/src/devices/xyzroe.ts +++ b/src/devices/xyzroe.ts @@ -107,9 +107,9 @@ const tzLocal = { const state = utils.isString(meta.message.state) ? meta.message.state.toLowerCase() : null; utils.validateValue(state, ['toggle', 'off', 'on']); - if (state === 'on' && (meta.message.hasOwnProperty('on_time') || meta.message.hasOwnProperty('off_wait_time'))) { - const onTime = meta.message.hasOwnProperty('on_time') ? meta.message.on_time : 0; - const offWaitTime = meta.message.hasOwnProperty('off_wait_time') ? meta.message.off_wait_time : 0; + if (state === 'on' && (meta.message.on_time !== undefined || meta.message.off_wait_time !== undefined)) { + const onTime = meta.message.on_time !== undefined ? meta.message.on_time : 0; + const offWaitTime = meta.message.off_wait_time !== undefined ? meta.message.off_wait_time : 0; if (typeof onTime !== 'number') { throw Error('The on_time value must be a number!'); @@ -228,7 +228,7 @@ const fzLocal = { payload[name] = utils.precisionRound(msg.data['presentValue'], 3); if (channel === 5) { payload[`uptime_${name}`] = utils.precisionRound(msg.data['presentValue'], 3); - } else if (msg.data.hasOwnProperty('description')) { + } else if (msg.data.description !== undefined) { const data1 = msg.data['description']; if (data1) { const data2 = data1.split(','); @@ -279,9 +279,9 @@ const fzLocal = { cluster: 'genOnOff', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('onOff')) { + if (msg.data.onOff !== undefined) { const payload: KeyValueAny = {}; - const endpointName = model.hasOwnProperty('endpoint') ? utils.getKey(model.endpoint(meta.device), msg.endpoint.ID) : msg.endpoint.ID; + const endpointName = model.endpoint !== undefined ? utils.getKey(model.endpoint(meta.device), msg.endpoint.ID) : msg.endpoint.ID; const state = msg.data['onOff'] === 1 ? 'OFF' : 'ON'; payload[`state_${endpointName}`] = state; return payload; diff --git a/src/lib/color.ts b/src/lib/color.ts index 48d03d702606a..f18c55dba84c0 100644 --- a/src/lib/color.ts +++ b/src/lib/color.ts @@ -58,7 +58,7 @@ export class ColorRGB { * @returns new ColoRGB object */ static fromObject(rgb: {red: number; green: number; blue: number}) { - if (!rgb.hasOwnProperty('red') || !rgb.hasOwnProperty('green') || !rgb.hasOwnProperty('blue')) { + if (rgb.red === undefined || rgb.green === undefined || rgb.blue === undefined) { throw new Error('One or more required properties missing. Required properties: "red", "green", "blue"'); } return new ColorRGB(rgb.red, rgb.green, rgb.blue); @@ -219,7 +219,7 @@ export class ColorXY { * @returns new ColorXY object */ static fromObject(xy: {x: number; y: number}): ColorXY { - if (!xy.hasOwnProperty('x') || !xy.hasOwnProperty('y')) { + if (xy.x === undefined || xy.y === undefined) { throw new Error('One or more required properties missing. Required properties: "x", "y"'); } return new ColorXY(xy.x, xy.y); @@ -341,7 +341,7 @@ class ColorHSV { * Create HSV color from object */ static fromObject(hsv: {hue?: number; saturation?: number; value: number}): ColorHSV { - if (!hsv.hasOwnProperty('hue') && !hsv.hasOwnProperty('saturation')) { + if (hsv.hue === undefined && hsv.saturation === undefined) { throw new Error('HSV color must specify at least hue or saturation.'); } return new ColorHSV(hsv.hue === undefined ? null : hsv.hue, hsv.saturation, hsv.value); @@ -353,7 +353,7 @@ class ColorHSV { * @returns color in HSV space */ static fromHSL(hsl: {hue: number; saturation: number; lightness: number}): ColorHSV { - if (!hsl.hasOwnProperty('hue') || !hsl.hasOwnProperty('saturation') || !hsl.hasOwnProperty('lightness')) { + if (hsl.hue === undefined || hsl.saturation === undefined || hsl.lightness === undefined) { throw new Error('One or more required properties missing. Required properties: "hue", "saturation", "lightness"'); } const retH = hsl.hue; @@ -518,7 +518,7 @@ class ColorHSV { */ static correctHue(hue: number, meta: Tz.Meta): number { const {options} = meta; - if (options.hasOwnProperty('hue_correction')) { + if (options.hue_correction !== undefined) { // @ts-expect-error ignore return this.interpolateHue(hue, options.hue_correction); } else { @@ -585,53 +585,53 @@ export class Color { */ // eslint-disable-next-line @typescript-eslint/no-explicit-any static fromConverterArg(value: any): Color { - if (value.hasOwnProperty('x') && value.hasOwnProperty('y')) { + if (value.x !== undefined && value.y !== undefined) { const xy = ColorXY.fromObject(value); return new Color(null, null, xy); - } else if (value.hasOwnProperty('r') && value.hasOwnProperty('g') && value.hasOwnProperty('b')) { + } else if (value.r !== undefined && value.g !== undefined && value.b !== undefined) { const rgb = new ColorRGB(value.r / 255, value.g / 255, value.b / 255); return new Color(null, rgb, null); - } else if (value.hasOwnProperty('rgb')) { + } else if (value.rgb !== undefined) { const [r, g, b] = value.rgb.split(',').map((i: string) => parseInt(i)); const rgb = new ColorRGB(r / 255, g / 255, b / 255); return new Color(null, rgb, null); - } else if (value.hasOwnProperty('hex')) { + } else if (value.hex !== undefined) { const rgb = ColorRGB.fromHex(value.hex); return new Color(null, rgb, null); } else if (typeof value === 'string' && value.startsWith('#')) { const rgb = ColorRGB.fromHex(value); return new Color(null, rgb, null); - } else if (value.hasOwnProperty('h') && value.hasOwnProperty('s') && value.hasOwnProperty('l')) { + } else if (value.h !== undefined && value.s !== undefined && value.l !== undefined) { const hsv = ColorHSV.fromHSL({hue: value.h, saturation: value.s, lightness: value.l}); return new Color(hsv, null, null); - } else if (value.hasOwnProperty('hsl')) { + } else if (value.hsl !== undefined) { const [h, s, l] = value.hsl.split(',').map((i: string) => parseInt(i)); const hsv = ColorHSV.fromHSL({hue: h, saturation: s, lightness: l}); return new Color(hsv, null, null); - } else if (value.hasOwnProperty('h') && value.hasOwnProperty('s') && value.hasOwnProperty('b')) { + } else if (value.h !== undefined && value.s !== undefined && value.b !== undefined) { const hsv = new ColorHSV(value.h, value.s, value.b); return new Color(hsv, null, null); - } else if (value.hasOwnProperty('hsb')) { + } else if (value.hsb !== undefined) { const [h, s, b] = value.hsb.split(',').map((i: string) => parseInt(i)); const hsv = new ColorHSV(h, s, b); return new Color(hsv, null, null); - } else if (value.hasOwnProperty('h') && value.hasOwnProperty('s') && value.hasOwnProperty('v')) { + } else if (value.h !== undefined && value.s !== undefined && value.v !== undefined) { const hsv = new ColorHSV(value.h, value.s, value.v); return new Color(hsv, null, null); - } else if (value.hasOwnProperty('hsv')) { + } else if (value.hsv !== undefined) { const [h, s, v] = value.hsv.split(',').map((i: string) => parseInt(i)); const hsv = new ColorHSV(h, s, v); return new Color(hsv, null, null); - } else if (value.hasOwnProperty('h') && value.hasOwnProperty('s')) { + } else if (value.h !== undefined && value.s !== undefined) { const hsv = new ColorHSV(value.h, value.s); return new Color(hsv, null, null); - } else if (value.hasOwnProperty('h')) { + } else if (value.h !== undefined) { const hsv = new ColorHSV(value.h); return new Color(hsv, null, null); - } else if (value.hasOwnProperty('s')) { + } else if (value.s !== undefined) { const hsv = new ColorHSV(null, value.s); return new Color(hsv, null, null); - } else if (value.hasOwnProperty('hue') || value.hasOwnProperty('saturation')) { + } else if (value.hue !== undefined || value.saturation !== undefined) { const hsv = ColorHSV.fromObject(value); return new Color(hsv, null, null); } else { @@ -673,16 +673,16 @@ export class Color { */ export function syncColorState(newState: KeyValueAny, oldState: KeyValueAny, endpoint: Zh.Endpoint | Zh.Group, options: KeyValue): KeyValueAny { const colorTargets = []; - const colorSync = options && options.hasOwnProperty('color_sync') ? options.color_sync : true; + const colorSync = options && options.color_sync !== undefined ? options.color_sync : true; const result: KeyValueAny = {}; const [colorTempMin, colorTempMax] = findColorTempRange(endpoint); // check if color sync is enabled if (!colorSync) { // copy newState.{color_mode,color,color_temp} - if (newState.hasOwnProperty('color_mode')) result.color_mode = newState.color_mode; - if (newState.hasOwnProperty('color')) result.color = newState.color; - if (newState.hasOwnProperty('color_temp')) result.color_temp = newState.color_temp; + if (newState.color_mode !== undefined) result.color_mode = newState.color_mode; + if (newState.color !== undefined) result.color = newState.color; + if (newState.color_temp !== undefined) result.color_temp = newState.color_temp; return result; } @@ -691,31 +691,28 @@ export function syncColorState(newState: KeyValueAny, oldState: KeyValueAny, end if (oldState === undefined) oldState = {}; // figure out current color_mode - if (newState.hasOwnProperty('color_mode')) { + if (newState.color_mode !== undefined) { result.color_mode = newState.color_mode; - } else if (oldState.hasOwnProperty('color_mode')) { + } else if (oldState.color_mode !== undefined) { result.color_mode = oldState.color_mode; } else { - result.color_mode = newState.hasOwnProperty('color_temp') - ? 'color_temp' - : newState.hasOwnProperty('color') && newState.color.hasOwnProperty('hue') - ? 'hs' - : 'xy'; + result.color_mode = + newState.color_temp !== undefined ? 'color_temp' : newState.color !== undefined && newState.color.hue !== undefined ? 'hs' : 'xy'; } // figure out target attributes - if (oldState.hasOwnProperty('color_temp') || newState.hasOwnProperty('color_temp')) { + if (oldState.color_temp !== undefined || newState.color_temp !== undefined) { colorTargets.push('color_temp'); } if ( - (oldState.hasOwnProperty('color') && oldState.color.hasOwnProperty('hue') && oldState.color.hasOwnProperty('saturation')) || - (newState.hasOwnProperty('color') && newState.color.hasOwnProperty('hue') && newState.color.hasOwnProperty('saturation')) + (oldState.color !== undefined && oldState.color.hue !== undefined && oldState.color.saturation !== undefined) || + (newState.color !== undefined && newState.color.hue !== undefined && newState.color.saturation !== undefined) ) { colorTargets.push('hs'); } if ( - (oldState.hasOwnProperty('color') && oldState.color.hasOwnProperty('x') && oldState.color.hasOwnProperty('y')) || - (newState.hasOwnProperty('color') && newState.color.hasOwnProperty('x') && newState.color.hasOwnProperty('y')) + (oldState.color !== undefined && oldState.color.x !== undefined && oldState.color.y !== undefined) || + (newState.color !== undefined && newState.color.x !== undefined && newState.color.y !== undefined) ) { colorTargets.push('xy'); } @@ -724,18 +721,18 @@ export function syncColorState(newState: KeyValueAny, oldState: KeyValueAny, end result.color = {}; switch (result.color_mode) { case 'hs': - if (newState.hasOwnProperty('color') && newState.color.hasOwnProperty('hue')) { + if (newState.color !== undefined && newState.color.hue !== undefined) { Object.assign(result.color, {hue: newState.color.hue}); - } else if (oldState.hasOwnProperty('color') && oldState.color.hasOwnProperty('hue')) { + } else if (oldState.color !== undefined && oldState.color.hue !== undefined) { Object.assign(result.color, {hue: oldState.color.hue}); } - if (newState.hasOwnProperty('color') && newState.color.hasOwnProperty('saturation')) { + if (newState.color !== undefined && newState.color.saturation !== undefined) { Object.assign(result.color, {saturation: newState.color.saturation}); - } else if (oldState.hasOwnProperty('color') && oldState.color.hasOwnProperty('saturation')) { + } else if (oldState.color !== undefined && oldState.color.saturation !== undefined) { Object.assign(result.color, {saturation: oldState.color.saturation}); } - if (result.color.hasOwnProperty('hue') && result.color.hasOwnProperty('saturation')) { + if (result.color.hue !== undefined && result.color.saturation !== undefined) { const hsv = new ColorHSV(result.color.hue, result.color.saturation); if (colorTargets.includes('color_temp')) { result.color_temp = clampColorTemp(precisionRound(hsv.toMireds(), 0), colorTempMin, colorTempMax); @@ -746,18 +743,18 @@ export function syncColorState(newState: KeyValueAny, oldState: KeyValueAny, end } break; case 'xy': - if (newState.hasOwnProperty('color') && newState.color.hasOwnProperty('x')) { + if (newState.color !== undefined && newState.color.x !== undefined) { Object.assign(result.color, {x: newState.color.x}); - } else if (oldState.hasOwnProperty('color') && oldState.color.hasOwnProperty('x')) { + } else if (oldState.color !== undefined && oldState.color.x !== undefined) { Object.assign(result.color, {x: oldState.color.x}); } - if (newState.hasOwnProperty('color') && newState.color.hasOwnProperty('y')) { + if (newState.color !== undefined && newState.color.y !== undefined) { Object.assign(result.color, {y: newState.color.y}); - } else if (oldState.hasOwnProperty('color') && oldState.color.hasOwnProperty('y')) { + } else if (oldState.color !== undefined && oldState.color.y !== undefined) { Object.assign(result.color, {y: oldState.color.y}); } - if (result.color.hasOwnProperty('x') && result.color.hasOwnProperty('y')) { + if (result.color.x !== undefined && result.color.y !== undefined) { const xy = new ColorXY(result.color.x, result.color.y); if (colorTargets.includes('color_temp')) { result.color_temp = clampColorTemp(precisionRound(xy.toMireds(), 0), colorTempMin, colorTempMax); @@ -768,13 +765,13 @@ export function syncColorState(newState: KeyValueAny, oldState: KeyValueAny, end } break; case 'color_temp': - if (newState.hasOwnProperty('color_temp')) { + if (newState.color_temp !== undefined) { result.color_temp = newState.color_temp; - } else if (oldState.hasOwnProperty('color_temp')) { + } else if (oldState.color_temp !== undefined) { result.color_temp = oldState.color_temp; } - if (result.hasOwnProperty('color_temp')) { + if (result.color_temp !== undefined) { const xy = ColorXY.fromMireds(result.color_temp); if (colorTargets.includes('xy')) { Object.assign(result.color, xy.rounded(4).toObject()); diff --git a/src/lib/develco.ts b/src/lib/develco.ts index 5732aa7b25f30..f806d640ba248 100644 --- a/src/lib/develco.ts +++ b/src/lib/develco.ts @@ -43,11 +43,11 @@ export const develcoModernExtend = { try { const data = await ep.read('genBasic', ['develcoPrimarySwVersion', 'develcoPrimaryHwVersion'], manufacturerOptions); - if (data.hasOwnProperty('develcoPrimarySwVersion')) { + if (data.develcoPrimarySwVersion !== undefined) { device.softwareBuildID = data.develcoPrimarySwVersion.join('.'); } - if (data.hasOwnProperty('develcoPrimaryHwVersion')) { + if (data.develcoPrimaryHwVersion !== undefined) { device.hardwareVersion = data.develcoPrimaryHwVersion.join('.'); } @@ -99,7 +99,7 @@ export const develcoModernExtend = { cluster: clusterName, type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty(attributeName)) { + if (msg.data[attributeName] !== undefined) { const vocPpb = parseFloat(msg.data[attributeName]); // from aqszb-110-technical-manual-air-quality-sensor-04-08-20.pdf page 6, section 2.2 voc @@ -149,7 +149,7 @@ export const develcoModernExtend = { cluster: clusterName, type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty(attributeName) && msg.data[attributeName] < 255) { + if (msg.data[attributeName] !== undefined && msg.data[attributeName] < 255) { const voltage = parseInt(msg.data[attributeName]); return {[propertyName]: voltage <= 25}; } diff --git a/src/lib/ikea.ts b/src/lib/ikea.ts index 5fd47d30e52f5..a998625588026 100644 --- a/src/lib/ikea.ts +++ b/src/lib/ikea.ts @@ -137,7 +137,7 @@ export function ikeaBattery(): ModernExtend { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const payload: KeyValue = {}; - if (msg.data.hasOwnProperty('batteryPercentageRemaining') && msg.data['batteryPercentageRemaining'] < 255) { + if (msg.data.batteryPercentageRemaining !== undefined && msg.data['batteryPercentageRemaining'] < 255) { // Some devices do not comply to the ZCL and report a // batteryPercentageRemaining of 100 when the battery is full (should be 200). let dividePercentage = true; @@ -251,7 +251,7 @@ export function ikeaAirPurifier(): ModernExtend { convert: (model, msg, publish, options, meta) => { const state: KeyValue = {}; - if (msg.data.hasOwnProperty('particulateMatter25Measurement')) { + if (msg.data.particulateMatter25Measurement !== undefined) { const pm25Property = postfixWithEndpointName('pm25', msg, model, meta); let pm25 = parseFloat(msg.data['particulateMatter25Measurement']); @@ -284,25 +284,25 @@ export function ikeaAirPurifier(): ModernExtend { state[airQualityProperty] = airQuality; } - if (msg.data.hasOwnProperty('filterRunTime')) { + if (msg.data.filterRunTime !== undefined) { // Filter needs to be replaced after 6 months state['replace_filter'] = parseInt(msg.data['filterRunTime']) >= 259200; state['filter_age'] = parseInt(msg.data['filterRunTime']); } - if (msg.data.hasOwnProperty('deviceRunTime')) { + if (msg.data.deviceRunTime !== undefined) { state['device_age'] = parseInt(msg.data['deviceRunTime']); } - if (msg.data.hasOwnProperty('controlPanelLight')) { + if (msg.data.controlPanelLight !== undefined) { state['led_enable'] = msg.data['controlPanelLight'] == 0; } - if (msg.data.hasOwnProperty('childLock')) { + if (msg.data.childLock !== undefined) { state['child_lock'] = msg.data['childLock'] == 0 ? 'UNLOCK' : 'LOCK'; } - if (msg.data.hasOwnProperty('fanSpeed')) { + if (msg.data.fanSpeed !== undefined) { let fanSpeed = msg.data['fanSpeed']; if (fanSpeed >= 10) { fanSpeed = ((fanSpeed - 5) * 2) / 10; @@ -313,7 +313,7 @@ export function ikeaAirPurifier(): ModernExtend { state['fan_speed'] = fanSpeed; } - if (msg.data.hasOwnProperty('fanMode')) { + if (msg.data.fanMode !== undefined) { let fanMode = msg.data['fanMode']; if (fanMode >= 10) { fanMode = (((fanMode - 5) * 2) / 10).toString(); @@ -500,12 +500,12 @@ export function tradfriOccupancy(): ModernExtend { const onlyWhenOnFlag = (msg.data.ctrlbits & 1) != 0; if ( onlyWhenOnFlag && - (!options || !options.hasOwnProperty('illuminance_below_threshold_check') || options.illuminance_below_threshold_check) && + (!options || options.illuminance_below_threshold_check === undefined || options.illuminance_below_threshold_check) && !globalStore.hasValue(msg.endpoint, 'timer') ) return; - const timeout = options && options.hasOwnProperty('occupancy_timeout') ? Number(options.occupancy_timeout) : msg.data.ontime / 10; + const timeout = options && options.occupancy_timeout !== undefined ? Number(options.occupancy_timeout) : msg.data.ontime / 10; // Stop existing timer because motion is detected and set a new one. clearTimeout(globalStore.getValue(msg.endpoint, 'timer')); diff --git a/src/lib/legacy.ts b/src/lib/legacy.ts index 29dbfdc59c710..d2651c23a4561 100644 --- a/src/lib/legacy.ts +++ b/src/lib/legacy.ts @@ -1090,7 +1090,7 @@ function getMetaValue(entity: any, definition: any, key: string, groupStrategy = if (entity.constructor.name === 'Group' && entity.members.length > 0) { const values = []; for (const memberMeta of definition) { - if (memberMeta.meta && memberMeta.meta.hasOwnProperty(key)) { + if (memberMeta.meta && memberMeta.meta[key] !== undefined) { if (groupStrategy === 'first') { return memberMeta.meta[key]; } @@ -1104,7 +1104,7 @@ function getMetaValue(entity: any, definition: any, key: string, groupStrategy = if (groupStrategy === 'allEqual' && new Set(values).size === 1) { return values[0]; } - } else if (definition && definition.meta && definition.meta.hasOwnProperty(key)) { + } else if (definition && definition.meta && definition.meta[key] !== undefined) { return definition.meta[key]; } @@ -1146,7 +1146,7 @@ const toPercentage = (value: number, min: number, max: number) => { const postfixWithEndpointName = (name: string, msg: KeyValueAny, definition: Definition) => { if (definition.meta && definition.meta.multiEndpoint) { - const endpointName = definition.hasOwnProperty('endpoint') ? getKey(definition.endpoint(msg.device), msg.endpoint.ID) : msg.endpoint.ID; + const endpointName = definition.endpoint !== undefined ? getKey(definition.endpoint(msg.device), msg.endpoint.ID) : msg.endpoint.ID; return `${name}_${endpointName}`; } else { return name; @@ -2082,7 +2082,7 @@ const fromZigbee1 = { 3: 'hold', }; - if (msg.data.hasOwnProperty('data')) { + if (msg.data.data !== undefined) { const zoneStatus = msg.data.zonestatus; return {click: buttonStates[zoneStatus]}; } else { @@ -3021,23 +3021,19 @@ const fromZigbee1 = { result[postfixWithEndpointName('remote_sensing', msg, model)] = msg.data['remoteSensing']; } const ctrl = msg.data['ctrlSeqeOfOper']; - if (typeof ctrl == 'number' && thermostatControlSequenceOfOperations.hasOwnProperty(ctrl)) { - result[postfixWithEndpointName('control_sequence_of_operation', msg, model)] = - // @ts-expect-error ignore - thermostatControlSequenceOfOperations[ctrl]; + if (typeof ctrl == 'number' && thermostatControlSequenceOfOperations[ctrl] !== undefined) { + result[postfixWithEndpointName('control_sequence_of_operation', msg, model)] = thermostatControlSequenceOfOperations[ctrl]; } const smode = msg.data['systemMode']; - if (typeof smode == 'number' && thermostatSystemModes.hasOwnProperty(smode)) { - // @ts-expect-error ignore + if (typeof smode == 'number' && thermostatSystemModes[smode] !== undefined) { result[postfixWithEndpointName('system_mode', msg, model)] = thermostatSystemModes[smode]; } const rmode = msg.data['runningMode']; - if (typeof rmode == 'number' && thermostatSystemModes.hasOwnProperty(rmode)) { - // @ts-expect-error ignore + if (typeof rmode == 'number' && thermostatSystemModes[rmode] !== undefined) { result[postfixWithEndpointName('running_mode', msg, model)] = thermostatSystemModes[rmode]; } const state = msg.data['runningState']; - if (typeof state == 'number' && constants.thermostatRunningStates.hasOwnProperty(state)) { + if (typeof state == 'number' && constants.thermostatRunningStates[state] !== undefined) { result[postfixWithEndpointName('running_state', msg, model)] = constants.thermostatRunningStates[state]; } if (typeof msg.data['pIHeatingDemand'] == 'number') { @@ -3296,7 +3292,7 @@ const fromZigbee1 = { return fromZigbeeConverters.hue_dimmer_switch.convert(model, msg, publish, options, meta); } - const multiplePressTimeout = options && options.hasOwnProperty('multiple_press_timeout') ? options.multiple_press_timeout : 0.25; + const multiplePressTimeout = options && options.multiple_press_timeout !== undefined ? options.multiple_press_timeout : 0.25; const getPayload = function ( button: any, @@ -3325,7 +3321,7 @@ const fromZigbee1 = { const typeLookup: KeyValueAny = {0: 'press', 1: 'hold', 2: 'release', 3: 'release'}; const type = typeLookup[msg.data['type']]; - const brightnessEnabled = options && options.hasOwnProperty('send_brightess') ? options.send_brightess : true; + const brightnessEnabled = options && options.send_brightess !== undefined ? options.send_brightess : true; const brightnessSend = brightnessEnabled && button && (button == 'up' || button == 'down'); // Initialize store @@ -3800,7 +3796,7 @@ const fromZigbee1 = { return {away_mode: 'OFF', preset_mode: 'none'}; } case dataPoints.saswellScheduleMode: - if (thermostatScheduleMode.hasOwnProperty(value)) { + if (thermostatScheduleMode[value] !== undefined) { return {schedule_mode: thermostatScheduleMode[value]}; } else { logger.warning(`Unknown schedule mode ${value}`, 'zhc:legacy:fz:saswell_thermostat'); @@ -4060,7 +4056,7 @@ const fromZigbee1 = { return {away_preset_days: value}; case dataPoints.mode: { const ret: KeyValueAny = {}; - const presetOk = getMetaValue(msg.endpoint, model, 'tuyaThermostatPreset').hasOwnProperty(value); + const presetOk = getMetaValue(msg.endpoint, model, 'tuyaThermostatPreset')[value] !== undefined; if (presetOk) { ret.preset = getMetaValue(msg.endpoint, model, 'tuyaThermostatPreset')[value]; ret.away_mode = ret.preset == 'away' ? 'ON' : 'OFF'; // Away is special HA mode @@ -5513,7 +5509,7 @@ const fromZigbee1 = { return result; } - if (thermostatMeta.hasOwnProperty('weeklyScheduleConversion')) { + if (thermostatMeta.weeklyScheduleConversion !== undefined) { conversion = thermostatMeta.weeklyScheduleConversion; } if (conversion == 'saswell') { @@ -5702,7 +5698,7 @@ const fromZigbee2 = { return result; } - if (thermostatMeta.hasOwnProperty('weeklyScheduleConversion')) { + if (thermostatMeta.weeklyScheduleConversion !== undefined) { conversion = thermostatMeta.weeklyScheduleConversion; } if (conversion == 'saswell') { @@ -6153,9 +6149,9 @@ const toZigbee2 = { 'away_preset_days', ]) { let v = 0; - if (value.hasOwnProperty(attrName)) { + if (value[attrName] !== undefined) { v = value[attrName]; - } else if (meta.state.hasOwnProperty(attrName)) { + } else if (meta.state[attrName] !== undefined) { // @ts-expect-error ignore v = meta.state[attrName]; } @@ -6210,9 +6206,9 @@ const toZigbee2 = { // temperature const attrName = `${key}_temp_${i}`; let v = 17; - if (value.hasOwnProperty(attrName)) { + if (value[attrName] !== undefined) { v = value[attrName]; - } else if (meta.state.hasOwnProperty(attrName)) { + } else if (meta.state[attrName] !== undefined) { // @ts-expect-error ignore v = meta.state[attrName]; } @@ -6222,18 +6218,18 @@ const toZigbee2 = { // hour let attrName = `${key}_hour_${i}`; let h = 0; - if (value.hasOwnProperty(attrName)) { + if (value[attrName] !== undefined) { h = value[attrName]; - } else if (meta.state.hasOwnProperty(attrName)) { + } else if (meta.state[attrName] !== undefined) { // @ts-expect-error ignore h = meta.state[attrName]; } // minute attrName = `${key}_minute_${i}`; let m = 0; - if (value.hasOwnProperty(attrName)) { + if (value[attrName] !== undefined) { m = value[attrName]; - } else if (meta.state.hasOwnProperty(attrName)) { + } else if (meta.state[attrName] !== undefined) { // @ts-expect-error ignore m = meta.state[attrName]; } @@ -6304,7 +6300,7 @@ const toZigbee2 = { matsee_garage_door_opener: { key: ['trigger'], convertSet: async (entity, key, value, meta) => { - const state = meta.message.hasOwnProperty('trigger') ? meta.message.trigger : true; + const state = meta.message.trigger !== undefined ? meta.message.trigger : true; // @ts-expect-error ignore await sendDataPointBool(entity, dataPoints.garageDoorTrigger, state); return {state: {trigger: state}}; @@ -6806,7 +6802,7 @@ const toZigbee2 = { ret['state'][key] = value; return ret; } else { - if ((meta.state.hasOwnProperty(key) && meta.state[key] == '') || !meta.state.hasOwnProperty(key)) { + if ((meta.state[key] !== undefined && meta.state[key] == '') || meta.state[key] === undefined) { data.push(0x03); } else { data.push(0x02); @@ -6868,7 +6864,7 @@ const toZigbee2 = { ret['state'][key] = value; return ret; } else { - if ((meta.state.hasOwnProperty(key) && meta.state[key] == '') || !meta.state.hasOwnProperty(key)) { + if ((meta.state[key] !== undefined && meta.state[key] == '') || meta.state[key] === undefined) { data.push(0x03); } else { data.push(0x02); @@ -6958,8 +6954,7 @@ const toZigbee2 = { // @ts-expect-error ignore const firstDayDpId = thermostatMeta.weeklyScheduleFirstDayDpId; let conversion = 'generic'; - if (thermostatMeta.hasOwnProperty('weeklyScheduleConversion')) { - // @ts-expect-error ignore + if (utils.isObject(thermostatMeta) && thermostatMeta.weeklyScheduleConversion !== undefined) { conversion = thermostatMeta.weeklyScheduleConversion; } @@ -7682,7 +7677,7 @@ const toZigbee2 = { let hsb: KeyValueAny = {}; - if (value.hasOwnProperty('hsb')) { + if (value.hsb !== undefined) { const split = value.hsb.split(',').map((i: string) => parseInt(i)); hsb = fillInHSB(split[0], split[1], split[2], meta.state); } else { @@ -8403,7 +8398,7 @@ const toZigbee2 = { } satisfies Tz.Converter, }; -const thermostatControlSequenceOfOperations = { +const thermostatControlSequenceOfOperations: {[s: number]: string} = { 0: 'cooling only', 1: 'cooling with reheat', 2: 'heating only', @@ -8412,7 +8407,7 @@ const thermostatControlSequenceOfOperations = { 5: 'cooling and heating 4-pipes with reheat', }; -const thermostatSystemModes = { +const thermostatSystemModes: {[s: number]: string} = { 0: 'off', 1: 'auto', 3: 'cool', diff --git a/src/lib/legrand.ts b/src/lib/legrand.ts index 6de716f4606a8..dd2588a0589a3 100644 --- a/src/lib/legrand.ts +++ b/src/lib/legrand.ts @@ -185,7 +185,7 @@ export const fzLegrand = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const attr = 'calibrationMode'; - if (msg.data.hasOwnProperty(attr)) { + if (msg.data[attr] !== undefined) { const applicableModes = getApplicableCalibrationModes(isNLLVSwitch); const idx = msg.data[attr]; utils.validateValue(String(idx), Object.keys(applicableModes)); @@ -201,7 +201,7 @@ export const fzLegrand = { convert: (model, msg, publish, options, meta) => { const payload: KeyValueAny = {}; - if (msg.data.hasOwnProperty('0')) { + if (msg.data['0'] !== undefined) { const option0 = msg.data['0']; if (option0 === 0x0001) payload.device_mode = 'pilot_off'; @@ -215,8 +215,8 @@ export const fzLegrand = { payload.device_mode = 'unknown'; } } - if (msg.data.hasOwnProperty('1')) payload.led_in_dark = msg.data['1'] === 0x00 ? 'OFF' : 'ON'; - if (msg.data.hasOwnProperty('2')) payload.led_if_on = msg.data['2'] === 0x00 ? 'OFF' : 'ON'; + if (msg.data['1'] !== undefined) payload.led_in_dark = msg.data['1'] === 0x00 ? 'OFF' : 'ON'; + if (msg.data['2'] !== undefined) payload.led_if_on = msg.data['2'] === 0x00 ? 'OFF' : 'ON'; return payload; }, } satisfies Fz.Converter, diff --git a/src/lib/light.ts b/src/lib/light.ts index 75d8a5601c229..6dae0d478fc22 100644 --- a/src/lib/light.ts +++ b/src/lib/light.ts @@ -24,22 +24,22 @@ export function readColorAttributes(entity: Zh.Endpoint | Zh.Group, meta: Tz.Met */ const attributes = ['colorMode']; if (meta && meta.message) { - if (!meta.message.color || (typeof meta.message.color === 'object' && meta.message.color.hasOwnProperty('x'))) { + if (!meta.message.color || (utils.isObject(meta.message.color) && meta.message.color.x !== undefined)) { attributes.push('currentX'); } - if (!meta.message.color || (typeof meta.message.color === 'object' && meta.message.color.hasOwnProperty('y'))) { + if (!meta.message.color || (utils.isObject(meta.message.color) && meta.message.color.y !== undefined)) { attributes.push('currentY'); } if (utils.getMetaValue(entity, meta.mapped, 'supportsHueAndSaturation', 'allEqual', true)) { - if (!meta.message.color || (typeof meta.message.color === 'object' && meta.message.color.hasOwnProperty('hue'))) { + if (!meta.message.color || (utils.isObject(meta.message.color) && meta.message.color.hue !== undefined)) { if (utils.getMetaValue(entity, meta.mapped, 'supportsEnhancedHue', 'allEqual', true)) { attributes.push('enhancedCurrentHue'); } else { attributes.push('currentHue'); } } - if (!meta.message.color || (typeof meta.message.color === 'object' && meta.message.color.hasOwnProperty('saturation'))) { + if (!meta.message.color || (utils.isObject(meta.message.color) && meta.message.color.saturation !== undefined)) { attributes.push('currentSaturation'); } } diff --git a/src/lib/lumi.ts b/src/lib/lumi.ts index 0dea92d4b2f4d..bf622e11c775d 100644 --- a/src/lib/lumi.ts +++ b/src/lib/lumi.ts @@ -1780,9 +1780,9 @@ export const lumiModernExtend = { // there is however an outage counter published in the 'special' buffer data reported // under the manuSpecificLumi cluster as attribute 247, we simple decode and grab value with ID 5. // Normal attribute publishing and decoding will be left to the classic fromZigbee or modernExtends. - if (msg.data.hasOwnProperty('247')) { + if (msg.data['247'] !== undefined) { const dataDecoded = buffer2DataObject(model, msg.data['247']); - if (dataDecoded.hasOwnProperty('5')) { + if (dataDecoded['5'] !== undefined) { assertNumber(dataDecoded['5']); const currentOutageCount = dataDecoded['5'] - 1; @@ -1982,7 +1982,7 @@ export const lumiModernExtend = { cluster: 'manuSpecificLumi', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty(652)) { + if (msg.data[652] !== undefined) { const actionLookup: KeyValueNumberString = { 1: 'slider_single', 2: 'slider_double', @@ -2056,7 +2056,7 @@ export const lumiModernExtend = { cluster: 'ssIasZone', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty(45)) { + if (msg.data[45] !== undefined) { const zoneStatus = msg.data[45]; const actionLookup: KeyValueNumberString = {1: 'shake', 2: 'triple_strike'}; return {action: actionLookup[zoneStatus]}; @@ -2082,12 +2082,12 @@ export const lumiModernExtend = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const payload: KeyValueAny = {}; - if (msg.data.hasOwnProperty(args.deviceTemperatureAttribute)) { + if (msg.data[args.deviceTemperatureAttribute] !== undefined) { const value = msg.data[args.deviceTemperatureAttribute]; assertNumber(value); payload['device_temperature'] = value; } - if (msg.data.hasOwnProperty(args.powerOutageCountAttribute)) { + if (msg.data[args.powerOutageCountAttribute] !== undefined) { const value = msg.data[args.powerOutageCountAttribute]; assertNumber(value); payload['power_outage_count'] = value - 1; @@ -2118,7 +2118,7 @@ export const lumiModernExtend = { cluster: 'manuSpecificLumi', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty(570)) { + if (msg.data[570] !== undefined) { const act: KeyValueNumberString = {1: 'start_rotating', 2: 'rotation', 3: 'stop_rotating'}; const state: KeyValueNumberString = {0: 'released', 128: 'pressed'}; return { @@ -2825,17 +2825,17 @@ export const fromZigbee = { type: ['attributeReport', 'readResponse'], options: [exposes.options.occupancy_timeout_2(), exposes.options.no_occupancy_since_true()], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('illuminance')) { + if (msg.data.illuminance !== undefined) { // The occupancy sensor only sends a message when motion detected. // Therefore we need to publish the no_motion detected by ourselves. let timeout = - meta && meta.state && meta.state.hasOwnProperty('detection_interval') + meta && meta.state && meta.state.detection_interval !== undefined ? Number(meta.state.detection_interval) : ['RTCGQ14LM'].includes(model.model) ? 30 : 60; timeout = - options && options.hasOwnProperty('occupancy_timeout') && Number(options.occupancy_timeout) >= timeout + options && options.occupancy_timeout !== undefined && Number(options.occupancy_timeout) >= timeout ? Number(options.occupancy_timeout) : timeout + 2; @@ -2883,14 +2883,14 @@ export const fromZigbee = { convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; const invert = model.meta && model.meta.coverInverted ? !options.invert_cover : options.invert_cover; - if (msg.data.hasOwnProperty('currentPositionLiftPercentage') && msg.data['currentPositionLiftPercentage'] <= 100) { + if (msg.data.currentPositionLiftPercentage !== undefined && msg.data['currentPositionLiftPercentage'] <= 100) { const value = msg.data['currentPositionLiftPercentage']; const position = invert ? 100 - value : value; const state = invert ? (position > 0 ? 'CLOSE' : 'OPEN') : position > 0 ? 'OPEN' : 'CLOSE'; result[postfixWithEndpointName('position', msg, model, meta)] = position; result[postfixWithEndpointName('state', msg, model, meta)] = state; } - if (msg.data.hasOwnProperty('currentPositionTiltPercentage') && msg.data['currentPositionTiltPercentage'] <= 100) { + if (msg.data.currentPositionTiltPercentage !== undefined && msg.data['currentPositionTiltPercentage'] <= 100) { const value = msg.data['currentPositionTiltPercentage']; result[postfixWithEndpointName('tilt', msg, model, meta)] = invert ? 100 - value : value; } @@ -2906,14 +2906,14 @@ export const fromZigbee = { if (model.meta && !model.meta.multiEndpoint) { const mappingMode: KeyValueNumberString = {0x12: 'control_relay', 0xfe: 'decoupled'}; const key = 0xff22; - if (msg.data.hasOwnProperty(key)) { + if (msg.data[key] !== undefined) { payload.operation_mode = mappingMode[msg.data[key]]; } } else { const mappingButton: KeyValueNumberString = {0xff22: 'left', 0xff23: 'right'}; const mappingMode: KeyValueNumberString = {0x12: 'control_left_relay', 0x22: 'control_right_relay', 0xfe: 'decoupled'}; for (const key in mappingButton) { - if (msg.data.hasOwnProperty(key)) { + if (msg.data[key] !== undefined) { payload[`operation_mode_${mappingButton[key]}`] = mappingMode[msg.data[key]]; } } @@ -2941,7 +2941,7 @@ export const fromZigbee = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { // Lumi wall switches use endpoint 4, 5 or 6 to indicate an action on the button so we have to skip that. - if (msg.data.hasOwnProperty('onOff') && ![4, 5, 6].includes(msg.endpoint.ID)) { + if (msg.data.onOff !== undefined && ![4, 5, 6].includes(msg.endpoint.ID)) { const property = postfixWithEndpointName('state', msg, model, meta); return {[property]: msg.data['onOff'] === 1 ? 'ON' : 'OFF'}; } @@ -2960,7 +2960,7 @@ export const fromZigbee = { // for lumi.curtain.acn002 if (['ZNJLBL01LM'].includes(model.model)) lookup = {0: 'closing', 1: 'opening', 2: 'stopped', 3: 'blocked'}; - if (data && data.hasOwnProperty('presentValue')) { + if (data && data.presentValue !== undefined) { const value = data['presentValue']; if (value < 2) { running = true; @@ -2976,11 +2976,11 @@ export const fromZigbee = { cluster: 'manuSpecificLumi', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('curtainHandOpen')) { + if (msg.data.curtainHandOpen !== undefined) { return {hand_open: msg.data['curtainHandOpen'] === 0}; - } else if (msg.data.hasOwnProperty('curtainReverse')) { + } else if (msg.data.curtainReverse !== undefined) { return {reverse_direction: msg.data['curtainReverse'] === 1}; - } else if (msg.data.hasOwnProperty('curtainCalibrated')) { + } else if (msg.data.curtainCalibrated !== undefined) { return {limits_calibration: msg.data['curtainCalibrated'] === 1 ? 'calibrated' : 'recalibrate'}; } }, @@ -3006,7 +3006,7 @@ export const fromZigbee = { if (result.action === 'vibration') { result.vibration = true; - const timeout = options && options.hasOwnProperty('vibration_timeout') ? Number(options.vibration_timeout) : 90; + const timeout = options && options.vibration_timeout !== undefined ? Number(options.vibration_timeout) : 90; // Stop any existing timer cause vibration detected clearTimeout(globalStore.getValue(msg.endpoint, 'vibration_timer', null)); @@ -3106,9 +3106,9 @@ export const fromZigbee = { // The occupancy sensor only sends a message when motion detected. // Therefore we need to publish the no_motion detected by ourselves. - let timeout: number = meta && meta.state && meta.state.hasOwnProperty('detection_interval') ? Number(meta.state.detection_interval) : 60; + let timeout: number = meta && meta.state && meta.state.detection_interval !== undefined ? Number(meta.state.detection_interval) : 60; timeout = - options && options.hasOwnProperty('occupancy_timeout') && Number(options.occupancy_timeout) >= timeout + options && options.occupancy_timeout !== undefined && Number(options.occupancy_timeout) >= timeout ? Number(options.occupancy_timeout) : timeout + 2; @@ -3145,7 +3145,7 @@ export const fromZigbee = { const data = msg.data; if (data && data['65281']) { const basicAttrs = data['65281']; - if (basicAttrs.hasOwnProperty('100')) { + if (basicAttrs['100'] !== undefined) { return {gas_density: basicAttrs['100']}; } } @@ -3158,7 +3158,7 @@ export const fromZigbee = { const data = msg.data; const lookup: KeyValueAny = {'1': 'low', '2': 'medium', '3': 'high'}; - if (data && data.hasOwnProperty('65520')) { + if (data && data['65520'] !== undefined) { const value = data['65520']; if (value && value.startsWith('0x020')) { return { @@ -3172,7 +3172,7 @@ export const fromZigbee = { cluster: 'genPowerCfg', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('batteryAlarmMask')) { + if (msg.data.batteryAlarmMask !== undefined) { return {battery_low: msg.data['batteryAlarmMask'] === 1}; } }, @@ -3521,65 +3521,65 @@ export const fromZigbee = { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const result: KeyValueAny = {}; - if (msg.data.hasOwnProperty(0x0215)) { + if (msg.data[0x0215] !== undefined) { const lookup: KeyValueAny = {0: 'classic', 1: 'concise'}; result.theme = lookup[msg.data[0x0215]]; } - if (msg.data.hasOwnProperty(0x0214)) { + if (msg.data[0x0214] !== undefined) { const lookup: KeyValueAny = {1: 'classic', 2: 'analog clock'}; result.screen_saver_style = lookup[msg.data[0x0214]]; } - if (msg.data.hasOwnProperty(0x0213)) { + if (msg.data[0x0213] !== undefined) { result.standby_enabled = msg.data[0x0213] & 1 ? true : false; } - if (msg.data.hasOwnProperty(0x0212)) { + if (msg.data[0x0212] !== undefined) { const lookup: KeyValueAny = {0: 'mute', 1: 'low', 2: 'medium', 3: 'high'}; result.beep_volume = lookup[msg.data[0x0212]]; } - if (msg.data.hasOwnProperty(0x0211)) { + if (msg.data[0x0211] !== undefined) { result.lcd_brightness = msg.data[0x0211]; } - if (msg.data.hasOwnProperty(0x022b)) { + if (msg.data[0x022b] !== undefined) { const lookup: KeyValueAny = {0: 'none', 1: '1', 2: '2', 3: '1 and 2', 4: '3', 5: '1 and 3', 6: '2 and 3', 7: 'all'}; result.available_switches = lookup[msg.data[0x022b]]; } - if (msg.data.hasOwnProperty(0x217)) { + if (msg.data[0x217] !== undefined) { const lookup: KeyValueAny = {3: 'small', 4: 'medium', 5: 'large'}; result.font_size = lookup[msg.data[0x217]]; } - if (msg.data.hasOwnProperty(0x219)) { + if (msg.data[0x219] !== undefined) { const lookup: KeyValueAny = {0: 'scene', 1: 'feel', 2: 'thermostat', 3: 'switch'}; result.homepage = lookup[msg.data[0x219]]; } - if (msg.data.hasOwnProperty(0x210)) { + if (msg.data[0x210] !== undefined) { const lookup: KeyValueAny = {0: 'chinese', 1: 'english'}; result.language = lookup[msg.data[0x210]]; } - if (msg.data.hasOwnProperty(0x216)) { + if (msg.data[0x216] !== undefined) { result.standby_time = msg.data[0x216]; } - if (msg.data.hasOwnProperty(0x218)) { + if (msg.data[0x218] !== undefined) { result.lcd_auto_brightness_enabled = msg.data[0x218] & 1 ? true : false; } - if (msg.data.hasOwnProperty(0x221)) { + if (msg.data[0x221] !== undefined) { result.screen_saver_enabled = msg.data[0x221] & 1 ? true : false; } - if (msg.data.hasOwnProperty(0x222)) { + if (msg.data[0x222] !== undefined) { result.standby_lcd_brightness = msg.data[0x222]; } - if (msg.data.hasOwnProperty(0x223)) { + if (msg.data[0x223] !== undefined) { const lookup: KeyValueAny = {1: '1', 2: '2', 3: '3', 4: '4', 5: '5', 6: '6', 7: '7', 8: '8', 9: '9', 10: '10', 11: '11'}; const textarr = msg.data[0x223].slice(1, msg.data[0x223].length); result.switch_1_icon = lookup[msg.data[0x223][0]]; result.switch_1_text = String.fromCharCode(...textarr); } - if (msg.data.hasOwnProperty(0x224)) { + if (msg.data[0x224] !== undefined) { const lookup: KeyValueAny = {1: '1', 2: '2', 3: '3', 4: '4', 5: '5', 6: '6', 7: '7', 8: '8', 9: '9', 10: '10', 11: '11'}; const textarr = msg.data[0x224].slice(1, msg.data[0x224].length); result.switch_2_icon = lookup[msg.data[0x224][0]]; result.switch_2_text = String.fromCharCode(...textarr); } - if (msg.data.hasOwnProperty(0x225)) { + if (msg.data[0x225] !== undefined) { const lookup: KeyValueAny = {1: '1', 2: '2', 3: '3', 4: '4', 5: '5', 6: '6', 7: '7', 8: '8', 9: '9', 10: '10', 11: '11'}; const textarr = msg.data[0x225].slice(1, msg.data[0x225].length); result.switch_3_icon = lookup[msg.data[0x225][0]]; @@ -4014,9 +4014,7 @@ export const toZigbee = { schedule_settings: 0x0276, }; - if (dict.hasOwnProperty(key)) { - await entity.read('manuSpecificLumi', [getFromLookup(key, dict)], {manufacturerCode: manufacturerCode}); - } + await entity.read('manuSpecificLumi', [getFromLookup(key, dict)], {manufacturerCode: manufacturerCode}); }, } satisfies Tz.Converter, lumi_presence_region_upsert: { @@ -4152,7 +4150,7 @@ export const toZigbee = { convertSet: async (entity, key, value, meta) => { assertEndpoint(entity); if (Array.isArray(meta.mapped)) throw new Error(`Not supported for groups`); - let targetValue = isObject(value) && value.hasOwnProperty('state') ? value.state : value; + let targetValue = isObject(value) && value.state !== undefined ? value.state : value; // 1/2 gang switches using genBasic on endpoint 1. let attrId; @@ -4202,7 +4200,7 @@ export const toZigbee = { key: ['operation_mode'], convertSet: async (entity, key, value, meta) => { // Support existing syntax of a nested object just for the state field. Though it's quite silly IMO. - const targetValue = isObject(value) && value.hasOwnProperty('state') ? value.state : value; + const targetValue = isObject(value) && value.state !== undefined ? value.state : value; // Switches using manuSpecificLumi 0x0200 on the same endpoints as the onOff clusters. const lookupState = {control_relay: 0x01, decoupled: 0x00}; await entity.write('manuSpecificLumi', {0x0200: {value: getFromLookup(targetValue, lookupState), type: 0x20}}, manufacturerOptions.lumi); @@ -4388,7 +4386,7 @@ export const toZigbee = { await entity.write('genBasic', {0xfff0: {value: payload, type: 0x41}}, manufacturerOptions.lumi); } else if (['ZNQBKG38LM', 'ZNQBKG39LM', 'ZNQBKG40LM', 'ZNQBKG41LM'].includes(meta.mapped.model)) { // Support existing syntax of a nested object just for the state field. Though it's quite silly IMO. - const targetValue = isObject(value) && value.hasOwnProperty('state') ? value.state : value; + const targetValue = isObject(value) && value.state !== undefined ? value.state : value; const lookupState = {on: 0x01, electric_appliances_on: 0x00, electric_appliances_off: 0x02, inverted: 0x03}; await entity.write( 'manuSpecificLumi', @@ -4653,8 +4651,8 @@ export const toZigbee = { }; // Legacy names - if (value.hasOwnProperty('auto_close')) opts.hand_open = value.auto_close; - if (value.hasOwnProperty('reset_move')) opts.reset_limits = value.reset_move; + if (value.auto_close !== undefined) opts.hand_open = value.auto_close; + if (value.reset_move !== undefined) opts.reset_limits = value.reset_move; if (meta.mapped.model === 'ZNCLDJ12LM') { await entity.write('genBasic', {0xff28: {value: opts.reverse_direction, type: 0x10}}, manufacturerOptions.lumi); @@ -5114,14 +5112,14 @@ export const toZigbee = { const payload = []; const statearr: KeyValue = {}; assertObject(value); - if (value.hasOwnProperty('switch_1_icon')) { + if (value.switch_1_icon !== undefined) { payload.push(getFromLookup(value.switch_1_icon, lookup)); statearr.switch_1_icon = value.switch_1_icon; } else { payload.push(1); statearr.switch_1_icon = '1'; } - if (value.hasOwnProperty('switch_1_text')) { + if (value.switch_1_text !== undefined) { payload.push(...value.switch_1_text.split('').map((c: string) => c.charCodeAt(0))); statearr.switch_1_text = value.switch_1_text; } else { @@ -5136,14 +5134,14 @@ export const toZigbee = { const payload = []; const statearr: KeyValue = {}; assertObject(value); - if (value.hasOwnProperty('switch_2_icon')) { + if (value.switch_2_icon !== undefined) { payload.push(getFromLookup(value.switch_2_icon, lookup)); statearr.switch_2_icon = value.switch_2_icon; } else { payload.push(1); statearr.switch_2_icon = '1'; } - if (value.hasOwnProperty('switch_2_text')) { + if (value.switch_2_text !== undefined) { payload.push(...value.switch_2_text.split('').map((c: string) => c.charCodeAt(0))); statearr.switch_2_text = value.switch_2_text; } else { @@ -5158,14 +5156,14 @@ export const toZigbee = { const payload = []; const statearr: KeyValue = {}; assertObject(value); - if (value.hasOwnProperty('switch_3_icon')) { + if (value.switch_3_icon !== undefined) { payload.push(getFromLookup(value.switch_3_icon, lookup)); statearr.switch_3_icon = value.switch_3_icon; } else { payload.push(1); statearr.switch_3_icon = '1'; } - if (value.hasOwnProperty('switch_3_text')) { + if (value.switch_3_text !== undefined) { payload.push(...value.switch_3_text.split('').map((c: string) => c.charCodeAt(0))); statearr.switch_3_text = value.switch_3_text; } else { diff --git a/src/lib/modernExtend.ts b/src/lib/modernExtend.ts index c6e94ca4ca176..a8db928526ef6 100644 --- a/src/lib/modernExtend.ts +++ b/src/lib/modernExtend.ts @@ -321,7 +321,7 @@ export function battery(args?: BatteryArgs): ModernExtend { type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { const payload: KeyValueAny = {}; - if (msg.data.hasOwnProperty('batteryPercentageRemaining') && msg.data['batteryPercentageRemaining'] < 255) { + if (msg.data.batteryPercentageRemaining !== undefined && msg.data['batteryPercentageRemaining'] < 255) { // Some devices do not comply to the ZCL and report a // batteryPercentageRemaining of 100 when the battery is full (should be 200). const dontDividePercentage = args.dontDividePercentage; @@ -330,7 +330,7 @@ export function battery(args?: BatteryArgs): ModernExtend { if (args.percentage) payload.battery = precisionRound(percentage, 2); } - if (msg.data.hasOwnProperty('batteryVoltage') && msg.data['batteryVoltage'] < 255) { + if (msg.data.batteryVoltage !== undefined && msg.data['batteryVoltage'] < 255) { // Deprecated: voltage is = mV now but should be V if (args.voltage) payload.voltage = msg.data['batteryVoltage'] * 100; @@ -339,7 +339,7 @@ export function battery(args?: BatteryArgs): ModernExtend { } } - if (msg.data.hasOwnProperty('batteryAlarmState')) { + if (msg.data.batteryAlarmState !== undefined) { const battery1Low = (msg.data.batteryAlarmState & (1 << 0) || msg.data.batteryAlarmState & (1 << 1) || @@ -1008,7 +1008,7 @@ export function light(args?: LightArgs): ModernExtend { toZigbee.push(tz.power_on_behavior); } - if (args.hasOwnProperty('turnsOffAtBrightness1')) { + if (args.turnsOffAtBrightness1 !== undefined) { meta.turnsOffAtBrightness1 = args.turnsOffAtBrightness1; } @@ -1483,7 +1483,7 @@ export function iasZoneAlarm(args: IasArgs): ModernExtend { const zoneStatus = msg.type === 'commandStatusChangeNotification' ? msg.data.zonestatus : msg.data.zoneStatus; if (args.alarmTimeout) { - const timeout = options?.hasOwnProperty(timeoutProperty) ? Number(options[timeoutProperty]) : 90; + const timeout = options?.[timeoutProperty] !== undefined ? Number(options[timeoutProperty]) : 90; clearTimeout(globalStore.getValue(msg.endpoint, 'timer')); if (timeout !== 0) { const timer = setTimeout(() => publish({[alarm1Name]: false, [alarm2Name]: false}), timeout * 1000); @@ -1569,13 +1569,13 @@ export function iasWarning(args?: IasWarningArgs): ModernExtend { // @ts-expect-error ignore level: value.level || 'medium', // @ts-expect-error ignore - strobe: value.hasOwnProperty('strobe') ? value.strobe : true, + strobe: value.strobe !== undefined ? value.strobe : true, // @ts-expect-error ignore - duration: value.hasOwnProperty('duration') ? value.duration : 10, + duration: value.duration !== undefined ? value.duration : 10, // @ts-expect-error ignore - strobeDutyCycle: value.hasOwnProperty('strobe_duty_cycle') ? value.strobe_duty_cycle * 10 : 0, + strobeDutyCycle: value.strobe_duty_cycle !== undefined ? value.strobe_duty_cycle * 10 : 0, // @ts-expect-error ignore - strobeLevel: value.hasOwnProperty('strobe_level') ? utils.getFromLookup(value.strobe_level, strobeLevel) : 1, + strobeLevel: value.strobe_level !== undefined ? utils.getFromLookup(value.strobe_level, strobeLevel) : 1, }; let info; diff --git a/src/lib/ota/zigbeeOTA.ts b/src/lib/ota/zigbeeOTA.ts index b119fea963304..9f6fdadc77b1e 100644 --- a/src/lib/ota/zigbeeOTA.ts +++ b/src/lib/ota/zigbeeOTA.ts @@ -21,7 +21,7 @@ function fillImageInfo(meta: KeyValueAny) { } // Nothing to do if needed fields were filled already - if (meta.hasOwnProperty('imageType') && meta.hasOwnProperty('manufacturerCode') && meta.hasOwnProperty('fileVersion')) { + if (meta.imageType !== undefined && meta.manufacturerCode !== undefined && meta.fileVersion !== undefined) { return meta; } @@ -31,9 +31,9 @@ function fillImageInfo(meta: KeyValueAny) { const image = common.parseImage(buffer.subarray(start)); // Will fill only those fields that were absent - if (!meta.hasOwnProperty('imageType')) meta.imageType = image.header.imageType; - if (!meta.hasOwnProperty('manufacturerCode')) meta.manufacturerCode = image.header.manufacturerCode; - if (!meta.hasOwnProperty('fileVersion')) meta.fileVersion = image.header.fileVersion; + if (meta.imageType === undefined) meta.imageType = image.header.imageType; + if (meta.manufacturerCode === undefined) meta.manufacturerCode = image.header.manufacturerCode; + if (meta.fileVersion === undefined) meta.fileVersion = image.header.fileVersion; return meta; } diff --git a/src/lib/philips.ts b/src/lib/philips.ts index e02275b4b426b..58080f64835d4 100644 --- a/src/lib/philips.ts +++ b/src/lib/philips.ts @@ -167,7 +167,7 @@ export const philipsTz = { } else if (value === 'on') { await entity.write('genOnOff', {0x4003: {value: 0x01, type: 0x30}}); - let brightness = meta.message.hasOwnProperty('hue_power_on_brightness') ? meta.message.hue_power_on_brightness : 0xfe; + let brightness = meta.message.hue_power_on_brightness !== undefined ? meta.message.hue_power_on_brightness : 0xfe; if (brightness === 255) { // 255 (0xFF) is the value for recover, therefore set it to 254 (0xFE) brightness = 254; @@ -176,9 +176,9 @@ export const philipsTz = { utils.assertEndpoint(entity); if (entity.supportsInputCluster('lightingColorCtrl')) { - if (meta.message.hasOwnProperty('hue_power_on_color_temperature') && meta.message.hasOwnProperty('hue_power_on_color')) { + if (meta.message.hue_power_on_color_temperature !== undefined && meta.message.hue_power_on_color !== undefined) { logger.error(`Provide either color temperature or color, not both`, NS); - } else if (meta.message.hasOwnProperty('hue_power_on_color_temperature')) { + } else if (meta.message.hue_power_on_color_temperature !== undefined) { const colortemp = meta.message.hue_power_on_color_temperature; await entity.write('lightingColorCtrl', {0x4010: {value: colortemp, type: 0x21}}); // Set color to default @@ -186,7 +186,7 @@ export const philipsTz = { await entity.write('lightingColorCtrl', {0x0003: {value: 0xffff, type: 0x21}}, manufacturerOptions); await entity.write('lightingColorCtrl', {0x0004: {value: 0xffff, type: 0x21}}, manufacturerOptions); } - } else if (meta.message.hasOwnProperty('hue_power_on_color')) { + } else if (meta.message.hue_power_on_color !== undefined) { // @ts-expect-error ignore const colorXY = libColor.ColorRGB.fromHex(meta.message.hue_power_on_color).toXY(); const xy = {x: utils.mapNumberRange(colorXY.x, 0, 1, 0, 65535), y: utils.mapNumberRange(colorXY.y, 0, 1, 0, 65535)}; @@ -218,7 +218,7 @@ export const philipsTz = { hue_power_on_error: { key: ['hue_power_on_brightness', 'hue_power_on_color_temperature', 'hue_power_on_color'], convertSet: async (entity, key, value, meta) => { - if (!meta.message.hasOwnProperty('hue_power_on_behavior')) { + if (meta.message.hue_power_on_behavior === undefined) { throw new Error(`Provide a value for 'hue_power_on_behavior'`); } }, @@ -349,7 +349,7 @@ export const philipsFz = { convert: (model, msg, publish, options, meta) => { if (msg.type === 'commandOff' || msg.type === 'commandOn') { return {contact: msg.type === 'commandOff'}; - } else if (msg.data.hasOwnProperty('onOff')) { + } else if (msg.data.onOff !== undefined) { return {contact: msg.data['onOff'] === 0}; } }, @@ -382,7 +382,7 @@ export const philipsFz = { if (options.simulated_brightness) { const opts = options.simulated_brightness; // @ts-expect-error ignore - const deltaOpts = typeof opts === 'object' && opts.hasOwnProperty('delta') ? opts.delta : 35; + const deltaOpts = typeof opts === 'object' && opts.delta !== undefined ? opts.delta : 35; const delta = direction === 'right' ? deltaOpts : deltaOpts * -1; const brightness = globalStore.getValue(msg.endpoint, 'brightness', 255) + delta; payload.brightness = utils.numberWithinRange(brightness, 0, 255); @@ -405,7 +405,7 @@ export const philipsFz = { cluster: 'manuSpecificPhilips2', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data && msg.data.hasOwnProperty('state')) { + if (msg.data && msg.data.state !== undefined) { const input = msg.data['state'].toString('hex'); const decoded = decodeGradientColors(input, {reverse: true}); if (decoded.color_mode === 'gradient') { diff --git a/src/lib/reporting.ts b/src/lib/reporting.ts index 9a65a18a60f3b..da2bb773e9a97 100644 --- a/src/lib/reporting.ts +++ b/src/lib/reporting.ts @@ -12,10 +12,10 @@ export function payload(attribute: string | number, min: number, max: number, ch }; if (overrides) { - if (overrides.hasOwnProperty('min')) payload.minimumReportInterval = overrides.min; - if (overrides.hasOwnProperty('max')) payload.maximumReportInterval = overrides.max; + if (overrides.min !== undefined) payload.minimumReportInterval = overrides.min; + if (overrides.max !== undefined) payload.maximumReportInterval = overrides.max; // @ts-expect-error ignore - if (overrides.hasOwnProperty('change')) payload.reportableChange = overrides.change; + if (overrides.change !== undefined) payload.reportableChange = overrides.change; } return [payload]; diff --git a/src/lib/store.ts b/src/lib/store.ts index 9e4e9d8dd35ef..35caa45cf265b 100644 --- a/src/lib/store.ts +++ b/src/lib/store.ts @@ -17,12 +17,12 @@ function getEntityKey(entity: Zh.Endpoint | Zh.Group | Zh.Device) { export function hasValue(entity: Zh.Endpoint | Zh.Group | Zh.Device, key: string) { const entityKey = getEntityKey(entity); - return store.has(entityKey) && store.get(entityKey).hasOwnProperty(key); + return store.has(entityKey) && store.get(entityKey)[key] !== undefined; } export function getValue(entity: Zh.Endpoint | Zh.Group | Zh.Device, key: string, default_: unknown = undefined) { const entityKey = getEntityKey(entity); - if (store.has(entityKey) && store.get(entityKey).hasOwnProperty(key)) { + if (store.has(entityKey) && store.get(entityKey)[key] !== undefined) { return store.get(entityKey)[key]; } diff --git a/src/lib/tuya.ts b/src/lib/tuya.ts index fecfc5b22b61a..c5a71951e0fac 100644 --- a/src/lib/tuya.ts +++ b/src/lib/tuya.ts @@ -416,7 +416,7 @@ export const skip = { stateOnAndBrightnessPresent: (meta: Tz.Meta) => { if (Array.isArray(meta.mapped)) throw new Error('Not supported'); const convertedKey = meta.mapped.meta.multiEndpoint && meta.endpoint_name ? `state_${meta.endpoint_name}` : 'state'; - return meta.message.hasOwnProperty('brightness') && meta.state[convertedKey] === meta.message.state; + return meta.message.brightness !== undefined && meta.state[convertedKey] === meta.message.state; }, }; @@ -909,7 +909,7 @@ export const valueConverter = { let weekdayFormat: string; let holidayFormat: string; - if (meta.message.hasOwnProperty('schedule_weekday')) { + if (meta.message.schedule_weekday !== undefined) { weekdayFormat = v; holidayFormat = meta.state['schedule_holiday'] as string; } else { @@ -1232,12 +1232,9 @@ const tuyaTz = { // provide datapoints so there is little reason to provide support. key: ['state', 'countdown'], convertSet: async (entity, key, value, meta) => { - const state = meta.message.hasOwnProperty('state') - ? utils.isString(meta.message.state) - ? meta.message.state.toLowerCase() - : undefined - : undefined; - const countdown = meta.message.hasOwnProperty('countdown') ? meta.message.countdown : undefined; + const state = + meta.message.state !== undefined ? (utils.isString(meta.message.state) ? meta.message.state.toLowerCase() : undefined) : undefined; + const countdown = meta.message.countdown !== undefined ? meta.message.countdown : undefined; const result: KeyValue = {}; if (countdown !== undefined) { // OnTime is a 16bit register and so might very well work up to 0xFFFF seconds but @@ -1267,7 +1264,7 @@ const tuyaTz = { // be set to the same value than ontime. const payload = {ctrlbits: 0, ontime: countdown, offwaittime: countdown}; await entity.command('genOnOff', 'onWithTimedOff', payload, utils.getOptions(meta.mapped, entity)); - if (result.hasOwnProperty('state')) { + if (result.state !== undefined) { result.countdown = countdown; } } @@ -1300,7 +1297,7 @@ const tuyaFz = { cluster: 'genLevelCtrl', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('61440')) { + if (msg.data['61440'] !== undefined) { const property = utils.postfixWithEndpointName('brightness', msg, model, meta); return {[property]: utils.mapNumberRange(msg.data['61440'], 0, 1000, 0, 255)}; } @@ -1322,7 +1319,7 @@ const tuyaFz = { cluster: 'genOnOff', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('moesStartUpOnOff')) { + if (msg.data.moesStartUpOnOff !== undefined) { const lookup: KeyValue = {0: 'off', 1: 'on', 2: 'previous'}; const property = utils.postfixWithEndpointName('power_on_behavior', msg, model, meta); return {[property]: lookup[msg.data['moesStartUpOnOff']]}; @@ -1335,7 +1332,7 @@ const tuyaFz = { convert: (model, msg, publish, options, meta) => { const attribute = 'powerOnBehavior'; const lookup: KeyValue = {0: 'off', 1: 'on', 2: 'previous'}; - if (msg.data.hasOwnProperty(attribute)) { + if (msg.data[attribute] !== undefined) { const property = utils.postfixWithEndpointName('power_on_behavior', msg, model, meta); return {[property]: lookup[msg.data[attribute]]}; } @@ -1345,7 +1342,7 @@ const tuyaFz = { cluster: 'genOnOff', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('moesStartUpOnOff')) { + if (msg.data.moesStartUpOnOff !== undefined) { const lookup: KeyValue = {0x00: 'off', 0x01: 'on', 0x02: 'restore'}; const property = utils.postfixWithEndpointName('power_outage_memory', msg, model, meta); return {[property]: lookup[msg.data['moesStartUpOnOff']]}; @@ -1356,7 +1353,7 @@ const tuyaFz = { cluster: 'manuSpecificTuya_3', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('switchType')) { + if (msg.data.switchType !== undefined) { const lookup: KeyValue = {0: 'toggle', 1: 'state', 2: 'momentary'}; return {switch_type: lookup[msg.data['switchType']]}; } @@ -1366,7 +1363,7 @@ const tuyaFz = { cluster: 'genOnOff', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('tuyaBacklightMode')) { + if (msg.data.tuyaBacklightMode !== undefined) { const value = msg.data['tuyaBacklightMode']; const backlightLookup: KeyValue = {0: 'low', 1: 'medium', 2: 'high'}; return {backlight_mode: backlightLookup[value]}; @@ -1377,7 +1374,7 @@ const tuyaFz = { cluster: 'genOnOff', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('tuyaBacklightMode')) { + if (msg.data.tuyaBacklightMode !== undefined) { return {backlight_mode: utils.getFromLookup(msg.data['tuyaBacklightMode'], {0: 'off', 1: 'normal', 2: 'inverted'})}; } }, @@ -1386,7 +1383,7 @@ const tuyaFz = { cluster: 'genOnOff', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('tuyaBacklightSwitch')) { + if (msg.data.tuyaBacklightSwitch !== undefined) { return {backlight_mode: utils.getFromLookup(msg.data['tuyaBacklightSwitch'], {0: 'OFF', 1: 'ON'})}; } }, @@ -1395,7 +1392,7 @@ const tuyaFz = { cluster: 'genOnOff', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('tuyaBacklightMode')) { + if (msg.data.tuyaBacklightMode !== undefined) { return {indicator_mode: utils.getFromLookup(msg.data['tuyaBacklightMode'], {0: 'off', 1: 'off/on', 2: 'on/off', 3: 'on'})}; } }, @@ -1404,7 +1401,7 @@ const tuyaFz = { cluster: 'genOnOff', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('32768')) { + if (msg.data['32768'] !== undefined) { const value = msg.data['32768']; return {child_lock: value ? 'LOCK' : 'UNLOCK'}; } @@ -1414,7 +1411,7 @@ const tuyaFz = { cluster: 'genLevelCtrl', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty(0xfc00)) { + if (msg.data[0xfc00] !== undefined) { const property = utils.postfixWithEndpointName('min_brightness', msg, model, meta); const value = parseInt(msg.data[0xfc00].toString(16).slice(0, 2), 16); return {[property]: value}; @@ -1465,7 +1462,7 @@ const tuyaFz = { cluster: 'genOnOff', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('onTime')) { + if (msg.data.onTime !== undefined) { const payload: KeyValue = {}; const property = utils.postfixWithEndpointName('countdown', msg, model, meta); const countdown = msg.data['onTime']; @@ -1478,7 +1475,7 @@ const tuyaFz = { cluster: 'manuSpecificTuya_4', type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty('inching')) { + if (msg.data.inching !== undefined) { const payload: KeyValue = {}; const value = valueConverter.inchingSwitch.from(msg.data['inching']); payload['inching_control_set'] = value; diff --git a/src/lib/ubisys.ts b/src/lib/ubisys.ts index 863382723e2a7..2403d24fab328 100644 --- a/src/lib/ubisys.ts +++ b/src/lib/ubisys.ts @@ -214,7 +214,7 @@ export const ubisysModernExtend = { cluster: clusterName, type: ['attributeReport', 'readResponse'], convert: (model, msg, publish, options, meta) => { - if (msg.data.hasOwnProperty(readableAttributeName)) { + if (msg.data[readableAttributeName] !== undefined) { return {[propertyName]: msg.data.occupancy === 0}; } }, diff --git a/src/lib/utils.ts b/src/lib/utils.ts index f1b4140583f32..481eb4a3dd9c3 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -21,7 +21,7 @@ import { const NS = 'zhc:utils'; export function isLegacyEnabled(options: KeyValue) { - return !options.hasOwnProperty('legacy') || options.legacy; + return options.legacy === undefined || options.legacy; } export function flatten(arr: Type[][]): Type[] { @@ -180,7 +180,7 @@ export function calibrateAndPrecisionRoundOptionsIsPercentual(type: string) { export function calibrateAndPrecisionRoundOptions(number: number, options: KeyValue, type: string) { // Calibrate const calibrateKey = `${type}_calibration`; - let calibrationOffset = toNumber(options && options.hasOwnProperty(calibrateKey) ? options[calibrateKey] : 0, calibrateKey); + let calibrationOffset = toNumber(options && options[calibrateKey] !== undefined ? options[calibrateKey] : 0, calibrateKey); if (calibrateAndPrecisionRoundOptionsIsPercentual(type)) { // linear calibration because measured value is zero based // +/- percent @@ -191,7 +191,7 @@ export function calibrateAndPrecisionRoundOptions(number: number, options: KeyVa // Precision round const precisionKey = `${type}_precision`; const defaultValue = calibrateAndPrecisionRoundOptionsDefaultPrecision[type] || 0; - const precision = toNumber(options && options.hasOwnProperty(precisionKey) ? options[precisionKey] : defaultValue, precisionKey); + const precision = toNumber(options && options[precisionKey] !== undefined ? options[precisionKey] : defaultValue, precisionKey); return precisionRound(number, precision); } @@ -233,7 +233,7 @@ export function postfixWithEndpointName(value: string, msg: Fz.Message, definiti definition.meta.multiEndpoint && (!definition.meta.multiEndpointSkip || !definition.meta.multiEndpointSkip.includes(value)) ) { - const endpointName = definition.hasOwnProperty('endpoint') ? getKey(definition.endpoint(meta.device), msg.endpoint.ID) : msg.endpoint.ID; + const endpointName = definition.endpoint !== undefined ? getKey(definition.endpoint(meta.device), msg.endpoint.ID) : msg.endpoint.ID; // NOTE: endpointName can be undefined if we have a definition.endpoint and the endpoint is // not listed. @@ -243,9 +243,9 @@ export function postfixWithEndpointName(value: string, msg: Fz.Message, definiti } export function enforceEndpoint(entity: Zh.Endpoint, key: string, meta: Tz.Meta) { - const multiEndpointEnforce = getMetaValue(entity, meta.mapped, 'multiEndpointEnforce', 'allEqual', []); - if (multiEndpointEnforce && multiEndpointEnforce.hasOwnProperty(key)) { - // @ts-expect-error ignore + // @ts-expect-error ignore + const multiEndpointEnforce: {[s: string]: number} = getMetaValue(entity, meta.mapped, 'multiEndpointEnforce', 'allEqual', []); + if (multiEndpointEnforce && isObject(multiEndpointEnforce) && multiEndpointEnforce[key] !== undefined) { const endpoint = entity.getDevice().getEndpoint(multiEndpointEnforce[key]); if (endpoint) return endpoint; } @@ -423,7 +423,7 @@ export function getLabelFromName(name: string) { export function saveSceneState(entity: Zh.Endpoint, sceneID: number, groupID: number, state: KeyValue, name: string) { const attributes = ['state', 'brightness', 'color', 'color_temp', 'color_mode']; - if (!entity.meta.hasOwnProperty('scenes')) entity.meta.scenes = {}; + if (entity.meta.scenes === undefined) entity.meta.scenes = {}; const metaKey = `${sceneID}_${groupID}`; entity.meta.scenes[metaKey] = {name, state: filterObject(state, attributes)}; entity.save(); @@ -435,7 +435,7 @@ export function deleteSceneState(entity: Zh.Endpoint, sceneID: number = null, gr entity.meta.scenes = {}; } else { const metaKey = `${sceneID}_${groupID}`; - if (entity.meta.scenes.hasOwnProperty(metaKey)) { + if (entity.meta.scenes[metaKey] !== undefined) { delete entity.meta.scenes[metaKey]; } } @@ -445,7 +445,7 @@ export function deleteSceneState(entity: Zh.Endpoint, sceneID: number = null, gr export function getSceneState(entity: Zh.Group | Zh.Endpoint, sceneID: number, groupID: number) { const metaKey = `${sceneID}_${groupID}`; - if (entity.meta.hasOwnProperty('scenes') && entity.meta.scenes.hasOwnProperty(metaKey)) { + if (entity.meta.scenes !== undefined && entity.meta.scenes[metaKey] !== undefined) { return entity.meta.scenes[metaKey].state; } @@ -477,15 +477,15 @@ export function getTransition(entity: Zh.Endpoint | Zh.Group, key: string, meta: * To workaround this we skip the transition for the brightness as it is applied first. * https://github.com/Koenkk/zigbee2mqtt/issues/1810 */ - if (key === 'brightness' && (message.hasOwnProperty('color') || message.hasOwnProperty('color_temp'))) { + if (key === 'brightness' && (message.color !== undefined || message.color_temp !== undefined)) { return {time: 0, specified: false}; } } - if (message.hasOwnProperty('transition')) { + if (message.transition !== undefined) { const time = toNumber(message.transition, 'transition'); return {time: time * 10, specified: true}; - } else if (options.hasOwnProperty('transition') && options.transition !== '') { + } else if (options.transition !== undefined && options.transition !== '') { const transition = toNumber(options.transition, 'transition'); return {time: transition * 10, specified: true}; } else { @@ -521,7 +521,7 @@ export function getMetaValues(definitions: Definition | Definition[], entity: Zh } export function getObjectProperty(object: KeyValue, key: string, defaultValue: unknown) { - return object && object.hasOwnProperty(key) ? object[key] : defaultValue; + return object && object[key] !== undefined ? object[key] : defaultValue; } export function validateValue(value: unknown, allowed: unknown[]) { @@ -640,12 +640,12 @@ export function getFromLookup(value: unknown, lookup: {[s: number | string]: if (!keyIsBool) { if (typeof value === 'string') { for (const key of [value, value.toLowerCase(), value.toUpperCase()]) { - if (lookup.hasOwnProperty(key)) { + if (lookup[key] !== undefined) { return lookup[key]; } } } else if (typeof value === 'number') { - if (lookup.hasOwnProperty(value)) { + if (lookup[value] !== undefined) { return lookup[value]; } } else { @@ -656,7 +656,7 @@ export function getFromLookup(value: unknown, lookup: {[s: number | string]: if (typeof value === 'boolean') { const stringValue = value.toString(); for (const key of [stringValue, stringValue.toLowerCase(), stringValue.toUpperCase()]) { - if (lookup.hasOwnProperty(key)) { + if (lookup[key] !== undefined) { return lookup[key]; } } diff --git a/test/index.test.js b/test/index.test.js index b8fc36f04ee9b..b881098102a56 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -203,7 +203,7 @@ describe('index.js', () => { index.definitions.forEach((device) => { // Check for duplicate zigbee model ids - if (device.hasOwnProperty('zigbeeModel')) { + if (device.zigbeeModel !== undefined) { device.zigbeeModel.forEach((m) => { if (foundZigbeeModels.includes(m.toLowerCase())) { throw new Error(`Duplicate zigbee model ${m}`); From 097c04009b05508e04bedce5a2332dacb525a9c6 Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Mon, 9 Sep 2024 23:24:41 +0200 Subject: [PATCH 10/12] process feedback --- scripts/modernExtendRefactor.ts | 3 +-- src/converters/fromZigbee.ts | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/modernExtendRefactor.ts b/scripts/modernExtendRefactor.ts index f9b4da654a274..6467308d8c77b 100644 --- a/scripts/modernExtendRefactor.ts +++ b/scripts/modernExtendRefactor.ts @@ -60,8 +60,7 @@ project.getSourceFiles().forEach((sourceFile) => { const evalOpts = Object.entries(eval(`(${opts})`)); for (const [key, value] of evalOpts) { if (key === 'colorTempRange') { - // @ts-expect-error ignore - newOpts.colorTemp = {...newOpts.colorTemp, range: value}; + newOpts.colorTemp = {...(newOpts.colorTemp as object), range: value}; } else if (key === 'disableColorTempStartup') { // @ts-expect-error ignore newOpts.colorTemp = {...newOpts.colorTemp, startup: !value}; diff --git a/src/converters/fromZigbee.ts b/src/converters/fromZigbee.ts index a487d7a538b26..0fe67e122738c 100644 --- a/src/converters/fromZigbee.ts +++ b/src/converters/fromZigbee.ts @@ -2360,8 +2360,7 @@ const converters1 = { convert: (model, msg, publish, options, meta) => { const dp = msg.data[10]; const defaults = {motor_direction: 'FORWARD', motor_speed: 40}; - // @ts-expect-error ignore - if ((msg.data[0] === 0x7a) & (msg.data[1] === 0xd1)) { + if (msg.data[0] === 0x7a && msg.data[1] === 0xd1) { const reportType = msg.data[12]; switch (dp) { case 0x0c: From 5b35244adec2350233a0ce666895004ed71bcc86 Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Thu, 12 Sep 2024 21:13:50 +0200 Subject: [PATCH 11/12] @typescript-eslint/return-await --- eslint.config.mjs | 2 +- src/lib/ota/common.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index d18724fb43e23..bb9c6d327531a 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -21,7 +21,7 @@ export default tseslint.config( '@typescript-eslint/no-explicit-any': 'error', '@typescript-eslint/no-unused-vars': ['error', {args: 'none'}], 'array-bracket-spacing': ['error', 'never'], - 'no-return-await': 'error', + '@typescript-eslint/return-await': 'error', 'object-curly-spacing': ['error', 'never'], '@typescript-eslint/no-floating-promises': 'error', }, diff --git a/src/lib/ota/common.ts b/src/lib/ota/common.ts index 7971429ec9ed3..f9a5a43b7359a 100644 --- a/src/lib/ota/common.ts +++ b/src/lib/ota/common.ts @@ -712,7 +712,7 @@ export async function updateToLatest( let timer: NodeJS.Timeout = null; - return new Promise((resolve) => { + return await new Promise((resolve) => { const onDeviceAnnounce = () => { clearTimeout(timer); logger.debug(`Received device announce, update finished.`, NS); From 5ba3ab18769907258ca519c2c2275204736caf8e Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Thu, 12 Sep 2024 21:18:11 +0200 Subject: [PATCH 12/12] `@typescript-eslint/return-await` `always` --- eslint.config.mjs | 2 +- src/converters/toZigbee.ts | 24 ++++++++++++------------ src/devices/custom_devices_diy.ts | 4 ++-- src/devices/gledopto.ts | 10 +++++----- src/devices/livolo.ts | 8 ++++---- src/devices/multiterm.ts | 2 +- src/devices/schneider_electric.ts | 2 +- src/devices/siglis.ts | 6 +++--- src/devices/sunricher.ts | 2 +- src/devices/tuya.ts | 2 +- src/devices/ubisys.ts | 2 +- src/lib/legacy.ts | 16 ++++++++-------- src/lib/lumi.ts | 8 ++++---- src/lib/ota/common.ts | 2 +- src/lib/ota/gmmts.ts | 4 ++-- src/lib/ota/inovelli.ts | 4 ++-- src/lib/ota/jethome.ts | 4 ++-- src/lib/ota/ledvance.ts | 4 ++-- src/lib/ota/lixee.ts | 4 ++-- src/lib/ota/salus.ts | 6 +++--- src/lib/ota/securifi.ts | 4 ++-- src/lib/ota/tradfri.ts | 4 ++-- src/lib/ota/ubisys.ts | 4 ++-- src/lib/ota/zigbeeOTA.ts | 6 +++--- src/lib/philips.ts | 2 +- src/lib/tuya.ts | 12 ++++++------ src/lib/utils.ts | 2 +- 27 files changed, 75 insertions(+), 75 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index bb9c6d327531a..bbd931215bbd3 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -21,7 +21,7 @@ export default tseslint.config( '@typescript-eslint/no-explicit-any': 'error', '@typescript-eslint/no-unused-vars': ['error', {args: 'none'}], 'array-bracket-spacing': ['error', 'never'], - '@typescript-eslint/return-await': 'error', + '@typescript-eslint/return-await': ['error', 'always'], 'object-curly-spacing': ['error', 'never'], '@typescript-eslint/no-floating-promises': 'error', }, diff --git a/src/converters/toZigbee.ts b/src/converters/toZigbee.ts index 0e2d5f566b7cf..42073fae94c59 100644 --- a/src/converters/toZigbee.ts +++ b/src/converters/toZigbee.ts @@ -965,7 +965,7 @@ const converters2 = { options: [exposes.options.color_sync(), exposes.options.transition()], convertSet: async (entity, key, value, meta) => { if (key == 'color') { - return converters1.light_color.convertSet(entity, key, value, meta); + return await converters1.light_color.convertSet(entity, key, value, meta); } else if (key == 'color_temp' || key == 'color_temp_percent') { utils.assertNumber(value); const xy = libColor.ColorXY.fromMireds(value); @@ -2548,7 +2548,7 @@ const converters2 = { utils.assertNumber(value, key); if (meta.options.time_close !== undefined && meta.options.time_open !== undefined) { const sleepSeconds = async (s: number) => { - return new Promise((resolve) => setTimeout(resolve, s * 1000)); + return await new Promise((resolve) => setTimeout(resolve, s * 1000)); }; const oldPosition = meta.state.position; @@ -4370,10 +4370,10 @@ const converters3 = { message.brightness = deviceState.brightness; } - return converters2.light_onoff_brightness.convertSet(entity, key, value, meta); + return await converters2.light_onoff_brightness.convertSet(entity, key, value, meta); }, convertGet: async (entity, key, meta) => { - return converters2.light_onoff_brightness.convertGet(entity, key, meta); + return await converters2.light_onoff_brightness.convertGet(entity, key, meta); }, } satisfies Tz.Converter, RM01_light_onoff_brightness: { @@ -4382,7 +4382,7 @@ const converters3 = { convertSet: async (entity, key, value, meta) => { if (utils.hasEndpoints(meta.device, [0x12])) { const endpoint = meta.device.getEndpoint(0x12); - return converters2.light_onoff_brightness.convertSet(endpoint, key, value, meta); + return await converters2.light_onoff_brightness.convertSet(endpoint, key, value, meta); } else { throw new Error('OnOff and LevelControl not supported on this RM01 device.'); } @@ -4390,7 +4390,7 @@ const converters3 = { convertGet: async (entity, key, meta) => { if (utils.hasEndpoints(meta.device, [0x12])) { const endpoint = meta.device.getEndpoint(0x12); - return converters2.light_onoff_brightness.convertGet(endpoint, key, meta); + return await converters2.light_onoff_brightness.convertGet(endpoint, key, meta); } else { throw new Error('OnOff and LevelControl not supported on this RM01 device.'); } @@ -4402,7 +4402,7 @@ const converters3 = { convertSet: async (entity, key, value, meta) => { if (utils.hasEndpoints(meta.device, [0x12])) { const endpoint = meta.device.getEndpoint(0x12); - return converters2.light_brightness_step.convertSet(endpoint, key, value, meta); + return await converters2.light_brightness_step.convertSet(endpoint, key, value, meta); } else { throw new Error('LevelControl not supported on this RM01 device.'); } @@ -4413,7 +4413,7 @@ const converters3 = { convertSet: async (entity, key, value, meta) => { if (utils.hasEndpoints(meta.device, [0x12])) { const endpoint = meta.device.getEndpoint(0x12); - return converters2.light_brightness_move.convertSet(endpoint, key, value, meta); + return await converters2.light_brightness_move.convertSet(endpoint, key, value, meta); } else { throw new Error('LevelControl not supported on this RM01 device.'); } @@ -4440,7 +4440,7 @@ const converters3 = { message.state = 'off'; message.brightness = 1; } - return converters2.light_onoff_brightness.convertSet(entity, key, value, meta); + return await converters2.light_onoff_brightness.convertSet(entity, key, value, meta); } else { throw new Error('LevelControl not supported on this endpoint.'); } @@ -4449,7 +4449,7 @@ const converters3 = { const cluster = 'genLevelCtrl'; utils.assertEndpoint(entity); if (entity.supportsInputCluster(cluster) || entity.supportsOutputCluster(cluster)) { - return converters2.light_onoff_brightness.convertGet(entity, key, meta); + return await converters2.light_onoff_brightness.convertGet(entity, key, meta); } else { throw new Error('LevelControl not supported on this endpoint.'); } @@ -4483,7 +4483,7 @@ const converters3 = { convertSet: async (entity, key, value, meta) => { const {message, state} = meta; if (message.state === 'OFF' || (message.state !== undefined && message.brightness === undefined)) { - return converters1.on_off.convertSet(entity, key, value, meta); + return await converters1.on_off.convertSet(entity, key, value, meta); } else if (message.brightness !== undefined) { // set brightness if (state.state === 'OFF') { @@ -4510,7 +4510,7 @@ const converters3 = { // https://github.com/Koenkk/zigbee2mqtt/issues/15902#issuecomment-1382848150 await entity.command('genOnOff', 'on', {}, utils.getOptions(meta.mapped, entity)); } - return converters2.light_onoff_brightness.convertSet(entity, key, value, meta); + return await converters2.light_onoff_brightness.convertSet(entity, key, value, meta); }, } satisfies Tz.Converter, }; diff --git a/src/devices/custom_devices_diy.ts b/src/devices/custom_devices_diy.ts index fadef0d5edd15..0d6b4605cd82b 100644 --- a/src/devices/custom_devices_diy.ts +++ b/src/devices/custom_devices_diy.ts @@ -56,12 +56,12 @@ const tzLocal = { ptvo_on_off: { key: ['state'], convertSet: async (entity, key, value, meta) => { - return tz.on_off.convertSet(entity, key, value, meta); + return await tz.on_off.convertSet(entity, key, value, meta); }, convertGet: async (entity, key, meta) => { const cluster = 'genOnOff'; if (isEndpoint(entity) && (entity.supportsInputCluster(cluster) || entity.supportsOutputCluster(cluster))) { - return tz.on_off.convertGet(entity, key, meta); + return await tz.on_off.convertGet(entity, key, meta); } return; }, diff --git a/src/devices/gledopto.ts b/src/devices/gledopto.ts index daa35e70e9b9c..7f6e0570001cc 100644 --- a/src/devices/gledopto.ts +++ b/src/devices/gledopto.ts @@ -29,10 +29,10 @@ const tzLocal1 = { } } - return tz.light_onoff_brightness.convertSet(entity, key, value, meta); + return await tz.light_onoff_brightness.convertSet(entity, key, value, meta); }, convertGet: async (entity, key, meta) => { - return tz.light_onoff_brightness.convertGet(entity, key, meta); + return await tz.light_onoff_brightness.convertGet(entity, key, meta); }, } satisfies Tz.Converter, gledopto_light_colortemp: { @@ -54,7 +54,7 @@ const tzLocal1 = { return result; }, convertGet: async (entity, key, meta) => { - return tz.light_colortemp.convertGet(entity, key, meta); + return await tz.light_colortemp.convertGet(entity, key, meta); }, } satisfies Tz.Converter, gledopto_light_color: { @@ -81,7 +81,7 @@ const tzLocal1 = { return result; }, convertGet: async (entity, key, meta) => { - return tz.light_color.convertGet(entity, key, meta); + return await tz.light_color.convertGet(entity, key, meta); }, } satisfies Tz.Converter, }; @@ -108,7 +108,7 @@ const tzLocal = { } }, convertGet: async (entity, key, meta) => { - return tz.light_color_colortemp.convertGet(entity, key, meta); + return await tz.light_color_colortemp.convertGet(entity, key, meta); }, } satisfies Tz.Converter, }; diff --git a/src/devices/livolo.ts b/src/devices/livolo.ts index 4b7f355102160..82bb6e452df3c 100644 --- a/src/devices/livolo.ts +++ b/src/devices/livolo.ts @@ -43,7 +43,7 @@ const definitions: DefinitionWithExtend[] = [ if (['start', 'deviceAnnounce'].includes(type)) { await poll(device); if (!globalStore.hasValue(device, 'interval')) { - const interval = setInterval(async () => poll(device), 300 * 1000); + const interval = setInterval(async () => await poll(device), 300 * 1000); globalStore.putValue(device, 'interval', interval); } } @@ -271,7 +271,7 @@ const definitions: DefinitionWithExtend[] = [ if (['start', 'deviceAnnounce'].includes(type)) { await poll(device); if (!globalStore.hasValue(device, 'interval')) { - const interval = setInterval(async () => poll(device), 10 * 1000); + const interval = setInterval(async () => await poll(device), 10 * 1000); globalStore.putValue(device, 'interval', interval); } } @@ -312,7 +312,7 @@ const definitions: DefinitionWithExtend[] = [ if (['start', 'deviceAnnounce'].includes(type)) { await poll(device); if (!globalStore.hasValue(device, 'interval')) { - const interval = setInterval(async () => poll(device), 60 * 1000); + const interval = setInterval(async () => await poll(device), 60 * 1000); globalStore.putValue(device, 'interval', interval); } } @@ -357,7 +357,7 @@ const definitions: DefinitionWithExtend[] = [ if (['start', 'deviceAnnounce'].includes(type)) { await poll(device); if (!globalStore.hasValue(device, 'interval')) { - const interval = setInterval(async () => poll(device), 300 * 1000); + const interval = setInterval(async () => await poll(device), 300 * 1000); globalStore.putValue(device, 'interval', interval); } } diff --git a/src/devices/multiterm.ts b/src/devices/multiterm.ts index 6aa236dea29b8..c27102ffcb58c 100644 --- a/src/devices/multiterm.ts +++ b/src/devices/multiterm.ts @@ -36,7 +36,7 @@ const tzLocal = { ...tz.fan_mode, convertSet: async (entity, key, value, meta) => { if (String(value).toLowerCase() === 'on') value = 'high'; - return tz.fan_mode.convertSet(entity, key, value, meta); + return await tz.fan_mode.convertSet(entity, key, value, meta); }, } satisfies Tz.Converter, binary_output: { diff --git a/src/devices/schneider_electric.ts b/src/devices/schneider_electric.ts index a9a4065450934..c00f29968ab18 100644 --- a/src/devices/schneider_electric.ts +++ b/src/devices/schneider_electric.ts @@ -326,7 +326,7 @@ const tzLocal = { convertSet: async (entity, key, value, meta) => { utils.assertString(value); if (value.toLowerCase() === 'on') value = 'low'; - return tz.fan_mode.convertSet(entity, key, value, meta); + return await tz.fan_mode.convertSet(entity, key, value, meta); }, } satisfies Tz.Converter, }; diff --git a/src/devices/siglis.ts b/src/devices/siglis.ts index c75605b7dd00e..02bc1d1d2cb94 100644 --- a/src/devices/siglis.ts +++ b/src/devices/siglis.ts @@ -49,13 +49,13 @@ const coverAndLightToZigbee: Tz.Converter = { const isCover = entity.ID === 0x0b || entity.ID === 0x0c; if (isCover) { if (key === 'state') { - return tz.cover_state.convertSet(entity, key, value, meta); + return await tz.cover_state.convertSet(entity, key, value, meta); } else if (key === 'position' || key === 'tilt') { - return tz.cover_position_tilt.convertSet(entity, key, value, meta); + return await tz.cover_position_tilt.convertSet(entity, key, value, meta); } } else { if (key === 'state' || key === 'brightness' || key === 'brightness_percent' || key === 'on_time') { - return tz.light_onoff_brightness.convertSet(entity, key, value, meta); + return await tz.light_onoff_brightness.convertSet(entity, key, value, meta); } } }, diff --git a/src/devices/sunricher.ts b/src/devices/sunricher.ts index 621949582de65..202f3fc963b85 100644 --- a/src/devices/sunricher.ts +++ b/src/devices/sunricher.ts @@ -594,7 +594,7 @@ const definitions: DefinitionWithExtend[] = [ const endpoint = device.getEndpoint(1); const hours24 = 1000 * 60 * 60 * 24; // Device does not ask for the time with binding, therefore we write the time every 24 hours - const interval = setInterval(async () => syncTime(endpoint), hours24); + const interval = setInterval(async () => await syncTime(endpoint), hours24); globalStore.putValue(device, 'time', interval); } }, diff --git a/src/devices/tuya.ts b/src/devices/tuya.ts index 1f235835d52fd..47d2ba53adb45 100644 --- a/src/devices/tuya.ts +++ b/src/devices/tuya.ts @@ -401,7 +401,7 @@ const tzLocal = { } return {state: libColor.syncColorState(newState, meta.state, entity, meta.options) as KeyValue}; } else { - return tz.light_color.convertSet(entity, key, value, meta); + return await tz.light_color.convertSet(entity, key, value, meta); } }, convertGet: tz.light_color.convertGet, diff --git a/src/devices/ubisys.ts b/src/devices/ubisys.ts index c8bb9bf83ef43..56eb53aa74935 100644 --- a/src/devices/ubisys.ts +++ b/src/devices/ubisys.ts @@ -129,7 +129,7 @@ const ubisys = { logger.warning(`ubisys: ${message}`, NS); }; const sleepSeconds = async (s: number) => { - return new Promise((resolve) => setTimeout(resolve, s * 1000)); + return await new Promise((resolve) => setTimeout(resolve, s * 1000)); }; const waitUntilStopped = async () => { let operationalStatus = 0; diff --git a/src/lib/legacy.ts b/src/lib/legacy.ts index d2651c23a4561..5618afa5e1421 100644 --- a/src/lib/legacy.ts +++ b/src/lib/legacy.ts @@ -180,31 +180,31 @@ function dpValueFromBitmap(dp: number, bitmapBuffer: any) { // Return `seq` - transaction ID for handling concrete response async function sendDataPoint(entity: Zh.Endpoint | Zh.Group, dpValue: any, cmd?: string, seq: number = undefined) { - return sendDataPoints(entity, [dpValue], cmd, seq); + return await sendDataPoints(entity, [dpValue], cmd, seq); } async function sendDataPointValue(entity: Zh.Endpoint | Zh.Group, dp: number, value: any, cmd?: string, seq: number = undefined) { - return sendDataPoints(entity, [dpValueFromIntValue(dp, value)], cmd, seq); + return await sendDataPoints(entity, [dpValueFromIntValue(dp, value)], cmd, seq); } async function sendDataPointBool(entity: Zh.Endpoint | Zh.Group, dp: number, value: boolean | number, cmd?: string, seq: number = undefined) { - return sendDataPoints(entity, [dpValueFromBool(dp, value)], cmd, seq); + return await sendDataPoints(entity, [dpValueFromBool(dp, value)], cmd, seq); } async function sendDataPointEnum(entity: Zh.Endpoint | Zh.Group, dp: number, value: number, cmd?: string, seq: number = undefined) { - return sendDataPoints(entity, [dpValueFromEnum(dp, value)], cmd, seq); + return await sendDataPoints(entity, [dpValueFromEnum(dp, value)], cmd, seq); } async function sendDataPointRaw(entity: Zh.Endpoint | Zh.Group, dp: number, value: any, cmd?: string, seq: number = undefined) { - return sendDataPoints(entity, [dpValueFromRaw(dp, value)], cmd, seq); + return await sendDataPoints(entity, [dpValueFromRaw(dp, value)], cmd, seq); } async function sendDataPointBitmap(entity: Zh.Endpoint | Zh.Group, dp: number, value: any, cmd?: string, seq: number = undefined) { - return sendDataPoints(entity, [dpValueFromBitmap(dp, value)], cmd, seq); + return await sendDataPoints(entity, [dpValueFromBitmap(dp, value)], cmd, seq); } async function sendDataPointStringBuffer(entity: Zh.Endpoint | Zh.Group, dp: number, value: any, cmd?: string, seq: number = undefined) { - return sendDataPoints(entity, [dpValueFromStringBuffer(dp, value)], cmd, seq); + return await sendDataPoints(entity, [dpValueFromStringBuffer(dp, value)], cmd, seq); } function convertRawToCycleTimer(value: any) { @@ -5880,7 +5880,7 @@ const toZigbee2 = { } else { value = parseInt(value); } - return toZigbee1.tuya_cover_control.convertSet(entity, 'position', value, meta); + return await toZigbee1.tuya_cover_control.convertSet(entity, 'position', value, meta); } case 'report': { await sendDataPointBool(entity, 116, 0); diff --git a/src/lib/lumi.ts b/src/lib/lumi.ts index bf622e11c775d..6a40f9e90c20e 100644 --- a/src/lib/lumi.ts +++ b/src/lib/lumi.ts @@ -1867,7 +1867,7 @@ export const lumiModernExtend = { cluster: 'manuSpecificLumi', type: ['attributeReport', 'readResponse'], convert: async (model, msg, publish, options, meta) => { - return numericAttributes2Payload(msg, meta, model, options, msg.data); + return await numericAttributes2Payload(msg, meta, model, options, msg.data); }, }, ]; @@ -2240,7 +2240,7 @@ export const fromZigbee = { cluster: 'genBasic', type: ['attributeReport', 'readResponse'], convert: async (model, msg, publish, options, meta) => { - return numericAttributes2Payload(msg, meta, model, options, msg.data); + return await numericAttributes2Payload(msg, meta, model, options, msg.data); }, } satisfies Fz.Converter, lumi_basic_raw: { @@ -2259,7 +2259,7 @@ export const fromZigbee = { cluster: 'manuSpecificLumi', type: ['attributeReport', 'readResponse'], convert: async (model, msg, publish, options, meta) => { - return numericAttributes2Payload(msg, meta, model, options, msg.data); + return await numericAttributes2Payload(msg, meta, model, options, msg.data); }, } satisfies Fz.Converter, lumi_co2: { @@ -4889,7 +4889,7 @@ export const toZigbee = { // Wait until the curtain gets into a moving state, then wait until it gets blocked or stopped const waitForStateTransition = async (initialStates: number[], desiredStates: number[]): Promise => { - return new Promise((resolve) => { + return await new Promise((resolve) => { const checkState = async () => { const result = await entity.read('manuSpecificLumi', [0x0421]); const state = result ? result[0x0421] : null; diff --git a/src/lib/ota/common.ts b/src/lib/ota/common.ts index f9a5a43b7359a..f8fb0a594e62b 100644 --- a/src/lib/ota/common.ts +++ b/src/lib/ota/common.ts @@ -154,7 +154,7 @@ export async function getFirmwareFile(image: KeyValueAny): Promise<{data: Buffer // First try to download firmware file with the URL provided if (isValidUrl(urlOrName)) { logger.debug(`Downloading firmware image from '${urlOrName}'`, NS); - return getAxios().get(urlOrName, {responseType: 'arraybuffer'}); + return await getAxios().get(urlOrName, {responseType: 'arraybuffer'}); } logger.debug(`Try to read firmware image from local file '${urlOrName}'`, NS); diff --git a/src/lib/ota/gmmts.ts b/src/lib/ota/gmmts.ts index ce0593d0b7a36..d5f2e15e3a575 100644 --- a/src/lib/ota/gmmts.ts +++ b/src/lib/ota/gmmts.ts @@ -38,11 +38,11 @@ export async function getImageMeta(current: Ota.ImageInfo, device: Zh.Device): P */ export async function isUpdateAvailable(device: Zh.Device, requestPayload: Ota.ImageInfo = null) { - return common.isUpdateAvailable(device, requestPayload, common.isNewImageAvailable, getImageMeta); + return await common.isUpdateAvailable(device, requestPayload, common.isNewImageAvailable, getImageMeta); } export async function updateToLatest(device: Zh.Device, onProgress: Ota.OnProgress) { - return common.updateToLatest(device, onProgress, common.getNewImage, getImageMeta); + return await common.updateToLatest(device, onProgress, common.getNewImage, getImageMeta); } exports.isUpdateAvailable = isUpdateAvailable; diff --git a/src/lib/ota/inovelli.ts b/src/lib/ota/inovelli.ts index fa5d62a89fd8a..d5621af26acbc 100644 --- a/src/lib/ota/inovelli.ts +++ b/src/lib/ota/inovelli.ts @@ -66,11 +66,11 @@ export async function getImageMeta(current: Ota.ImageInfo, device: Zh.Device): P */ export async function isUpdateAvailable(device: Zh.Device, requestPayload: Ota.ImageInfo = null) { - return common.isUpdateAvailable(device, requestPayload, common.isNewImageAvailable, getImageMeta); + return await common.isUpdateAvailable(device, requestPayload, common.isNewImageAvailable, getImageMeta); } export async function updateToLatest(device: Zh.Device, onProgress: Ota.OnProgress) { - return common.updateToLatest(device, onProgress, common.getNewImage, getImageMeta); + return await common.updateToLatest(device, onProgress, common.getNewImage, getImageMeta); } exports.isUpdateAvailable = isUpdateAvailable; diff --git a/src/lib/ota/jethome.ts b/src/lib/ota/jethome.ts index b2c0138e3ef05..1b3a6025f0c9b 100644 --- a/src/lib/ota/jethome.ts +++ b/src/lib/ota/jethome.ts @@ -63,11 +63,11 @@ export async function getImageMeta(current: Ota.ImageInfo, device: Zh.Device): P */ export async function isUpdateAvailable(device: Zh.Device, requestPayload: Ota.ImageInfo = null) { - return common.isUpdateAvailable(device, requestPayload, common.isNewImageAvailable, getImageMeta); + return await common.isUpdateAvailable(device, requestPayload, common.isNewImageAvailable, getImageMeta); } export async function updateToLatest(device: Zh.Device, onProgress: Ota.OnProgress) { - return common.updateToLatest(device, onProgress, common.getNewImage, getImageMeta, common.getFirmwareFile); + return await common.updateToLatest(device, onProgress, common.getNewImage, getImageMeta, common.getFirmwareFile); } export const useIndexOverride = (indexFileName: string) => { diff --git a/src/lib/ota/ledvance.ts b/src/lib/ota/ledvance.ts index 60cca26886e9d..75e7b4bac0ac4 100644 --- a/src/lib/ota/ledvance.ts +++ b/src/lib/ota/ledvance.ts @@ -46,14 +46,14 @@ export async function getImageMeta(current: Ota.ImageInfo, device: Zh.Device): P */ export async function isUpdateAvailable(device: Zh.Device, requestPayload: Ota.ImageInfo = null) { - return common.isUpdateAvailable(device, requestPayload, common.isNewImageAvailable, getImageMeta); + return await common.isUpdateAvailable(device, requestPayload, common.isNewImageAvailable, getImageMeta); } export async function updateToLatest(device: Zh.Device, onProgress: Ota.OnProgress) { // Ledvance OTAs are not valid against the Zigbee spec, the last image element fails to parse but the // update succeeds even without sending it. Therefore set suppressElementImageParseFailure to true // https://github.com/Koenkk/zigbee2mqtt/issues/16900 - return common.updateToLatest(device, onProgress, common.getNewImage, getImageMeta, null, true); + return await common.updateToLatest(device, onProgress, common.getNewImage, getImageMeta, null, true); } exports.isUpdateAvailable = isUpdateAvailable; diff --git a/src/lib/ota/lixee.ts b/src/lib/ota/lixee.ts index 7b9572bdefbea..cb3ed9a6a1560 100644 --- a/src/lib/ota/lixee.ts +++ b/src/lib/ota/lixee.ts @@ -51,11 +51,11 @@ export async function getImageMeta(current: Ota.ImageInfo, device: Zh.Device): P */ export async function isUpdateAvailable(device: Zh.Device, requestPayload: Ota.ImageInfo = null) { - return common.isUpdateAvailable(device, requestPayload, common.isNewImageAvailable, getImageMeta); + return await common.isUpdateAvailable(device, requestPayload, common.isNewImageAvailable, getImageMeta); } export async function updateToLatest(device: Zh.Device, onProgress: Ota.OnProgress) { - return common.updateToLatest(device, onProgress, common.getNewImage, getImageMeta); + return await common.updateToLatest(device, onProgress, common.getNewImage, getImageMeta); } exports.isUpdateAvailable = isUpdateAvailable; diff --git a/src/lib/ota/salus.ts b/src/lib/ota/salus.ts index 13b8f21cef129..64789f5bdd64a 100644 --- a/src/lib/ota/salus.ts +++ b/src/lib/ota/salus.ts @@ -34,7 +34,7 @@ export async function getImageMeta(current: Ota.ImageInfo, device: Zh.Device): P } async function untar(tarStream: NodeJS.ReadStream) { - return new Promise((resolve, reject) => { + return await new Promise((resolve, reject) => { const extract = tar.extract(); const result: KeyValue[] = []; @@ -84,11 +84,11 @@ async function downloadImage(meta: KeyValueAny) { */ export async function isUpdateAvailable(device: Zh.Device, requestPayload: Ota.ImageInfo = null) { - return common.isUpdateAvailable(device, requestPayload, common.isNewImageAvailable, getImageMeta); + return await common.isUpdateAvailable(device, requestPayload, common.isNewImageAvailable, getImageMeta); } export async function updateToLatest(device: Zh.Device, onProgress: Ota.OnProgress) { - return common.updateToLatest(device, onProgress, common.getNewImage, getImageMeta, downloadImage); + return await common.updateToLatest(device, onProgress, common.getNewImage, getImageMeta, downloadImage); } exports.isUpdateAvailable = isUpdateAvailable; diff --git a/src/lib/ota/securifi.ts b/src/lib/ota/securifi.ts index 01ed9cc82d15c..c7be9703f4ea2 100644 --- a/src/lib/ota/securifi.ts +++ b/src/lib/ota/securifi.ts @@ -8,7 +8,7 @@ export async function isUpdateAvailable(device: Zh.Device, requestPayload: Ota.I const scenesEndpoint = device.endpoints.find((e) => e.supportsOutputCluster('genScenes')); await scenesEndpoint.write('genScenes', {currentGroup: 49502}); } - return common.isUpdateAvailable(device, requestPayload, common.isNewImageAvailable, zigbeeOTA.getImageMeta); + return await common.isUpdateAvailable(device, requestPayload, common.isNewImageAvailable, zigbeeOTA.getImageMeta); } export async function updateToLatest(device: Zh.Device, onProgress: Ota.OnProgress) { @@ -17,7 +17,7 @@ export async function updateToLatest(device: Zh.Device, onProgress: Ota.OnProgre const scenesEndpoint = device.endpoints.find((e) => e.supportsOutputCluster('genScenes')); await scenesEndpoint.write('genScenes', {currentGroup: 49502}); } - return common.updateToLatest(device, onProgress, common.getNewImage, zigbeeOTA.getImageMeta); + return await common.updateToLatest(device, onProgress, common.getNewImage, zigbeeOTA.getImageMeta); } exports.isUpdateAvailable = isUpdateAvailable; diff --git a/src/lib/ota/tradfri.ts b/src/lib/ota/tradfri.ts index 42ac00be732ef..0e43de668ec49 100644 --- a/src/lib/ota/tradfri.ts +++ b/src/lib/ota/tradfri.ts @@ -39,11 +39,11 @@ export async function getImageMeta(current: Ota.ImageInfo, device: Zh.Device): P */ export async function isUpdateAvailable(device: Zh.Device, requestPayload: Ota.ImageInfo = null) { - return common.isUpdateAvailable(device, requestPayload, common.isNewImageAvailable, getImageMeta); + return await common.isUpdateAvailable(device, requestPayload, common.isNewImageAvailable, getImageMeta); } export async function updateToLatest(device: Zh.Device, onProgress: Ota.OnProgress) { - return common.updateToLatest(device, onProgress, common.getNewImage, getImageMeta); + return await common.updateToLatest(device, onProgress, common.getNewImage, getImageMeta); } const useTestURL_ = () => { diff --git a/src/lib/ota/ubisys.ts b/src/lib/ota/ubisys.ts index bd4634c759e79..70e1785baf802 100644 --- a/src/lib/ota/ubisys.ts +++ b/src/lib/ota/ubisys.ts @@ -69,11 +69,11 @@ export async function getImageMeta(current: Ota.ImageInfo, device: Zh.Device): P */ export async function isUpdateAvailable(device: Zh.Device, requestPayload: Ota.ImageInfo = null) { - return common.isUpdateAvailable(device, requestPayload, common.isNewImageAvailable, getImageMeta); + return await common.isUpdateAvailable(device, requestPayload, common.isNewImageAvailable, getImageMeta); } export async function updateToLatest(device: Zh.Device, onProgress: Ota.OnProgress) { - return common.updateToLatest(device, onProgress, common.getNewImage, getImageMeta); + return await common.updateToLatest(device, onProgress, common.getNewImage, getImageMeta); } exports.isUpdateAvailable = isUpdateAvailable; diff --git a/src/lib/ota/zigbeeOTA.ts b/src/lib/ota/zigbeeOTA.ts index 9f6fdadc77b1e..0491bdaa9e69c 100644 --- a/src/lib/ota/zigbeeOTA.ts +++ b/src/lib/ota/zigbeeOTA.ts @@ -96,7 +96,7 @@ async function isNewImageAvailable(current: Ota.ImageInfo, device: Zh.Device, ge current = {...current, fileVersion: device.meta.lumiFileVersion}; } } - return common.isNewImageAvailable(current, device, getImageMeta); + return await common.isNewImageAvailable(current, device, getImageMeta); } export async function getFirmwareFile(image: KeyValueAny) { @@ -119,11 +119,11 @@ export async function getFirmwareFile(image: KeyValueAny) { */ export async function isUpdateAvailable(device: Zh.Device, requestPayload: Ota.ImageInfo = null) { - return common.isUpdateAvailable(device, requestPayload, isNewImageAvailable, getImageMeta); + return await common.isUpdateAvailable(device, requestPayload, isNewImageAvailable, getImageMeta); } export async function updateToLatest(device: Zh.Device, onProgress: Ota.OnProgress) { - return common.updateToLatest(device, onProgress, common.getNewImage, getImageMeta, getFirmwareFile); + return await common.updateToLatest(device, onProgress, common.getNewImage, getImageMeta, getFirmwareFile); } export const useIndexOverride = (indexFileName: string) => { diff --git a/src/lib/philips.ts b/src/lib/philips.ts index 58080f64835d4..b9ce930e8e7aa 100644 --- a/src/lib/philips.ts +++ b/src/lib/philips.ts @@ -128,7 +128,7 @@ export const philipsTz = { if (Object.keys(hueEffects).includes(value.toLowerCase())) { await entity.command('manuSpecificPhilips2', 'multiColor', {data: Buffer.from(utils.getFromLookup(value, hueEffects), 'hex')}); } else { - return tz.effect.convertSet(entity, key, value, meta); + return await tz.effect.convertSet(entity, key, value, meta); } }, } satisfies Tz.Converter, diff --git a/src/lib/tuya.ts b/src/lib/tuya.ts index c5a71951e0fac..05c79e2c97ba8 100644 --- a/src/lib/tuya.ts +++ b/src/lib/tuya.ts @@ -253,27 +253,27 @@ function dpValueFromBitmap(dp: number, bitmapBuffer: number) { } export async function sendDataPointValue(entity: Zh.Group | Zh.Endpoint, dp: number, value: number, cmd?: string, seq?: number) { - return sendDataPoints(entity, [dpValueFromNumberValue(dp, value)], cmd, seq); + return await sendDataPoints(entity, [dpValueFromNumberValue(dp, value)], cmd, seq); } export async function sendDataPointBool(entity: Zh.Group | Zh.Endpoint, dp: number, value: boolean, cmd?: string, seq?: number) { - return sendDataPoints(entity, [dpValueFromBool(dp, value)], cmd, seq); + return await sendDataPoints(entity, [dpValueFromBool(dp, value)], cmd, seq); } export async function sendDataPointEnum(entity: Zh.Group | Zh.Endpoint, dp: number, value: number, cmd?: string, seq?: number) { - return sendDataPoints(entity, [dpValueFromEnum(dp, value)], cmd, seq); + return await sendDataPoints(entity, [dpValueFromEnum(dp, value)], cmd, seq); } export async function sendDataPointRaw(entity: Zh.Group | Zh.Endpoint, dp: number, value: number[], cmd?: string, seq?: number) { - return sendDataPoints(entity, [dpValueFromRaw(dp, value)], cmd, seq); + return await sendDataPoints(entity, [dpValueFromRaw(dp, value)], cmd, seq); } export async function sendDataPointBitmap(entity: Zh.Group | Zh.Endpoint, dp: number, value: number, cmd?: string, seq?: number) { - return sendDataPoints(entity, [dpValueFromBitmap(dp, value)], cmd, seq); + return await sendDataPoints(entity, [dpValueFromBitmap(dp, value)], cmd, seq); } export async function sendDataPointStringBuffer(entity: Zh.Group | Zh.Endpoint, dp: number, value: string, cmd?: string, seq?: number) { - return sendDataPoints(entity, [dpValueFromString(dp, value)], cmd, seq); + return await sendDataPoints(entity, [dpValueFromString(dp, value)], cmd, seq); } const tuyaExposes = { diff --git a/src/lib/utils.ts b/src/lib/utils.ts index e6e34ac14a1bf..f28b4fa0d6e62 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -378,7 +378,7 @@ export function filterObject(obj: KeyValue, keys: string[]) { } export async function sleep(ms: number) { - return new Promise((resolve) => setTimeout(resolve, ms)); + return await new Promise((resolve) => setTimeout(resolve, ms)); } export function toSnakeCase(value: string | KeyValueAny) {