diff --git a/CHANGELOG.md b/CHANGELOG.md index 91e1cc4f..9a4d8145 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,17 @@ All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/) +## [Version 1.1.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.1.0) (2021-11-16) + +## What's Changed +* Fixed Bug: Curtains alternate between open/close state. [#85](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/85) +* Fixed Bug: IR Fan won't be hidden in Home app. [#90](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/90) +* Fixed Bug: `hide_temperature` config option causing `Cannot read property 'updateCharacteristic' of undefined` for Humidifiers. [#90](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/90) +* Add option to Hide Curtain's Light Sensor. [#91](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/91) +* Add option to Hide Contact Sensor's Motion Sensor or Light Sensor. + +**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.0.2...v1.1.0 + ## [Version 1.0.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.0.2) (2021-11-15) ## What's Changed diff --git a/config.schema.json b/config.schema.json index cb5a9225..a7c5445b 100644 --- a/config.schema.json +++ b/config.schema.json @@ -249,6 +249,13 @@ "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].deviceType === 'Curtain' && model.options.devices[arrayIndices].deviceId);" } }, + "hide_lightsensor": { + "title": "Hide Curtain's Light Sensor", + "type": "boolean", + "condition": { + "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].deviceType === 'Curtain' && model.options.devices[arrayIndices].deviceId);" + } + }, "refreshRate": { "title": "Refresh Rate", "type": "number", @@ -285,6 +292,25 @@ } } }, + "contact": { + "type": "object", + "properties": { + "hide_lightsensor": { + "title": "Hide Curtains's Light Sensor", + "type": "boolean", + "condition": { + "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].deviceType === 'Contact Sensor' && model.options.devices[arrayIndices].deviceId);" + } + }, + "hide_motionsensor": { + "title": "Hide Curtains's Motion Sensor", + "type": "boolean", + "condition": { + "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].deviceType === 'Contact Sensor' && model.options.devices[arrayIndices].deviceId);" + } + } + } + }, "colorbulb": { "type": "object", "properties": { @@ -674,10 +700,13 @@ "options.devices[].humidifier.set_minStep", "options.devices[].humidifier.hide_temperature", "options.devices[].curtain.disable_group", + "options.devices[].curtain.hide_lightsensor", "options.devices[].curtain.refreshRate", "options.devices[].curtain.set_minStep", "options.devices[].curtain.set_min", "options.devices[].curtain.set_max", + "options.devices[].contact.hide_lightsensor", + "options.devices[].contact.hide_motionsensor", "options.devices[].colorbulb.set_minStep" ] } diff --git a/package-lock.json b/package-lock.json index f6836f3e..075a4984 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@switchbot/homebridge-switchbot", - "version": "1.0.2", + "version": "1.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@switchbot/homebridge-switchbot", - "version": "1.0.2", + "version": "1.1.0", "funding": [ { "type": "Paypal", @@ -184,9 +184,9 @@ "dev": true }, "node_modules/@mapbox/node-pre-gyp": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.6.tgz", - "integrity": "sha512-qK1ECws8UxuPqOA8F5LFD90vyVU33W7N3hGfgsOVfrJaRVc8McC3JClTDHpeSbL9CBrOHly/4GsNPAvIgNZE+g==", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.7.tgz", + "integrity": "sha512-PplSvl4pJ5N3BkVjAdDzpPhVUPdC73JgttkR+LnBx2OORC1GCQsBjUeEuipf9uOaAM1SbxcdZFfR3KDTKm2S0A==", "optional": true, "dependencies": { "detect-libc": "^1.0.3", @@ -194,7 +194,7 @@ "make-dir": "^3.1.0", "node-fetch": "^2.6.5", "nopt": "^5.0.0", - "npmlog": "^5.0.1", + "npmlog": "^6.0.0", "rimraf": "^3.0.2", "semver": "^7.3.5", "tar": "^6.1.11" @@ -667,29 +667,6 @@ "string-width": "^4.1.0" } }, - "node_modules/ansi-align/node_modules/is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/ansi-align/node_modules/string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, - "dependencies": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/ansi-colors": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", @@ -703,7 +680,7 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true, + "devOptional": true, "engines": { "node": ">=8" } @@ -852,29 +829,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/boxen/node_modules/is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/boxen/node_modules/string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, - "dependencies": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -1437,7 +1391,7 @@ "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", - "dev": true + "devOptional": true }, "node_modules/encoding": { "version": "0.1.13", @@ -2022,44 +1976,23 @@ } }, "node_modules/gauge": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/gauge/-/gauge-3.0.1.tgz", - "integrity": "sha512-6STz6KdQgxO4S/ko+AbjlFGGdGcknluoqU+79GOFCDqqyYj5OanQf9AjxwN0jCidtT+ziPMmPSt9E4hfQ0CwIQ==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/gauge/-/gauge-4.0.0.tgz", + "integrity": "sha512-F8sU45yQpjQjxKkm1UOAhf0U/O0aFt//Fl7hsrNVto+patMHjs7dPI9mFOGUKbhrgKm0S3EjW3scMFuQmWSROw==", "optional": true, "dependencies": { + "ansi-regex": "^5.0.1", "aproba": "^1.0.3 || ^2.0.0", "color-support": "^1.1.2", "console-control-strings": "^1.0.0", "has-unicode": "^2.0.1", - "object-assign": "^4.1.1", "signal-exit": "^3.0.0", - "string-width": "^1.0.1 || ^2.0.0", - "strip-ansi": "^3.0.1 || ^4.0.0", + "string-width": "^4.2.3", + "strip-ansi": "^6.0.1", "wide-align": "^1.1.2" }, "engines": { - "node": ">=10" - } - }, - "node_modules/gauge/node_modules/ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", - "optional": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/gauge/node_modules/strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", - "optional": true, - "dependencies": { - "ansi-regex": "^3.0.0" - }, - "engines": { - "node": ">=4" + "node": "^12.13.0 || ^14.15.0 || >=16" } }, "node_modules/get-intrinsic": { @@ -2639,12 +2572,12 @@ } }, "node_modules/is-fullwidth-code-point": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", "devOptional": true, "engines": { - "node": ">=4" + "node": ">=8" } }, "node_modules/is-glob": { @@ -3851,15 +3784,18 @@ } }, "node_modules/npmlog": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-5.0.1.tgz", - "integrity": "sha512-AqZtDUWOMKs1G/8lwylVjrdYgqA4d9nu8hc+0gzRxlDb1I10+FHBGMXs6aiQHFdCUUlqH99MUMuLfzWDNDtfxw==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-6.0.0.tgz", + "integrity": "sha512-03ppFRGlsyUaQFbGC2C8QWJN/C/K7PsfyD9aQdhVKAQIH4sQBc8WASqFBP7O+Ut4d2oo5LoeoboB3cGdBZSp6Q==", "optional": true, "dependencies": { "are-we-there-yet": "^2.0.0", "console-control-strings": "^1.1.0", - "gauge": "^3.0.0", + "gauge": "^4.0.0", "set-blocking": "^2.0.0" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || >=16" } }, "node_modules/number-is-nan": { @@ -3875,7 +3811,7 @@ "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", - "devOptional": true, + "dev": true, "engines": { "node": ">=0.10.0" } @@ -4755,37 +4691,17 @@ } }, "node_modules/string-width": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", - "devOptional": true, - "dependencies": { - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^4.0.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/string-width/node_modules/ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", - "devOptional": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/string-width/node_modules/strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", "devOptional": true, "dependencies": { - "ansi-regex": "^3.0.0" + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" }, "engines": { - "node": ">=4" + "node": ">=8" } }, "node_modules/string.prototype.trimend": { @@ -4818,7 +4734,7 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dev": true, + "devOptional": true, "dependencies": { "ansi-regex": "^5.0.1" }, @@ -5327,29 +5243,6 @@ "node": ">=8" } }, - "node_modules/widest-line/node_modules/is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/widest-line/node_modules/string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, - "dependencies": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/word-wrap": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", @@ -5376,29 +5269,6 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, - "node_modules/wrap-ansi/node_modules/is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/wrap-ansi/node_modules/string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, - "dependencies": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", @@ -5564,9 +5434,9 @@ "dev": true }, "@mapbox/node-pre-gyp": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.6.tgz", - "integrity": "sha512-qK1ECws8UxuPqOA8F5LFD90vyVU33W7N3hGfgsOVfrJaRVc8McC3JClTDHpeSbL9CBrOHly/4GsNPAvIgNZE+g==", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.7.tgz", + "integrity": "sha512-PplSvl4pJ5N3BkVjAdDzpPhVUPdC73JgttkR+LnBx2OORC1GCQsBjUeEuipf9uOaAM1SbxcdZFfR3KDTKm2S0A==", "optional": true, "requires": { "detect-libc": "^1.0.3", @@ -5574,7 +5444,7 @@ "make-dir": "^3.1.0", "node-fetch": "^2.6.5", "nopt": "^5.0.0", - "npmlog": "^5.0.1", + "npmlog": "^6.0.0", "rimraf": "^3.0.2", "semver": "^7.3.5", "tar": "^6.1.11" @@ -5909,25 +5779,6 @@ "dev": true, "requires": { "string-width": "^4.1.0" - }, - "dependencies": { - "is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true - }, - "string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, - "requires": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - } - } } }, "ansi-colors": { @@ -5940,7 +5791,7 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true + "devOptional": true }, "ansi-styles": { "version": "4.3.0", @@ -6054,25 +5905,6 @@ "type-fest": "^0.20.2", "widest-line": "^3.1.0", "wrap-ansi": "^7.0.0" - }, - "dependencies": { - "is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true - }, - "string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, - "requires": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - } - } } }, "brace-expansion": { @@ -6510,7 +6342,7 @@ "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", - "dev": true + "devOptional": true }, "encoding": { "version": "0.1.13", @@ -6961,37 +6793,20 @@ "dev": true }, "gauge": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/gauge/-/gauge-3.0.1.tgz", - "integrity": "sha512-6STz6KdQgxO4S/ko+AbjlFGGdGcknluoqU+79GOFCDqqyYj5OanQf9AjxwN0jCidtT+ziPMmPSt9E4hfQ0CwIQ==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/gauge/-/gauge-4.0.0.tgz", + "integrity": "sha512-F8sU45yQpjQjxKkm1UOAhf0U/O0aFt//Fl7hsrNVto+patMHjs7dPI9mFOGUKbhrgKm0S3EjW3scMFuQmWSROw==", "optional": true, "requires": { + "ansi-regex": "^5.0.1", "aproba": "^1.0.3 || ^2.0.0", "color-support": "^1.1.2", "console-control-strings": "^1.0.0", "has-unicode": "^2.0.1", - "object-assign": "^4.1.1", "signal-exit": "^3.0.0", - "string-width": "^1.0.1 || ^2.0.0", - "strip-ansi": "^3.0.1 || ^4.0.0", + "string-width": "^4.2.3", + "strip-ansi": "^6.0.1", "wide-align": "^1.1.2" - }, - "dependencies": { - "ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", - "optional": true - }, - "strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", - "optional": true, - "requires": { - "ansi-regex": "^3.0.0" - } - } } }, "get-intrinsic": { @@ -7417,9 +7232,9 @@ "dev": true }, "is-fullwidth-code-point": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", "devOptional": true }, "is-glob": { @@ -8366,14 +8181,14 @@ } }, "npmlog": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-5.0.1.tgz", - "integrity": "sha512-AqZtDUWOMKs1G/8lwylVjrdYgqA4d9nu8hc+0gzRxlDb1I10+FHBGMXs6aiQHFdCUUlqH99MUMuLfzWDNDtfxw==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-6.0.0.tgz", + "integrity": "sha512-03ppFRGlsyUaQFbGC2C8QWJN/C/K7PsfyD9aQdhVKAQIH4sQBc8WASqFBP7O+Ut4d2oo5LoeoboB3cGdBZSp6Q==", "optional": true, "requires": { "are-we-there-yet": "^2.0.0", "console-control-strings": "^1.1.0", - "gauge": "^3.0.0", + "gauge": "^4.0.0", "set-blocking": "^2.0.0" } }, @@ -8387,7 +8202,7 @@ "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", - "devOptional": true + "dev": true }, "object-inspect": { "version": "1.11.0", @@ -9015,30 +8830,14 @@ } }, "string-width": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", "devOptional": true, "requires": { - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^4.0.0" - }, - "dependencies": { - "ansi-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", - "devOptional": true - }, - "strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", - "devOptional": true, - "requires": { - "ansi-regex": "^3.0.0" - } - } + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" } }, "string.prototype.trimend": { @@ -9065,7 +8864,7 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dev": true, + "devOptional": true, "requires": { "ansi-regex": "^5.0.1" } @@ -9455,25 +9254,6 @@ "dev": true, "requires": { "string-width": "^4.0.0" - }, - "dependencies": { - "is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true - }, - "string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, - "requires": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - } - } } }, "word-wrap": { @@ -9491,25 +9271,6 @@ "ansi-styles": "^4.0.0", "string-width": "^4.1.0", "strip-ansi": "^6.0.0" - }, - "dependencies": { - "is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true - }, - "string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, - "requires": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - } - } } }, "wrappy": { diff --git a/package.json b/package.json index b9e844d7..531eb842 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "displayName": "Homebridge SwitchBot", "name": "@switchbot/homebridge-switchbot", - "version": "1.0.2", + "version": "1.1.0", "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", diff --git a/src/devices/contact.ts b/src/devices/contact.ts index 385a215c..8efcbd1a 100644 --- a/src/devices/contact.ts +++ b/src/devices/contact.ts @@ -12,8 +12,8 @@ import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusR export class Contact { // Services private service: Service; - private motionService: Service; - private lightSensorService: Service; + private motionService?: Service; + private lightSensorService?: Service; private batteryService?: Service; // Characteristic Values @@ -87,17 +87,40 @@ export class Contact { // each service must implement at-minimum the "required characteristics" for the given service type // see https://developers.homebridge.io/#/service/MotionSensor - (this.motionService = - accessory.getService(this.platform.Service.MotionSensor) || - accessory.addService(this.platform.Service.MotionSensor)), `${accessory.displayName} Motion Sensor`; - this.motionService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Motion Sensor`); + // Motion Sensor Service + if (this.device.contact?.hide_motionsensor) { + this.platform.device(`Contact: ${accessory.displayName} Removing Motion Sensor Service`); + this.motionService = this.accessory.getService(this.platform.Service.MotionSensor); + accessory.removeService(this.motionService!); + } else if (!this.motionService) { + this.platform.device(`Contact: ${accessory.displayName} Add Motion Sensor Service`); + (this.motionService = + this.accessory.getService(this.platform.Service.MotionSensor) || + this.accessory.addService(this.platform.Service.MotionSensor)), `${accessory.displayName} Motion Sensor`; - (this.lightSensorService = - accessory.getService(this.platform.Service.LightSensor) || - accessory.addService(this.platform.Service.LightSensor)), `${accessory.displayName} Light Sensor`; + this.motionService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Motion Sensor`); - this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`); + } else { + this.platform.device(`Contact: ${accessory.displayName} Motion Sensor Service Not Added`); + } + + // Light Sensor Service + if (this.device.contact?.hide_lightsensor) { + this.platform.device(`Contact: ${accessory.displayName} Removing Light Sensor Service`); + this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor); + accessory.removeService(this.lightSensorService!); + } else if (!this.lightSensorService) { + this.platform.device(`Contact: ${accessory.displayName} Add Light Sensor Service`); + (this.lightSensorService = + this.accessory.getService(this.platform.Service.LightSensor) || + this.accessory.addService(this.platform.Service.LightSensor)), `${accessory.displayName} Light Sensor`; + + this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`); + + } else { + this.platform.device(`Contact: ${accessory.displayName} Light Sensor Service Not Added`); + } if (device.ble) { (this.batteryService = @@ -133,8 +156,10 @@ export class Contact { private async BLEparseStatus() { this.platform.debug('Contact BLE Device parseStatus'); - // Movement - this.MotionDetected = Boolean(this.movement); + if (this.device.contact?.hide_motionsensor) { + // Movement + this.MotionDetected = Boolean(this.movement); + } // Door State switch (this.doorState) { case 'open': @@ -148,14 +173,15 @@ export class Contact { default: this.platform.log.error('timeout no closed'); } - // Light Level - switch (this.lightLevel) { - case 'dark': - case 0: - this.CurrentAmbientLightLevel = 0.0001; - break; - default: - this.CurrentAmbientLightLevel = 100000; + if (this.device.contact?.hide_lightsensor) {// Light Level + switch (this.lightLevel) { + case 'dark': + case 0: + this.CurrentAmbientLightLevel = 0.0001; + break; + default: + this.CurrentAmbientLightLevel = 100000; + } } // Battery this.BatteryLevel = Number(this.battery); @@ -179,7 +205,9 @@ export class Contact { } else { this.platform.device(`${this.accessory.displayName} ${this.deviceStatus.body.openState}`); } - this.MotionDetected = Boolean(this.deviceStatus.body.moveDetected); + if (this.device.contact?.hide_motionsensor) { + this.MotionDetected = Boolean(this.deviceStatus.body.moveDetected); + } this.platform.debug(`${this.accessory.displayName} , ContactSensorState: ${this.ContactSensorState}, MotionDetected: ${this.MotionDetected}`); } @@ -265,37 +293,49 @@ export class Contact { this.service.updateCharacteristic(this.platform.Characteristic.ContactSensorState, this.ContactSensorState); this.platform.device(`Contact ${this.accessory.displayName} updateCharacteristic ContactSensorState: ${this.ContactSensorState}`); } - if (this.MotionDetected === undefined) { - this.platform.debug(`Contact ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`); - } else { - this.motionService.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected); - this.platform.device(`Contact ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`); - } - if (this.CurrentAmbientLightLevel === undefined) { - this.platform.debug(`Contact ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`); - } else { - this.lightSensorService.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel); - this.platform.device(`Contact ${this.accessory.displayName} updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`); + if (!this.device.contact?.hide_motionsensor) { + if (this.MotionDetected === undefined) { + this.platform.debug(`Contact ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`); + } else { + this.motionService!.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.MotionDetected); + this.platform.device(`Contact ${this.accessory.displayName} updateCharacteristic MotionDetected: ${this.MotionDetected}`); + } } - if (this.BatteryLevel === undefined) { - this.platform.debug(`Contact ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`); - } else { - this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel); - this.platform.device(`Contact ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`); + if (!this.device.contact?.hide_lightsensor) { + if (this.CurrentAmbientLightLevel === undefined) { + this.platform.debug(`Contact ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`); + } else { + this.lightSensorService!.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel); + this.platform.device(`Contact ${this.accessory.displayName} updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`); + } } - if (this.StatusLowBattery === undefined) { - this.platform.debug(`Contact ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`); - } else { - this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery); - this.platform.device(`Contact ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`); + if (this.device.ble) { + if (this.BatteryLevel === undefined) { + this.platform.debug(`Contact ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`); + } else { + this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel); + this.platform.device(`Contact ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`); + } + if (this.StatusLowBattery === undefined) { + this.platform.debug(`Contact ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`); + } else { + this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery); + this.platform.device(`Contact ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`); + } } } public apiError(e: any) { this.service.updateCharacteristic(this.platform.Characteristic.ContactSensorState, e); - this.motionService.updateCharacteristic(this.platform.Characteristic.MotionDetected, e); - this.lightSensorService.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e); - this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e); - this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e); + if (!this.device.contact?.hide_motionsensor) { + this.motionService!.updateCharacteristic(this.platform.Characteristic.MotionDetected, e); + } + if (!this.device.contact?.hide_lightsensor) { + this.lightSensorService!.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e); + } + if (this.device.ble) { + this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e); + this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e); + } } } diff --git a/src/devices/curtains.ts b/src/devices/curtains.ts index fd583140..b21907d0 100644 --- a/src/devices/curtains.ts +++ b/src/devices/curtains.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-var-requires */ import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge'; import { SwitchBotPlatform } from '../platform'; import { interval, Subject } from 'rxjs'; @@ -9,14 +8,14 @@ import { AxiosResponse } from 'axios'; export class Curtain { // Services private service: Service; - private lightSensorService: Service; + private lightSensorService?: Service; private batteryService?: Service; // Characteristic Values CurrentPosition!: CharacteristicValue; PositionState!: CharacteristicValue; TargetPosition!: CharacteristicValue; - CurrentAmbientLightLevel!: CharacteristicValue; + CurrentAmbientLightLevel?: CharacteristicValue; BatteryLevel?: CharacteristicValue; StatusLowBattery?: CharacteristicValue; @@ -48,25 +47,15 @@ export class Curtain { ) { // Curtain Config this.platform.device(`[Curtain Config] ble: ${device.ble}, disable_group: ${device.curtain?.disable_group},` - + ` refreshRate: ${device.curtain?.refreshRate}, set_max: ${device.curtain?.set_max}, set_min: ${device.curtain?.set_min},` - + ` set_minStep: ${device.curtain?.set_minStep}`); + + ` refreshRate: ${device.curtain?.refreshRate}, set_max: ${device.curtain?.set_max}, set_min: ${device.curtain?.set_min},` + + ` set_minStep: ${device.curtain?.set_minStep}`); // default placeholders + this.setMinMax(); this.CurrentPosition = 0; this.TargetPosition = 0; this.PositionState = this.platform.Characteristic.PositionState.STOPPED; - // BLE Connection - if (device.ble) { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const SwitchBot = require('node-switchbot'); - this.switchbot = new SwitchBot(); - const colon = device.deviceId!.match(/.{1,2}/g); - const bleMac = colon!.join(':'); //returns 1A:23:B4:56:78:9A; - this.device.bleMac = bleMac.toLowerCase(); - this.platform.device(this.device.bleMac.toLowerCase()); - } - // this is subject we use to track when we need to POST changes to the SwitchBot API this.doCurtainUpdate = new Subject(); this.curtainUpdateInProgress = false; @@ -79,8 +68,8 @@ export class Curtain { accessory .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') - .setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-WOCURTAIN-W0701600') - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); + .setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-CURTAIN-W0701600') + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId); // get the WindowCovering service if it exists, otherwise create a new WindowCovering service // you can create multiple services for each accessory @@ -122,11 +111,23 @@ export class Curtain { }) .onSet(this.TargetPositionSet.bind(this)); - //set up brightness level from the builtin sensor as light sensor accessory - (this.lightSensorService = - accessory.getService(this.platform.Service.LightSensor) || - accessory.addService(this.platform.Service.LightSensor)), `${device.deviceName} Light Sensor`; - this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${device.deviceName} Light Sensor`); + // Light Sensor Service + if (this.device.curtain?.hide_lightsensor) { + this.platform.device(`Curtain: ${accessory.displayName} Removing Light Sensor Service`); + this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor); + accessory.removeService(this.lightSensorService!); + } else if (!this.lightSensorService) { + this.platform.device(`Curtain: ${accessory.displayName} Add Light Sensor Service`); + (this.lightSensorService = + this.accessory.getService(this.platform.Service.LightSensor) || + this.accessory.addService(this.platform.Service.LightSensor)), `${accessory.displayName} Light Sensor`; + + this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`); + + } else { + this.platform.device(`Curtain: ${accessory.displayName} Light Sensor Service Not Added`); + } + // Update Homekit this.updateHomeKitCharacteristics(); @@ -145,7 +146,7 @@ export class Curtain { if (this.PositionState === this.platform.Characteristic.PositionState.STOPPED) { return; } - this.platform.debug('Refresh status when moving', this.PositionState); + this.platform.debug(`Curtain: ${accessory.displayName} Refresh Status When Moving, PositionState: ${this.PositionState}`); this.refreshStatus(); }); @@ -163,14 +164,25 @@ export class Curtain { try { await this.pushChanges(); } catch (e: any) { - this.platform.log.error(JSON.stringify(e.message)); - this.platform.debug(`Curtain ${accessory.displayName} - ${JSON.stringify(e)}`); + this.platform.log.error(`Curtain: ${this.accessory.displayName} Error Message ${JSON.stringify(e.message)}`); + this.platform.debug(`Curtain: ${accessory.displayName} Error: ${JSON.stringify(e)}`); this.apiError(e); } this.curtainUpdateInProgress = false; }); } + private connectBLE() { + // eslint-disable-next-line @typescript-eslint/no-var-requires + const Switchbot = require('node-switchbot'); + const switchbot = new Switchbot(); + const colon = this.device.deviceId!.match(/.{1,2}/g); + const bleMac = colon!.join(':'); //returns 1A:23:B4:56:78:9A; + this.device.bleMac = bleMac.toLowerCase(); + this.platform.device(this.device.bleMac.toLowerCase()); + return switchbot; + } + private curtainRefreshRate() { if (this.device?.curtain?.refreshRate) { this.refreshRate = this.device?.curtain?.refreshRate; @@ -180,7 +192,6 @@ export class Curtain { this.platform.log.warn('Using Default Curtain Refresh Rate.'); } } - return this.refreshRate; } @@ -206,63 +217,69 @@ export class Curtain { private async BLEparseStatus() { this.platform.device('Curtains BLE Device parseStatus'); this.CurrentPosition = 100 - Number(this.position); - this.setMinMax(); - this.platform.debug(`Curtain ${this.accessory.displayName} CurrentPosition - Device is Currently: ${this.CurrentPosition}`); + this.platform.debug(`Curtain ${this.accessory.displayName} CurrentPosition ${this.CurrentPosition}`); if (this.setNewTarget) { this.platform.log.info(`Checking ${this.accessory.displayName} Status ...`); } if (this.setNewTarget) { + this.setMinMax(); if (this.TargetPosition > this.CurrentPosition) { - this.platform.debug(`Curtain ${this.accessory.displayName} - Current position: ${this.CurrentPosition} closing`); + this.platform.debug(`Curtain ${this.accessory.displayName} Closing, Current position: ${this.CurrentPosition}`); this.PositionState = this.platform.Characteristic.PositionState.INCREASING; } else if (this.TargetPosition < this.CurrentPosition) { - this.platform.debug(`Curtain ${this.accessory.displayName} - Current position: ${this.CurrentPosition} opening`); + this.platform.debug(`Curtain ${this.accessory.displayName} Opening, Current position: ${this.CurrentPosition}`); this.PositionState = this.platform.Characteristic.PositionState.DECREASING; } else { - this.platform.debug(`Curtain ${this.CurrentPosition} - standby`); + this.platform.debug(`Curtain ${this.CurrentPosition} Standby, Current position: ${this.CurrentPosition}`); this.PositionState = this.platform.Characteristic.PositionState.STOPPED; } } else { - this.platform.debug(`Curtain ${this.accessory.displayName} - Current position: ${this.CurrentPosition} standby`); + this.platform.debug(`Curtain ${this.accessory.displayName} Standby, Current position: ${this.CurrentPosition}`); if (!this.setNewTarget) { - /*If Curtain calibration distance is short, there will be an error between the current percentage and the target percentage.*/ + // If Curtain calibration distance is short, there will be an error between the current percentage and the target percentage. this.TargetPosition = this.CurrentPosition; this.PositionState = this.platform.Characteristic.PositionState.STOPPED; } } - // Brightness - switch (this.lightLevel) { - case 1: - this.CurrentAmbientLightLevel = 0.0001; - break; - case 2: - this.CurrentAmbientLightLevel = 100; - break; - case 3: - this.CurrentAmbientLightLevel = 200; - break; - case 4: - this.CurrentAmbientLightLevel = 4000; - break; - case 5: - this.CurrentAmbientLightLevel = 12000; - break; - case 6: - this.CurrentAmbientLightLevel = 28000; - break; - case 7: - this.CurrentAmbientLightLevel = 56000; - break; - case 8: - this.CurrentAmbientLightLevel = 75000; - break; - case 9: - this.CurrentAmbientLightLevel = 90000; - break; - case 10: - default: - this.CurrentAmbientLightLevel = 100000; + this.platform.debug(`Curtain ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},` + + ` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`); + + if (!this.device.curtain?.hide_lightsensor) { + // Brightness + switch (this.lightLevel) { + case 1: + this.CurrentAmbientLightLevel = 1; + break; + case 2: + this.CurrentAmbientLightLevel = 2; + break; + case 3: + this.CurrentAmbientLightLevel = 3; + break; + case 4: + this.CurrentAmbientLightLevel = 4; + break; + case 5: + this.CurrentAmbientLightLevel = 5; + break; + case 6: + this.CurrentAmbientLightLevel = 6; + break; + case 7: + this.CurrentAmbientLightLevel = 7; + break; + case 8: + this.CurrentAmbientLightLevel = 8; + break; + case 9: + this.CurrentAmbientLightLevel = 9; + break; + case 10: + default: + this.CurrentAmbientLightLevel = 10; + } + this.platform.debug(`Curtain ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`); } // Battery this.BatteryLevel = Number(this.battery); @@ -271,54 +288,53 @@ export class Curtain { } else { this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL; } - this.platform.debug( - `Curtain ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},` - + ` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},` - + ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`); + this.platform.debug(`Curtain ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`); } private async openAPIparseStatus() { this.platform.device('Curtains OpenAPI Device parseStatus'); + // CurrentPosition this.CurrentPosition = 100 - this.deviceStatus.body.slidePosition!; - this.setMinMax(); this.platform.debug(`Curtain ${this.accessory.displayName} CurrentPosition - Device is Currently: ${this.CurrentPosition}`); if (this.setNewTarget) { this.platform.log.info(`Checking ${this.accessory.displayName} Status ...`); } if (this.deviceStatus.body.moving) { + this.setMinMax(); if (this.TargetPosition > this.CurrentPosition) { - this.platform.debug(`Curtain ${this.accessory.displayName} - Current position: ${this.CurrentPosition} closing`); + this.platform.debug(`Curtain: ${this.accessory.displayName} Closing, Current Position: ${this.CurrentPosition} `); this.PositionState = this.platform.Characteristic.PositionState.INCREASING; } else if (this.TargetPosition < this.CurrentPosition) { - this.platform.debug(`Curtain ${this.accessory.displayName} - Current position: ${this.CurrentPosition} opening`); + this.platform.debug(`Curtain: ${this.accessory.displayName} Opening, Current Position: ${this.CurrentPosition} `); this.PositionState = this.platform.Characteristic.PositionState.DECREASING; } else { - this.platform.debug(`Curtain ${this.CurrentPosition} - standby`); + this.platform.debug(`Curtain: ${this.CurrentPosition} Standby, Current position: ${this.CurrentPosition}`); this.PositionState = this.platform.Characteristic.PositionState.STOPPED; } } else { - this.platform.debug(`Curtain ${this.accessory.displayName} - Current position: ${this.CurrentPosition} standby`); + this.platform.debug(`Curtain: ${this.accessory.displayName} Standby, Current position: ${this.CurrentPosition}`); if (!this.setNewTarget) { /*If Curtain calibration distance is short, there will be an error between the current percentage and the target percentage.*/ this.TargetPosition = this.CurrentPosition; this.PositionState = this.platform.Characteristic.PositionState.STOPPED; } } - - // Brightness - switch (this.deviceStatus.body.brightness) { - case 'dim': - this.CurrentAmbientLightLevel = 0.0001; - break; - case 'bright': - default: - this.CurrentAmbientLightLevel = 100000; + this.platform.debug(`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},` + + ` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`); + + if (!this.device.curtain?.hide_lightsensor) { + // Brightness + switch (this.deviceStatus.body.brightness) { + case 'dim': + this.CurrentAmbientLightLevel = 0.0001; + break; + case 'bright': + default: + this.CurrentAmbientLightLevel = 100000; + } + this.platform.debug(`Curtain: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`); } - this.platform.debug( - `Curtain ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition},` - + ` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},` - + ` CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`); } async refreshStatus() { @@ -331,17 +347,6 @@ export class Curtain { } } - private connectBLE() { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const Switchbot = require('node-switchbot'); - const switchbot = new Switchbot(); - const colon = this.device.deviceId!.match(/.{1,2}/g); - const bleMac = colon!.join(':'); //returns 1A:23:B4:56:78:9A; - this.device.bleMac = bleMac.toLowerCase(); - this.platform.device(this.device.bleMac!); - return switchbot; - } - private async BLERefreshStatus() { this.platform.debug('Curtains BLE Device RefreshStatus'); // eslint-disable-next-line @typescript-eslint/no-var-requires @@ -380,12 +385,12 @@ export class Curtain { this.platform.debug('Curtains OpenAPI Device RefreshStatus'); try { this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data; - this.platform.debug(`Curtain ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`); + this.platform.debug(`Curtain: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`); this.parseStatus(); this.updateHomeKitCharacteristics(); } catch (e: any) { - this.platform.log.error(`Curtain ${this.accessory.displayName} failed to refresh status, Eror Message ${JSON.stringify(e.message)}`); - this.platform.debug(`Curtain ${this.accessory.displayName}, Error: ${JSON.stringify(e)}`); + this.platform.log.error(`Curtain: ${this.accessory.displayName} failed to refresh status, Error Message ${JSON.stringify(e.message)}`); + this.platform.debug(`Curtain: ${this.accessory.displayName} Error: ${JSON.stringify(e)}`); this.apiError(e); } } @@ -404,7 +409,7 @@ export class Curtain { this.platform.device('Curtains BLE Device pushChanges'); const switchbot = this.connectBLE(); switchbot.discover({ model: 'c', quick: true, id: this.device.bleMac }).then((device_list) => { - this.platform.log.info(`${this.accessory.displayName}, Target Position: ${this.TargetPosition}`); + this.platform.log.info(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`); return device_list[0].runToPos(100 - Number(this.TargetPosition)); }).then(() => { this.platform.device('Done.'); @@ -433,47 +438,42 @@ export class Curtain { 'commandType:', payload.commandType, ); - this.platform.debug(`Curtain ${this.accessory.displayName} pushchanges: ${JSON.stringify(payload)}`); + this.platform.debug(`Curtain: ${this.accessory.displayName} pushchanges: ${JSON.stringify(payload)}`); // Make the API request const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId!}/commands`, payload)); - this.platform.debug(`Curtain ${this.accessory.displayName} Changes pushed: ${JSON.stringify(push.data)}`); + this.platform.debug(`Curtain: ${this.accessory.displayName} Changes pushed: ${JSON.stringify(push.data)}`); this.statusCode(push); } } updateHomeKitCharacteristics() { - this.platform.debug( - `Curtain ${this.accessory.displayName} updateHomeKitCharacteristics - ${JSON.stringify({ - CurrentPosition: this.CurrentPosition, - PositionState: this.PositionState, - TargetPosition: this.TargetPosition, - CurrentAmbientLightLevel: this.CurrentAmbientLightLevel, - })}`, - ); - if (this.CurrentPosition === undefined) { - this.platform.debug(`Curtain ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`); + this.setMinMax(); + if (this.CurrentPosition === undefined || Number.isNaN(this.CurrentPosition)) { + this.platform.debug(`Curtain: ${this.accessory.displayName} CurrentPosition: ${this.CurrentPosition}`); } else { - this.service.updateCharacteristic(this.platform.Characteristic.CurrentPosition, Number.isNaN(this.CurrentPosition)); - this.platform.device(`Curtain ${this.accessory.displayName} updateCharacteristic CurrentPosition: ${this.CurrentPosition}`); + this.service.updateCharacteristic(this.platform.Characteristic.CurrentPosition, Number(this.CurrentPosition)); + this.platform.device(`Curtain: ${this.accessory.displayName} updateCharacteristic CurrentPosition: ${this.CurrentPosition}`); } if (this.PositionState === undefined) { - this.platform.debug(`Curtain ${this.accessory.displayName} PositionState: ${this.PositionState}`); + this.platform.debug(`Curtain: ${this.accessory.displayName} PositionState: ${this.PositionState}`); } else { - this.service.updateCharacteristic(this.platform.Characteristic.PositionState, this.PositionState); - this.platform.device(`Curtain ${this.accessory.displayName} updateCharacteristic PositionState: ${this.PositionState}`); + this.platform.device(`Curtain: ${this.accessory.displayName} updateCharacteristic PositionState: ${this.PositionState}`); } - if (this.TargetPosition === undefined) { - this.platform.debug(`Curtain ${this.accessory.displayName} TargetPosition: ${this.TargetPosition}`); + if (this.TargetPosition === undefined || Number.isNaN(this.TargetPosition)) { + this.platform.debug(`Curtain: ${this.accessory.displayName} TargetPosition: ${this.TargetPosition}`); } else { - this.service.updateCharacteristic(this.platform.Characteristic.TargetPosition, Number.isNaN(this.TargetPosition)); - this.platform.device(`Curtain ${this.accessory.displayName} updateCharacteristic TargetPosition: ${this.TargetPosition}`); + this.service.updateCharacteristic(this.platform.Characteristic.TargetPosition, Number(this.TargetPosition)); + this.platform.device(`Curtain: ${this.accessory.displayName} updateCharacteristic TargetPosition: ${this.TargetPosition}`); } - if (this.CurrentAmbientLightLevel === undefined) { - this.platform.debug(`Curtain ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`); - } else { - this.lightSensorService.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel); - this.platform.device(`Curtain ${this.accessory.displayName} updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`); + if (!this.device.curtain?.hide_lightsensor) { + if (this.CurrentAmbientLightLevel === undefined || Number.isNaN(this.CurrentAmbientLightLevel)) { + this.platform.debug(`Curtain: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`); + } else { + this.lightSensorService!.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, this.CurrentAmbientLightLevel); + this.platform.device(`Curtain: ${this.accessory.displayName}` + + ` updateCharacteristic CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`); + } } if (this.device.ble) { if (this.BatteryLevel === undefined) { @@ -495,7 +495,9 @@ export class Curtain { this.service.updateCharacteristic(this.platform.Characteristic.CurrentPosition, e); this.service.updateCharacteristic(this.platform.Characteristic.PositionState, e); this.service.updateCharacteristic(this.platform.Characteristic.TargetPosition, e); - this.lightSensorService.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e); + if (!this.device.curtain?.hide_lightsensor) { + this.lightSensorService!.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, e); + } if (this.device.ble) { this.batteryService!.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e); this.batteryService!.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e); @@ -534,7 +536,7 @@ export class Curtain { * Handle requests to set the value of the "Target Position" characteristic */ TargetPositionSet(value: CharacteristicValue) { - this.platform.debug(`Curtain ${this.accessory.displayName} - Set TargetPosition: ${value}`); + this.platform.debug(`Curtain: ${this.accessory.displayName} - Set TargetPosition: ${value}`); this.TargetPosition = value; @@ -542,12 +544,15 @@ export class Curtain { if (value > this.CurrentPosition) { this.PositionState = this.platform.Characteristic.PositionState.INCREASING; this.setNewTarget = true; + //this.setMinMax(); } else if (value < this.CurrentPosition) { this.PositionState = this.platform.Characteristic.PositionState.DECREASING; this.setNewTarget = true; + //this.setMinMax(); } else { this.PositionState = this.platform.Characteristic.PositionState.STOPPED; this.setNewTarget = false; + //this.setMinMax(); } this.service.setCharacteristic(this.platform.Characteristic.PositionState, this.PositionState); @@ -558,7 +563,7 @@ export class Curtain { clearTimeout(this.setNewTargetTimer); if (this.setNewTarget) { this.setNewTargetTimer = setTimeout(() => { - this.platform.debug(`Curtain ${this.accessory.displayName} - setNewTarget ${this.setNewTarget} timeout`); + this.platform.debug(`Curtain: ${this.accessory.displayName} - setNewTarget ${this.setNewTarget} timeout`); this.setNewTarget = false; }, 10000); } diff --git a/src/devices/humidifiers.ts b/src/devices/humidifiers.ts index e69edfd8..2e9363cb 100644 --- a/src/devices/humidifiers.ts +++ b/src/devices/humidifiers.ts @@ -120,11 +120,11 @@ export class Humidifier { // create a new Temperature Sensor service // Temperature Sensor Service if (device.humidifier?.hide_temperature) { - this.platform.device('Removing Temerature Sensor Service'); + this.platform.device(`Humidifier: ${accessory.displayName} Removing Temperature Sensor Service`); this.temperatureservice = this.accessory.getService(this.platform.Service.TemperatureSensor); accessory.removeService(this.temperatureservice!); } else if (!this.temperatureservice) { - this.platform.device('Adding Temerature Sensor Service'); + this.platform.device(`Humidifier: ${accessory.displayName} Add Temperature Sensor Service`); (this.temperatureservice = this.accessory.getService(this.platform.Service.TemperatureSensor) || this.accessory.addService(this.platform.Service.TemperatureSensor)), `${accessory.displayName} Temperature Sensor`; @@ -144,7 +144,7 @@ export class Humidifier { }); } else { if (this.platform.config.options?.debug) { - this.platform.device('Temperature Sensor Not Added'); + this.platform.device(`Humidifier: ${accessory.displayName} Temperature Sensor Service Not Added`); } } @@ -499,11 +499,13 @@ export class Humidifier { this.platform.device(`Humidifier ${this.accessory.displayName}` + ` updateCharacteristic RelativeHumidityHumidifierThreshold: ${this.RelativeHumidityHumidifierThreshold}`); } - if (!this.device.humidifier?.hide_temperature || this.CurrentTemperature === undefined) { - this.platform.debug(`Humidifier ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`); - } else { - this.temperatureservice!.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature); - this.platform.device(`Humidifier ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`); + if (!this.device.humidifier?.hide_temperature) { + if (this.CurrentTemperature === undefined) { + this.platform.debug(`Humidifier ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`); + } else { + this.temperatureservice!.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature); + this.platform.device(`Humidifier ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`); + } } } diff --git a/src/devices/meters.ts b/src/devices/meters.ts index 4bed9d2e..6a2ce7ef 100644 --- a/src/devices/meters.ts +++ b/src/devices/meters.ts @@ -46,7 +46,7 @@ export class Meter { ) { // Meter Config this.platform.device(`[Meter Config] ble: ${device.ble}, unit: ${device.meter?.unit},` - + ` hide_temperature: ${device.meter?.hide_temperature}, hide_humidity: ${device.meter?.hide_humidity}`); + + ` hide_temperature: ${device.meter?.hide_temperature}, hide_humidity: ${device.meter?.hide_humidity}`); // default placeholders this.BatteryLevel = 0; @@ -102,11 +102,11 @@ export class Meter { // Temperature Sensor Service if (device.meter?.hide_temperature) { - this.platform.device('Removing Temperature Sensor Service'); + this.platform.device(`Meter: ${accessory.displayName} Removing Temperature Sensor Service`); this.temperatureservice = this.accessory.getService(this.platform.Service.TemperatureSensor); accessory.removeService(this.temperatureservice!); } else if (!this.temperatureservice) { - this.platform.device('Adding Temperature Sensor Service'); + this.platform.device(`Meter: ${accessory.displayName} Add Temperature Sensor Service`); (this.temperatureservice = this.accessory.getService(this.platform.Service.TemperatureSensor) || this.accessory.addService(this.platform.Service.TemperatureSensor)), `${accessory.displayName} Temperature Sensor`; @@ -126,16 +126,16 @@ export class Meter { return this.CurrentTemperature; }); } else { - this.platform.device('Temperature Sensor Not Added'); + this.platform.device(`Meter: ${accessory.displayName} Temperature Sensor Service Not Added`); } // Humidity Sensor Service if (device.meter?.hide_humidity) { - this.platform.device('Removing Humidity Sensor Service'); + this.platform.device(`Meter: ${accessory.displayName} Removing Humidity Sensor Service`); this.humidityservice = this.accessory.getService(this.platform.Service.HumiditySensor); accessory.removeService(this.humidityservice!); } else if (!this.humidityservice) { - this.platform.device('Adding Humidity Sensor Service'); + this.platform.device(`Meter: ${accessory.displayName} Add Humidity Sensor Service`); (this.humidityservice = this.accessory.getService(this.platform.Service.HumiditySensor) || this.accessory.addService(this.platform.Service.HumiditySensor)), `${accessory.displayName} Humidity Sensor`; @@ -151,7 +151,7 @@ export class Meter { return this.CurrentRelativeHumidity; }); } else { - this.platform.device('Adding Humidity Sensor Not Added'); + this.platform.device(`Meter: ${accessory.displayName} Humidity Sensor Service Not Added`); } // Retrieve initial values and updateHomekit @@ -273,8 +273,8 @@ export class Meter { this.battery = ad.serviceData.battery; this.platform.device(`${this.device.bleMac}: ${JSON.stringify(ad.serviceData)}`); this.platform.device(`${this.accessory.displayName}, Model: ${ad.serviceData.model}, Model Name: ${ad.serviceData.modelName},` - + `Temperature: ${ad.serviceData.temperature}, Fahrenheit: ${ad.serviceData.fahrenheit}, Humidity: ${ad.serviceData.humidity}` - + `Battery: ${ad.serviceData.battery}`); + + `Temperature: ${ad.serviceData.temperature}, Fahrenheit: ${ad.serviceData.fahrenheit}, Humidity: ${ad.serviceData.humidity}` + + `Battery: ${ad.serviceData.battery}`); }; // Wait 10 seconds return switchbot.wait(10000); @@ -319,17 +319,21 @@ export class Meter { this.service.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel); this.platform.device(`Meter ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`); } - if (this.device.meter?.hide_humidity && this.CurrentRelativeHumidity === undefined) { - this.platform.debug(`Meter ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`); - } else { - this.humidityservice?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity); - this.platform.device(`Meter ${this.accessory.displayName} updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`); + if (!this.device.meter?.hide_humidity) { + if (this.CurrentRelativeHumidity === undefined) { + this.platform.debug(`Meter ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`); + } else { + this.humidityservice?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity); + this.platform.device(`Meter ${this.accessory.displayName} updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`); + } } - if (this.device.meter?.hide_temperature || this.CurrentTemperature === undefined) { - this.platform.debug(`Meter ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`); - } else { - this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature); - this.platform.device(`Meter ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`); + if (!this.device.meter?.hide_temperature) { + if (this.CurrentTemperature === undefined) { + this.platform.debug(`Meter ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`); + } else { + this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature); + this.platform.device(`Meter ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`); + } } } diff --git a/src/irdevices/tvs.ts b/src/irdevices/tvs.ts index 990fb298..042e8061 100644 --- a/src/irdevices/tvs.ts +++ b/src/irdevices/tvs.ts @@ -201,10 +201,13 @@ export class TV { } else { this.pushTvOnChanges(); } - } - this.ActiveIdentifier = value; - if (this.ActiveIdentifier !== undefined) { - this.service.updateCharacteristic(this.platform.Characteristic.Active, this.ActiveIdentifier); + this.ActiveIdentifier = value; + if (this.ActiveIdentifier === undefined) { + this.platform.debug(`IR TV ${this.accessory.displayName} ActiveIdentifier: ${this.ActiveIdentifier}`); + } else { + this.service!.updateCharacteristic(this.platform.Characteristic.Active, this.ActiveIdentifier); + this.platform.device(`Humidifier ${this.accessory.displayName} updateCharacteristic Active: ${this.ActiveIdentifier}`); + } } } @@ -343,7 +346,7 @@ export class TV { } - private statusCode(push: AxiosResponse<{ statusCode: number;}>) { + private statusCode(push: AxiosResponse<{ statusCode: number; }>) { switch (push.data.statusCode) { case 151: this.platform.log.error('Command not supported by this device type.'); diff --git a/src/platform.ts b/src/platform.ts index 5a8da772..0b0bed02 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -869,7 +869,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { // the cached devices we stored in the `configureAccessory` method above const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid); - if (existingAccessory) { + if (!device.hide_device && existingAccessory) { this.log.info(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.: @@ -883,7 +883,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { // this is imported from `platformAccessory.ts` new TV(this, existingAccessory, device); this.debug(`${device.remoteType} uuid: ${device.deviceId}-${device.remoteType}, (${existingAccessory.UUID})`); - } else if (device.hubDeviceId) { + } else if (!device.hide_device && device.hubDeviceId) { // the accessory does not yet exist, so we need to create it this.log.info(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`); @@ -923,7 +923,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { if (existingAccessory) { // the accessory already exists - if (device.hubDeviceId) { + if (!device.hide_device && device.hubDeviceId) { this.log.info(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.: @@ -941,7 +941,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { } else { this.unregisterPlatformAccessories(existingAccessory); } - } else if (device.hubDeviceId) { + } else if (!device.hide_device && device.hubDeviceId) { // the accessory does not yet exist, so we need to create it this.log.info(`Adding new accessory: ${device.deviceName} ${device.remoteType} DeviceID: ${device.deviceId}`); diff --git a/src/settings.ts b/src/settings.ts index 23600392..c545bf70 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -44,6 +44,7 @@ export interface devicesConfig extends device { meter?: meter; humidifier?: humidifier; curtain?: curtain; + contact?: contact; colorbulb?: colorbulb; ble?: string; hide_device?: boolean; @@ -67,12 +68,18 @@ export type humidifier = { export type curtain = { disable_group?: boolean; + hide_lightsensor?: boolean; refreshRate?: number; set_max?: number; set_min?: number; set_minStep?: number; }; +export type contact = { + hide_lightsensor?: boolean; + hide_motionsensor?: boolean; +}; + export type colorbulb = { set_minStep?: number; };