From a54b7db51f4f75f75e19aa4dcc9e14c02060b795 Mon Sep 17 00:00:00 2001 From: Donavan Becker Date: Fri, 31 Dec 2021 16:19:15 -0600 Subject: [PATCH] v1.6.0 (#175) ## [Version 1.6.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.6.0) (2021-12-31) ## What's Changed * Added `scanDuration` config option to set how long BLE scans, Scanning Duration is defaulted to 1 second. * Now Setting `switch` as the default bot mode for Bots, to change to press, config must be set under `SwitchBot Device Settings` in the Plugin Settings. * Fixed Bug: Contact Sensor talks about Curtain Light + Motion Sensor. [#164](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/164) * Fixed Bug: Reboot causes No Device Type Set Error. [#172](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/172) * Fixed Bug: Bot Status not working Correction with Switch and Press. [#105](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/105), [#130](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/130), [#132](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/132), [#165](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/165), [#174](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/174) * Fixed some issues with the New Logging Options release with v1.5.0, now logging when configured. **Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.5.0...v1.6.0 --- CHANGELOG.md | 12 ++ config.schema.json | 22 ++- package-lock.json | 236 +++++++++++++++---------------- package.json | 12 +- src/devices/bots.ts | 145 ++++++++++++++----- src/devices/colorbulb.ts | 26 ++-- src/devices/contact.ts | 46 ++++-- src/devices/curtains.ts | 54 ++++--- src/devices/humidifiers.ts | 46 ++++-- src/devices/meters.ts | 44 ++++-- src/devices/motion.ts | 44 ++++-- src/devices/plugs.ts | 42 ++++-- src/irdevices/airconditioners.ts | 11 +- src/irdevices/airpurifiers.ts | 11 +- src/irdevices/cameras.ts | 11 +- src/irdevices/fans.ts | 11 +- src/irdevices/lights.ts | 11 +- src/irdevices/others.ts | 47 ++++-- src/irdevices/tvs.ts | 11 +- src/irdevices/vacuumcleaners.ts | 11 +- src/irdevices/waterheaters.ts | 11 +- src/platform.ts | 5 - src/settings.ts | 2 + 23 files changed, 580 insertions(+), 291 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdec0d45..e24b18a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/) +## [Version 1.6.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.6.0) (2021-12-31) + +## What's Changed +* Added `scanDuration` config option to set how long BLE scans, Scanning Duration is defaulted to 1 second. +* Now Setting `switch` as the default bot mode for Bots, to change to press, config must be set under `SwitchBot Device Settings` in the Plugin Settings. +* Fixed Bug: Contact Sensor talks about Curtain Light + Motion Sensor. [#164](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/164) +* Fixed Bug: Reboot causes No Device Type Set Error. [#172](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/172) +* Fixed Bug: Bot Status not working Correction with Switch and Press. [#105](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/105), [#130](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/130), [#132](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/132), [#165](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/165), [#174](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/174) +* Fixed some issues with the New Logging Options release with v1.5.0, now logging when configured. + +**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.5.0...v1.6.0 + ## [Version 1.5.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.5.0) (2021-12-27) ## What's Changed diff --git a/config.schema.json b/config.schema.json index 9fba30ba..566e5d98 100644 --- a/config.schema.json +++ b/config.schema.json @@ -140,6 +140,14 @@ "functionBody": "return (model.options && model.options.devices && model.options.devices[arrayIndices].deviceId && !model.options.devices[arrayIndices].hide_device);" } }, + "scanDuration": { + "title": "Scan Duration (Default is 1 Second)", + "type": "number", + "placeholder": 1, + "condition": { + "functionBody": "return (model.options && model.options.devices && model.options.devices[arrayIndices].deviceId && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].ble);" + } + }, "bot": { "type": "object", "properties": { @@ -185,6 +193,14 @@ "condition": { "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType === 'Bot' && model.options.devices[arrayIndices].deviceId && model.options.devices[arrayIndices].bot && model.options.devices[arrayIndices].bot.mode);" } + }, + "doublePress": { + "title": "Do you want to similate a double press?", + "type": "number", + "placeholder": "2", + "condition": { + "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType === 'Bot' && model.options.devices[arrayIndices].deviceId && model.options.devices[arrayIndices].bot && model.options.devices[arrayIndices].bot.mode);" + } } } }, @@ -303,14 +319,14 @@ "type": "object", "properties": { "hide_lightsensor": { - "title": "Hide Curtains's Light Sensor", + "title": "Hide Contact Sensor's Light Sensor", "type": "boolean", "condition": { "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType === 'Contact Sensor' && model.options.devices[arrayIndices].deviceId);" } }, "hide_motionsensor": { - "title": "Hide Curtains's Motion Sensor", + "title": "Hide Contact Sensor's Motion Sensor", "type": "boolean", "condition": { "functionBody": "return (model.options && model.options.devices && !model.options.devices[arrayIndices].hide_device && model.options.devices[arrayIndices].configDeviceType === 'Contact Sensor' && model.options.devices[arrayIndices].deviceId);" @@ -774,9 +790,11 @@ "options.devices[].hide_device", "options.devices[].offline", "options.devices[].ble", + "options.devices[].scanDuration", "options.devices[].configDeviceType", "options.devices[].bot.mode", "options.devices[].bot.deviceType", + "options.devices[].bot.doublePress", "options.devices[].meter.hide_temperature", "options.devices[].meter.hide_humidity", "options.devices[].humidifier.set_minStep", diff --git a/package-lock.json b/package-lock.json index f432e10a..745d8060 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@switchbot/homebridge-switchbot", - "version": "1.5.0", + "version": "1.6.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@switchbot/homebridge-switchbot", - "version": "1.5.0", + "version": "1.6.0", "funding": [ { "type": "Paypal", @@ -22,14 +22,14 @@ "@homebridge/plugin-ui-utils": "^0.0.19", "axios": "^0.24.0", "node-switchbot": "^1.1.2", - "rxjs": "^7.4.0" + "rxjs": "^7.5.1" }, "devDependencies": { "@types/node": "^17.0.5", - "@typescript-eslint/eslint-plugin": "^5.8.0", - "@typescript-eslint/parser": "^5.8.0", + "@typescript-eslint/eslint-plugin": "^5.8.1", + "@typescript-eslint/parser": "^5.8.1", "eslint": "^8.5.0", - "homebridge": "^1.3.8", + "homebridge": "^1.3.9", "nodemon": "^2.0.15", "npm-check-updates": "^12.0.5", "rimraf": "^3.0.2", @@ -38,7 +38,7 @@ "typescript-axios-wb": "^1.0.3" }, "engines": { - "homebridge": "^1.3.8", + "homebridge": "^1.3.9", "node": "^14.18.2 || ^16.13.1" } }, @@ -418,13 +418,13 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.8.0.tgz", - "integrity": "sha512-spu1UW7QuBn0nJ6+psnfCc3iVoQAifjKORgBngKOmC8U/1tbe2YJMzYQqDGYB4JCss7L8+RM2kKLb1B1Aw9BNA==", + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.8.1.tgz", + "integrity": "sha512-wTZ5oEKrKj/8/366qTM366zqhIKAp6NCMweoRONtfuC07OAU9nVI2GZZdqQ1qD30WAAtcPdkH+npDwtRFdp4Rw==", "dev": true, "dependencies": { - "@typescript-eslint/experimental-utils": "5.8.0", - "@typescript-eslint/scope-manager": "5.8.0", + "@typescript-eslint/experimental-utils": "5.8.1", + "@typescript-eslint/scope-manager": "5.8.1", "debug": "^4.3.2", "functional-red-black-tree": "^1.0.1", "ignore": "^5.1.8", @@ -450,15 +450,15 @@ } }, "node_modules/@typescript-eslint/experimental-utils": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-5.8.0.tgz", - "integrity": "sha512-KN5FvNH71bhZ8fKtL+lhW7bjm7cxs1nt+hrDZWIqb6ViCffQcWyLunGrgvISgkRojIDcXIsH+xlFfI4RCDA0xA==", + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-5.8.1.tgz", + "integrity": "sha512-fbodVnjIDU4JpeXWRDsG5IfIjYBxEvs8EBO8W1+YVdtrc2B9ppfof5sZhVEDOtgTfFHnYQJDI8+qdqLYO4ceww==", "dev": true, "dependencies": { "@types/json-schema": "^7.0.9", - "@typescript-eslint/scope-manager": "5.8.0", - "@typescript-eslint/types": "5.8.0", - "@typescript-eslint/typescript-estree": "5.8.0", + "@typescript-eslint/scope-manager": "5.8.1", + "@typescript-eslint/types": "5.8.1", + "@typescript-eslint/typescript-estree": "5.8.1", "eslint-scope": "^5.1.1", "eslint-utils": "^3.0.0" }, @@ -474,14 +474,14 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.8.0.tgz", - "integrity": "sha512-Gleacp/ZhRtJRYs5/T8KQR3pAQjQI89Dn/k+OzyCKOsLiZH2/Vh60cFBTnFsHNI6WAD+lNUo/xGZ4NeA5u0Ipw==", + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.8.1.tgz", + "integrity": "sha512-K1giKHAjHuyB421SoXMXFHHVI4NdNY603uKw92++D3qyxSeYvC10CBJ/GE5Thpo4WTUvu1mmJI2/FFkz38F2Gw==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "5.8.0", - "@typescript-eslint/types": "5.8.0", - "@typescript-eslint/typescript-estree": "5.8.0", + "@typescript-eslint/scope-manager": "5.8.1", + "@typescript-eslint/types": "5.8.1", + "@typescript-eslint/typescript-estree": "5.8.1", "debug": "^4.3.2" }, "engines": { @@ -501,13 +501,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.8.0.tgz", - "integrity": "sha512-x82CYJsLOjPCDuFFEbS6e7K1QEWj7u5Wk1alw8A+gnJiYwNnDJk0ib6PCegbaPMjrfBvFKa7SxE3EOnnIQz2Gg==", + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.8.1.tgz", + "integrity": "sha512-DGxJkNyYruFH3NIZc3PwrzwOQAg7vvgsHsHCILOLvUpupgkwDZdNq/cXU3BjF4LNrCsVg0qxEyWasys5AiJ85Q==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.8.0", - "@typescript-eslint/visitor-keys": "5.8.0" + "@typescript-eslint/types": "5.8.1", + "@typescript-eslint/visitor-keys": "5.8.1" }, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -518,9 +518,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.8.0.tgz", - "integrity": "sha512-LdCYOqeqZWqCMOmwFnum6YfW9F3nKuxJiR84CdIRN5nfHJ7gyvGpXWqL/AaW0k3Po0+wm93ARAsOdzlZDPCcXg==", + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.8.1.tgz", + "integrity": "sha512-L/FlWCCgnjKOLefdok90/pqInkomLnAcF9UAzNr+DSqMC3IffzumHTQTrINXhP1gVp9zlHiYYjvozVZDPleLcA==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -531,13 +531,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.8.0.tgz", - "integrity": "sha512-srfeZ3URdEcUsSLbkOFqS7WoxOqn8JNil2NSLO9O+I2/Uyc85+UlfpEvQHIpj5dVts7KKOZnftoJD/Fdv0L7nQ==", + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.8.1.tgz", + "integrity": "sha512-26lQ8l8tTbG7ri7xEcCFT9ijU5Fk+sx/KRRyyzCv7MQ+rZZlqiDPtMKWLC8P7o+dtCnby4c+OlxuX1tp8WfafQ==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.8.0", - "@typescript-eslint/visitor-keys": "5.8.0", + "@typescript-eslint/types": "5.8.1", + "@typescript-eslint/visitor-keys": "5.8.1", "debug": "^4.3.2", "globby": "^11.0.4", "is-glob": "^4.0.3", @@ -558,12 +558,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.8.0.tgz", - "integrity": "sha512-+HDIGOEMnqbxdAHegxvnOqESUH6RWFRR2b8qxP1W9CZnnYh4Usz6MBL+2KMAgPk/P0o9c1HqnYtwzVH6GTIqug==", + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.8.1.tgz", + "integrity": "sha512-SWgiWIwocK6NralrJarPZlWdr0hZnj5GXHIgfdm8hNkyKvpeQuFyLP6YjSIe9kf3YBIfU6OHSZLYkQ+smZwtNg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "5.8.0", + "@typescript-eslint/types": "5.8.1", "eslint-visitor-keys": "^3.0.0" }, "engines": { @@ -581,9 +581,9 @@ "devOptional": true }, "node_modules/acorn": { - "version": "8.6.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.6.0.tgz", - "integrity": "sha512-U1riIR+lBSNi3IbxtaHOIKdH8sLFv3NYfNv8sg7ZsNhcfl4HF2++BfqqrNAxoCLQW1iiylOj76ecnaUxz+z9yw==", + "version": "8.7.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.0.tgz", + "integrity": "sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ==", "dev": true, "bin": { "acorn": "bin/acorn" @@ -623,9 +623,9 @@ } }, "node_modules/agentkeepalive": { - "version": "4.1.4", - "resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.1.4.tgz", - "integrity": "sha512-+V/rGa3EuU74H6wR04plBb7Ks10FbtUQgRj/FQOG7uUIEuaINI+AiqJR1k6t3SVNs7o7ZjIdus6706qqzVq8jQ==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.2.0.tgz", + "integrity": "sha512-0PhAp58jZNw13UJv7NVdTGb0ZcghHUb3DrZ046JiiJY/BOaTTpbwdHq2VObPCBV8M2GPh7sgrJ3AQ8Ey468LJw==", "dev": true, "dependencies": { "debug": "^4.1.0", @@ -2161,9 +2161,9 @@ "dev": true }, "node_modules/hap-nodejs": { - "version": "0.9.7", - "resolved": "https://registry.npmjs.org/hap-nodejs/-/hap-nodejs-0.9.7.tgz", - "integrity": "sha512-DrXqNK+vrdjABKxKg0XNdgrycEHEwmSg81AMX8dmp86inex+rvx4qPd9fJRktt3Ed+u8I7ePDy26T4xGxdgc0g==", + "version": "0.9.8", + "resolved": "https://registry.npmjs.org/hap-nodejs/-/hap-nodejs-0.9.8.tgz", + "integrity": "sha512-+IENi8nFh/yOvVZEEIgY+nVppoXgY3mN8CfRh/I9tlhDbp3rXlsjdvHFVOgk7qJNa6cwzKu0KzNUs+n3XpO1Iw==", "dev": true, "dependencies": { "@homebridge/ciao": "~1.1.3", @@ -2254,15 +2254,15 @@ } }, "node_modules/homebridge": { - "version": "1.3.8", - "resolved": "https://registry.npmjs.org/homebridge/-/homebridge-1.3.8.tgz", - "integrity": "sha512-LGX5qbLAWRfNpifaO2EN5+h78d70BctXryDN9QXXlPOQQziGMrvo9rBLQmihTNtJQut+P2JnUg+cBgcR1HYmIQ==", + "version": "1.3.9", + "resolved": "https://registry.npmjs.org/homebridge/-/homebridge-1.3.9.tgz", + "integrity": "sha512-/QYosrEmxao6EekPMU3la3j3qx0UWLcYQN01qbZ7s1ZrKp8aC+aShgNx1borFrY/0fHsZauGcbuNqFh+XSKNXw==", "dev": true, "dependencies": { "chalk": "^4.1.2", "commander": "5.1.0", "fs-extra": "^10.0.0", - "hap-nodejs": "0.9.7", + "hap-nodejs": "0.9.8", "qrcode-terminal": "^0.12.0", "semver": "^7.3.5", "source-map-support": "^0.5.20" @@ -4346,18 +4346,13 @@ } }, "node_modules/rxjs": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.4.0.tgz", - "integrity": "sha512-7SQDi7xeTMCJpqViXh8gL/lebcwlp3d831F05+9B44A4B0WfsEwUQHR64gsH1kvJ+Ep/J9K2+n1hVl1CsGN23w==", + "version": "7.5.1", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.5.1.tgz", + "integrity": "sha512-KExVEeZWxMZnZhUZtsJcFwz8IvPvgu4G2Z2QyqjZQzUGr32KDYuSxrEYO4w3tFFNbfLozcrKUTvTPi+E9ywJkQ==", "dependencies": { - "tslib": "~2.1.0" + "tslib": "^2.1.0" } }, - "node_modules/rxjs/node_modules/tslib": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.1.0.tgz", - "integrity": "sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==" - }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -4791,8 +4786,7 @@ "node_modules/tslib": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", - "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==", - "dev": true + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" }, "node_modules/tsutils": { "version": "3.21.0", @@ -5509,13 +5503,13 @@ "dev": true }, "@typescript-eslint/eslint-plugin": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.8.0.tgz", - "integrity": "sha512-spu1UW7QuBn0nJ6+psnfCc3iVoQAifjKORgBngKOmC8U/1tbe2YJMzYQqDGYB4JCss7L8+RM2kKLb1B1Aw9BNA==", + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.8.1.tgz", + "integrity": "sha512-wTZ5oEKrKj/8/366qTM366zqhIKAp6NCMweoRONtfuC07OAU9nVI2GZZdqQ1qD30WAAtcPdkH+npDwtRFdp4Rw==", "dev": true, "requires": { - "@typescript-eslint/experimental-utils": "5.8.0", - "@typescript-eslint/scope-manager": "5.8.0", + "@typescript-eslint/experimental-utils": "5.8.1", + "@typescript-eslint/scope-manager": "5.8.1", "debug": "^4.3.2", "functional-red-black-tree": "^1.0.1", "ignore": "^5.1.8", @@ -5525,55 +5519,55 @@ } }, "@typescript-eslint/experimental-utils": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-5.8.0.tgz", - "integrity": "sha512-KN5FvNH71bhZ8fKtL+lhW7bjm7cxs1nt+hrDZWIqb6ViCffQcWyLunGrgvISgkRojIDcXIsH+xlFfI4RCDA0xA==", + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-5.8.1.tgz", + "integrity": "sha512-fbodVnjIDU4JpeXWRDsG5IfIjYBxEvs8EBO8W1+YVdtrc2B9ppfof5sZhVEDOtgTfFHnYQJDI8+qdqLYO4ceww==", "dev": true, "requires": { "@types/json-schema": "^7.0.9", - "@typescript-eslint/scope-manager": "5.8.0", - "@typescript-eslint/types": "5.8.0", - "@typescript-eslint/typescript-estree": "5.8.0", + "@typescript-eslint/scope-manager": "5.8.1", + "@typescript-eslint/types": "5.8.1", + "@typescript-eslint/typescript-estree": "5.8.1", "eslint-scope": "^5.1.1", "eslint-utils": "^3.0.0" } }, "@typescript-eslint/parser": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.8.0.tgz", - "integrity": "sha512-Gleacp/ZhRtJRYs5/T8KQR3pAQjQI89Dn/k+OzyCKOsLiZH2/Vh60cFBTnFsHNI6WAD+lNUo/xGZ4NeA5u0Ipw==", + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.8.1.tgz", + "integrity": "sha512-K1giKHAjHuyB421SoXMXFHHVI4NdNY603uKw92++D3qyxSeYvC10CBJ/GE5Thpo4WTUvu1mmJI2/FFkz38F2Gw==", "dev": true, "requires": { - "@typescript-eslint/scope-manager": "5.8.0", - "@typescript-eslint/types": "5.8.0", - "@typescript-eslint/typescript-estree": "5.8.0", + "@typescript-eslint/scope-manager": "5.8.1", + "@typescript-eslint/types": "5.8.1", + "@typescript-eslint/typescript-estree": "5.8.1", "debug": "^4.3.2" } }, "@typescript-eslint/scope-manager": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.8.0.tgz", - "integrity": "sha512-x82CYJsLOjPCDuFFEbS6e7K1QEWj7u5Wk1alw8A+gnJiYwNnDJk0ib6PCegbaPMjrfBvFKa7SxE3EOnnIQz2Gg==", + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.8.1.tgz", + "integrity": "sha512-DGxJkNyYruFH3NIZc3PwrzwOQAg7vvgsHsHCILOLvUpupgkwDZdNq/cXU3BjF4LNrCsVg0qxEyWasys5AiJ85Q==", "dev": true, "requires": { - "@typescript-eslint/types": "5.8.0", - "@typescript-eslint/visitor-keys": "5.8.0" + "@typescript-eslint/types": "5.8.1", + "@typescript-eslint/visitor-keys": "5.8.1" } }, "@typescript-eslint/types": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.8.0.tgz", - "integrity": "sha512-LdCYOqeqZWqCMOmwFnum6YfW9F3nKuxJiR84CdIRN5nfHJ7gyvGpXWqL/AaW0k3Po0+wm93ARAsOdzlZDPCcXg==", + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.8.1.tgz", + "integrity": "sha512-L/FlWCCgnjKOLefdok90/pqInkomLnAcF9UAzNr+DSqMC3IffzumHTQTrINXhP1gVp9zlHiYYjvozVZDPleLcA==", "dev": true }, "@typescript-eslint/typescript-estree": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.8.0.tgz", - "integrity": "sha512-srfeZ3URdEcUsSLbkOFqS7WoxOqn8JNil2NSLO9O+I2/Uyc85+UlfpEvQHIpj5dVts7KKOZnftoJD/Fdv0L7nQ==", + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.8.1.tgz", + "integrity": "sha512-26lQ8l8tTbG7ri7xEcCFT9ijU5Fk+sx/KRRyyzCv7MQ+rZZlqiDPtMKWLC8P7o+dtCnby4c+OlxuX1tp8WfafQ==", "dev": true, "requires": { - "@typescript-eslint/types": "5.8.0", - "@typescript-eslint/visitor-keys": "5.8.0", + "@typescript-eslint/types": "5.8.1", + "@typescript-eslint/visitor-keys": "5.8.1", "debug": "^4.3.2", "globby": "^11.0.4", "is-glob": "^4.0.3", @@ -5582,12 +5576,12 @@ } }, "@typescript-eslint/visitor-keys": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.8.0.tgz", - "integrity": "sha512-+HDIGOEMnqbxdAHegxvnOqESUH6RWFRR2b8qxP1W9CZnnYh4Usz6MBL+2KMAgPk/P0o9c1HqnYtwzVH6GTIqug==", + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.8.1.tgz", + "integrity": "sha512-SWgiWIwocK6NralrJarPZlWdr0hZnj5GXHIgfdm8hNkyKvpeQuFyLP6YjSIe9kf3YBIfU6OHSZLYkQ+smZwtNg==", "dev": true, "requires": { - "@typescript-eslint/types": "5.8.0", + "@typescript-eslint/types": "5.8.1", "eslint-visitor-keys": "^3.0.0" } }, @@ -5598,9 +5592,9 @@ "devOptional": true }, "acorn": { - "version": "8.6.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.6.0.tgz", - "integrity": "sha512-U1riIR+lBSNi3IbxtaHOIKdH8sLFv3NYfNv8sg7ZsNhcfl4HF2++BfqqrNAxoCLQW1iiylOj76ecnaUxz+z9yw==", + "version": "8.7.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.0.tgz", + "integrity": "sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ==", "dev": true }, "acorn-jsx": { @@ -5626,9 +5620,9 @@ } }, "agentkeepalive": { - "version": "4.1.4", - "resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.1.4.tgz", - "integrity": "sha512-+V/rGa3EuU74H6wR04plBb7Ks10FbtUQgRj/FQOG7uUIEuaINI+AiqJR1k6t3SVNs7o7ZjIdus6706qqzVq8jQ==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.2.0.tgz", + "integrity": "sha512-0PhAp58jZNw13UJv7NVdTGb0ZcghHUb3DrZ046JiiJY/BOaTTpbwdHq2VObPCBV8M2GPh7sgrJ3AQ8Ey468LJw==", "dev": true, "requires": { "debug": "^4.1.0", @@ -6808,9 +6802,9 @@ "dev": true }, "hap-nodejs": { - "version": "0.9.7", - "resolved": "https://registry.npmjs.org/hap-nodejs/-/hap-nodejs-0.9.7.tgz", - "integrity": "sha512-DrXqNK+vrdjABKxKg0XNdgrycEHEwmSg81AMX8dmp86inex+rvx4qPd9fJRktt3Ed+u8I7ePDy26T4xGxdgc0g==", + "version": "0.9.8", + "resolved": "https://registry.npmjs.org/hap-nodejs/-/hap-nodejs-0.9.8.tgz", + "integrity": "sha512-+IENi8nFh/yOvVZEEIgY+nVppoXgY3mN8CfRh/I9tlhDbp3rXlsjdvHFVOgk7qJNa6cwzKu0KzNUs+n3XpO1Iw==", "dev": true, "requires": { "@homebridge/ciao": "~1.1.3", @@ -6874,15 +6868,15 @@ "dev": true }, "homebridge": { - "version": "1.3.8", - "resolved": "https://registry.npmjs.org/homebridge/-/homebridge-1.3.8.tgz", - "integrity": "sha512-LGX5qbLAWRfNpifaO2EN5+h78d70BctXryDN9QXXlPOQQziGMrvo9rBLQmihTNtJQut+P2JnUg+cBgcR1HYmIQ==", + "version": "1.3.9", + "resolved": "https://registry.npmjs.org/homebridge/-/homebridge-1.3.9.tgz", + "integrity": "sha512-/QYosrEmxao6EekPMU3la3j3qx0UWLcYQN01qbZ7s1ZrKp8aC+aShgNx1borFrY/0fHsZauGcbuNqFh+XSKNXw==", "dev": true, "requires": { "chalk": "^4.1.2", "commander": "5.1.0", "fs-extra": "^10.0.0", - "hap-nodejs": "0.9.7", + "hap-nodejs": "0.9.8", "qrcode-terminal": "^0.12.0", "semver": "^7.3.5", "source-map-support": "^0.5.20" @@ -8433,18 +8427,11 @@ } }, "rxjs": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.4.0.tgz", - "integrity": "sha512-7SQDi7xeTMCJpqViXh8gL/lebcwlp3d831F05+9B44A4B0WfsEwUQHR64gsH1kvJ+Ep/J9K2+n1hVl1CsGN23w==", + "version": "7.5.1", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.5.1.tgz", + "integrity": "sha512-KExVEeZWxMZnZhUZtsJcFwz8IvPvgu4G2Z2QyqjZQzUGr32KDYuSxrEYO4w3tFFNbfLozcrKUTvTPi+E9ywJkQ==", "requires": { - "tslib": "~2.1.0" - }, - "dependencies": { - "tslib": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.1.0.tgz", - "integrity": "sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==" - } + "tslib": "^2.1.0" } }, "safe-buffer": { @@ -8762,8 +8749,7 @@ "tslib": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", - "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==", - "dev": true + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" }, "tsutils": { "version": "3.21.0", diff --git a/package.json b/package.json index f516651c..b37b50bb 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "displayName": "Homebridge SwitchBot", "name": "@switchbot/homebridge-switchbot", - "version": "1.5.0", + "version": "1.6.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", @@ -13,7 +13,7 @@ "url": "https://github.com/OpenWonderLabs/homebridge-switchbot/issues" }, "engines": { - "homebridge": "^1.3.8", + "homebridge": "^1.3.9", "node": "^14.18.2 || ^16.13.1" }, "main": "dist/index.js", @@ -54,14 +54,14 @@ "@homebridge/plugin-ui-utils": "^0.0.19", "axios": "^0.24.0", "node-switchbot": "^1.1.2", - "rxjs": "^7.4.0" + "rxjs": "^7.5.1" }, "devDependencies": { "@types/node": "^17.0.5", - "@typescript-eslint/eslint-plugin": "^5.8.0", - "@typescript-eslint/parser": "^5.8.0", + "@typescript-eslint/eslint-plugin": "^5.8.1", + "@typescript-eslint/parser": "^5.8.1", "eslint": "^8.5.0", - "homebridge": "^1.3.8", + "homebridge": "^1.3.9", "nodemon": "^2.0.15", "npm-check-updates": "^12.0.5", "rimraf": "^3.0.2", diff --git a/src/devices/bots.ts b/src/devices/bots.ts index 0c390b02..1f492e9f 100644 --- a/src/devices/bots.ts +++ b/src/devices/bots.ts @@ -36,9 +36,14 @@ export class Bot { battery!: serviceData['battery']; // Config + botMode!: string; + scanDuration!: number; deviceLogging!: string; deviceRefreshRate!: number; + // Others + doublePress!: number; + // Updates botUpdateInProgress!: boolean; doBotUpdate!: Subject; @@ -49,19 +54,29 @@ export class Bot { public device: device & devicesConfig, ) { // default placeholders + this.logs(); + this.scan(); + this.refreshRate(); + this.PressOrSwitch(); + if (this.On === undefined) { this.On = false; + this.accessory.context.On = this.On; } else { this.On = this.accessory.context.On; } - this.refreshRate(); - this.logs(); + if (device.bot?.doublePress) { + this.doublePress = device.bot?.doublePress; + this.accessory.context.doublePress = this.doublePress; + } else { + this.doublePress = 1; + } this.BatteryLevel = 100; - this.StatusLowBattery = 1; + this.StatusLowBattery = 0; // Bot Config this.debugLog(`Bot: ${this.accessory.displayName} Config: (ble: ${device.ble}, offline: ${device.offline}, mode: ${device.bot?.mode},` - + ` deviceType: ${device.bot?.deviceType})`); + + ` deviceType: ${device.bot?.deviceType}, doublePress: ${this.doublePress})`); // this is subject we use to track when we need to POST changes to the SwitchBot API this.doBotUpdate = new Subject(); @@ -151,7 +166,11 @@ export class Bot { ) .subscribe(async () => { try { - await this.pushChanges(); + interval(100) + .pipe(take(this.doublePress!)) + .subscribe(async () => { + await this.pushChanges(); + }); } catch (e: any) { this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges`); if (this.deviceLogging === 'debug') { @@ -170,33 +189,65 @@ export class Bot { refreshRate() { if (this.device.refreshRate) { this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate; - if (this.platform.debugMode) { - this.warnLog(`Using Device Config refreshRate: ${this.deviceRefreshRate}`); + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`); } } else if (this.platform.config.options!.refreshRate) { this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate; - if (this.platform.debugMode) { - this.warnLog(`Using Platform Config refreshRate: ${this.deviceRefreshRate}`); + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Bot: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`); } } } + scan() { + if (this.device.scanDuration) { + this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration; + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`); + } + } else { + this.scanDuration = this.accessory.context.scanDuration = 1; + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`); + } + } + } + + + logs() { - if (this.device.logging) { + if (this.platform.debugMode) { + this.deviceLogging = this.accessory.context.logging = 'debug'; + this.warnLog(`Bot: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`); + } else if (this.device.logging) { this.deviceLogging = this.accessory.context.logging = this.device.logging; - if (this.platform.debugMode) { - this.warnLog(`Using Device Config Logging: ${this.deviceLogging}`); + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`); } } else if (this.platform.config.options?.logging) { this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging; - if (this.platform.debugMode) { - this.warnLog(`Using Platform Config Logging: ${this.deviceLogging}`); + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Bot: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`); } } else { this.deviceLogging = this.accessory.context.logging = 'standard'; - if (this.platform.debugMode) { - this.warnLog('Using Device Standard Logging'); - } + } + } + + PressOrSwitch() { + if (!this.device.bot?.mode) { + this.botMode = 'switch'; + this.warnLog(`Bot: ${this.accessory.displayName} does not have bot mode set in the Plugin's SwitchBot Device Settings,`); + this.warnLog(`Bot: ${this.accessory.displayName} is defaulting to "${this.botMode}" mode, you may experience issues.`); + } else if (this.device.bot?.mode === 'switch') { + this.botMode = 'switch'; + this.infoLog(`Bot: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`); + } else if (this.device.bot?.mode === 'press') { + this.botMode = 'press'; + this.infoLog(`Bot: ${this.accessory.displayName} Using Bot Mode: ${this.botMode}`); + } else { + throw new Error(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`); } } @@ -215,10 +266,17 @@ export class Bot { this.debugLog(`Bot: ${this.accessory.displayName} BLE parseStatus`); // BLEmode (true if Switch Mode) | (false if Press Mode) if (this.mode) { - this.On = Boolean(this.state); - this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, mode: ${JSON.stringify(this.mode)}, On: ${JSON.stringify(this.On)}`); + this.OnCached = this.On; + this.accessory.context.On = this.OnCached; + if (this.On === undefined) { + this.On = Boolean(this.state); + } + this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, mode: ${this.mode}, On: ${this.On}`); } else { - this.debugLog(`Bot: ${this.accessory.displayName} Press Mode, mode: ${JSON.stringify(this.mode)}, On: ${JSON.stringify(this.On)}`); + this.On = false; + this.OnCached = this.On; + this.accessory.context.On = this.OnCached; + this.debugLog(`Bot: ${this.accessory.displayName} Press Mode, mode: ${this.mode}, On: ${this.On}`); } this.BatteryLevel = Number(this.battery); @@ -236,16 +294,22 @@ export class Bot { private async openAPIparseStatus() { if (this.platform.config.credentials?.openToken) { this.debugLog(`Bot: ${this.accessory.displayName} OpenAPI parseStatus`); - if (this.device.bot?.mode === 'press') { + if (this.botMode === 'press') { this.On = false; + this.OnCached = this.On; + this.accessory.context.On = this.OnCached; } else { if (this.deviceStatus.body.power === 'on') { this.On = true; + this.OnCached = this.On; + this.accessory.context.On = this.OnCached; } else { this.On = false; + this.OnCached = this.On; + this.accessory.context.On = this.OnCached; } } - this.debugLog(`Bot ${this.accessory.displayName} On: ${this.On}`); + this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}`); } } @@ -294,8 +358,8 @@ export class Bot { this.debugLog(`Bot: ${this.accessory.displayName} connected: ${this.connected}`); } }; - // Wait 10 seconds - return switchbot.wait(10000); + // Wait 2 seconds + return switchbot.wait(this.scanDuration * 1000); }).then(async () => { // Stop to monitor switchbot.stopScan(); @@ -375,14 +439,25 @@ export class Bot { if (this.On !== this.OnCached) { this.debugLog(`Bot: ${this.accessory.displayName} BLE pushChanges`); const switchbot = this.connectBLE(); - if (this.device.bot?.mode === 'press') { - this.debugLog(`Bot: ${this.accessory.displayName} Press Mode: ${this.device.bot?.mode}`); + if (this.botMode === 'press') { + this.debugLog(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`); switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac }) .then((device_list: { press: (arg0: { id: string | undefined; }) => any; }[]) => { - this.infoLog(`Bot: ${this.accessory.displayName}, On: ${this.On}`); + this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`); return device_list[0].press({ id: this.device.bleMac }); }).then(() => { this.debugLog(`Bot: ${this.accessory.displayName} Done.`); + this.On = false; + this.OnCached = this.On; + this.accessory.context.On = this.OnCached; + setTimeout(() => { + if (this.device.bot?.deviceType === 'switch') { + this.switchService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On); + } else { + this.outletService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On); + } + this.debugLog(`Bot: ${this.accessory.displayName} On: ${this.On}, Switch Timeout`); + }, 500); }).catch(async (e: any) => { this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`); if (this.deviceLogging === 'debug') { @@ -399,13 +474,15 @@ export class Bot { } this.apiError(e); }); - } else if (this.device.bot?.mode === 'switch') { - this.debugLog(`Bot: ${this.accessory.displayName} Press Mode: ${this.device.bot?.mode}`); + } else if (this.botMode === 'switch') { + this.debugLog(`Bot: ${this.accessory.displayName} Press Mode: ${this.botMode}`); switchbot.discover({ model: 'H', quick: true, id: this.device.bleMac }).then((device_list: any) => { this.infoLog(`Bot: ${this.accessory.displayName} On: ${this.On}`); return this.turnOnOff(device_list); }).then(() => { this.debugLog(`Bot: ${this.accessory.displayName} Done.`); + this.OnCached = this.On; + this.accessory.context.On = this.OnCached; }).catch(async (e: any) => { this.errorLog(`Bot: ${this.accessory.displayName} failed pushChanges with BLE Connection`); if (this.deviceLogging === 'debug') { @@ -423,7 +500,7 @@ export class Bot { this.apiError(e); }); } else { - this.errorLog(`Bot: ${this.accessory.displayName} Mode Not Set, mode: ${this.device.bot?.mode}`); + throw new Error(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`); } } this.OnCached = this.On; @@ -448,15 +525,15 @@ export class Bot { parameter: 'default', } as payload; - if (this.device.bot?.mode === 'switch' && this.On) { + if (this.botMode === 'switch' && this.On) { payload.command = 'turnOn'; this.On = true; this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`); - } else if (this.device.bot?.mode === 'switch' && !this.On) { + } else if (this.botMode === 'switch' && !this.On) { payload.command = 'turnOff'; this.On = false; this.debugLog(`Bot: ${this.accessory.displayName} Switch Mode, Turning ${this.On}`); - } else if (this.device.bot?.mode === 'press') { + } else if (this.botMode === 'press') { payload.command = 'press'; this.debugLog(`Bot: ${this.accessory.displayName} Press Mode`); this.On = false; @@ -469,7 +546,7 @@ export class Bot { // Make the API request const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload)); - this.debugLog(`Bot ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`); + this.debugLog(`Bot: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`); this.statusCode(push); this.OnCached = this.On; this.accessory.context.On = this.OnCached; diff --git a/src/devices/colorbulb.ts b/src/devices/colorbulb.ts index ca2b4edb..69bc58b3 100644 --- a/src/devices/colorbulb.ts +++ b/src/devices/colorbulb.ts @@ -53,8 +53,8 @@ export class ColorBulb { public device: device & devicesConfig, ) { // default placeholders - this.refreshRate(); this.logs(); + this.refreshRate(); if (this.On === undefined) { this.On = false; } else { @@ -200,33 +200,33 @@ export class ColorBulb { refreshRate() { if (this.device.refreshRate) { this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate; - if (this.platform.debugMode) { - this.warnLog(`Using Device Config refreshRate: ${this.deviceRefreshRate}`); + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`); } } else if (this.platform.config.options!.refreshRate) { this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate; - if (this.platform.debugMode) { - this.warnLog(`Using Platform Config refreshRate: ${this.deviceRefreshRate}`); + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`); } } } logs() { - if (this.device.logging) { + if (this.platform.debugMode) { + this.deviceLogging = this.accessory.context.logging = 'debug'; + this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`); + } else if (this.device.logging) { this.deviceLogging = this.accessory.context.logging = this.device.logging; - if (this.platform.debugMode) { - this.warnLog(`Using Device Config Logging: ${this.deviceLogging}`); + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`); } } else if (this.platform.config.options?.logging) { this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging; - if (this.platform.debugMode) { - this.warnLog(`Using Platform Config Logging: ${this.deviceLogging}`); + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`); } } else { this.deviceLogging = this.accessory.context.logging = 'standard'; - if (this.platform.debugMode) { - this.warnLog('Using Device Standard Logging'); - } } } diff --git a/src/devices/contact.ts b/src/devices/contact.ts index 094e7cbd..952d429f 100644 --- a/src/devices/contact.ts +++ b/src/devices/contact.ts @@ -37,6 +37,7 @@ export class Contact { lightLevel!: serviceData['lightLevel']; // Config + scanDuration!: number; deviceLogging!: string; deviceRefreshRate!: number; @@ -50,8 +51,9 @@ export class Contact { public device: device & devicesConfig, ) { // default placeholders - this.refreshRate(); this.logs(); + this.scan(); + this.refreshRate(); this.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED; // Contact Config @@ -146,33 +148,47 @@ export class Contact { refreshRate() { if (this.device.refreshRate) { this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate; - if (this.platform.debugMode) { - this.warnLog(`Using Device Config refreshRate: ${this.deviceRefreshRate}`); + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`); } } else if (this.platform.config.options!.refreshRate) { this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate; - if (this.platform.debugMode) { - this.warnLog(`Using Platform Config refreshRate: ${this.deviceRefreshRate}`); + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`); + } + } + } + + scan() { + if (this.device.scanDuration) { + this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration; + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`); + } + } else { + this.scanDuration = this.accessory.context.scanDuration = 1; + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`); } } } logs() { - if (this.device.logging) { + if (this.platform.debugMode) { + this.deviceLogging = this.accessory.context.logging = 'debug'; + this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`); + } else if (this.device.logging) { this.deviceLogging = this.accessory.context.logging = this.device.logging; - if (this.platform.debugMode) { - this.warnLog(`Using Device Config Logging: ${this.deviceLogging}`); + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`); } } else if (this.platform.config.options?.logging) { this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging; - if (this.platform.debugMode) { - this.warnLog(`Using Platform Config Logging: ${this.deviceLogging}`); + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Contact Sensor: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`); } } else { this.deviceLogging = this.accessory.context.logging = 'standard'; - if (this.platform.debugMode) { - this.warnLog('Using Device Standard Logging'); - } } } @@ -293,8 +309,8 @@ export class Contact { this.debugLog(`Contact Sensor: ${this.accessory.displayName} connected: ${this.connected}`); } }; - // Wait 10 seconds - return switchbot.wait(10000); + // Wait 2 seconds + return switchbot.wait(this.scanDuration * 1000); }).then(async () => { // Stop to monitor switchbot.stopScan(); diff --git a/src/devices/curtains.ts b/src/devices/curtains.ts index 6880971f..2e7b757a 100644 --- a/src/devices/curtains.ts +++ b/src/devices/curtains.ts @@ -4,7 +4,7 @@ import Switchbot from 'node-switchbot'; import { interval, Subject } from 'rxjs'; import { SwitchBotPlatform } from '../platform'; import { debounceTime, skipWhile, take, tap } from 'rxjs/operators'; -import { Service, PlatformAccessory, CharacteristicValue, HAPStatus } from 'homebridge'; +import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge'; import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse, payload } from '../settings'; export class Curtain { @@ -42,6 +42,7 @@ export class Curtain { curtainRefreshRate!: number; set_minLux!: number; set_maxLux!: number; + scanDuration!: number; deviceLogging!: string; deviceRefreshRate!: number; spaceBetweenLevels!: number; @@ -56,9 +57,10 @@ export class Curtain { public device: device & devicesConfig, ) { // default placeholders - this.refreshRate(); this.logs(); + this.scan(); this.setMinMax(); + this.refreshRate(); this.CurrentPosition = 0; this.TargetPosition = 0; this.PositionState = this.platform.Characteristic.PositionState.STOPPED; @@ -196,45 +198,59 @@ export class Curtain { // refreshRate if (this.device.refreshRate) { this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate; - if (this.platform.debugMode) { - this.warnLog(`Using Device Config refreshRate: ${this.deviceRefreshRate}`); + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Curtain: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`); } } else if (this.platform.config.options!.refreshRate) { this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate; - if (this.platform.debugMode) { - this.warnLog(`Using Platform Config refreshRate: ${this.deviceRefreshRate}`); + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Curtain: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`); } } // curtainRefreshRate if (this.device?.curtain?.refreshRate) { this.curtainRefreshRate = this.device?.curtain?.refreshRate; - if (this.platform.debugMode) { - this.warnLog(`Using Device Config Curtain refreshRate: ${this.deviceRefreshRate}`); + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Curtain: ${this.accessory.displayName} Using Device Config Curtain refreshRate: ${this.deviceRefreshRate}`); } } else { this.curtainRefreshRate = 5; - if (this.deviceLogging === 'debug') { + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { this.warnLog(`Curtain: ${this.accessory.displayName} Using Default Curtain Refresh Rate.`); } } } + scan() { + if (this.device.scanDuration) { + this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration; + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`); + } + } else { + this.scanDuration = this.accessory.context.scanDuration = 1; + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`); + } + } + } + logs() { - if (this.device.logging) { + if (this.platform.debugMode) { + this.deviceLogging = this.accessory.context.logging = 'debug'; + this.warnLog(`Curtain: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`); + } else if (this.device.logging) { this.deviceLogging = this.accessory.context.logging = this.device.logging; - if (this.platform.debugMode) { - this.warnLog(`Using Device Config Logging: ${this.deviceLogging}`); + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Curtain: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`); } } else if (this.platform.config.options?.logging) { this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging; - if (this.platform.debugMode) { - this.warnLog(`Using Platform Config Logging: ${this.deviceLogging}`); + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Curtain: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`); } } else { this.deviceLogging = this.accessory.context.logging = 'standard'; - if (this.platform.debugMode) { - this.warnLog('Using Device Standard Logging'); - } } } @@ -461,8 +477,8 @@ export class Curtain { this.debugLog(`Curtain: ${this.accessory.displayName} connected: ${this.connected}`); } }; - // Wait 10 seconds - return switchbot.wait(10000); + // Wait 2 seconds + return switchbot.wait(this.scanDuration * 1000); }).then(async () => { // Stop to monitor switchbot.stopScan(); diff --git a/src/devices/humidifiers.ts b/src/devices/humidifiers.ts index 09fed144..e337acda 100644 --- a/src/devices/humidifiers.ts +++ b/src/devices/humidifiers.ts @@ -37,6 +37,7 @@ export class Humidifier { // Config set_minStep?: number; + scanDuration!: number; deviceLogging!: string; deviceRefreshRate!: number; @@ -50,8 +51,9 @@ export class Humidifier { public device: device & devicesConfig, ) { // default placeholders - this.refreshRate(); this.logs(); + this.scan(); + this.refreshRate(); this.CurrentRelativeHumidity = 0; this.TargetHumidifierDehumidifierState = this.platform.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER; this.CurrentHumidifierDehumidifierState = this.platform.Characteristic.CurrentHumidifierDehumidifierState.INACTIVE; @@ -193,33 +195,47 @@ export class Humidifier { refreshRate() { if (this.device.refreshRate) { this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate; - if (this.platform.debugMode) { - this.warnLog(`Using Device Config refreshRate: ${this.deviceRefreshRate}`); + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Humidifier: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`); } } else if (this.platform.config.options!.refreshRate) { this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate; - if (this.platform.debugMode) { - this.warnLog(`Using Platform Config refreshRate: ${this.deviceRefreshRate}`); + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Humidifier: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`); + } + } + } + + scan() { + if (this.device.scanDuration) { + this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration; + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`); + } + } else { + this.scanDuration = this.accessory.context.scanDuration = 1; + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`); } } } logs() { - if (this.device.logging) { + if (this.platform.debugMode) { + this.deviceLogging = this.accessory.context.logging = 'debug'; + this.warnLog(`Humidifier: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`); + } else if (this.device.logging) { this.deviceLogging = this.accessory.context.logging = this.device.logging; - if (this.platform.debugMode) { - this.warnLog(`Using Device Config Logging: ${this.deviceLogging}`); + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Humidifier: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`); } } else if (this.platform.config.options?.logging) { this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging; - if (this.platform.debugMode) { - this.warnLog(`Using Platform Config Logging: ${this.deviceLogging}`); + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Humidifier: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`); } } else { this.deviceLogging = this.accessory.context.logging = 'standard'; - if (this.platform.debugMode) { - this.warnLog('Using Device Standard Logging'); - } } } @@ -358,8 +374,8 @@ export class Humidifier { this.debugLog(`Humidifier: ${this.accessory.displayName} connected: ${this.connected}`); } }; - // Wait 10 seconds - return switchbot.wait(10000); + // Wait 2 seconds + return switchbot.wait(this.scanDuration * 1000); }).then(async () => { // Stop to monitor switchbot.stopScan(); diff --git a/src/devices/meters.ts b/src/devices/meters.ts index 66ed79ff..c842e3d8 100644 --- a/src/devices/meters.ts +++ b/src/devices/meters.ts @@ -40,6 +40,7 @@ export class Meter { humidity!: serviceData['humidity']; // Config + scanDuration!: number; deviceLogging!: string; deviceRefreshRate!: number; @@ -53,8 +54,9 @@ export class Meter { public device: device & devicesConfig, ) { // default placeholders - this.refreshRate(); this.logs(); + this.scan(); + this.refreshRate(); if (this.BatteryLevel === undefined) { this.BatteryLevel = 100; } else { @@ -183,33 +185,47 @@ export class Meter { refreshRate() { if (this.device.refreshRate) { this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate; - if (this.platform.debugMode) { - this.warnLog(`Using Device Config refreshRate: ${this.deviceRefreshRate}`); + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Meter: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`); } } else if (this.platform.config.options!.refreshRate) { this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate; - if (this.platform.debugMode) { - this.warnLog(`Using Platform Config refreshRate: ${this.deviceRefreshRate}`); + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Meter: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`); + } + } + } + + scan() { + if (this.device.scanDuration) { + this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration; + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`); + } + } else { + this.scanDuration = this.accessory.context.scanDuration = 1; + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`); } } } logs() { - if (this.device.logging) { + if (this.platform.debugMode) { + this.deviceLogging = this.accessory.context.logging = 'debug'; + this.warnLog(`Meter: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`); + } else if (this.device.logging) { this.deviceLogging = this.accessory.context.logging = this.device.logging; - if (this.platform.debugMode) { - this.warnLog(`Using Device Config Logging: ${this.deviceLogging}`); + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Meter: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`); } } else if (this.platform.config.options?.logging) { this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging; - if (this.platform.debugMode) { - this.warnLog(`Using Platform Config Logging: ${this.deviceLogging}`); + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Meter: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`); } } else { this.deviceLogging = this.accessory.context.logging = 'standard'; - if (this.platform.debugMode) { - this.warnLog('Using Device Standard Logging'); - } } } @@ -324,7 +340,7 @@ export class Meter { } }; // Wait 10 seconds - return switchbot.wait(10000); + return switchbot.wait(this.scanDuration * 1000); }).then(async () => { // Stop to monitor switchbot.stopScan(); diff --git a/src/devices/motion.ts b/src/devices/motion.ts index 1c8bb1ba..da5a480e 100644 --- a/src/devices/motion.ts +++ b/src/devices/motion.ts @@ -34,6 +34,7 @@ export class Motion { lightLevel!: serviceData['lightLevel']; // Config + scanDuration!: number; deviceLogging!: string; deviceRefreshRate!: number; @@ -47,8 +48,9 @@ export class Motion { public device: device & devicesConfig, ) { // default placeholders - this.refreshRate(); this.logs(); + this.scan(); + this.refreshRate(); this.MotionDetected = false; // this is subject we use to track when we need to POST changes to the SwitchBot API @@ -114,33 +116,47 @@ export class Motion { refreshRate() { if (this.device.refreshRate) { this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate; - if (this.platform.debugMode) { - this.warnLog(`Using Device Config refreshRate: ${this.deviceRefreshRate}`); + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`); } } else if (this.platform.config.options!.refreshRate) { this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate; - if (this.platform.debugMode) { - this.warnLog(`Using Platform Config refreshRate: ${this.deviceRefreshRate}`); + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`); + } + } + } + + scan() { + if (this.device.scanDuration) { + this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration; + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`); + } + } else { + this.scanDuration = this.accessory.context.scanDuration = 1; + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`); } } } logs() { - if (this.device.logging) { + if (this.platform.debugMode) { + this.deviceLogging = this.accessory.context.logging = 'debug'; + this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`); + } else if (this.device.logging) { this.deviceLogging = this.accessory.context.logging = this.device.logging; - if (this.platform.debugMode) { - this.warnLog(`Using Device Config Logging: ${this.deviceLogging}`); + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`); } } else if (this.platform.config.options?.logging) { this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging; - if (this.platform.debugMode) { - this.warnLog(`Using Platform Config Logging: ${this.deviceLogging}`); + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Motion Sensor: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`); } } else { this.deviceLogging = this.accessory.context.logging = 'standard'; - if (this.platform.debugMode) { - this.warnLog('Using Device Standard Logging'); - } } } @@ -231,7 +247,7 @@ export class Motion { } }; // Wait 10 seconds - return switchbot.wait(10000); + return switchbot.wait(this.scanDuration * 1000); }).then(async () => { // Stop to monitor switchbot.stopScan(); diff --git a/src/devices/plugs.ts b/src/devices/plugs.ts index 4c266ed4..3bc069b1 100644 --- a/src/devices/plugs.ts +++ b/src/devices/plugs.ts @@ -18,6 +18,7 @@ export class Plug { deviceStatus!: deviceStatusResponse; // Config + scanDuration!: number; deviceLogging!: string; deviceRefreshRate!: number; @@ -31,8 +32,9 @@ export class Plug { public device: device & devicesConfig, ) { // default placeholders - this.refreshRate(); this.logs(); + this.scan(); + this.refreshRate(); if (this.On === undefined) { this.On = false; } else { @@ -117,33 +119,47 @@ export class Plug { refreshRate() { if (this.device.refreshRate) { this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate; - if (this.platform.debugMode) { - this.warnLog(`Using Device Config refreshRate: ${this.deviceRefreshRate}`); + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Plug: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`); } } else if (this.platform.config.options!.refreshRate) { this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate; - if (this.platform.debugMode) { - this.warnLog(`Using Platform Config refreshRate: ${this.deviceRefreshRate}`); + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Plug: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`); + } + } + } + + scan() { + if (this.device.scanDuration) { + this.scanDuration = this.accessory.context.scanDuration = this.device.scanDuration; + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`); + } + } else { + this.scanDuration = this.accessory.context.scanDuration = 1; + if (this.platform.debugMode || (this.deviceLogging === 'debug')) { + this.warnLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`); } } } logs() { - if (this.device.logging) { + if (this.platform.debugMode) { + this.deviceLogging = this.accessory.context.logging = 'debug'; + this.warnLog(`Plug: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`); + } else if (this.device.logging) { this.deviceLogging = this.accessory.context.logging = this.device.logging; - if (this.platform.debugMode) { - this.warnLog(`Using Device Config Logging: ${this.deviceLogging}`); + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Plug: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`); } } else if (this.platform.config.options?.logging) { this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging; - if (this.platform.debugMode) { - this.warnLog(`Using Platform Config Logging: ${this.deviceLogging}`); + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Plug: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`); } } else { this.deviceLogging = this.accessory.context.logging = 'standard'; - if (this.platform.debugMode) { - this.warnLog('Using Device Standard Logging'); - } } } diff --git a/src/irdevices/airconditioners.ts b/src/irdevices/airconditioners.ts index 81f0bb05..6ae700ca 100644 --- a/src/irdevices/airconditioners.ts +++ b/src/irdevices/airconditioners.ts @@ -167,10 +167,19 @@ export class AirConditioner { } logs() { - if (this.device.logging) { + if (this.platform.debugMode) { + this.deviceLogging = this.accessory.context.logging = 'debug'; + this.warnLog(`Air Conditioner: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`); + } else if (this.device.logging) { this.deviceLogging = this.accessory.context.logging = this.device.logging; + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Air Conditioner: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`); + } } else if (this.platform.config.options?.logging) { this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging; + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Air Conditioner: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`); + } } else { this.deviceLogging = this.accessory.context.logging = 'standard'; } diff --git a/src/irdevices/airpurifiers.ts b/src/irdevices/airpurifiers.ts index 55538971..a112d040 100644 --- a/src/irdevices/airpurifiers.ts +++ b/src/irdevices/airpurifiers.ts @@ -88,10 +88,19 @@ export class AirPurifier { } logs() { - if (this.device.logging) { + if (this.platform.debugMode) { + this.deviceLogging = this.accessory.context.logging = 'debug'; + this.warnLog(`Air Purifier: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`); + } else if (this.device.logging) { this.deviceLogging = this.accessory.context.logging = this.device.logging; + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Air Purifier: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`); + } } else if (this.platform.config.options?.logging) { this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging; + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Air Purifier: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`); + } } else { this.deviceLogging = this.accessory.context.logging = 'standard'; } diff --git a/src/irdevices/cameras.ts b/src/irdevices/cameras.ts index 04e4a6e4..4d3224a5 100644 --- a/src/irdevices/cameras.ts +++ b/src/irdevices/cameras.ts @@ -58,10 +58,19 @@ export class Camera { } logs() { - if (this.device.logging) { + if (this.platform.debugMode) { + this.deviceLogging = this.accessory.context.logging = 'debug'; + this.warnLog(`Camera: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`); + } else if (this.device.logging) { this.deviceLogging = this.accessory.context.logging = this.device.logging; + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Camera: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`); + } } else if (this.platform.config.options?.logging) { this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging; + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Camera: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`); + } } else { this.deviceLogging = this.accessory.context.logging = 'standard'; } diff --git a/src/irdevices/fans.ts b/src/irdevices/fans.ts index 9d9ad9bc..db24466c 100644 --- a/src/irdevices/fans.ts +++ b/src/irdevices/fans.ts @@ -117,10 +117,19 @@ export class Fan { } logs() { - if (this.device.logging) { + if (this.platform.debugMode) { + this.deviceLogging = this.accessory.context.logging = 'debug'; + this.warnLog(`Fan: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`); + } else if (this.device.logging) { this.deviceLogging = this.accessory.context.logging = this.device.logging; + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Fan: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`); + } } else if (this.platform.config.options?.logging) { this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging; + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Fan: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`); + } } else { this.deviceLogging = this.accessory.context.logging = 'standard'; } diff --git a/src/irdevices/lights.ts b/src/irdevices/lights.ts index 037afaf0..cae0c070 100644 --- a/src/irdevices/lights.ts +++ b/src/irdevices/lights.ts @@ -73,10 +73,19 @@ export class Light { } logs() { - if (this.device.logging) { + if (this.platform.debugMode) { + this.deviceLogging = this.accessory.context.logging = 'debug'; + this.warnLog(`Light: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`); + } else if (this.device.logging) { this.deviceLogging = this.accessory.context.logging = this.device.logging; + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Light: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`); + } } else if (this.platform.config.options?.logging) { this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging; + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Light: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`); + } } else { this.deviceLogging = this.accessory.context.logging = 'standard'; } diff --git a/src/irdevices/others.ts b/src/irdevices/others.ts index c1dc3d21..9ae83323 100644 --- a/src/irdevices/others.ts +++ b/src/irdevices/others.ts @@ -1,7 +1,7 @@ import { AxiosResponse } from 'axios'; import { SwitchBotPlatform } from '../platform'; import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings'; -import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge'; +import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'; /** * Platform Accessory @@ -18,6 +18,7 @@ export class Others { // Config deviceLogging!: string; + otherDeviceType?: string; constructor( private readonly platform: SwitchBotPlatform, @@ -26,6 +27,7 @@ export class Others { ) { // default placeholders this.logs(); + this.deviceType(); if (this.Active === undefined) { this.Active = this.platform.Characteristic.Active.INACTIVE; } else { @@ -41,24 +43,53 @@ export class Others { // get the Television service if it exists, otherwise create a new Television service // you can create multiple services for each accessory - this.service = accessory.getService(this.platform.Service.Fanv2); - if (!this.service && device?.other?.deviceType === 'Fan') { - this.service = accessory.addService(this.platform.Service.Fanv2, `${accessory.displayName} Fan`); + if (this.otherDeviceType !== 'Fan') { + this.debugLog(`Other: ${accessory.displayName} Removing Fanv2 Service`); - this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); + if (this.otherDeviceType === undefined) { + this.errorLog(`Other: ${this.accessory.displayName} No Device Type Set, deviceType: ${device.other?.deviceType}`); + } + this.service = this.accessory.getService(this.platform.Service.Fanv2); + accessory.removeService(this.service!); + } else if (!this.service && this.otherDeviceType === 'Fan') { + this.debugLog(`Other: ${accessory.displayName} Add Fanv2 Service`); + (this.service = + this.accessory.getService(this.platform.Service.Fanv2) || + this.accessory.addService(this.platform.Service.Fanv2)), `${accessory.displayName} Fan`; + + this.service.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Fan`); this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this)); } else { - accessory.removeService(this.service!); - this.errorLog(`Other: ${this.accessory.displayName} No Device Type Set, deviceType: ${device.other?.deviceType}`); + this.debugLog(`Other: ${accessory.displayName} Fanv2 Service Not Added, deviceType: ${device.other?.deviceType}`); + } + } + + deviceType() { + if (this.device?.other?.deviceType) { + this.otherDeviceType = this.accessory.context.deviceType = this.device?.other?.deviceType; + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Other: ${this.accessory.displayName} Using Device Type: ${this.otherDeviceType}`); + } + } else { + this.errorLog(`Other: ${this.accessory.displayName} No Device Type Set, deviceType: ${this.device.other?.deviceType}`); } } logs() { - if (this.device.logging) { + if (this.platform.debugMode) { + this.deviceLogging = this.accessory.context.logging = 'debug'; + this.warnLog(`Other: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`); + } else if (this.device.logging) { this.deviceLogging = this.accessory.context.logging = this.device.logging; + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Other: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`); + } } else if (this.platform.config.options?.logging) { this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging; + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Other: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`); + } } else { this.deviceLogging = this.accessory.context.logging = 'standard'; } diff --git a/src/irdevices/tvs.ts b/src/irdevices/tvs.ts index 9a513320..cb3641fd 100644 --- a/src/irdevices/tvs.ts +++ b/src/irdevices/tvs.ts @@ -129,10 +129,19 @@ export class TV { } logs() { - if (this.device.logging) { + if (this.platform.debugMode) { + this.deviceLogging = this.accessory.context.logging = 'debug'; + this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`); + } else if (this.device.logging) { this.deviceLogging = this.accessory.context.logging = this.device.logging; + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`); + } } else if (this.platform.config.options?.logging) { this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging; + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`); + } } else { this.deviceLogging = this.accessory.context.logging = 'standard'; } diff --git a/src/irdevices/vacuumcleaners.ts b/src/irdevices/vacuumcleaners.ts index 3d21e7bd..1173ae49 100644 --- a/src/irdevices/vacuumcleaners.ts +++ b/src/irdevices/vacuumcleaners.ts @@ -58,10 +58,19 @@ export class VacuumCleaner { } logs() { - if (this.device.logging) { + if (this.platform.debugMode) { + this.deviceLogging = this.accessory.context.logging = 'debug'; + this.warnLog(`Vacuum Cleaner: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`); + } else if (this.device.logging) { this.deviceLogging = this.accessory.context.logging = this.device.logging; + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Vacuum Cleaner: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`); + } } else if (this.platform.config.options?.logging) { this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging; + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Vacuum Cleaner: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`); + } } else { this.deviceLogging = this.accessory.context.logging = 'standard'; } diff --git a/src/irdevices/waterheaters.ts b/src/irdevices/waterheaters.ts index 2e681eef..90382ba5 100644 --- a/src/irdevices/waterheaters.ts +++ b/src/irdevices/waterheaters.ts @@ -67,10 +67,19 @@ export class WaterHeater { } logs() { - if (this.device.logging) { + if (this.platform.debugMode) { + this.deviceLogging = this.accessory.context.logging = 'debug'; + this.warnLog(`Water Heater: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`); + } else if (this.device.logging) { this.deviceLogging = this.accessory.context.logging = this.device.logging; + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Water Heater: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`); + } } else if (this.platform.config.options?.logging) { this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging; + if (this.deviceLogging === 'debug' || this.deviceLogging === 'standard') { + this.warnLog(`Water Heater: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`); + } } else { this.deviceLogging = this.accessory.context.logging = 'standard'; } diff --git a/src/platform.ts b/src/platform.ts index cf4af03f..2a9b4a26 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -144,11 +144,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { if (!deviceConfig.configDeviceType && deviceConfig.ble) { throw new Error('The devices config section is missing the *Device Type* in the config, Check Your Conifg.'); } - if (deviceConfig.bot) { - if (!deviceConfig.bot?.mode) { - this.errorLog('You must set your Bot to Press or Switch Mode'); - } - } } } } diff --git a/src/settings.ts b/src/settings.ts index bd31a7ea..8d9f7f72 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -50,6 +50,7 @@ export interface devicesConfig extends device { contact?: contact; colorbulb?: colorbulb; ble?: string; + scanDuration?: number; hide_device?: boolean; offline?: boolean; } @@ -62,6 +63,7 @@ export type meter = { export type bot = { mode?: string; deviceType?: string; + doublePress?: number; }; export type humidifier = {