diff --git a/CHANGELOG.md b/CHANGELOG.md index 011b2051..bd0c9e2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,20 @@ All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/) +## [Version 2.5.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.5.2) (2023-02-10) + +## What's Changed + +- Fixes mappingMode not being read from the config directly, Thanks [@AndreasVerhoeven](https://github.com/AndreasVerhoeven). [#667](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/667) +- Fixes only_up mode in settings configuration, Thanks [@AndreasVerhoeven](https://github.com/AndreasVerhoeven). [#669](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/669) +- Removes runStatus check, fixes some logic, Thanks [@AndreasVerhoeven](https://github.com/AndreasVerhoeven). [#672](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/672) +- Remove unneeded async, Thanks [@dnicolson](https://github.com/dnicolson). [#675](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/675) +- Replace switchbot wait with utility function, Thanks [@dnicolson](https://github.com/dnicolson). [#674](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/674) +- Remove incorrect warning message, Thanks [@dnicolson](https://github.com/dnicolson). [#673](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/673) +- Housekeeping and updated dependencies. + +**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.5.1....v2.5.2 + ## [Version 2.5.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.5.1) (2023-01-28) ## What's Changed @@ -15,10 +29,9 @@ All notable changes to this project will be documented in this file. This projec ## What's Changed - Add Intial Support for Blind Tilt (OpenAPI Only), Thanks [@AndreasVerhoeven](https://github.com/AndreasVerhoeven). [#649](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/649) -@dnicolson - Remove incorrect warning message, Thanks [@dnicolson](https://github.com/dnicolson). [#661](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/661) - Replace switchbot wait with utility function, Thanks [@dnicolson](https://github.com/dnicolson). [#633](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/633) -- Enhancements to BLE functionality +- Enhancements to BLE functionality. - Housekeeping and updated dependencies. **Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.4.0....v2.5.0 diff --git a/config.schema.json b/config.schema.json index 7ed85eac..fed79558 100644 --- a/config.schema.json +++ b/config.schema.json @@ -455,7 +455,7 @@ "oneOf": [ { "title": "Middle to Up", - "enum": ["up"] + "enum": ["only_up"] }, { "title": "Middle to Down", @@ -479,6 +479,40 @@ "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType === 'Blind Tilt' && model.options.devices[arrayIndices].deviceId);" } }, + "set_minStep": { + "title": "Set Minimum Step", + "type": "number", + "placeholder": "1", + "description": "Sets the minimum steps that blind tilt allows. So if set to 20, it would allow you to set the blind tilt state to 0, 20, 40, 60, 80, and 100", + "condition": { + "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType === 'Blind Tilt' && model.options.devices[arrayIndices].deviceId);" + } + }, + "set_min": { + "title": "Set Minimum Open State", + "type": "number", + "placeholder": "0", + "description": "Sets the minimum percentage before needed to set Blind Tilt to Open", + "condition": { + "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType === 'Blind Tilt' && model.options.devices[arrayIndices].deviceId);" + } + }, + "set_max": { + "title": "Set Maximum Close State", + "type": "number", + "placeholder": "100", + "description": "Sets the maximum percentage before needing to set Blind Tilt to Closed", + "condition": { + "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType === 'Blind Tilt' && model.options.devices[arrayIndices].deviceId);" + } + }, + "hide_lightsensor": { + "title": "Hide Light Sensor", + "type": "boolean", + "condition": { + "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType === 'Blind Tilt' && model.options.devices[arrayIndices].deviceId);" + } + }, "updateRate": { "title": "Blind Tilt Update Rate", "type": "number", @@ -562,7 +596,7 @@ "type": "number", "placeholder": "1", "condition": { - "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && (model.options.devices[arrayIndices].configDeviceType === 'Color Bulb' || model.options.devices[arrayIndices].configDeviceType === 'Strip Light') && model.options.devices[arrayIndices].deviceId);" + "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType === 'Color Bulb' && model.options.devices[arrayIndices].deviceId);" } }, "adaptiveLightingShift": { @@ -576,6 +610,28 @@ } } }, + "striplight": { + "type": "object", + "properties": { + "set_minStep": { + "title": "Set Min Step", + "type": "number", + "placeholder": "1", + "condition": { + "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType === 'Strip Light' && model.options.devices[arrayIndices].deviceId);" + } + }, + "adaptiveLightingShift": { + "title": "Adaptive Lighting Shift", + "type": "number", + "placeholder": "-1", + "description": "The mired for each Adaptive Lighting update will be increased by this value, making the light appear warmer. Set to -1 to remove Adaptive Lighting feature. Must be -1 or more.", + "condition": { + "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType === 'Strip Light' && model.options.devices[arrayIndices].deviceId);" + } + } + } + }, "lock": { "type": "object", "properties": { @@ -1097,6 +1153,10 @@ "options.devices[].curtain.set_minlux", "options.devices[].curtain.set_maxlux", "options.devices[].blindTilt.mode", + "options.devices[].blindTilt.set_minStep", + "options.devices[].blindTilt.set_min", + "options.devices[].blindTilt.set_max", + "options.devices[].blindTilt.hide_lightsensor", "options.devices[].blindTilt.updateRate", "options.devices[].contact.hide_lightsensor", "options.devices[].contact.set_minlux", @@ -1107,6 +1167,8 @@ "options.devices[].motion.set_maxlux", "options.devices[].colorbulb.set_minStep", "options.devices[].colorbulb.adaptiveLightingShift", + "options.devices[].striplight.set_minStep", + "options.devices[].striplight.adaptiveLightingShift", "options.devices[].lock.hide_contactsensor", "options.devices[].mqttURL", "options.devices[].mqttOptions", diff --git a/package-lock.json b/package-lock.json index 0d3de073..1622bb37 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@switchbot/homebridge-switchbot", - "version": "2.5.1", + "version": "2.5.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@switchbot/homebridge-switchbot", - "version": "2.5.1", + "version": "2.5.2", "funding": [ { "type": "Paypal", @@ -28,23 +28,23 @@ }, "devDependencies": { "@types/crypto-js": "^4.1.1", - "@types/node": "^18.11.18", - "@typescript-eslint/eslint-plugin": "^5.49.0", - "@typescript-eslint/parser": "^5.49.0", - "eslint": "^8.33.0", + "@types/node": "^18.13.0", + "@typescript-eslint/eslint-plugin": "^5.51.0", + "@typescript-eslint/parser": "^5.51.0", + "eslint": "^8.34.0", "eslint-config-prettier": "8.6.0", "eslint-plugin-prettier": "4.2.1", "homebridge": "^1.6.0", "nodemon": "^2.0.20", - "npm-check-updates": "^16.6.3", - "prettier": "2.8.3", + "npm-check-updates": "^16.7.4", + "prettier": "2.8.4", "rimraf": "^4.1.2", "ts-node": "^10.9.1", - "typescript": "^4.9.4" + "typescript": "^4.9.5" }, "engines": { "homebridge": "^1.6.0 || ^2.0.0-beta.0", - "node": "^14.21.2 || ^16.19.0 || ^18.12.1" + "node": "^14.21.2 || ^16.19.0 || ^18.14.0" }, "optionalDependencies": { "node-switchbot": "^1.8.0" @@ -617,9 +617,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "18.11.18", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz", - "integrity": "sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==", + "version": "18.13.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.13.0.tgz", + "integrity": "sha512-gC3TazRzGoOnoKAhUx+Q0t8S9Tzs74z7m0ipwGpSqQrleP14hKxP4/JUeEQcD3W1/aIpnWl8pHowI7WokuZpXg==", "dev": true }, "node_modules/@types/semver": { @@ -629,15 +629,16 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.49.0.tgz", - "integrity": "sha512-IhxabIpcf++TBaBa1h7jtOWyon80SXPRLDq0dVz5SLFC/eW6tofkw/O7Ar3lkx5z5U6wzbKDrl2larprp5kk5Q==", + "version": "5.51.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.51.0.tgz", + "integrity": "sha512-wcAwhEWm1RgNd7dxD/o+nnLW8oH+6RK1OGnmbmkj/GGoDPV1WWMVP0FXYQBivKHdwM1pwii3bt//RC62EriIUQ==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "5.49.0", - "@typescript-eslint/type-utils": "5.49.0", - "@typescript-eslint/utils": "5.49.0", + "@typescript-eslint/scope-manager": "5.51.0", + "@typescript-eslint/type-utils": "5.51.0", + "@typescript-eslint/utils": "5.51.0", "debug": "^4.3.4", + "grapheme-splitter": "^1.0.4", "ignore": "^5.2.0", "natural-compare-lite": "^1.4.0", "regexpp": "^3.2.0", @@ -662,14 +663,14 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.49.0.tgz", - "integrity": "sha512-veDlZN9mUhGqU31Qiv2qEp+XrJj5fgZpJ8PW30sHU+j/8/e5ruAhLaVDAeznS7A7i4ucb/s8IozpDtt9NqCkZg==", + "version": "5.51.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.51.0.tgz", + "integrity": "sha512-fEV0R9gGmfpDeRzJXn+fGQKcl0inIeYobmmUWijZh9zA7bxJ8clPhV9up2ZQzATxAiFAECqPQyMDB4o4B81AaA==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "5.49.0", - "@typescript-eslint/types": "5.49.0", - "@typescript-eslint/typescript-estree": "5.49.0", + "@typescript-eslint/scope-manager": "5.51.0", + "@typescript-eslint/types": "5.51.0", + "@typescript-eslint/typescript-estree": "5.51.0", "debug": "^4.3.4" }, "engines": { @@ -689,13 +690,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.49.0.tgz", - "integrity": "sha512-clpROBOiMIzpbWNxCe1xDK14uPZh35u4QaZO1GddilEzoCLAEz4szb51rBpdgurs5k2YzPtJeTEN3qVbG+LRUQ==", + "version": "5.51.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.51.0.tgz", + "integrity": "sha512-gNpxRdlx5qw3yaHA0SFuTjW4rxeYhpHxt491PEcKF8Z6zpq0kMhe0Tolxt0qjlojS+/wArSDlj/LtE69xUJphQ==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.49.0", - "@typescript-eslint/visitor-keys": "5.49.0" + "@typescript-eslint/types": "5.51.0", + "@typescript-eslint/visitor-keys": "5.51.0" }, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -706,13 +707,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.49.0.tgz", - "integrity": "sha512-eUgLTYq0tR0FGU5g1YHm4rt5H/+V2IPVkP0cBmbhRyEmyGe4XvJ2YJ6sYTmONfjmdMqyMLad7SB8GvblbeESZA==", + "version": "5.51.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.51.0.tgz", + "integrity": "sha512-QHC5KKyfV8sNSyHqfNa0UbTbJ6caB8uhcx2hYcWVvJAZYJRBo5HyyZfzMdRx8nvS+GyMg56fugMzzWnojREuQQ==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "5.49.0", - "@typescript-eslint/utils": "5.49.0", + "@typescript-eslint/typescript-estree": "5.51.0", + "@typescript-eslint/utils": "5.51.0", "debug": "^4.3.4", "tsutils": "^3.21.0" }, @@ -733,9 +734,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.49.0.tgz", - "integrity": "sha512-7If46kusG+sSnEpu0yOz2xFv5nRz158nzEXnJFCGVEHWnuzolXKwrH5Bsf9zsNlOQkyZuk0BZKKoJQI+1JPBBg==", + "version": "5.51.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.51.0.tgz", + "integrity": "sha512-SqOn0ANn/v6hFn0kjvLwiDi4AzR++CBZz0NV5AnusT2/3y32jdc0G4woXPWHCumWtUXZKPAS27/9vziSsC9jnw==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -746,13 +747,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.49.0.tgz", - "integrity": "sha512-PBdx+V7deZT/3GjNYPVQv1Nc0U46dAHbIuOG8AZ3on3vuEKiPDwFE/lG1snN2eUB9IhF7EyF7K1hmTcLztNIsA==", + "version": "5.51.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.51.0.tgz", + "integrity": "sha512-TSkNupHvNRkoH9FMA3w7TazVFcBPveAAmb7Sz+kArY6sLT86PA5Vx80cKlYmd8m3Ha2SwofM1KwraF24lM9FvA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.49.0", - "@typescript-eslint/visitor-keys": "5.49.0", + "@typescript-eslint/types": "5.51.0", + "@typescript-eslint/visitor-keys": "5.51.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -773,16 +774,16 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.49.0.tgz", - "integrity": "sha512-cPJue/4Si25FViIb74sHCLtM4nTSBXtLx1d3/QT6mirQ/c65bV8arBEebBJJizfq8W2YyMoPI/WWPFWitmNqnQ==", + "version": "5.51.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.51.0.tgz", + "integrity": "sha512-76qs+5KWcaatmwtwsDJvBk4H76RJQBFe+Gext0EfJdC3Vd2kpY2Pf//OHHzHp84Ciw0/rYoGTDnIAr3uWhhJYw==", "dev": true, "dependencies": { "@types/json-schema": "^7.0.9", "@types/semver": "^7.3.12", - "@typescript-eslint/scope-manager": "5.49.0", - "@typescript-eslint/types": "5.49.0", - "@typescript-eslint/typescript-estree": "5.49.0", + "@typescript-eslint/scope-manager": "5.51.0", + "@typescript-eslint/types": "5.51.0", + "@typescript-eslint/typescript-estree": "5.51.0", "eslint-scope": "^5.1.1", "eslint-utils": "^3.0.0", "semver": "^7.3.7" @@ -799,12 +800,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "5.49.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.49.0.tgz", - "integrity": "sha512-v9jBMjpNWyn8B6k/Mjt6VbUS4J1GvUlR4x3Y+ibnP1z7y7V4n0WRz+50DY6+Myj0UaXVSuUlHohO+eZ8IJEnkg==", + "version": "5.51.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.51.0.tgz", + "integrity": "sha512-Oh2+eTdjHjOFjKA27sxESlA87YPSOJafGCR0md5oeMdh1ZcCfAGCIOL216uTBAkAIptvLIfKQhl7lHxMJet4GQ==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.49.0", + "@typescript-eslint/types": "5.51.0", "eslint-visitor-keys": "^3.3.0" }, "engines": { @@ -1331,14 +1332,14 @@ } }, "node_modules/cacheable-request": { - "version": "10.2.5", - "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-10.2.5.tgz", - "integrity": "sha512-5RwYYCfzjNPsyJxb/QpaM0bfzx+kw5/YpDhZPm9oMIDntHFQ9YXeyV47ZvzlTE0XrrrbyO2UITJH4GF9eRLdXQ==", + "version": "10.2.7", + "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-10.2.7.tgz", + "integrity": "sha512-I4SA6mKgDxcxVbSt/UmIkb9Ny8qSkg6ReBHtAAXnZHk7KOSx5g3DTiAOaYzcHCs6oOdHn+bip9T48E6tMvK9hw==", "dev": true, "dependencies": { "@types/http-cache-semantics": "^4.0.1", "get-stream": "^6.0.1", - "http-cache-semantics": "^4.1.0", + "http-cache-semantics": "^4.1.1", "keyv": "^4.5.2", "mimic-response": "^4.0.0", "normalize-url": "^8.0.0", @@ -1755,9 +1756,9 @@ } }, "node_modules/define-properties": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.4.tgz", - "integrity": "sha512-uckOqKcfaVvtBdsVkdPv3XjveQJsNQqmhXgRi8uhvWWuPYZCNlzT8qAyblUgNoXdHdjMTzAqeGjAoli8f+bzPA==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.0.tgz", + "integrity": "sha512-xvqAVKGfT1+UAvPwKTVw/njhdQ8ZhXK4lI0bCIuCMrp2up9nPnaDftrLtmpTazqd1o+UY4zgzU+avtMbDP+ldA==", "dev": true, "dependencies": { "has-property-descriptors": "^1.0.0", @@ -1968,9 +1969,9 @@ } }, "node_modules/eslint": { - "version": "8.33.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.33.0.tgz", - "integrity": "sha512-WjOpFQgKK8VrCnAtl8We0SUOy/oVZ5NHykyMiagV1M9r8IFpIJX7DduK6n1mpfhlG7T1NLWm2SuD8QB7KFySaA==", + "version": "8.34.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.34.0.tgz", + "integrity": "sha512-1Z8iFsucw+7kSqXNZVslXS8Ioa4u2KM7GPwuKtkTFAqZ/cHMcEaR+1+Br0wLlot49cNxIiZk5wp8EAbPcYZxTg==", "dev": true, "dependencies": { "@eslint/eslintrc": "^1.4.1", @@ -2453,9 +2454,9 @@ } }, "node_modules/fs-minipass": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-3.0.0.tgz", - "integrity": "sha512-EUojgQaSPy6sxcqcZgQv6TVF6jiKvurji3AxhAivs/Ep4O1UpS8TusaxpybfFHZ2skRhLqzk6WR8nqNYIMMDeA==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-3.0.1.tgz", + "integrity": "sha512-MhaJDcFRTuLidHrIttu0RDGyyXs/IYHVmlcxfLAEFIWjc1vdLAkdwT7Ace2u7DbitWC0toKMl5eJZRYNVreIMw==", "dev": true, "dependencies": { "minipass": "^4.0.0" @@ -2713,9 +2714,9 @@ } }, "node_modules/googleapis": { - "version": "110.0.0", - "resolved": "https://registry.npmjs.org/googleapis/-/googleapis-110.0.0.tgz", - "integrity": "sha512-k6de3PGsdFEBULMiFwPYCKOBljDTDvHD3YGe/OFqe8Ot0lYQPL8QV1qjxjrPWiE/Ftf0Ar2v4DNES66jLfSO7w==", + "version": "111.0.0", + "resolved": "https://registry.npmjs.org/googleapis/-/googleapis-111.0.0.tgz", + "integrity": "sha512-nIIH+J/o/xjIscJcv3H3BCYgsFiI5ziM3Nbh2lHOWglYGqXE0Nqdt2lfCt4hX257QHEyC1y1iODDkmAMPWDYlw==", "dependencies": { "google-auth-library": "^8.0.2", "googleapis-common": "^6.0.0" @@ -3069,12 +3070,12 @@ "dev": true }, "node_modules/ignore-walk": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/ignore-walk/-/ignore-walk-6.0.0.tgz", - "integrity": "sha512-bTf9UWe/UP1yxG3QUrj/KOvEhTAUWPcv+WvbFZ28LcqznXabp7Xu6o9y1JEC18+oqODuS7VhTpekV5XvFwsxJg==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ignore-walk/-/ignore-walk-6.0.1.tgz", + "integrity": "sha512-/c8MxUAqpRccq+LyDOecwF+9KqajueJHh8fz7g3YqjMZt+NSfJzx05zrKiXwa2sKwFCzaiZ5qUVfRj0pmxixEA==", "dev": true, "dependencies": { - "minimatch": "^5.0.1" + "minimatch": "^6.1.6" }, "engines": { "node": "^14.17.0 || ^16.13.0 || >=18.0.0" @@ -3090,15 +3091,18 @@ } }, "node_modules/ignore-walk/node_modules/minimatch": { - "version": "5.1.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", - "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "version": "6.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-6.1.6.tgz", + "integrity": "sha512-6bR3UIeh/DF8+p6A9Spyuy67ShOq42rOkHWi7eUe3Ua99Zo5lZfGC6lJJWkeoK4k9jQFT3Pl7czhTXimG2XheA==", "dev": true, "dependencies": { "brace-expansion": "^2.0.1" }, "engines": { "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, "node_modules/import-fresh": { @@ -3174,12 +3178,12 @@ } }, "node_modules/internal-slot": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.4.tgz", - "integrity": "sha512-tA8URYccNzMo94s5MQZgH8NB/XTa6HsOo0MLfXTKKEnHVVdegzaQoFZ7Jp44bdvLvY2waT5dc+j5ICEswhi7UQ==", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.5.tgz", + "integrity": "sha512-Y+R5hJrzs52QCG2laLn4udYVnxsfny9CpOhNhUvk/SSSVyF6T27FzRbF0sroPidSu3X8oEAkOn2K804mjpt6UQ==", "dev": true, "dependencies": { - "get-intrinsic": "^1.1.3", + "get-intrinsic": "^1.2.0", "has": "^1.0.3", "side-channel": "^1.0.4" }, @@ -4137,21 +4141,18 @@ } }, "node_modules/minimist": { - "version": "1.2.7", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz", - "integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==", + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/minipass": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-4.0.0.tgz", - "integrity": "sha512-g2Uuh2jEKoht+zvO6vJqXmYpflPqzRBT+Th2h01DKh5z7wbY/AZ2gCQ78cP70YoHPyFdY30YBV5WxgLOEwOykw==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-4.0.3.tgz", + "integrity": "sha512-OW2r4sQ0sI+z5ckEt5c1Tri4xTgZwYDxpE54eqWlQloQRoWtXjqt9udJ5Z4dSv7wK+nfFI7FRXyCpBSft+gpFw==", "devOptional": true, - "dependencies": { - "yallist": "^4.0.0" - }, "engines": { "node": ">=8" } @@ -4446,9 +4447,9 @@ "optional": true }, "node_modules/node-fetch": { - "version": "2.6.8", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.8.tgz", - "integrity": "sha512-RZ6dBYuj8dRSfxpUSu+NsdF1dpPpluJxwOp+6IoDp/sH2QNDSvurYsAa+F1WxY2RjA1iP93xhcsUoYbF2XBqVg==", + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.9.tgz", + "integrity": "sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==", "dependencies": { "whatwg-url": "^5.0.0" }, @@ -4755,14 +4756,14 @@ } }, "node_modules/npm-check-updates": { - "version": "16.6.3", - "resolved": "https://registry.npmjs.org/npm-check-updates/-/npm-check-updates-16.6.3.tgz", - "integrity": "sha512-EKhsCbBcVrPlYKzaYQtRhGv9fxpexwROcvl5HebCUNpiCSlOWrzaJvrMlwi9i9GCyJCnH+YAeBPYdqnArA390A==", + "version": "16.7.4", + "resolved": "https://registry.npmjs.org/npm-check-updates/-/npm-check-updates-16.7.4.tgz", + "integrity": "sha512-joYzlwYN4I3QDOOcAoaFS4qo/Vq1fZN86b14pjyiJw82NxerY+Zk1MzMHKAsKypKlSANjFO4CibdkDVlKQ7IKg==", "dev": true, "dependencies": { "chalk": "^5.2.0", "cli-table": "^0.3.11", - "commander": "^9.4.1", + "commander": "^10.0.0", "fast-memoize": "^2.5.2", "find-up": "5.0.0", "fp-and-or": "^0.1.3", @@ -4773,22 +4774,23 @@ "json-parse-helpfulerror": "^1.0.3", "jsonlines": "^0.1.1", "lodash": "^4.17.21", - "minimatch": "^5.1.2", + "minimatch": "^6.1.6", "p-map": "^4.0.0", "pacote": "15.0.8", "parse-github-url": "^1.0.2", "progress": "^2.0.3", "prompts-ncu": "^2.5.1", - "rc-config-loader": "^4.1.1", + "rc-config-loader": "^4.1.2", "remote-git-tags": "^3.0.0", - "rimraf": "^3.0.2", + "rimraf": "^4.1.2", "semver": "^7.3.8", "semver-utils": "^1.1.4", "source-map-support": "^0.5.21", "spawn-please": "^2.0.1", + "strip-json-comments": "^5.0.0", "untildify": "^4.0.0", "update-notifier": "^6.0.2", - "yaml": "^2.2.0" + "yaml": "^2.2.1" }, "bin": { "ncu": "build/src/bin/cli.js", @@ -4820,39 +4822,39 @@ } }, "node_modules/npm-check-updates/node_modules/commander": { - "version": "9.5.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz", - "integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==", + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.0.tgz", + "integrity": "sha512-zS5PnTI22FIRM6ylNW8G4Ap0IEOyk62fhLSD0+uHRT9McRCLGpkVNvao4bjimpK/GShynyQkFFxHhwMcETmduA==", "dev": true, "engines": { - "node": "^12.20.0 || >=14" + "node": ">=14" } }, "node_modules/npm-check-updates/node_modules/minimatch": { - "version": "5.1.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", - "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "version": "6.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-6.1.6.tgz", + "integrity": "sha512-6bR3UIeh/DF8+p6A9Spyuy67ShOq42rOkHWi7eUe3Ua99Zo5lZfGC6lJJWkeoK4k9jQFT3Pl7czhTXimG2XheA==", "dev": true, "dependencies": { "brace-expansion": "^2.0.1" }, "engines": { "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/npm-check-updates/node_modules/rimraf": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", - "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "node_modules/npm-check-updates/node_modules/strip-json-comments": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-5.0.0.tgz", + "integrity": "sha512-V1LGY4UUo0jgwC+ELQ2BNWfPa17TIuwBLg+j1AA/9RPzKINl1lhxVEu2r+ZTTO8aetIsUzE5Qj6LMSBkoGYKKw==", "dev": true, - "dependencies": { - "glob": "^7.1.3" - }, - "bin": { - "rimraf": "bin.js" + "engines": { + "node": ">=14.16" }, "funding": { - "url": "https://github.com/sponsors/isaacs" + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/npm-install-checks": { @@ -4967,20 +4969,19 @@ } }, "node_modules/npm-registry-fetch/node_modules/make-fetch-happen": { - "version": "11.0.2", - "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-11.0.2.tgz", - "integrity": "sha512-5n/Pq41w/uZghpdlXAY5kIM85RgJThtTH/NYBRAZ9VUOBWV90USaQjwGrw76fZP3Lj5hl/VZjpVvOaRBMoL/2w==", + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-11.0.3.tgz", + "integrity": "sha512-oPLh5m10lRNNZDjJ2kP8UpboUx2uFXVaVweVe/lWut4iHWcQEmfqSVJt2ihZsFI8HbpwyyocaXbCAWf0g1ukIA==", "dev": true, "dependencies": { "agentkeepalive": "^4.2.1", "cacache": "^17.0.0", - "http-cache-semantics": "^4.1.0", + "http-cache-semantics": "^4.1.1", "http-proxy-agent": "^5.0.0", "https-proxy-agent": "^5.0.0", "is-lambda": "^1.0.1", "lru-cache": "^7.7.1", "minipass": "^4.0.0", - "minipass-collect": "^1.0.2", "minipass-fetch": "^3.0.0", "minipass-flush": "^1.0.5", "minipass-pipeline": "^1.2.4", @@ -5309,9 +5310,9 @@ } }, "node_modules/prettier": { - "version": "2.8.3", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.3.tgz", - "integrity": "sha512-tJ/oJ4amDihPoufT5sM0Z1SKEuKay8LfVAMlbbhnnkvt6BUserZylqo2PN+p9KeljLr0OHa2rXHU1T8reeoTrw==", + "version": "2.8.4", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.4.tgz", + "integrity": "sha512-vIS4Rlc2FNh0BySk3Wkd6xmwxB0FpOndW5fisM5H8hsZSxU2VWVB5CWIkIjWvrHjIhxk2g3bfMKM87zNTrZddw==", "dev": true, "bin": { "prettier": "bin-prettier.js" @@ -6421,9 +6422,9 @@ } }, "node_modules/typescript": { - "version": "4.9.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.4.tgz", - "integrity": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==", + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", "dev": true, "bin": { "tsc": "bin/tsc", diff --git a/package.json b/package.json index ecaf4b1d..f3afa5e6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "displayName": "Homebridge SwitchBot", "name": "@switchbot/homebridge-switchbot", - "version": "2.5.1", + "version": "2.5.2", "description": "The [Homebridge](https://homebridge.io) SwitchBot plugin allows you to access your [SwitchBot](https://www.switch-bot.com) device(s) from HomeKit.", "author": "SwitchBot (https://github.com/SwitchBot)", "license": "ISC", @@ -14,7 +14,7 @@ }, "engines": { "homebridge": "^1.6.0 || ^2.0.0-beta.0", - "node": "^14.21.2 || ^16.19.0 || ^18.12.1" + "node": "^14.21.2 || ^16.19.0 || ^18.14.0" }, "main": "dist/index.js", "scripts": { @@ -63,20 +63,20 @@ "rxjs": "^7.8.0" }, "devDependencies": { - "@types/node": "^18.11.18", + "@types/node": "^18.13.0", "@types/crypto-js": "^4.1.1", - "@typescript-eslint/eslint-plugin": "^5.49.0", - "@typescript-eslint/parser": "^5.49.0", - "eslint": "^8.33.0", + "@typescript-eslint/eslint-plugin": "^5.51.0", + "@typescript-eslint/parser": "^5.51.0", + "eslint": "^8.34.0", "eslint-config-prettier": "8.6.0", "eslint-plugin-prettier": "4.2.1", "homebridge": "^1.6.0", "nodemon": "^2.0.20", - "npm-check-updates": "^16.6.3", - "prettier": "2.8.3", + "npm-check-updates": "^16.7.4", + "prettier": "2.8.4", "rimraf": "^4.1.2", "ts-node": "^10.9.1", - "typescript": "^4.9.4" + "typescript": "^4.9.5" }, "optionalDependencies": { "node-switchbot": "^1.8.0" diff --git a/src/device/blindtilt.ts b/src/device/blindtilt.ts index 228111c9..06196066 100644 --- a/src/device/blindtilt.ts +++ b/src/device/blindtilt.ts @@ -42,7 +42,6 @@ export class BlindTilt { slidePosition: deviceStatus['slidePosition']; direction: deviceStatus['direction']; moving: deviceStatus['moving']; - runStatus: deviceStatus['runStatus']; brightness: deviceStatus['brightness']; setPositionMode?: string | number; Mode!: string; @@ -96,7 +95,7 @@ export class BlindTilt { this.setupMqtt(device); this.context(); - this.mappingMode = (device.blindTilt?.mappingMode as BlindTiltMappingMode) ?? BlindTiltMappingMode.OnlyUp; + this.mappingMode = (device.blindTilt?.mode as BlindTiltMappingMode) ?? BlindTiltMappingMode.OnlyUp; this.debugLog(`Mapping mode: ${this.mappingMode}`); // this is subject we use to track when we need to POST changes to the SwitchBot API @@ -303,7 +302,7 @@ export class BlindTilt { ` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`, ); - if (!this.device.curtain?.hide_lightsensor) { + if (!this.device.blindTilt?.hide_lightsensor) { this.set_minLux = this.minLux(); this.set_maxLux = this.maxLux(); this.spaceBetweenLevels = 9; @@ -390,8 +389,7 @@ export class BlindTilt { this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Checking Status ...`); } - this.debugLog(`runStatus: ${this.runStatus}`); - if (this.setNewTarget || (this.runStatus === undefined || this.runStatus !== 'static')) { + if (this.setNewTarget && this.moving) { await this.setMinMax(); if (this.TargetPosition > this.CurrentPosition || (homekitTiltAngle && (this.TargetHorizontalTiltAngle !== this.CurrentHorizontalTiltAngle))) { this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Closing, CurrentPosition: ${this.CurrentPosition} `); @@ -425,7 +423,7 @@ export class BlindTilt { ` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`, ); - if (!this.device.curtain?.hide_lightsensor) { + if (!this.device.blindTilt?.hide_lightsensor) { this.set_minLux = this.minLux(); this.set_maxLux = this.maxLux(); // Brightness @@ -500,7 +498,7 @@ export class BlindTilt { } }; // Wait - return await switchbot.wait(this.scanDuration * 1000); + return await sleep(this.scanDuration * 1000); }) .then(async () => { // Stop to monitor @@ -553,7 +551,6 @@ export class BlindTilt { this.slidePosition = this.deviceStatus.body.slidePosition; this.direction = this.deviceStatus.body.direction; this.moving = this.deviceStatus.body.moving; - this.runStatus = this.deviceStatus.body.runStatus; this.brightness = this.deviceStatus.body.brightness; this.openAPIparseStatus(); this.updateHomeKitCharacteristics(); @@ -667,7 +664,11 @@ export class BlindTilt { async openAPIpushChanges(): Promise { try { this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI pushChanges`); - if ((this.TargetPosition !== this.CurrentPosition) || this.device.disableCaching) { + + const hasDifferentAndRelevantHorizontalTiltAngle = ( + this.mappingMode === BlindTiltMappingMode.UseTiltForDirection + && this.TargetHorizontalTiltAngle !== this.CurrentHorizontalTiltAngle); + if ((this.TargetPosition !== this.CurrentPosition) || hasDifferentAndRelevantHorizontalTiltAngle || this.device.disableCaching) { // Make Push On request to the API const t = Date.now(); const nonce = 'requestID'; @@ -683,11 +684,26 @@ export class BlindTilt { this.debugLog(`Pushing ${this.TargetPosition} (device = ${direction};${position})`); this.debugLog(`${this.accessory.displayName} Mode: ${this.Mode}`); - const body = superStringify({ - 'command': 'setPosition', - 'parameter': `${direction};${position}`, - 'commandType': 'command', - }); + + let body = ''; + if(position === 100) { + body = superStringify({ + 'command': 'fullyOpen', + 'commandType': 'command', + }); + } else if(position === 0) { + body = superStringify({ + 'command': direction === 'up' ? 'closeUp' : 'closeDown', + 'commandType': 'command', + }); + } else { + body = superStringify({ + 'command': 'setPosition', + 'parameter': `${direction};${position}`, + 'commandType': 'command', + }); + } + this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${body},`); const options = { hostname: HostDomain, @@ -718,7 +734,8 @@ export class BlindTilt { this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges: ${superStringify(req)}`); } else { this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No OpenAPI Changes, CurrentPosition & TargetPosition Are the Same.` - +` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`, + +` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}` + +` CurrentHorizontalTiltAngle: ${this.CurrentHorizontalTiltAngle}, TargetPosition ${this.TargetHorizontalTiltAngle}`, ); } } catch (e: any) { @@ -850,7 +867,7 @@ export class BlindTilt { this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.TargetPosition, Number(this.TargetPosition)); this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: ${this.TargetPosition}`); } - if (!this.device.curtain?.hide_lightsensor) { + if (!this.device.blindTilt?.hide_lightsensor) { if (this.CurrentAmbientLightLevel === undefined || Number.isNaN(this.CurrentAmbientLightLevel)) { this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`); } else { @@ -920,7 +937,7 @@ export class BlindTilt { } async stopScanning(switchbot: any) { - await switchbot.stopScan(); + switchbot.stopScan(); if (this.connected) { await this.BLEparseStatus(); await this.updateHomeKitCharacteristics(); @@ -940,7 +957,7 @@ export class BlindTilt { switchbot.onadvertisement = (ad: any) => { this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`); }; - await switchbot.wait(10000); + await sleep(10000); // Stop to monitor switchbot.stopScan(); })(); @@ -964,7 +981,7 @@ export class BlindTilt { async SilentPerformance() { if (this.TargetPosition > 50) { - if (this.device.curtain?.setOpenMode === '1') { + if (this.device.blindTilt?.setOpenMode === '1') { this.setPositionMode = 1; this.Mode = 'Silent Mode'; } else { @@ -972,7 +989,7 @@ export class BlindTilt { this.Mode = 'Performance Mode'; } } else { - if (this.device.curtain?.setCloseMode === '1') { + if (this.device.blindTilt?.setCloseMode === '1') { this.setPositionMode = 1; this.Mode = 'Silent Mode'; } else { @@ -983,13 +1000,13 @@ export class BlindTilt { } async setMinMax(): Promise { - if (this.device.curtain?.set_min) { - if (this.CurrentPosition <= this.device.curtain?.set_min) { + if (this.device.blindTilt?.set_min) { + if (this.CurrentPosition <= this.device.blindTilt?.set_min) { this.CurrentPosition = 0; } } - if (this.device.curtain?.set_max) { - if (this.CurrentPosition >= this.device.curtain?.set_max) { + if (this.device.blindTilt?.set_max) { + if (this.CurrentPosition >= this.device.blindTilt?.set_max) { this.CurrentPosition = 100; } } @@ -1000,8 +1017,8 @@ export class BlindTilt { } minStep(device: device & devicesConfig): number { - if (device.curtain?.set_minStep) { - this.set_minStep = device.curtain?.set_minStep; + if (device.blindTilt?.set_minStep) { + this.set_minStep = device.blindTilt?.set_minStep; } else { this.set_minStep = 1; } @@ -1009,8 +1026,8 @@ export class BlindTilt { } minLux(): number { - if (this.device.curtain?.set_minLux) { - this.set_minLux = this.device.curtain?.set_minLux; + if (this.device.blindTilt?.set_minLux) { + this.set_minLux = this.device.blindTilt?.set_minLux; } else { this.set_minLux = 1; } @@ -1018,8 +1035,8 @@ export class BlindTilt { } maxLux(): number { - if (this.device.curtain?.set_maxLux) { - this.set_maxLux = this.device.curtain?.set_maxLux; + if (this.device.blindTilt?.set_maxLux) { + this.set_maxLux = this.device.blindTilt?.set_maxLux; } else { this.set_maxLux = 6001; } @@ -1032,7 +1049,7 @@ export class BlindTilt { this.scanDuration = this.updateRate; if (this.BLE) { this.warnLog(`${this.device.deviceType}: ` - + `${this.accessory.displayName} scanDuration is less then updateRate, overriding scanDuration with updateRate`); + + `${this.accessory.displayName} scanDuration is less than updateRate, overriding scanDuration with updateRate`); } } else { this.scanDuration = this.accessory.context.scanDuration = device.scanDuration; @@ -1043,10 +1060,6 @@ export class BlindTilt { } else { if (this.updateRate > 1) { this.scanDuration = this.updateRate; - if (this.BLE) { - this.warnLog(`${this.device.deviceType}: ` - + `${this.accessory.displayName} scanDuration is less then updateRate, overriding scanDuration with updateRate`); - } } else { this.scanDuration = this.accessory.context.scanDuration = 1; } @@ -1261,7 +1274,7 @@ export class BlindTilt { } else { // upwards // homekit 0..100 -> device 0..100, so invert - return ['up,', homekitPosition]; + return ['up', homekitPosition]; } } } @@ -1312,10 +1325,10 @@ export class BlindTilt { config['maxRetry'] = device.maxRetry; } - if(device.blindTilt?.mappingMode === undefined) { - config['mappingMode'] = BlindTiltMappingMode.OnlyUp; + if(device.blindTilt?.mode === undefined) { + config['mode'] = BlindTiltMappingMode.OnlyUp; } else { - config['mappingMode'] = device.blindTilt?.mappingMode; + config['mode'] = device.blindTilt?.mode; } if (Object.entries(config).length !== 0) { diff --git a/src/device/bot.ts b/src/device/bot.ts index 0d0d00da..2c9b47a7 100644 --- a/src/device/bot.ts +++ b/src/device/bot.ts @@ -518,7 +518,7 @@ export class Bot { } }; // Wait - return await switchbot.wait(this.scanDuration * 1000); + return await sleep(this.scanDuration * 1000); }) .then(async () => { // Stop to monitor @@ -1130,7 +1130,7 @@ export class Bot { } async stopScanning(switchbot: any) { - await switchbot.stopScan(); + switchbot.stopScan(); if (this.connected) { await this.BLEparseStatus(); await this.updateHomeKitCharacteristics(); @@ -1150,7 +1150,7 @@ export class Bot { switchbot.onadvertisement = (ad: any) => { this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`); }; - await switchbot.wait(10000); + await sleep(10000); // Stop to monitor switchbot.stopScan(); })(); diff --git a/src/device/ceilinglight.ts b/src/device/ceilinglight.ts index 69934340..a51b5db2 100644 --- a/src/device/ceilinglight.ts +++ b/src/device/ceilinglight.ts @@ -368,7 +368,7 @@ export class CeilingLight { } }; // Wait - return await switchbot.wait(this.scanDuration * 1000); + return await sleep(this.scanDuration * 1000); }) .then(async () => { // Stop to monitor @@ -922,7 +922,7 @@ export class CeilingLight { } async stopScanning(switchbot: any) { - await switchbot.stopScan(); + switchbot.stopScan(); if (this.connected) { await this.BLEparseStatus(); await this.updateHomeKitCharacteristics(); @@ -943,7 +943,7 @@ export class CeilingLight { switchbot.onadvertisement = (ad: any) => { this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`); }; - await switchbot.wait(10000); + await sleep(10000); // Stop to monitor switchbot.stopScan(); })(); diff --git a/src/device/colorbulb.ts b/src/device/colorbulb.ts index d8f726ab..21a8c8cc 100644 --- a/src/device/colorbulb.ts +++ b/src/device/colorbulb.ts @@ -403,7 +403,7 @@ export class ColorBulb { } }; // Wait - return await switchbot.wait(this.scanDuration * 1000); + return await sleep(this.scanDuration * 1000); }) .then(async () => { // Stop to monitor @@ -1079,7 +1079,7 @@ export class ColorBulb { } async stopScanning(switchbot: any) { - await switchbot.stopScan(); + switchbot.stopScan(); if (this.connected) { await this.BLEparseStatus(); await this.updateHomeKitCharacteristics(); @@ -1100,7 +1100,7 @@ export class ColorBulb { switchbot.onadvertisement = (ad: any) => { this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`); }; - await switchbot.wait(10000); + await sleep(10000); // Stop to monitor switchbot.stopScan(); })(); diff --git a/src/device/contact.ts b/src/device/contact.ts index 04612cb9..3219cc89 100644 --- a/src/device/contact.ts +++ b/src/device/contact.ts @@ -8,6 +8,7 @@ import { SwitchBotPlatform } from '../platform'; import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge'; import { device, devicesConfig, serviceData, switchbot, deviceStatus, ad, HostDomain, DevicePath } from '../settings'; import { IncomingMessage } from 'http'; +import { sleep } from '../utils'; /** * Platform Accessory @@ -347,7 +348,7 @@ export class Contact { } }; // Wait - return await switchbot.wait(this.scanDuration * 1000); + return await sleep(this.scanDuration * 1000); }) .then(async () => { // Stop to monitor @@ -470,7 +471,7 @@ export class Contact { } async stopScanning(switchbot: any) { - await switchbot.stopScan(); + switchbot.stopScan(); if (this.connected) { await this.BLEparseStatus(); await this.updateHomeKitCharacteristics(); @@ -490,7 +491,7 @@ export class Contact { switchbot.onadvertisement = (ad: any) => { this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`); }; - await switchbot.wait(10000); + await sleep(10000); // Stop to monitor switchbot.stopScan(); })(); diff --git a/src/device/curtain.ts b/src/device/curtain.ts index 54729e81..24dde162 100644 --- a/src/device/curtain.ts +++ b/src/device/curtain.ts @@ -460,7 +460,7 @@ export class Curtain { } }; // Wait - return await switchbot.wait(this.scanDuration * 1000); + return await sleep(this.scanDuration * 1000); }) .then(async () => { // Stop to monitor @@ -846,7 +846,7 @@ export class Curtain { } async stopScanning(switchbot: any) { - await switchbot.stopScan(); + switchbot.stopScan(); if (this.connected) { await this.BLEparseStatus(); await this.updateHomeKitCharacteristics(); @@ -866,7 +866,7 @@ export class Curtain { switchbot.onadvertisement = (ad: any) => { this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`); }; - await switchbot.wait(10000); + await sleep(10000); // Stop to monitor switchbot.stopScan(); })(); diff --git a/src/device/humidifier.ts b/src/device/humidifier.ts index 76e79306..43aeca88 100644 --- a/src/device/humidifier.ts +++ b/src/device/humidifier.ts @@ -8,6 +8,7 @@ import { SwitchBotPlatform } from '../platform'; import { debounceTime, skipWhile, take, tap } from 'rxjs/operators'; import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge'; import { device, devicesConfig, serviceData, ad, deviceStatus, HostDomain, DevicePath } from '../settings'; +import { sleep } from '../utils'; /** * Platform Accessory @@ -343,7 +344,7 @@ export class Humidifier { } }; // Wait - return await switchbot.wait(this.scanDuration * 1000); + return await sleep(this.scanDuration * 1000); }) .then(async () => { // Stop to monitor @@ -771,7 +772,7 @@ export class Humidifier { } async stopScanning(switchbot: any) { - await switchbot.stopScan(); + switchbot.stopScan(); if (this.connected) { await this.BLEparseStatus(); await this.updateHomeKitCharacteristics(); @@ -791,7 +792,7 @@ export class Humidifier { switchbot.onadvertisement = (ad: any) => { this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`); }; - await switchbot.wait(10000); + await sleep(10000); // Stop to monitor switchbot.stopScan(); })(); diff --git a/src/device/lock.ts b/src/device/lock.ts index 4a9a3b18..323202d2 100644 --- a/src/device/lock.ts +++ b/src/device/lock.ts @@ -8,6 +8,7 @@ import { SwitchBotPlatform } from '../platform'; import { debounceTime, skipWhile, take, tap } from 'rxjs/operators'; import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge'; import { device, devicesConfig, deviceStatus, HostDomain, DevicePath, switchbot, ad, serviceData } from '../settings'; +import { sleep } from '../utils'; export class Lock { // Services @@ -274,7 +275,7 @@ export class Lock { } }; // Wait - return await switchbot.wait(this.scanDuration * 1000); + return await sleep(this.scanDuration * 1000); }) .then(async () => { // Stop to monitor @@ -513,7 +514,7 @@ export class Lock { } async stopScanning(switchbot: any) { - await switchbot.stopScan(); + switchbot.stopScan(); if (this.connected) { await this.BLEparseStatus(); await this.updateHomeKitCharacteristics(); @@ -533,7 +534,7 @@ export class Lock { switchbot.onadvertisement = (ad: any) => { this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`); }; - await switchbot.wait(10000); + await sleep(10000); // Stop to monitor switchbot.stopScan(); })(); diff --git a/src/device/meter.ts b/src/device/meter.ts index 1a9000ee..14dd73a1 100644 --- a/src/device/meter.ts +++ b/src/device/meter.ts @@ -11,6 +11,7 @@ import { SwitchBotPlatform } from '../platform'; import { Service, PlatformAccessory, Units, CharacteristicValue } from 'homebridge'; import { device, devicesConfig, serviceData, ad, switchbot, temperature, deviceStatus, HostDomain, DevicePath } from '../settings'; import { IncomingMessage } from 'http'; +import { sleep } from '../utils'; /** * Platform Accessory @@ -304,7 +305,7 @@ export class Meter { } }; // Wait - return await switchbot.wait(this.scanDuration * 1000); + return await sleep(this.scanDuration * 1000); }) .then(async () => { // Stop to monitor @@ -495,7 +496,7 @@ export class Meter { } async stopScanning(switchbot: any) { - await switchbot.stopScan(); + switchbot.stopScan(); if (this.connected) { await this.BLEparseStatus(); await this.updateHomeKitCharacteristics(); @@ -515,7 +516,7 @@ export class Meter { switchbot.onadvertisement = (ad: any) => { this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`); }; - await switchbot.wait(10000); + await sleep(10000); // Stop to monitor switchbot.stopScan(); })(); diff --git a/src/device/meterplus.ts b/src/device/meterplus.ts index 21ee6990..ded4a16f 100644 --- a/src/device/meterplus.ts +++ b/src/device/meterplus.ts @@ -11,6 +11,7 @@ import { SwitchBotPlatform } from '../platform'; import { Service, PlatformAccessory, Units, CharacteristicValue } from 'homebridge'; import { device, devicesConfig, serviceData, ad, switchbot, temperature, deviceStatus, HostDomain, DevicePath } from '../settings'; import { IncomingMessage } from 'http'; +import { sleep } from '../utils'; /** * Platform Accessory @@ -305,7 +306,7 @@ export class MeterPlus { } }; // Wait - return await switchbot.wait(this.scanDuration * 1000); + return await sleep(this.scanDuration * 1000); }) .then(async () => { // Stop to monitor @@ -495,7 +496,7 @@ export class MeterPlus { } async stopScanning(switchbot: any) { - await switchbot.stopScan(); + switchbot.stopScan(); if (this.connected) { await this.BLEparseStatus(); await this.updateHomeKitCharacteristics(); @@ -515,7 +516,7 @@ export class MeterPlus { switchbot.onadvertisement = (ad: any) => { this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`); }; - await switchbot.wait(10000); + await sleep(10000); // Stop to monitor switchbot.stopScan(); })(); diff --git a/src/device/motion.ts b/src/device/motion.ts index 046c84bd..02df067c 100644 --- a/src/device/motion.ts +++ b/src/device/motion.ts @@ -301,7 +301,7 @@ export class Motion { } }; // Wait - return await switchbot.wait(this.scanDuration * 1000); + return await sleep(this.scanDuration * 1000); }, }); }) @@ -420,7 +420,7 @@ export class Motion { } async stopScanning(switchbot: any) { - await switchbot.stopScan(); + switchbot.stopScan(); if (this.connected) { await this.BLEparseStatus(); await this.updateHomeKitCharacteristics(); @@ -440,7 +440,7 @@ export class Motion { switchbot.onadvertisement = (ad: any) => { this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`); }; - await switchbot.wait(10000); + await sleep(10000); // Stop to monitor switchbot.stopScan(); })(); diff --git a/src/device/plug.ts b/src/device/plug.ts index 7b170fc3..1472e696 100644 --- a/src/device/plug.ts +++ b/src/device/plug.ts @@ -231,7 +231,7 @@ export class Plug { } }; // Wait - return await switchbot.wait(this.scanDuration * 1000); + return await sleep(this.scanDuration * 1000); }) .then(async () => { // Stop to monitor @@ -471,7 +471,7 @@ export class Plug { } async stopScanning(switchbot: any) { - await switchbot.stopScan(); + switchbot.stopScan(); if (this.connected) { await this.BLEparseStatus(); await this.updateHomeKitCharacteristics(); @@ -499,7 +499,7 @@ export class Plug { switchbot.onadvertisement = (ad: any) => { this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`); }; - await switchbot.wait(10000); + await sleep(10000); // Stop to monitor switchbot.stopScan(); })(); diff --git a/src/device/robotvacuumcleaner.ts b/src/device/robotvacuumcleaner.ts index fd4875f9..0e341cd0 100644 --- a/src/device/robotvacuumcleaner.ts +++ b/src/device/robotvacuumcleaner.ts @@ -243,7 +243,7 @@ export class RobotVacuumCleaner { } }; // Wait - return await switchbot.wait(this.scanDuration * 1000); + return await sleep(this.scanDuration * 1000); }) .then(async () => { // Stop to monitor @@ -595,7 +595,7 @@ export class RobotVacuumCleaner { } async stopScanning(switchbot: any) { - await switchbot.stopScan(); + switchbot.stopScan(); if (this.connected) { await this.BLEparseStatus(); await this.updateHomeKitCharacteristics(); @@ -623,7 +623,7 @@ export class RobotVacuumCleaner { switchbot.onadvertisement = (ad: any) => { this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`); }; - await switchbot.wait(10000); + await sleep(10000); // Stop to monitor switchbot.stopScan(); })(); diff --git a/src/device/striplight.ts b/src/device/striplight.ts index e45538f7..3e912c91 100644 --- a/src/device/striplight.ts +++ b/src/device/striplight.ts @@ -345,7 +345,7 @@ export class StripLight { } }; // Wait - return await switchbot.wait(this.scanDuration * 1000); + return await sleep(this.scanDuration * 1000); }) .then(async () => { // Stop to monitor @@ -843,7 +843,7 @@ export class StripLight { } async stopScanning(switchbot: any) { - await switchbot.stopScan(); + switchbot.stopScan(); if (this.connected) { await this.BLEparseStatus(); await this.updateHomeKitCharacteristics(); @@ -864,7 +864,7 @@ export class StripLight { switchbot.onadvertisement = (ad: any) => { this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`); }; - await switchbot.wait(10000); + await sleep(10000); // Stop to monitor switchbot.stopScan(); })(); @@ -909,8 +909,8 @@ export class StripLight { } minStep(device: device & devicesConfig): number { - if (device.colorbulb?.set_minStep) { - this.set_minStep = device.colorbulb?.set_minStep; + if (device.striplight?.set_minStep) { + this.set_minStep = device.striplight?.set_minStep; } else { this.set_minStep = 1; } @@ -918,8 +918,8 @@ export class StripLight { } async adaptiveLighting(device: device & devicesConfig): Promise { - if (device.colorbulb?.adaptiveLightingShift) { - this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift; + if (device.striplight?.adaptiveLightingShift) { + this.adaptiveLightingShift = device.striplight.adaptiveLightingShift; this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`); } else { this.adaptiveLightingShift = 0; @@ -1050,8 +1050,8 @@ export class StripLight { async config(device: device & devicesConfig): Promise { let config = {}; - if (device.colorbulb) { - config = device.colorbulb; + if (device.striplight) { + config = device.striplight; } if (device.connectionType !== undefined) { config['connectionType'] = device.connectionType; diff --git a/src/platform.ts b/src/platform.ts index ca37ef4a..c08b7e3c 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -411,6 +411,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { case 'Hub Plus': this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`); break; + case 'Hub 2': + this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`); + break; case 'Bot': this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`); this.createBot(device); diff --git a/src/settings.ts b/src/settings.ts index db96acf6..2f6a6f3e 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -69,6 +69,7 @@ export interface devicesConfig extends device { contact?: contact; motion?: motion; colorbulb?: colorbulb; + striplight?: striplight; ceilinglight?: ceilinglight; plug?: Record; lock?: lock; @@ -107,8 +108,16 @@ export type curtain = { }; export type blindTilt = { - mappingMode?: string; + mode?: string; + hide_lightsensor?: boolean; + set_minLux?: number; + set_maxLux?: number; updateRate?: number; + set_max?: number; + set_min?: number; + set_minStep?: number; + setCloseMode?: string; + setOpenMode?: string; }; export type contact = { @@ -129,6 +138,11 @@ export type colorbulb = { adaptiveLightingShift?: number; }; +export type striplight = { + set_minStep?: number; + adaptiveLightingShift?: number; +}; + export type ceilinglight = { set_minStep?: number; adaptiveLightingShift?: number;