From c7f9cc1b982cba42e895418a2e3372e9431a9366 Mon Sep 17 00:00:00 2001 From: Donavan Becker Date: Sat, 14 Oct 2023 22:08:10 -0500 Subject: [PATCH] v2.9.1 (#840) ## [Version 2.9.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.9.1) (2023-10-14) ## What's Changed - Fix issue with `FirmwareRevision` causing Homebridge Crash. Fixes [#839](https://github.com/OpenWonderLabs/homebridge-switchbot/discussions/839), [#832](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/832), [#829](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/829), & [#828](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/828) - Housekeeping and updated dependencies. **Full Changelog**: --- .eslintrc | 61 +++- .prettierrc | 9 - .vscode/settings.json | 8 +- CHANGELOG.md | 149 +++++----- SECURITY.md | 4 +- config.schema.json | 462 +++++++++++++++++++++++-------- nodemon.json | 6 +- package-lock.json | 412 +++++++++++++-------------- package.json | 27 +- src/device/blindtilt.ts | 76 +---- src/device/bot.ts | 159 ++++------- src/device/ceilinglight.ts | 78 ++---- src/device/colorbulb.ts | 69 +---- src/device/contact.ts | 89 ++---- src/device/curtain.ts | 83 ++---- src/device/hub.ts | 86 ++---- src/device/humidifier.ts | 80 ++---- src/device/iosensor.ts | 83 ++---- src/device/lightstrip.ts | 69 +---- src/device/lock.ts | 91 ++---- src/device/meter.ts | 87 ++---- src/device/meterplus.ts | 87 ++---- src/device/motion.ts | 75 +---- src/device/plug.ts | 58 +--- src/device/robotvacuumcleaner.ts | 83 ++---- src/irdevice/airconditioner.ts | 55 +--- src/irdevice/airpurifier.ts | 57 +--- src/irdevice/camera.ts | 57 +--- src/irdevice/fan.ts | 57 +--- src/irdevice/light.ts | 57 +--- src/irdevice/other.ts | 122 +++----- src/irdevice/tv.ts | 75 ++--- src/irdevice/vacuumcleaner.ts | 57 +--- src/irdevice/waterheater.ts | 57 +--- src/platform.ts | 210 ++++++++++---- tsconfig.json | 20 +- 36 files changed, 1277 insertions(+), 2038 deletions(-) delete mode 100644 .prettierrc diff --git a/.eslintrc b/.eslintrc index bff07489..78428c3e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,9 +9,15 @@ "ecmaVersion": 2021, "sourceType": "module" }, - "ignorePatterns": ["dist", "server"], + "ignorePatterns": [ + "dist", + "server" + ], "rules": { - "quotes": ["warn", "single"], + "quotes": [ + "warn", + "single" + ], "indent": [ "warn", 2, @@ -19,25 +25,52 @@ "SwitchCase": 1 } ], - "linebreak-style": ["warn", "unix"], - "semi": ["warn", "always"], - "comma-dangle": ["warn", "always-multiline"], + "linebreak-style": [ + "warn", + "unix" + ], + "semi": [ + "warn", + "always" + ], + "comma-dangle": [ + "warn", + "always-multiline" + ], "dot-notation": "off", "eqeqeq": "warn", - "curly": ["warn", "all"], - "brace-style": ["warn"], - "prefer-arrow-callback": ["warn"], - "max-len": ["warn", 150], - "no-console": ["warn"], // use the provided Homebridge log method instead - "no-non-null-assertion": ["off"], - "comma-spacing": ["error"], + "curly": [ + "warn", + "all" + ], + "brace-style": [ + "warn" + ], + "prefer-arrow-callback": [ + "warn" + ], + "max-len": [ + "warn", + 150 + ], + "no-console": [ + "warn" + ], // use the provided Homebridge log method instead + "no-non-null-assertion": [ + "off" + ], + "comma-spacing": [ + "error" + ], "no-multi-spaces": [ "warn", { "ignoreEOLComments": true } ], - "no-trailing-spaces": ["warn"], + "no-trailing-spaces": [ + "warn" + ], "lines-between-class-members": [ "warn", "always", @@ -50,4 +83,4 @@ "@typescript-eslint/explicit-module-boundary-types": "off", "@typescript-eslint/no-explicit-any": "off" } -} +} \ No newline at end of file diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index 39f15e5a..00000000 --- a/.prettierrc +++ /dev/null @@ -1,9 +0,0 @@ -{ - "semi": true, - "singleQuote": true, - "bracketSameLine": true, - "printWidth": 150, - "tabWidth": 2, - "trailingComma": "all", - "useTabs": false -} diff --git a/.vscode/settings.json b/.vscode/settings.json index cfce933b..ebbc997a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -22,6 +22,12 @@ } ], "[json]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" + "editor.defaultFormatter": "vscode.json-language-features" + }, + "[markdown]": { + "editor.defaultFormatter": "DavidAnson.vscode-markdownlint" + }, + "[jsonc]": { + "editor.defaultFormatter": "vscode.json-language-features" } } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index c1f73490..601bf477 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/) +## [Version 2.9.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.9.1) (2023-10-14) + +## What's Changed + +- Fix issue with `FirmwareRevision` causing Homebridge Crash. Fixes [#839](https://github.com/OpenWonderLabs/homebridge-switchbot/discussions/839), [#832](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/832), [#829](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/829), & [#828](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/828) +- Housekeeping and updated dependencies. + +**Full Changelog**: + ## [Version 2.9.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.9.0) (2023-09-16) ## What's Changed @@ -9,7 +18,7 @@ All notable changes to this project will be documented in this file. This projec - Add other `deviceTypes` for IR Type `Other`. - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.8.2....v2.9.0 +**Full Changelog**: ## [Version 2.8.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.8.2) (2023-08-27) @@ -19,7 +28,7 @@ All notable changes to this project will be documented in this file. This projec - Fixed config issue where Eve History was not showing for WoIOSensor. - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.8.1....v2.8.2 +**Full Changelog**: ## [Version 2.8.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.8.1) (2023-08-22) @@ -28,7 +37,7 @@ All notable changes to this project will be documented in this file. This projec - Added additional logging to catch statusCodes like 190 (Requests reached the daily limit). - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.8.0....v2.8.1 +**Full Changelog**: ## [Version 2.8.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.8.0) (2023-08-19) @@ -40,7 +49,7 @@ All notable changes to this project will be documented in this file. This projec - Enable Battery Level and Version for OpenAPI for BlindTilt, Bot, Ceiling Lights, Color Bulb, Contact, Curtain, Hub, Humidifier, Indoor/Outdoor Sensor, Light Strip, Lock, Meter, Meter Plus, Motion , Plug, Plug Mini, & Robot Vacuum Cleaner - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.7.1....v2.8.0 +**Full Changelog**: ## [Version 2.7.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.7.1) (2023-07-29) @@ -50,7 +59,7 @@ All notable changes to this project will be documented in this file. This projec - Fixed TargetTemperature not being updated in the HomeKit, Thanks [@mrlt8](https://github.com/mrlt8) [#7779](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/779) - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.7.0....v2.7.1 +**Full Changelog**: ## [Version 2.7.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.7.0) (2023-07-25) @@ -61,7 +70,7 @@ All notable changes to this project will be documented in this file. This projec - Adds the ability to enable EVE history SwitchBot Curtains, Thanks [@banboobee](https://github.com/banboobee) [#766](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/766) - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.6.2....v2.7.0 +**Full Changelog**: ## [Version 2.6.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.6.2) (2023-04-17) @@ -70,7 +79,7 @@ All notable changes to this project will be documented in this file. This projec - Fix for Commands not being sent, [#721](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/721) - Housekeeping. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.6.1....v2.6.2 +**Full Changelog**: ## [Version 2.6.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.6.1) (2023-04-15) @@ -78,7 +87,7 @@ All notable changes to this project will be documented in this file. This projec - Add Support for [SwitchBot Meter Plus (JP)](https://www.switchbot.jp/products/switchbot-meter-plus), Thanks [@tikuwas](https://github.com/tikuwas) [#642](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/642) -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.6.0....v2.6.1 +**Full Changelog**: ## [Version 2.6.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.6.0) (2023-04-15) @@ -87,7 +96,7 @@ All notable changes to this project will be documented in this file. This projec - Add Support for [SwitchBot Hub 2](https://us.switch-bot.com/pages/switchbot-hub-2) Humidity and Temperature Sensor, Thanks [@alvie](https://github.com/alvie). [#716](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/716) - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.5.3....v2.6.0 +**Full Changelog**: ## [Version 2.5.3](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.5.3) (2023-04-08) @@ -101,7 +110,7 @@ All notable changes to this project will be documented in this file. This projec - Housekeeping and updated dependencies. - This release will end support for Node v14. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.5.2....v2.5.3 +**Full Changelog**: ## [Version 2.5.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.5.2) (2023-02-10) @@ -112,10 +121,10 @@ All notable changes to this project will be documented in this file. This projec - Removes runStatus check, fixes some logic, Thanks [@AndreasVerhoeven](https://github.com/AndreasVerhoeven). [#672](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/672) - Remove unneeded async, Thanks [@dnicolson](https://github.com/dnicolson). [#675](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/675) - Replace switchbot wait with utility function, Thanks [@dnicolson](https://github.com/dnicolson). [#674](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/674) -- Remove incorrect warning message, Thanks [@dnicolson](https://github.com/dnicolson). [#673](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/673) +- Remove incorrect warning message, Thanks [@dnicolson](https://github.com/dnicolson). [#673](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/673) - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.5.1....v2.5.2 +**Full Changelog**: ## [Version 2.5.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.5.1) (2023-01-28) @@ -123,7 +132,7 @@ All notable changes to this project will be documented in this file. This projec - Fix Blind Tilt Config. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.5.0....v2.5.1 +**Full Changelog**: ## [Version 2.5.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.5.0) (2023-01-28) @@ -135,7 +144,7 @@ All notable changes to this project will be documented in this file. This projec - Enhancements to BLE functionality. - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.4.0....v2.5.0 +**Full Changelog**: ## [Version 2.4.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.4.0) (2022-12-27) @@ -148,7 +157,7 @@ All notable changes to this project will be documented in this file. This projec - **If you had this set for your `Bot` you will have to update this config.** - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.3.2....v2.4.0 +**Full Changelog**: ## [Version 2.3.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.3.2) (2022-12-16) @@ -156,7 +165,7 @@ All notable changes to this project will be documented in this file. This projec - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.3.1....v2.3.2 +**Full Changelog**: ## [Version 2.3.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.3.1) (2022-12-11) @@ -165,7 +174,7 @@ All notable changes to this project will be documented in this file. This projec - Fixed TypeError: Cannot read properties of undefined (reading 'setCharacteristic'). [#610](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/610) - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.3.0....v2.3.1 +**Full Changelog**: ## [Version 2.3.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.3.0) (2022-12-08) @@ -177,7 +186,7 @@ All notable changes to this project will be documented in this file. This projec - Fixed issue where Meter did not parsing temperature. [#571](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/571) - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.2.2....v2.3.0 +**Full Changelog**: ## [Version 2.2.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.2.2) (2022-10-22) @@ -190,7 +199,7 @@ All notable changes to this project will be documented in this file. This projec - Fix for node-switchbot showing not installed. - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.2.1....v2.2.2 +**Full Changelog**: ## [Version 2.2.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.2.1) (2022-10-18) @@ -198,7 +207,7 @@ All notable changes to this project will be documented in this file. This projec - Fix for node-switchbot showing not installed. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.2.0...v2.2.1 +**Full Changelog**: ## [Version 2.2.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.2.0) (2022-10-18) @@ -209,7 +218,7 @@ All notable changes to this project will be documented in this file. This projec - Fixed Issue where IR TVs would not default to External Device. [#520](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/518) - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.1.2...v2.2.0 +**Full Changelog**: ## [Version 2.1.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.1.2) (2022-10-14) @@ -218,7 +227,7 @@ All notable changes to this project will be documented in this file. This projec - Fix issue with IR Devices not having a default `ConnectionType`. [#527](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/527) - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.1.1...v2.1.2 +**Full Changelog**: ## [Version 2.1.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.1.1) (2022-10-14) @@ -230,7 +239,7 @@ All notable changes to this project will be documented in this file. This projec - Fix issue with IR Devices not having a default `ConnectionType`. [#527](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/527) - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.1.0...v2.1.1 +**Full Changelog**: ## [Version 2.1.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.1.0) (2022-10-13) @@ -246,7 +255,7 @@ All notable changes to this project will be documented in this file. This projec - Fixed issue were Plugin was waiting 15 seconds before sending command to SwitchBot API. [#509](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/509) - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.0.0...v2.1.0 +**Full Changelog**: ## [Version 2.0.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.0.0) (2022-10-12) @@ -262,10 +271,10 @@ All notable changes to this project will be documented in this file. This projec - `Disable` will disable all connections. This will also allow you to disable commands and refreshes for a specific device but leave it in HomeKit. - Added Support for Ceiling Light & Ceiling Light Pro - Fixes Smart Lock Issues fixed in v1.1 of OpenAPI. [#462](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/462) -= Fixes excesive logging from node-switchbot. [#435](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/435), [#444](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/444), [#446](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/446) += Fixes excesive logging from node-switchbot. [#435](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/435), [#444](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/444), [#446](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/446) - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.15.0...v2.0.0 +**Full Changelog**: ## [Version 1.15.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.15.0) (2022-08-27) @@ -274,7 +283,7 @@ All notable changes to this project will be documented in this file. This projec - Added BLE support for PlugMini (US) & PlugMini (JP) - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.14.2...v1.15.0 +**Full Changelog**: ## [Version 1.14.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.14.2) (2022-08-20) @@ -282,7 +291,7 @@ All notable changes to this project will be documented in this file. This projec - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.14.1...v1.14.2 +**Full Changelog**: ## [Version 1.14.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.14.1) (2022-06-28) @@ -291,7 +300,7 @@ All notable changes to this project will be documented in this file. This projec - Fixed some logging. - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.14.0...v1.14.1 +**Full Changelog**: ## [Version 1.14.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.14.0) (2022-06-25) @@ -300,7 +309,7 @@ All notable changes to this project will be documented in this file. This projec - Added support for Smart Lock commands over OpenAPI. Thanks [tom-todd](https://github.com/tom-todd) [#382](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/337) & [#387](https://github.com/OpenWonderLabs/homebridge-switchbot/pull/337) - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.13.0...v1.14.0 +**Full Changelog**: ## [Version 1.13.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.13.0) (2022-05-04) @@ -314,7 +323,7 @@ All notable changes to this project will be documented in this file. This projec - Still unable to control Locks because of API limitations. - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.12.8...v1.13.0 +**Full Changelog**: ## [Version 1.12.8](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.12.8) (2022-03-19) @@ -322,7 +331,7 @@ All notable changes to this project will be documented in this file. This projec - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.12.7...v1.12.8 +**Full Changelog**: ## [Version 1.12.7](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.12.7) (2022-03-07) @@ -334,7 +343,7 @@ All notable changes to this project will be documented in this file. This projec - Seperated Meter and Meter Plus for BLE purposes. - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.12.6...v1.12.7 +**Full Changelog**: ## [Version 1.12.6](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.12.6) (2022-03-04) @@ -343,7 +352,7 @@ All notable changes to this project will be documented in this file. This projec - Fix for Curtain v3.3 and above, from v1.2.0 node-switchbot update. - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.12.5...v1.12.6 +**Full Changelog**: ## [Version 1.12.5](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.12.5) (2022-02-15) @@ -351,7 +360,7 @@ All notable changes to this project will be documented in this file. This projec - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.12.4...v1.12.5 +**Full Changelog**: ## [Version 1.12.4](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.12.4) (2022-02-12) @@ -360,7 +369,7 @@ All notable changes to this project will be documented in this file. This projec - Fix support for Meter Plus - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.12.3...v1.12.4 +**Full Changelog**: ## [Version 1.12.3](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.12.3) (2022-02-05) @@ -368,7 +377,7 @@ All notable changes to this project will be documented in this file. This projec - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.12.2...v1.12.3 +**Full Changelog**: ## [Version 1.12.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.12.2) (2022-02-02) @@ -376,7 +385,7 @@ All notable changes to this project will be documented in this file. This projec - Fix: Issue where `PositionState` was not being sent back to Home App. Fixes [#123](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/123) Thanks [@dnicolson](https://github.com/dnicolson)! -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.12.1...v1.12.2 +**Full Changelog**: ## [Version 1.12.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.12.1) (2022-02-01) @@ -384,7 +393,7 @@ All notable changes to this project will be documented in this file. This projec - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.12.0...v1.12.1 +**Full Changelog**: ## [Version 1.12.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.12.0) (2022-01-29) @@ -392,7 +401,7 @@ All notable changes to this project will be documented in this file. This projec - Add option `maxRetry` for bots so you can set the number of retries for sending on or off for Bot. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.11.2...v1.12.0 +**Full Changelog**: ## [Version 1.11.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.11.2) (2022-01-29) @@ -400,7 +409,7 @@ All notable changes to this project will be documented in this file. This projec - Fix: Use `updateRate` instead of `refreshRate` when overriding `scanDuration`. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.11.1...v1.11.2 +**Full Changelog**: ## [Version 1.11.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.11.1) (2022-01-29) @@ -411,7 +420,7 @@ All notable changes to this project will be documented in this file. This projec - Fix: `This plugin generated a warning from the characteristic 'Hue': characteristic value expected valid finite number and received "undefined" (undefined)`. - Fix: `This plugin generated a warning from the characteristic 'Saturation': characteristic value expected valid finite number and received "undefined" (undefined)`. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.11.0...v1.11.1 +**Full Changelog**: ## [Version 1.11.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.11.0) (2022-01-29) @@ -426,7 +435,7 @@ All notable changes to this project will be documented in this file. This projec - Fixed: Curtain `set_min` and `set_max` options not work correctly with minimum and maximum curtain state. [#123](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/123) - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.10.1...v1.11.0 +**Full Changelog**: ## [Version 1.10.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.10.1) (2022-01-26) @@ -435,7 +444,7 @@ All notable changes to this project will be documented in this file. This projec - Fixed: Option `pushOn` was not push `On` commands. - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.10.0...v1.10.1 +**Full Changelog**: ## [Version 1.10.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.10.0) (2022-01-21) @@ -444,7 +453,7 @@ All notable changes to this project will be documented in this file. This projec - Add option `pushOn`, this will allow the `On` commands to be sent along side `Status` change commands. - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.9.0...v1.10.0 +**Full Changelog**: ## [Version 1.9.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.9.0) (2022-01-20) @@ -453,7 +462,7 @@ All notable changes to this project will be documented in this file. This projec - Add option `allowPush`, this will allow commands to be sent even if device state is already in state that is being pushed. - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.8.2...v1.9.0 +**Full Changelog**: ## [Version 1.8.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.8.2) (2022-01-15) @@ -461,7 +470,7 @@ All notable changes to this project will be documented in this file. This projec - Fixed Bug: Only log config if it is set. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.8.1...v1.8.2 +**Full Changelog**: ## [Version 1.8.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.8.1) (2022-01-15) @@ -469,7 +478,7 @@ All notable changes to this project will be documented in this file. This projec - Fixed Bug: Cannot set properties of undefined (setting 'logging') -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.8.0...v1.8.1 +**Full Changelog**: ## [Version 1.8.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.8.0) (2022-01-14) @@ -489,7 +498,7 @@ All notable changes to this project will be documented in this file. This projec - You will have to update your config for it to pickup the new `updateRate`. - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.7.0...v1.8.0 +**Full Changelog**: ## [Version 1.7.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.7.0) (2022-01-05) @@ -503,7 +512,7 @@ All notable changes to this project will be documented in this file. This projec - Added option to display Bot a WindowCovering. - Added option to display Bot a Garage Door Opener. [#179](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/179) -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.6.3...v1.7.0 +**Full Changelog**: ## [Version 1.6.3](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.6.3) (2022-01-03) @@ -511,7 +520,7 @@ All notable changes to this project will be documented in this file. This projec - Quick Fix for for issue not tested in `v1.6.2`. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.6.2...v1.6.3 +**Full Changelog**: ## [Version 1.6.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.6.2) (2022-01-03) @@ -522,7 +531,7 @@ All notable changes to this project will be documented in this file. This projec - So If `node-switchbot` doesn't get installed successfully then BLE will not work. - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.6.1...v1.6.2 +**Full Changelog**: ## [Version 1.6.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.6.1) (2022-01-02) @@ -535,7 +544,7 @@ All notable changes to this project will be documented in this file. This projec - So If `node-switchbot` doesn't get installed successfully then BLE will not work. - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.6.0...v1.6.1 +**Full Changelog**: ## [Version 1.6.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.6.0) (2021-12-31) @@ -548,13 +557,13 @@ All notable changes to this project will be documented in this file. This projec - 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 +**Full Changelog**: ## [Version 1.5.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.5.0) (2021-12-27) ## What's Changed -### Major Change To `Logging`: +### Major Change To `Logging` - Added the following Logging Options: - `Standard` @@ -563,7 +572,7 @@ All notable changes to this project will be documented in this file. This projec - Removed Device Logging Option, which was pushed into new logging under debug. - Added Device Logging Override for each Device, by using the Device Config. -### Major Changes to `refreshRate`: +### Major Changes to `refreshRate` - Added an option to override `refreshRate` for each Device, by using the Device Config. @@ -572,7 +581,7 @@ All notable changes to this project will be documented in this file. This projec - Fixed Bug: Air conditioner temperature not able to change. [#43](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/43) - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.4.0...v1.5.0 +**Full Changelog**: ## [Version 1.4.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.4.0) (2021-12-15) @@ -584,7 +593,7 @@ All notable changes to this project will be documented in this file. This projec - Removed Meter Unit Config Option as it was confusing and probably never used. - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.3.0...v1.4.0 +**Full Changelog**: ## [Version 1.3.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.3.0) (2021-12-02) @@ -594,7 +603,7 @@ All notable changes to this project will be documented in this file. This projec - Added Option `Adaptive Lighting Shift` to be able us this value to increase the mired for the Adaptive Lighting update, making the light appear warmer. - Fixed Bug: Color Bulb can't change color and is not dimmable. [#97](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/97) -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.2.5...v1.3.0 +**Full Changelog**: ## [Version 1.2.5](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.2.5) (2021-11-25) @@ -602,7 +611,7 @@ All notable changes to this project will be documented in this file. This projec - Fixed Bug: Where `set_minLux` & `set_maxLux` config settings not effecting OpenAPI Lux. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.2.4...v1.2.5 +**Full Changelog**: ## [Version 1.2.4](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.2.4) (2021-11-24) @@ -610,7 +619,7 @@ All notable changes to this project will be documented in this file. This projec - Fixed Bug: Cannot read properties of undefined (reading 'updateCharacteristic'). -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.2.3...v1.2.4 +**Full Changelog**: ## [Version 1.2.3](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.2.3) (2021-11-24) @@ -618,7 +627,7 @@ All notable changes to this project will be documented in this file. This projec - When BLE Connection isn't established, allow for OpenAPI to kick in if `openToken` is supplied. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.2.2...v1.2.3 +**Full Changelog**: ## [Version 1.2.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.2.2) (2021-11-24) @@ -627,7 +636,7 @@ All notable changes to this project will be documented in this file. This projec - Allow the `configDeviceName` to override `deviceName`. - Added Logging when BLE Connection wasn't established. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.2.1...v1.2.2 +**Full Changelog**: ## [Version 1.2.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.2.1) (2021-11-24) @@ -637,7 +646,7 @@ All notable changes to this project will be documented in this file. This projec - Fixed Bug: Meter not working with BLE. [#110](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/110) - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.2.0...v1.2.1 +**Full Changelog**: ## [Version 1.2.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.2.0) (2021-11-19) @@ -652,7 +661,7 @@ All notable changes to this project will be documented in this file. This projec - Add `Saturation` and `Hue` to Colorbulb. - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.1.0...v1.2.0 +**Full Changelog**: ## [Version 1.1.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.1.0) (2021-11-16) @@ -664,7 +673,7 @@ All notable changes to this project will be documented in this file. This projec - 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 +**Full Changelog**: ## [Version 1.0.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.0.2) (2021-11-15) @@ -673,7 +682,7 @@ All notable changes to this project will be documented in this file. This projec - Fixed Bug: `failed to discover devices. cannot read property 'touppercase' of undefined`. [#84](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/84) - Housekeeping and updated dependencies. -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.0.1...v1.0.2 +**Full Changelog**: ## [Version 1.0.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.0.1) (2021-11-14) @@ -682,7 +691,7 @@ All notable changes to this project will be documented in this file. This projec - Fixed `Cannot read properties of undefined (reading 'updateCharacteristic')` on Bots. [#77](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/77) - Fixed Temperature not being retrieved for Switchbot Meter. [#78](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/78) -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v1.0.0...v1.0.1 +**Full Changelog**: ## [Version 1.0.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.0.0) (2021-11-13) @@ -694,7 +703,7 @@ All notable changes to this project will be documented in this file. This projec - Adds Motion Sensor to Contact Sensors - Adds Support Color Bulbs -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v0.1.1...v1.0.0 +**Full Changelog**: ## [Version 0.1.1](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v0.1.1) (2021-09-11) @@ -702,7 +711,7 @@ All notable changes to this project will be documented in this file. This projec - Fix Contact Sensor adding as Motion Sensor instead of Contact Sensor -**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v0.1.0...v0.1.1 +**Full Changelog**: ## [Version 0.1.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v0.1.0) (2021-09-10) diff --git a/SECURITY.md b/SECURITY.md index 2959ba83..42053b73 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -7,8 +7,8 @@ currently being supported with security updates. | Version | Supported | | ------- | ------------------ | -| 1.9.x | :white_check_mark: | -| < 1.8.2 | :x: | +| 2.9.1 | :white_check_mark: | +| < 2.9.0 | :x: | ## Reporting a Vulnerability diff --git a/config.schema.json b/config.schema.json index 2fb8e257..7e483ea4 100644 --- a/config.schema.json +++ b/config.schema.json @@ -36,7 +36,11 @@ "default": "Keep your Token & Secret a secret!" } }, - "required": ["token", "secret", "notice"] + "required": [ + "token", + "secret", + "notice" + ] }, "options": { "type": "object", @@ -74,92 +78,135 @@ "oneOf": [ { "title": "Bot", - "enum": ["Bot"] + "enum": [ + "Bot" + ] }, { "title": "Curtain", - "enum": ["Curtain"] + "enum": [ + "Curtain" + ] }, { "title": "Blind Tilt", - "enum": ["Blind Tilt"] + "enum": [ + "Blind Tilt" + ] }, { "title": "Plug", - "enum": ["Plug"] + "enum": [ + "Plug" + ] }, { "title": "Meter", - "enum": ["Meter"] + "enum": [ + "Meter" + ] }, { "title": "Motion Sensor", - "enum": ["Motion Sensor"] + "enum": [ + "Motion Sensor" + ] }, - { "title": "Hub 2", - "enum": ["Hub 2"] + "enum": [ + "Hub 2" + ] }, { "title": "Contact Sensor", - "enum": ["Contact Sensor"] + "enum": [ + "Contact Sensor" + ] }, { "title": "Color Bulb", - "enum": ["Color Bulb"] + "enum": [ + "Color Bulb" + ] }, { "title": "Ceiling Light", - "enum": ["Ceiling Light"] + "enum": [ + "Ceiling Light" + ] }, { "title": "Ceiling Light Pro", - "enum": ["Ceiling Light Pro"] + "enum": [ + "Ceiling Light Pro" + ] }, { "title": "Humidifier", - "enum": ["Humidifier"] + "enum": [ + "Humidifier" + ] }, { "title": "Smart Fan", - "enum": ["Smart Fan"] + "enum": [ + "Smart Fan" + ] }, { "title": "Smart Lock", - "enum": ["Smart Lock"] + "enum": [ + "Smart Lock" + ] }, { "title": "Strip Light", - "enum": ["Strip Light"] + "enum": [ + "Strip Light" + ] }, { "title": "Meter Plus (US)", - "enum": ["MeterPlus"] + "enum": [ + "MeterPlus" + ] }, { "title": "Meter Plus (JP)", - "enum": ["Meter Plus (JP)"] + "enum": [ + "Meter Plus (JP)" + ] }, { "title": "Indoor/Outdoor Sensor", - "enum": ["WoIOSensor"] + "enum": [ + "WoIOSensor" + ] }, { "title": "Plug Mini (US)", - "enum": ["Plug Mini (US)"] + "enum": [ + "Plug Mini (US)" + ] }, { "title": "Plug Mini (JP)", - "enum": ["Plug Mini (JP)"] + "enum": [ + "Plug Mini (JP)" + ] }, { "title": "Robot Vacuum Cleaner S1", - "enum": ["Robot Vacuum Cleaner S1"] + "enum": [ + "Robot Vacuum Cleaner S1" + ] }, { "title": "Robot Vacuum Cleaner S1 Plus", - "enum": ["Robot Vacuum Cleaner S1 Plus"] + "enum": [ + "Robot Vacuum Cleaner S1 Plus" + ] } ], "condition": { @@ -172,19 +219,27 @@ "oneOf": [ { "title": "BLE/OpenAPI", - "enum": ["BLE/OpenAPI"] + "enum": [ + "BLE/OpenAPI" + ] }, { "title": "OpenAPI", - "enum": ["OpenAPI"] + "enum": [ + "OpenAPI" + ] }, { "title": "BLE", - "enum": ["BLE"] + "enum": [ + "BLE" + ] }, { "title": "Disable", - "enum": ["Disabled"] + "enum": [ + "Disabled" + ] } ], "description": "Bluetooth (BLE) API is only available for the following Device Types: Humidifier, Meter, MeterPlus, Curtain, Bot, Motion Sensor, Contact Sensor, Plug Mini (US), Plug Mini (JP), & Color Bulb", @@ -245,19 +300,27 @@ "oneOf": [ { "title": "Default", - "enum": [""] + "enum": [ + "" + ] }, { "title": "Press", - "enum": ["press"] + "enum": [ + "press" + ] }, { "title": "Switch", - "enum": ["switch"] + "enum": [ + "switch" + ] }, { "title": "Multi-Press", - "enum": ["multipress"] + "enum": [ + "multipress" + ] } ], "description": "Press Mode presses one time per 'On' state in the Home App/API. Switch Mode allows you to set how many presses occur when the device is set to 'On'. Multi-Press allows you to queue up multiple button presses. It creates a queue by counting each time the device is set to 'On'. It is most useful for scripting with cURL requests or other API calls. Multi-Press only works when using OpenAPI.", @@ -273,47 +336,69 @@ "oneOf": [ { "title": "Default", - "enum": [""] + "enum": [ + "" + ] }, { "title": "Outlet", - "enum": ["outlet"] + "enum": [ + "outlet" + ] }, { "title": "Garage Door", - "enum": ["garagedoor"] + "enum": [ + "garagedoor" + ] }, { "title": "Door", - "enum": ["door"] + "enum": [ + "door" + ] }, { "title": "Lock", - "enum": ["lock"] + "enum": [ + "lock" + ] }, { "title": "Faucet", - "enum": ["faucet"] + "enum": [ + "faucet" + ] }, { "title": "Fan", - "enum": ["fan"] + "enum": [ + "fan" + ] }, { "title": "Window", - "enum": ["window"] + "enum": [ + "window" + ] }, { "title": "Window Covering", - "enum": ["windowcovering"] + "enum": [ + "windowcovering" + ] }, { "title": "Stateful Programmable Switch (Only Works in 3rd Party Home Apps)", - "enum": ["stateful"] + "enum": [ + "stateful" + ] }, { "title": "Switch", - "enum": ["switch"] + "enum": [ + "switch" + ] } ], "placeholder": "outlet", @@ -440,11 +525,15 @@ "oneOf": [ { "title": "Performance Mode", - "enum": ["0"] + "enum": [ + "0" + ] }, { "title": "Silent Mode", - "enum": ["1"] + "enum": [ + "1" + ] } ], "condition": { @@ -457,11 +546,15 @@ "oneOf": [ { "title": "Performance Mode", - "enum": ["0"] + "enum": [ + "0" + ] }, { "title": "Silent Mode", - "enum": ["1"] + "enum": [ + "1" + ] } ], "condition": { @@ -502,23 +595,33 @@ "oneOf": [ { "title": "Middle to Up", - "enum": ["only_up"] + "enum": [ + "only_up" + ] }, { "title": "Middle to Down", - "enum": ["only_down"] + "enum": [ + "only_down" + ] }, { "title": "Down-to-Up", - "enum": ["down_and_up"] + "enum": [ + "down_and_up" + ] }, { "title": "Up-to-Down", - "enum": ["up_and_down"] + "enum": [ + "up_and_down" + ] }, { "title": "Tilt Direction", - "enum": ["use_tilt_for_direction"] + "enum": [ + "use_tilt_for_direction" + ] } ], "description": "Defines how the Home app sliders control the blind tilt.", @@ -774,19 +877,27 @@ "oneOf": [ { "title": "Default Logging", - "enum": [""] + "enum": [ + "" + ] }, { "title": "Standard Logging", - "enum": ["standard"] + "enum": [ + "standard" + ] }, { "title": "No Logging", - "enum": ["none"] + "enum": [ + "none" + ] }, { "title": "Debug Logging", - "enum": ["debug"] + "enum": [ + "debug" + ] } ], "condition": { @@ -794,7 +905,13 @@ } } }, - "required": ["deviceId", "configDeviceType", "configDeviceName", "connectionType", "logging"] + "required": [ + "deviceId", + "configDeviceType", + "configDeviceName", + "connectionType", + "logging" + ] }, "uniqueItems": true }, @@ -831,111 +948,165 @@ "oneOf": [ { "title": "Air Conditioner (IR)", - "enum": ["Air Conditioner"] + "enum": [ + "Air Conditioner" + ] }, { "title": "DIY Air Conditioner (IR)", - "enum": ["DIY Air Conditioner"] + "enum": [ + "DIY Air Conditioner" + ] }, { "title": "TV (IR)", - "enum": ["TV"] + "enum": [ + "TV" + ] }, { "title": "DIY TV (IR)", - "enum": ["DIY TV"] + "enum": [ + "DIY TV" + ] }, { "title": "Light (IR)", - "enum": ["Light"] + "enum": [ + "Light" + ] }, { "title": "DIY Light (IR)", - "enum": ["DIY Light"] + "enum": [ + "DIY Light" + ] }, { "title": "IPTV (IR)", - "enum": ["IPTV"] + "enum": [ + "IPTV" + ] }, { "title": "DIY IPTV (IR)", - "enum": ["DIY IPTV"] + "enum": [ + "DIY IPTV" + ] }, { "title": "Set Top Box (IR)", - "enum": ["Set Top Box"] + "enum": [ + "Set Top Box" + ] }, { "title": "DIY Set Top Box (IR)", - "enum": ["DIY Set Top Box"] + "enum": [ + "DIY Set Top Box" + ] }, { "title": "DVD (IR)", - "enum": ["DVD"] + "enum": [ + "DVD" + ] }, { "title": "DIY DVD (IR)", - "enum": ["DIY DVD"] + "enum": [ + "DIY DVD" + ] }, { "title": "Fan (IR)", - "enum": ["Fan"] + "enum": [ + "Fan" + ] }, { "title": "DIY Fan (IR)", - "enum": ["DIY Fan"] + "enum": [ + "DIY Fan" + ] }, { "title": "Projector (IR)", - "enum": ["Projector"] + "enum": [ + "Projector" + ] }, { "title": "DIY Projector (IR)", - "enum": ["DIY Projector"] + "enum": [ + "DIY Projector" + ] }, { "title": "Camera (IR)", - "enum": ["Camera"] + "enum": [ + "Camera" + ] }, { "title": "DIY Camera (IR)", - "enum": ["DIY Camera"] + "enum": [ + "DIY Camera" + ] }, { "title": "Air Purifier (IR)", - "enum": ["Air Purifier"] + "enum": [ + "Air Purifier" + ] }, { "title": "DIY Air Purifier (IR)", - "enum": ["DIY Air Purifier"] + "enum": [ + "DIY Air Purifier" + ] }, { "title": "Speaker (IR)", - "enum": ["Speaker"] + "enum": [ + "Speaker" + ] }, { "title": "DIY Speaker (IR)", - "enum": ["DIY Speaker"] + "enum": [ + "DIY Speaker" + ] }, { "title": "Water Heater (IR)", - "enum": ["Water Heater"] + "enum": [ + "Water Heater" + ] }, { "title": "DIY Water Heater (IR)", - "enum": ["DIY Water Heater"] + "enum": [ + "DIY Water Heater" + ] }, { "title": "Vacuum Cleaner (IR)", - "enum": ["Vacuum Cleaner"] + "enum": [ + "Vacuum Cleaner" + ] }, { "title": "DIY Vacuum Cleaner (IR)", - "enum": ["DIY Vacuum Cleaner"] + "enum": [ + "DIY Vacuum Cleaner" + ] }, { "title": "Others (IR)", - "enum": ["Others"] + "enum": [ + "Others" + ] } ], "condition": { @@ -948,11 +1119,15 @@ "oneOf": [ { "title": "OpenAPI", - "enum": ["OpenAPI"] + "enum": [ + "OpenAPI" + ] }, { "title": "Disable", - "enum": ["Disabled"] + "enum": [ + "Disabled" + ] } ], "description": "Enables OpenAPI, if disabled will leave device in HomeKit and commands will not be sent to OpenAPI.", @@ -1031,23 +1206,33 @@ "oneOf": [ { "title": "Meter", - "enum": ["Meter"] + "enum": [ + "Meter" + ] }, { "title": "MeterPlus", - "enum": ["MeterPlus"] + "enum": [ + "MeterPlus" + ] }, { "title": "Meter Plus (JP)", - "enum": ["Meter Plus (JP)"] + "enum": [ + "Meter Plus (JP)" + ] }, { "title": "Hub 2", - "enum": ["Hub 2"] + "enum": [ + "Hub 2" + ] }, { "title": "WoIOSensor", - "enum": ["WoIOSensor"] + "enum": [ + "WoIOSensor" + ] } ], "condition": { @@ -1117,47 +1302,69 @@ "oneOf": [ { "title": "Default", - "enum": [""] + "enum": [ + "" + ] }, { "title": "Outlet", - "enum": ["outlet"] + "enum": [ + "outlet" + ] }, { "title": "Garage Door", - "enum": ["garagedoor"] + "enum": [ + "garagedoor" + ] }, { "title": "Door", - "enum": ["door"] + "enum": [ + "door" + ] }, { "title": "Lock", - "enum": ["lock"] + "enum": [ + "lock" + ] }, { "title": "Faucet", - "enum": ["faucet"] + "enum": [ + "faucet" + ] }, { "title": "Fan", - "enum": ["fan"] + "enum": [ + "fan" + ] }, { "title": "Window", - "enum": ["window"] + "enum": [ + "window" + ] }, { "title": "Window Covering", - "enum": ["windowcovering"] + "enum": [ + "windowcovering" + ] }, { "title": "Stateful Programmable Switch (Only Works in 3rd Party Home Apps)", - "enum": ["stateful"] + "enum": [ + "stateful" + ] }, { "title": "Switch", - "enum": ["switch"] + "enum": [ + "switch" + ] } ], "condition": { @@ -1189,19 +1396,27 @@ "oneOf": [ { "title": "Default Logging", - "enum": [""] + "enum": [ + "" + ] }, { "title": "Standard Logging", - "enum": ["standard"] + "enum": [ + "standard" + ] }, { "title": "No Logging", - "enum": ["none"] + "enum": [ + "none" + ] }, { "title": "Debug Logging", - "enum": ["debug"] + "enum": [ + "debug" + ] } ], "condition": { @@ -1209,7 +1424,12 @@ } } }, - "required": ["deviceId", "configRemoteType", "connectionType", "logging"] + "required": [ + "deviceId", + "configRemoteType", + "connectionType", + "logging" + ] }, "uniqueItems": true }, @@ -1233,24 +1453,35 @@ "oneOf": [ { "title": "Default Logging", - "enum": [""] + "enum": [ + "" + ] }, { "title": "Standard Logging", - "enum": ["standard"] + "enum": [ + "standard" + ] }, { "title": "No Logging", - "enum": ["none"] + "enum": [ + "none" + ] }, { "title": "Debug Logging", - "enum": ["debug"] + "enum": [ + "debug" + ] } ] } }, - "required": ["name", "logging"] + "required": [ + "name", + "logging" + ] } } }, @@ -1260,7 +1491,10 @@ "title": "SwitchBot Account Info", "expandable": true, "expanded": false, - "items": ["credentials.token", "credentials.secret"] + "items": [ + "credentials.token", + "credentials.secret" + ] }, { "type": "fieldset", @@ -1407,4 +1641,4 @@ ] } ] -} +} \ No newline at end of file diff --git a/nodemon.json b/nodemon.json index b46d728d..db352cec 100644 --- a/nodemon.json +++ b/nodemon.json @@ -1,5 +1,7 @@ { - "watch": ["src"], + "watch": [ + "src" + ], "ext": "ts", "ignore": [], "exec": "DEBUG= tsc && homebridge -T -D -P -I -U ~/.homebridge-dev ..", @@ -7,4 +9,4 @@ "env": { "NODE_OPTIONS": "--trace-warnings" } -} +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 6884cec6..267cb34f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@switchbot/homebridge-switchbot", - "version": "2.9.0", + "version": "2.9.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@switchbot/homebridge-switchbot", - "version": "2.9.0", + "version": "2.9.1", "funding": [ { "type": "Paypal", @@ -21,31 +21,29 @@ "dependencies": { "@homebridge/plugin-ui-utils": "^0.1.0", "async-mqtt": "^2.6.3", - "crypto-js": "^4.1.1", "fakegato-history": "^0.6.4", - "homebridge-lib": "^6.5.0", + "homebridge-lib": "^6.6.1", "rxjs": "^7.8.1", - "undici": "^5.24.0" + "undici": "^5.26.3" }, "devDependencies": { - "@types/crypto-js": "^4.1.2", - "@types/node": "^20.6.2", - "@typescript-eslint/eslint-plugin": "^6.7.0", - "@typescript-eslint/parser": "^6.7.0", - "eslint": "^8.49.0", + "@types/node": "^20.8.6", + "@typescript-eslint/eslint-plugin": "^6.7.5", + "@typescript-eslint/parser": "^6.7.5", + "eslint": "^8.51.0", "eslint-config-prettier": "9.0.0", - "eslint-plugin-prettier": "5.0.0", + "eslint-plugin-prettier": "5.0.1", "homebridge": "^1.6.1", "nodemon": "^3.0.1", - "npm-check-updates": "^16.14.3", + "npm-check-updates": "^16.14.6", "prettier": "3.0.3", - "rimraf": "^5.0.1", + "rimraf": "^5.0.5", "ts-node": "^10.9.1", "typescript": "^5.2.2" }, "engines": { "homebridge": "^1.6.1", - "node": "^16.20.2 || ^18.17.1 || ^20.5.1" + "node": "^18.18.2 || ^20.8.1" }, "optionalDependencies": { "@abandonware/bluetooth-hci-socket": "^0.5.3-10", @@ -146,9 +144,9 @@ } }, "node_modules/@eslint-community/regexpp": { - "version": "4.8.1", - "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.8.1.tgz", - "integrity": "sha512-PWiOzLIUAjN/w5K17PoF4n6sKBw0gqLHPhywmYHP4t1VFQQVYeb1yWsJwnMVEMl3tUHME7X/SJPZLmtG7XBDxQ==", + "version": "4.9.1", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.9.1.tgz", + "integrity": "sha512-Y27x+MBLjXa+0JWDhykM3+JE+il3kHKAEqabfEWq3SDhZjLYb6/BHL/JKFnH3fe207JaXkyDo685Oc2Glt6ifA==", "dev": true, "engines": { "node": "^12.0.0 || ^14.0.0 || >=16.0.0" @@ -178,14 +176,22 @@ } }, "node_modules/@eslint/js": { - "version": "8.49.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.49.0.tgz", - "integrity": "sha512-1S8uAY/MTJqVx0SC4epBq+N2yhuwtNwLbJYNZyhL2pO1ZVKn5HFXav5T41Ryzy9K9V7ZId2JB2oy/W4aCd9/2w==", + "version": "8.51.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.51.0.tgz", + "integrity": "sha512-HxjQ8Qn+4SI3/AFv6sOrDB+g6PpUTDwSJiQqOrnneEk8L71161srI9gjzzZvYVbzHiVg/BvcH95+cK/zfIt4pg==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } }, + "node_modules/@fastify/busboy": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.0.0.tgz", + "integrity": "sha512-JUFJad5lv7jxj926GPgymrWQxxjPYuJNiNjNMzqT+HiuP6Vl3dk5xzG+8sTX96np0ZAluvaMzPsjhHZ5rNuNQQ==", + "engines": { + "node": ">=14" + } + }, "node_modules/@homebridge/ciao": { "version": "1.1.7", "resolved": "https://registry.npmjs.org/@homebridge/ciao/-/ciao-1.1.7.tgz", @@ -802,12 +808,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/@types/crypto-js": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/@types/crypto-js/-/crypto-js-4.1.2.tgz", - "integrity": "sha512-t33RNmTu5ufG/sorROIafiCVJMx3jz95bXUMoPAZcUD14fxMXnuTzqzXZoxpR0tNx2xpw11Dlmem9vGCsrSOfA==", - "dev": true - }, "node_modules/@types/http-cache-semantics": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.2.tgz", @@ -821,28 +821,31 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.6.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.6.2.tgz", - "integrity": "sha512-Y+/1vGBHV/cYk6OI1Na/LHzwnlNCAfU3ZNGrc1LdRe/LAIbdDPTTv/HU3M7yXN448aTVDq3eKRm2cg7iKLb8gw==", - "dev": true + "version": "20.8.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.6.tgz", + "integrity": "sha512-eWO4K2Ji70QzKUqRy6oyJWUeB7+g2cRagT3T/nxYibYcT4y2BDL8lqolRXjTHmkZCdJfIPaY73KbJAZmcryxTQ==", + "dev": true, + "dependencies": { + "undici-types": "~5.25.1" + } }, "node_modules/@types/semver": { - "version": "7.5.2", - "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.2.tgz", - "integrity": "sha512-7aqorHYgdNO4DM36stTiGO3DvKoex9TQRwsJU6vMaFGyqpBA1MNZkz+PG3gaNUPpTAOYhT1WR7M1JyA3fbS9Cw==", + "version": "7.5.3", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.3.tgz", + "integrity": "sha512-OxepLK9EuNEIPxWNME+C6WwbRAOOI2o2BaQEGzz5Lu2e4Z5eDnEo+/aVEDMIXywoJitJ7xWd641wrGLZdtwRyw==", "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "6.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.7.0.tgz", - "integrity": "sha512-gUqtknHm0TDs1LhY12K2NA3Rmlmp88jK9Tx8vGZMfHeNMLE3GH2e9TRub+y+SOjuYgtOmok+wt1AyDPZqxbNag==", + "version": "6.7.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.7.5.tgz", + "integrity": "sha512-JhtAwTRhOUcP96D0Y6KYnwig/MRQbOoLGXTON2+LlyB/N35SP9j1boai2zzwXb7ypKELXMx3DVk9UTaEq1vHEw==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.5.1", - "@typescript-eslint/scope-manager": "6.7.0", - "@typescript-eslint/type-utils": "6.7.0", - "@typescript-eslint/utils": "6.7.0", - "@typescript-eslint/visitor-keys": "6.7.0", + "@typescript-eslint/scope-manager": "6.7.5", + "@typescript-eslint/type-utils": "6.7.5", + "@typescript-eslint/utils": "6.7.5", + "@typescript-eslint/visitor-keys": "6.7.5", "debug": "^4.3.4", "graphemer": "^1.4.0", "ignore": "^5.2.4", @@ -868,15 +871,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "6.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.7.0.tgz", - "integrity": "sha512-jZKYwqNpNm5kzPVP5z1JXAuxjtl2uG+5NpaMocFPTNC2EdYIgbXIPImObOkhbONxtFTTdoZstLZefbaK+wXZng==", + "version": "6.7.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.7.5.tgz", + "integrity": "sha512-bIZVSGx2UME/lmhLcjdVc7ePBwn7CLqKarUBL4me1C5feOd663liTGjMBGVcGr+BhnSLeP4SgwdvNnnkbIdkCw==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "6.7.0", - "@typescript-eslint/types": "6.7.0", - "@typescript-eslint/typescript-estree": "6.7.0", - "@typescript-eslint/visitor-keys": "6.7.0", + "@typescript-eslint/scope-manager": "6.7.5", + "@typescript-eslint/types": "6.7.5", + "@typescript-eslint/typescript-estree": "6.7.5", + "@typescript-eslint/visitor-keys": "6.7.5", "debug": "^4.3.4" }, "engines": { @@ -896,13 +899,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "6.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.7.0.tgz", - "integrity": "sha512-lAT1Uau20lQyjoLUQ5FUMSX/dS07qux9rYd5FGzKz/Kf8W8ccuvMyldb8hadHdK/qOI7aikvQWqulnEq2nCEYA==", + "version": "6.7.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.7.5.tgz", + "integrity": "sha512-GAlk3eQIwWOJeb9F7MKQ6Jbah/vx1zETSDw8likab/eFcqkjSD7BI75SDAeC5N2L0MmConMoPvTsmkrg71+B1A==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.7.0", - "@typescript-eslint/visitor-keys": "6.7.0" + "@typescript-eslint/types": "6.7.5", + "@typescript-eslint/visitor-keys": "6.7.5" }, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -913,13 +916,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "6.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.7.0.tgz", - "integrity": "sha512-f/QabJgDAlpSz3qduCyQT0Fw7hHpmhOzY/Rv6zO3yO+HVIdPfIWhrQoAyG+uZVtWAIS85zAyzgAFfyEr+MgBpg==", + "version": "6.7.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.7.5.tgz", + "integrity": "sha512-Gs0qos5wqxnQrvpYv+pf3XfcRXW6jiAn9zE/K+DlmYf6FcpxeNYN0AIETaPR7rHO4K2UY+D0CIbDP9Ut0U4m1g==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "6.7.0", - "@typescript-eslint/utils": "6.7.0", + "@typescript-eslint/typescript-estree": "6.7.5", + "@typescript-eslint/utils": "6.7.5", "debug": "^4.3.4", "ts-api-utils": "^1.0.1" }, @@ -940,9 +943,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "6.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.7.0.tgz", - "integrity": "sha512-ihPfvOp7pOcN/ysoj0RpBPOx3HQTJTrIN8UZK+WFd3/iDeFHHqeyYxa4hQk4rMhsz9H9mXpR61IzwlBVGXtl9Q==", + "version": "6.7.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.7.5.tgz", + "integrity": "sha512-WboQBlOXtdj1tDFPyIthpKrUb+kZf2VroLZhxKa/VlwLlLyqv/PwUNgL30BlTVZV1Wu4Asu2mMYPqarSO4L5ZQ==", "dev": true, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -953,13 +956,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "6.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.7.0.tgz", - "integrity": "sha512-dPvkXj3n6e9yd/0LfojNU8VMUGHWiLuBZvbM6V6QYD+2qxqInE7J+J/ieY2iGwR9ivf/R/haWGkIj04WVUeiSQ==", + "version": "6.7.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.7.5.tgz", + "integrity": "sha512-NhJiJ4KdtwBIxrKl0BqG1Ur+uw7FiOnOThcYx9DpOGJ/Abc9z2xNzLeirCG02Ig3vkvrc2qFLmYSSsaITbKjlg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.7.0", - "@typescript-eslint/visitor-keys": "6.7.0", + "@typescript-eslint/types": "6.7.5", + "@typescript-eslint/visitor-keys": "6.7.5", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -980,17 +983,17 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "6.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.7.0.tgz", - "integrity": "sha512-MfCq3cM0vh2slSikQYqK2Gq52gvOhe57vD2RM3V4gQRZYX4rDPnKLu5p6cm89+LJiGlwEXU8hkYxhqqEC/V3qA==", + "version": "6.7.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.7.5.tgz", + "integrity": "sha512-pfRRrH20thJbzPPlPc4j0UNGvH1PjPlhlCMq4Yx7EGjV7lvEeGX0U6MJYe8+SyFutWgSHsdbJ3BXzZccYggezA==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", "@types/json-schema": "^7.0.12", "@types/semver": "^7.5.0", - "@typescript-eslint/scope-manager": "6.7.0", - "@typescript-eslint/types": "6.7.0", - "@typescript-eslint/typescript-estree": "6.7.0", + "@typescript-eslint/scope-manager": "6.7.5", + "@typescript-eslint/types": "6.7.5", + "@typescript-eslint/typescript-estree": "6.7.5", "semver": "^7.5.4" }, "engines": { @@ -1005,12 +1008,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "6.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.7.0.tgz", - "integrity": "sha512-/C1RVgKFDmGMcVGeD8HjKv2bd72oI1KxQDeY8uc66gw9R0OK0eMq48cA+jv9/2Ag6cdrsUGySm1yzYmfz0hxwQ==", + "version": "6.7.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.7.5.tgz", + "integrity": "sha512-3MaWdDZtLlsexZzDSdQWsFQ9l9nL8B80Z4fImSpyllFC/KLqWQRdEcB+gGGO+N3Q2uL40EsG66wZLsohPxNXvg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.7.0", + "@typescript-eslint/types": "6.7.5", "eslint-visitor-keys": "^3.4.1" }, "engines": { @@ -1489,17 +1492,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/busboy": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", - "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", - "dependencies": { - "streamsearch": "^1.1.0" - }, - "engines": { - "node": ">=10.16.0" - } - }, "node_modules/cacache": { "version": "17.1.4", "resolved": "https://registry.npmjs.org/cacache/-/cacache-17.1.4.tgz", @@ -1533,19 +1525,19 @@ } }, "node_modules/cacache/node_modules/glob": { - "version": "10.3.4", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.4.tgz", - "integrity": "sha512-6LFElP3A+i/Q8XQKEvZjkEWEOTgAIALR9AO2rwT8bgPhDd1anmqDJDZ6lLddI4ehxxxR1S5RIqKe1uapMQfYaQ==", + "version": "10.3.10", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.10.tgz", + "integrity": "sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==", "dev": true, "dependencies": { "foreground-child": "^3.1.0", - "jackspeak": "^2.0.3", + "jackspeak": "^2.3.5", "minimatch": "^9.0.1", "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0", "path-scurry": "^1.10.1" }, "bin": { - "glob": "dist/cjs/src/bin.js" + "glob": "dist/esm/bin.mjs" }, "engines": { "node": ">=16 || 14 >=14.17" @@ -1579,9 +1571,9 @@ } }, "node_modules/cacache/node_modules/minipass": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.0.3.tgz", - "integrity": "sha512-LhbbwCfz3vsb12j/WkWQPZfKTsgqIe1Nf/ti1pKjYESGLHIVjWU96G9/ljLH4F9mWNVhlQOm0VySdAWzf05dpg==", + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.0.4.tgz", + "integrity": "sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==", "dev": true, "engines": { "node": ">=16 || 14 >=14.17" @@ -1597,12 +1589,12 @@ } }, "node_modules/cacheable-request": { - "version": "10.2.13", - "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-10.2.13.tgz", - "integrity": "sha512-3SD4rrMu1msNGEtNSt8Od6enwdo//U9s4ykmXfA2TD58kcLkCobtCDiby7kNyj7a/Q7lz/mAesAFI54rTdnvBA==", + "version": "10.2.14", + "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-10.2.14.tgz", + "integrity": "sha512-zkDT5WAF4hSSoUgyfg5tFIxz8XQK+25W/TLVojJTMKBaxevLBBtLxgqguAuVQB8PVW79FVjHcU+GJ9tVbDZ9mQ==", "dev": true, "dependencies": { - "@types/http-cache-semantics": "^4.0.1", + "@types/http-cache-semantics": "^4.0.2", "get-stream": "^6.0.1", "http-cache-semantics": "^4.1.1", "keyv": "^4.5.3", @@ -1711,9 +1703,9 @@ } }, "node_modules/ci-info": { - "version": "3.8.0", - "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.8.0.tgz", - "integrity": "sha512-eXTggHWSooYhq49F2opQhuHWgzucfF2YgODK4e1566GQs5BIfP30B0oenwBJHfWxAs2fyPB1s7Mg949zLf61Yw==", + "version": "3.9.0", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.9.0.tgz", + "integrity": "sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ==", "dev": true, "funding": [ { @@ -1884,11 +1876,6 @@ "node": ">= 8" } }, - "node_modules/crypto-js": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.1.1.tgz", - "integrity": "sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==" - }, "node_modules/crypto-random-string": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-4.0.0.tgz", @@ -2046,9 +2033,9 @@ } }, "node_modules/define-data-property": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.0.tgz", - "integrity": "sha512-UzGwzcjyv3OtAvolTj1GoyNYzfFR+iqbGjcnBEENZVCpM4/Ng1yhGNvS3lR/xDS74Tb2wGG9WzNSNIOS9UVb2g==", + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.1.tgz", + "integrity": "sha512-E7uGkTzkk1d0ByLeSc6ZsFS79Axg+m1P/VsgYsxHgiuc3tFSj+MjMIwe90FC4lOAZzNBdY7kkO2P2wKdsQ1vgQ==", "dependencies": { "get-intrinsic": "^1.2.1", "gopd": "^1.0.1", @@ -2273,15 +2260,15 @@ } }, "node_modules/eslint": { - "version": "8.49.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.49.0.tgz", - "integrity": "sha512-jw03ENfm6VJI0jA9U+8H5zfl5b+FvuU3YYvZRdZHOlU2ggJkxrlkJH4HcDrZpj6YwD8kuYqvQM8LyesoazrSOQ==", + "version": "8.51.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.51.0.tgz", + "integrity": "sha512-2WuxRZBrlwnXi+/vFSJyjMqrNjtJqiasMzehF0shoLaW7DzS3/9Yvrmq5JiT66+pNjiX4UBnLDiKHcWAr/OInA==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", "@eslint/eslintrc": "^2.1.2", - "@eslint/js": "8.49.0", + "@eslint/js": "8.51.0", "@humanwhocodes/config-array": "^0.11.11", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", @@ -2339,9 +2326,9 @@ } }, "node_modules/eslint-plugin-prettier": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.0.0.tgz", - "integrity": "sha512-AgaZCVuYDXHUGxj/ZGu1u8H8CYgDY3iG6w5kUFw4AzMVXzB7VvbKgYR4nATIN+OvUrghMbiDLeimVjVY5ilq3w==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.0.1.tgz", + "integrity": "sha512-m3u5RnR56asrwV/lDC4GHorlW75DsFfmUcjfCYylTUs85dBRnB7VM6xG8eCMJdeDRnppzmxZVf1GEPJvl1JmNg==", "dev": true, "dependencies": { "prettier-linter-helpers": "^1.0.0", @@ -2658,12 +2645,12 @@ } }, "node_modules/flat-cache": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.1.0.tgz", - "integrity": "sha512-OHx4Qwrrt0E4jEIcI5/Xb+f+QmJYNj2rrK8wiIdQOIrB9WrrJL8cjZvXdXuBTkkEwEqLycb5BeZDV1o2i9bTew==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.1.1.tgz", + "integrity": "sha512-/qM2b3LUIaIgviBQovTLvijfyOQXPtSRnRK26ksj2J7rzPIecePUIpJsZ4T02Qg+xiAEKIs5K8dsHEd+VaKa/Q==", "dev": true, "dependencies": { - "flatted": "^3.2.7", + "flatted": "^3.2.9", "keyv": "^4.5.3", "rimraf": "^3.0.2" }, @@ -2687,9 +2674,9 @@ } }, "node_modules/flatted": { - "version": "3.2.8", - "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.8.tgz", - "integrity": "sha512-6qu0W+A94UKNJRs3ffE8s/fWSHQbjqdNx8elGAe95IqnJA77P68TFz4+2cwC28ouAibiZdGBeV6DsvvMg+4vhQ==", + "version": "3.2.9", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.9.tgz", + "integrity": "sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ==", "dev": true }, "node_modules/for-each": { @@ -2738,9 +2725,9 @@ } }, "node_modules/fp-and-or": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/fp-and-or/-/fp-and-or-0.1.3.tgz", - "integrity": "sha512-wJaE62fLaB3jCYvY2ZHjZvmKK2iiLiiehX38rz5QZxtdN8fVPJDeZUiVvJrHStdTc+23LHlyZuSEKgFc0pxi2g==", + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/fp-and-or/-/fp-and-or-0.1.4.tgz", + "integrity": "sha512-+yRYRhpnFPWXSly/6V4Lw9IfOV26uu30kynGJ03PW+MnjOEQe45RZ141QcS0aJehYBYA50GfCDnsRbFJdhssRw==", "dev": true, "engines": { "node": ">=10" @@ -2779,9 +2766,9 @@ } }, "node_modules/fs-minipass/node_modules/minipass": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.0.3.tgz", - "integrity": "sha512-LhbbwCfz3vsb12j/WkWQPZfKTsgqIe1Nf/ti1pKjYESGLHIVjWU96G9/ljLH4F9mWNVhlQOm0VySdAWzf05dpg==", + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.0.4.tgz", + "integrity": "sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==", "dev": true, "engines": { "node": ">=16 || 14 >=14.17" @@ -2807,9 +2794,12 @@ } }, "node_modules/function-bind": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } }, "node_modules/functions-have-names": { "version": "1.2.3", @@ -2991,9 +2981,9 @@ } }, "node_modules/globals": { - "version": "13.21.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.21.0.tgz", - "integrity": "sha512-ybyme3s4yy/t/3s35bewwXKOf7cvzfreG2lH0lZl0JB7I4GxRP2ghxOK/Nb9EkRXdbBXZLfq/p/0W2JUONB/Gg==", + "version": "13.23.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.23.0.tgz", + "integrity": "sha512-XAmF0RjlrjY23MA51q3HltdlGxUpXPvg0GioKiD9X6HD28iMjo2dKC8Vqwm7lne4GNr78+RHTfliktR6ZH09wA==", "dev": true, "dependencies": { "type-fest": "^0.20.2" @@ -3026,9 +3016,9 @@ } }, "node_modules/google-auth-library": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-9.0.0.tgz", - "integrity": "sha512-IQGjgQoVUAfOk6khqTVMLvWx26R+yPw9uLyb1MNyMQpdKiKt0Fd9sp4NWoINjyGHR8S3iw12hMTYK7O8J07c6Q==", + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-9.1.0.tgz", + "integrity": "sha512-1M9HdOcQNPV5BwSXqwwT238MTKodJFBxZ/V2JP397ieOLv4FjQdfYb9SooR7Mb+oUT2IJ92mLJQf804dyx0MJA==", "dependencies": { "base64-js": "^1.3.0", "ecdsa-sig-formatter": "^1.0.11", @@ -3043,9 +3033,9 @@ } }, "node_modules/googleapis": { - "version": "126.0.1", - "resolved": "https://registry.npmjs.org/googleapis/-/googleapis-126.0.1.tgz", - "integrity": "sha512-4N8LLi+hj6ytK3PhE52KcM8iSGhJjtXnCDYB4fp6l+GdLbYz4FoDmx074WqMbl7iYMDN87vqD/8drJkhxW92mQ==", + "version": "127.0.0", + "resolved": "https://registry.npmjs.org/googleapis/-/googleapis-127.0.0.tgz", + "integrity": "sha512-a27VnPktyqm+7TeWOAOV+iPL2fX2DJN0ueS/v9Zh5PN2PQI9sF/JxWGSeM5dAs5FBT+LI4oKcvCJS72AG9u9GQ==", "dependencies": { "google-auth-library": "^9.0.0", "googleapis-common": "^7.0.0" @@ -3152,12 +3142,9 @@ } }, "node_modules/has": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", - "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", - "dependencies": { - "function-bind": "^1.1.1" - }, + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.4.tgz", + "integrity": "sha512-qdSAmqLF6209RFj4VVItywPMbm3vWylknmB3nvNiUIs72xAimcM8nVYxYr7ncvZq5qzk9MKIZR8ijqD/1QuYjQ==", "engines": { "node": ">= 0.4.0" } @@ -3244,9 +3231,9 @@ } }, "node_modules/hb-lib-tools": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/hb-lib-tools/-/hb-lib-tools-1.1.0.tgz", - "integrity": "sha512-z6woiubNa6zSY6+ECcFG4g4ssaJaDw4LYoftsvl/vlKbFMgcUEBnavxeYh/uriA4MlqkAmMUFAsuurL4SDEeYA==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/hb-lib-tools/-/hb-lib-tools-1.1.2.tgz", + "integrity": "sha512-cVQN+Ymn9s/h42U/aktQVaHOQXS7G5YLxuaFt0h22ruBiM+ZklSs+fX8sNXkYdkR/8MSqXSOELItMnW7dlRKVQ==", "dependencies": { "bonjour-hap": "^3.6.4", "chalk": "^4.1.2", @@ -3259,7 +3246,7 @@ "upnp": "cli/upnp.js" }, "engines": { - "node": "18.17.1||^18||^16" + "node": "20.8.0||^20||^18" } }, "node_modules/help-me": { @@ -3302,12 +3289,12 @@ } }, "node_modules/homebridge-lib": { - "version": "6.5.0", - "resolved": "https://registry.npmjs.org/homebridge-lib/-/homebridge-lib-6.5.0.tgz", - "integrity": "sha512-fRnUOMdCzSXWCPe+MhDjq4OKFUjWE9/VCKaT2iB+4csQwLWdSI7nxemG8l1OH9uEK3WDhu77gRw+clQ10OSjsQ==", + "version": "6.6.1", + "resolved": "https://registry.npmjs.org/homebridge-lib/-/homebridge-lib-6.6.1.tgz", + "integrity": "sha512-enC/7xOoPVBx0zDZMyYYS2fE9IJakBQZr1lKAN0+Bfxi2SaqL7lgy3ximVaHebXz4O+HsiLGNOgvvh6VQzNhBw==", "dependencies": { - "@homebridge/plugin-ui-utils": "~0.0.19", - "hb-lib-tools": "~1.1.0" + "@homebridge/plugin-ui-utils": "~0.1.0", + "hb-lib-tools": "~1.1.2" }, "bin": { "hap": "cli/hap.js", @@ -3317,14 +3304,9 @@ }, "engines": { "homebridge": "^1.6.1", - "node": "18.17.1||^18||^16" + "node": "20.8.0||^20||^18" } }, - "node_modules/homebridge-lib/node_modules/@homebridge/plugin-ui-utils": { - "version": "0.0.19", - "resolved": "https://registry.npmjs.org/@homebridge/plugin-ui-utils/-/plugin-ui-utils-0.0.19.tgz", - "integrity": "sha512-axFX7lN2Yd7bz/6SlD7dzq5sY/N9+XYuLHPukuiyHQRDtNMRL1uDqJhOx6RVaN2tYDHB75h7YxRQWP7U44Mgzg==" - }, "node_modules/hosted-git-info": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-5.2.1.tgz", @@ -3998,9 +3980,9 @@ "dev": true }, "node_modules/jackspeak": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-2.3.3.tgz", - "integrity": "sha512-R2bUw+kVZFS/h1AZqBKrSgDmdmjApzgY0AlCPumopFiAlbUxE2gf+SCuBzQ0cP5hHmUmFYF5yw55T97Th5Kstg==", + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-2.3.6.tgz", + "integrity": "sha512-N3yCS/NegsOBokc8GAdM8UcmfsKiSS8cipheD/nivzr700H+nsMOxJjQnvwOcRYVuFkdH0wGUvW2WbXGmrZGbQ==", "dev": true, "dependencies": { "@isaacs/cliui": "^8.0.2" @@ -4145,9 +4127,9 @@ } }, "node_modules/keyv": { - "version": "4.5.3", - "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.3.tgz", - "integrity": "sha512-QCiSav9WaX1PgETJ+SpNnx2PRRapJ/oRSXM4VO5OGYGSjrxbKPVFVhB3l2OCbLCk329N8qyAtsJjSjvVBWzEug==", + "version": "4.5.4", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", + "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==", "dev": true, "dependencies": { "json-buffer": "3.0.1" @@ -4441,9 +4423,9 @@ } }, "node_modules/minipass-fetch/node_modules/minipass": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.0.3.tgz", - "integrity": "sha512-LhbbwCfz3vsb12j/WkWQPZfKTsgqIe1Nf/ti1pKjYESGLHIVjWU96G9/ljLH4F9mWNVhlQOm0VySdAWzf05dpg==", + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.0.4.tgz", + "integrity": "sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==", "dev": true, "engines": { "node": ">=16 || 14 >=14.17" @@ -4974,9 +4956,9 @@ } }, "node_modules/npm-check-updates": { - "version": "16.14.3", - "resolved": "https://registry.npmjs.org/npm-check-updates/-/npm-check-updates-16.14.3.tgz", - "integrity": "sha512-iviPM0LiTFGUtk+kMtcMVLNeGuSORThj9Cho7GV/Z2l5dMdXFrcgIarMSr6d6f1wYJJBIthuNdJWXZ4NH5VPEg==", + "version": "16.14.6", + "resolved": "https://registry.npmjs.org/npm-check-updates/-/npm-check-updates-16.14.6.tgz", + "integrity": "sha512-sJ6w4AmSDP7YzBXah94Ul2JhiIbjBDfx9XYgib15um2wtiQkOyjE7Lov3MNUSQ84Ry7T81mE4ynMbl/mGbK4HQ==", "dev": true, "dependencies": { "chalk": "^5.3.0", @@ -4984,7 +4966,7 @@ "commander": "^10.0.1", "fast-memoize": "^2.5.2", "find-up": "5.0.0", - "fp-and-or": "^0.1.3", + "fp-and-or": "^0.1.4", "get-stdin": "^8.0.0", "globby": "^11.0.4", "hosted-git-info": "^5.1.0", @@ -5002,11 +4984,11 @@ "prompts-ncu": "^3.0.0", "rc-config-loader": "^4.1.3", "remote-git-tags": "^3.0.0", - "rimraf": "^5.0.1", + "rimraf": "^5.0.5", "semver": "^7.5.4", "semver-utils": "^1.1.4", "source-map-support": "^0.5.21", - "spawn-please": "^2.0.1", + "spawn-please": "^2.0.2", "strip-ansi": "^7.1.0", "strip-json-comments": "^5.0.1", "untildify": "^4.0.0", @@ -5105,9 +5087,9 @@ } }, "node_modules/npm-install-checks": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/npm-install-checks/-/npm-install-checks-6.2.0.tgz", - "integrity": "sha512-744wat5wAAHsxa4590mWO0tJ8PKxR8ORZsH9wGpQc3nWTzozMAgBN/XyqYw7mg3yqLM8dLwEnwSfKMmXAjF69g==", + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/npm-install-checks/-/npm-install-checks-6.3.0.tgz", + "integrity": "sha512-W29RiK/xtpCGqn6f3ixfRYGk+zRyr+Ew9F2E20BfXxT5/euLdA/Nm7fO7OeTGuAmTs30cpgInyJ0cYe708YTZw==", "dev": true, "dependencies": { "semver": "^7.1.1" @@ -5865,19 +5847,19 @@ } }, "node_modules/read-package-json/node_modules/glob": { - "version": "10.3.4", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.4.tgz", - "integrity": "sha512-6LFElP3A+i/Q8XQKEvZjkEWEOTgAIALR9AO2rwT8bgPhDd1anmqDJDZ6lLddI4ehxxxR1S5RIqKe1uapMQfYaQ==", + "version": "10.3.10", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.10.tgz", + "integrity": "sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==", "dev": true, "dependencies": { "foreground-child": "^3.1.0", - "jackspeak": "^2.0.3", + "jackspeak": "^2.3.5", "minimatch": "^9.0.1", "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0", "path-scurry": "^1.10.1" }, "bin": { - "glob": "dist/cjs/src/bin.js" + "glob": "dist/esm/bin.mjs" }, "engines": { "node": ">=16 || 14 >=14.17" @@ -6047,15 +6029,15 @@ "integrity": "sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA==" }, "node_modules/rimraf": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-5.0.1.tgz", - "integrity": "sha512-OfFZdwtd3lZ+XZzYP/6gTACubwFcHdLRqS9UX3UwpU2dnGQYkPFISRwvM3w9IiB2w7bW5qGo/uAwE4SmXXSKvg==", + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-5.0.5.tgz", + "integrity": "sha512-CqDakW+hMe/Bz202FPEymy68P+G50RfMQK+Qo5YUqc9SPipvbGjCGKd0RSKEelbsfQuw3g5NZDSrlZZAJurH1A==", "dev": true, "dependencies": { - "glob": "^10.2.5" + "glob": "^10.3.7" }, "bin": { - "rimraf": "dist/cjs/src/bin.js" + "rimraf": "dist/esm/bin.mjs" }, "engines": { "node": ">=14" @@ -6074,19 +6056,19 @@ } }, "node_modules/rimraf/node_modules/glob": { - "version": "10.3.4", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.4.tgz", - "integrity": "sha512-6LFElP3A+i/Q8XQKEvZjkEWEOTgAIALR9AO2rwT8bgPhDd1anmqDJDZ6lLddI4ehxxxR1S5RIqKe1uapMQfYaQ==", + "version": "10.3.10", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.10.tgz", + "integrity": "sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==", "dev": true, "dependencies": { "foreground-child": "^3.1.0", - "jackspeak": "^2.0.3", + "jackspeak": "^2.3.5", "minimatch": "^9.0.1", "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0", "path-scurry": "^1.10.1" }, "bin": { - "glob": "dist/cjs/src/bin.js" + "glob": "dist/esm/bin.mjs" }, "engines": { "node": ">=16 || 14 >=14.17" @@ -6259,9 +6241,9 @@ "optional": true }, "node_modules/sax": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", - "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.3.0.tgz", + "integrity": "sha512-0s+oAmw9zLl1V1cS9BtZN7JAd0cW5e0QH4W3LWEK6a4LaLEA2OTpGYWDY+6XasBLtz6wkm3u1xRw95mRuJ59WA==", "dev": true }, "node_modules/semver": { @@ -6506,9 +6488,9 @@ } }, "node_modules/spdx-license-ids": { - "version": "3.0.13", - "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.13.tgz", - "integrity": "sha512-XkD+zwiqXHikFZm4AX/7JSCXA98U5Db4AFd5XUg/+9UNtnH75+Z9KxtpYiJZx36mUDVOwH83pl7yvCer6ewM3w==", + "version": "3.0.16", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.16.tgz", + "integrity": "sha512-eWN+LnM3GR6gPu35WxNgbGl8rmY1AEmoMDvL/QD6zYmPWgywxWqJWNdLGT+ke8dKNWrcYgYjPpG5gbTfghP8rw==", "dev": true }, "node_modules/split": { @@ -6544,9 +6526,9 @@ } }, "node_modules/ssri/node_modules/minipass": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.0.3.tgz", - "integrity": "sha512-LhbbwCfz3vsb12j/WkWQPZfKTsgqIe1Nf/ti1pKjYESGLHIVjWU96G9/ljLH4F9mWNVhlQOm0VySdAWzf05dpg==", + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.0.4.tgz", + "integrity": "sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==", "dev": true, "engines": { "node": ">=16 || 14 >=14.17" @@ -6578,14 +6560,6 @@ "resolved": "https://registry.npmjs.org/stream-shift/-/stream-shift-1.0.1.tgz", "integrity": "sha512-AiisoFqQ0vbGcZgQPY1cdP2I76glaVA/RauYR4G4thNFgkTqr90yXTo4LYX60Jl+sIlPNHHdGSwo01AvbKUSVQ==" }, - "node_modules/streamsearch": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", - "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==", - "engines": { - "node": ">=10.0.0" - } - }, "node_modules/string_decoder": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", @@ -6963,16 +6937,22 @@ "dev": true }, "node_modules/undici": { - "version": "5.24.0", - "resolved": "https://registry.npmjs.org/undici/-/undici-5.24.0.tgz", - "integrity": "sha512-OKlckxBjFl0oXxcj9FU6oB8fDAaiRUq+D8jrFWGmOfI/gIyjk/IeS75LMzgYKUaeHzLUcYvf9bbJGSrUwTfwwQ==", + "version": "5.26.3", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.26.3.tgz", + "integrity": "sha512-H7n2zmKEWgOllKkIUkLvFmsJQj062lSm3uA4EYApG8gLuiOM0/go9bIoC3HVaSnfg4xunowDE2i9p8drkXuvDw==", "dependencies": { - "busboy": "^1.6.0" + "@fastify/busboy": "^2.0.0" }, "engines": { "node": ">=14.0" } }, + "node_modules/undici-types": { + "version": "5.25.3", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.25.3.tgz", + "integrity": "sha512-Ga1jfYwRn7+cP9v8auvEXN1rX3sWqlayd4HP7OKk4mZWylEmu3KzXDUGrQUN6Ol7qo1gPvB2e5gX6udnyEPgdA==", + "dev": true + }, "node_modules/unique-filename": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/unique-filename/-/unique-filename-3.0.0.tgz", diff --git a/package.json b/package.json index 59045e3e..d7ab5789 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "displayName": "Homebridge SwitchBot", "name": "@switchbot/homebridge-switchbot", - "version": "2.9.0", + "version": "2.9.1", "description": "The [Homebridge](https://homebridge.io) SwitchBot plugin allows you to access your [SwitchBot](https://www.switch-bot.com) device(s) from HomeKit.", "author": "SwitchBot (https://github.com/SwitchBot)", "license": "ISC", @@ -14,7 +14,7 @@ }, "engines": { "homebridge": "^1.6.1", - "node": "^16.20.2 || ^18.17.1 || ^20.5.1" + "node": "^18.18.2 || ^20.8.1" }, "main": "dist/index.js", "scripts": { @@ -57,11 +57,10 @@ "dependencies": { "@homebridge/plugin-ui-utils": "^0.1.0", "async-mqtt": "^2.6.3", - "crypto-js": "^4.1.1", "fakegato-history": "^0.6.4", - "homebridge-lib": "^6.5.0", + "homebridge-lib": "^6.6.1", "rxjs": "^7.8.1", - "undici": "^5.24.0" + "undici": "^5.26.3" }, "optionalDependencies": { "@abandonware/bluetooth-hci-socket": "^0.5.3-10", @@ -69,19 +68,15 @@ "node-switchbot": "^1.9.0" }, "devDependencies": { - "@types/crypto-js": "^4.1.2", - "@types/node": "^20.6.2", - "@typescript-eslint/eslint-plugin": "^6.7.0", - "@typescript-eslint/parser": "^6.7.0", - "eslint": "^8.49.0", - "eslint-config-prettier": "9.0.0", - "eslint-plugin-prettier": "5.0.0", + "@types/node": "^20.8.6", + "@typescript-eslint/eslint-plugin": "^6.7.5", + "@typescript-eslint/parser": "^6.7.5", + "eslint": "^8.51.0", "homebridge": "^1.6.1", "nodemon": "^3.0.1", - "npm-check-updates": "^16.14.3", - "prettier": "3.0.3", - "rimraf": "^5.0.1", + "npm-check-updates": "^16.14.6", + "rimraf": "^5.0.5", "ts-node": "^10.9.1", "typescript": "^5.2.2" } -} +} \ No newline at end of file diff --git a/src/device/blindtilt.ts b/src/device/blindtilt.ts index 1a9a3ca4..eaac305a 100644 --- a/src/device/blindtilt.ts +++ b/src/device/blindtilt.ts @@ -1,4 +1,3 @@ -import { Context } from 'vm'; import { request } from 'undici'; import { sleep } from '../utils'; import { MqttClient } from 'mqtt'; @@ -114,26 +113,15 @@ export class BlindTilt { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, 'W2701600') - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // get the WindowCovering service if it exists, otherwise create a new WindowCovering service // you can create multiple services for each accessory + const windowCoveringService = `${device.deviceName} ${device.deviceType}`; (this.windowCoveringService = - accessory.getService(this.platform.Service.WindowCovering) || accessory.addService(this.platform.Service.WindowCovering)), - `${device.deviceName} ${device.deviceType}`; + accessory.getService(this.platform.Service.WindowCovering) + || accessory.addService(this.platform.Service.WindowCovering)), windowCoveringService; this.windowCoveringService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); if (!this.windowCoveringService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -191,8 +179,9 @@ export class BlindTilt { .onSet(this.TargetHorizontalTiltAngleSet.bind(this)); // Battery Service - (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)), - `${accessory.displayName} Battery`; + const batteryService = `${accessory.displayName} Battery`; + (this.batteryService = this.accessory.getService(this.platform.Service.Battery) + || accessory.addService(this.platform.Service.Battery)), batteryService; this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`); if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -451,10 +440,11 @@ export class BlindTilt { this.BatteryLevel = 100; } this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},` - + ` StatusLowBattery: ${this.StatusLowBattery}`); + + ` StatusLowBattery: ${this.StatusLowBattery}`); // FirmwareRevision this.FirmwareRevision = this.OpenAPI_FirmwareRevision!; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; } async refreshStatus(): Promise { @@ -897,22 +887,6 @@ export class BlindTilt { this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery); this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`); } - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - if (this.device.mqttURL) { - this.mqttPublish('FirmwareRevision', this.FirmwareRevision); - } - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.batteryService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - if (!this.device.blindTilt?.hide_lightsensor) { - this.lightSensorService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } } /* @@ -1145,32 +1119,6 @@ export class BlindTilt { //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE); } - async setFirmwareRevision(accessory: PlatformAccessory, device: device & devicesConfig) { - await this.refreshStatus(); - if (device.firmware) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else if (device.version) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`); - accessory.context.FirmwareRevision = device.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - async context() { if (this.CurrentPosition === undefined) { this.CurrentPosition = 0; @@ -1189,6 +1137,10 @@ export class BlindTilt { } else { this.PositionState = this.accessory.context.PositionState; } + if (this.FirmwareRevision === undefined) { + this.FirmwareRevision = this.platform.version; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; + } } /** diff --git a/src/device/bot.ts b/src/device/bot.ts index 29fb6b52..d9f33ed6 100644 --- a/src/device/bot.ts +++ b/src/device/bot.ts @@ -1,4 +1,3 @@ -import { Context } from 'vm'; import { request } from 'undici'; import { sleep } from '../utils'; import { interval, Subject } from 'rxjs'; @@ -94,20 +93,8 @@ export class Bot { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-BOT-S1') - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // deviceType if (this.botDeviceType === 'switch') { @@ -122,8 +109,9 @@ export class Bot { this.removeStatefulProgrammableSwitchService(accessory); // Add switchService - (this.switchService = accessory.getService(this.platform.Service.Switch) || accessory.addService(this.platform.Service.Switch)), - `${accessory.displayName} Switch`; + const switchService = `${accessory.displayName} Switch`; + (this.switchService = accessory.getService(this.platform.Service.Switch) + || accessory.addService(this.platform.Service.Switch)), switchService; this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Switch`); this.switchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); @@ -142,10 +130,10 @@ export class Bot { this.removeWindowCoveringService(accessory); this.removeStatefulProgrammableSwitchService(accessory); - // Add switchService - (this.garageDoorService = - accessory.getService(this.platform.Service.GarageDoorOpener) || accessory.addService(this.platform.Service.GarageDoorOpener)), - `${accessory.displayName} Garage Door Opener`; + // Add garageDoorService + const garageDoorService = `${accessory.displayName} Garage Door Opener`; + (this.garageDoorService = accessory.getService(this.platform.Service.GarageDoorOpener) + || accessory.addService(this.platform.Service.GarageDoorOpener)), garageDoorService; this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Garage Door Opener`); this.garageDoorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); @@ -165,9 +153,10 @@ export class Bot { this.removeWindowCoveringService(accessory); this.removeStatefulProgrammableSwitchService(accessory); - // Add switchService - (this.doorService = accessory.getService(this.platform.Service.Door) || accessory.addService(this.platform.Service.Door)), - `${accessory.displayName} Door`; + // Add doorService + const doorService = `${accessory.displayName} Door`; + (this.doorService = accessory.getService(this.platform.Service.Door) + || accessory.addService(this.platform.Service.Door)), doorService; this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Door`); this.doorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); @@ -195,9 +184,10 @@ export class Bot { this.removeWindowCoveringService(accessory); this.removeStatefulProgrammableSwitchService(accessory); - // Add switchService - (this.windowService = accessory.getService(this.platform.Service.Window) || accessory.addService(this.platform.Service.Window)), - `${accessory.displayName} Window`; + // Add windowService + const windowService = `${accessory.displayName} Window`; + (this.windowService = accessory.getService(this.platform.Service.Window) + || accessory.addService(this.platform.Service.Window)), windowService; this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window`); this.windowService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); @@ -225,10 +215,10 @@ export class Bot { this.removeGarageDoorService(accessory); this.removeStatefulProgrammableSwitchService(accessory); - // Add switchService - (this.windowCoveringService = - accessory.getService(this.platform.Service.WindowCovering) || accessory.addService(this.platform.Service.WindowCovering)), - `${accessory.displayName} Window Covering`; + // Add windowCoveringService + const windowCoveringService = `${accessory.displayName} Window Covering`; + (this.windowCoveringService = accessory.getService(this.platform.Service.WindowCovering) + || accessory.addService(this.platform.Service.WindowCovering)), windowCoveringService; this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Window Covering`); this.windowCoveringService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); @@ -256,9 +246,10 @@ export class Bot { this.removeWindowCoveringService(accessory); this.removeStatefulProgrammableSwitchService(accessory); - // Add switchService - (this.lockService = accessory.getService(this.platform.Service.LockMechanism) || accessory.addService(this.platform.Service.LockMechanism)), - `${accessory.displayName} Lock`; + // Add lockService + const lockService = `${accessory.displayName} Lock`; + (this.lockService = accessory.getService(this.platform.Service.LockMechanism) + || accessory.addService(this.platform.Service.LockMechanism)), lockService; this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Lock`); this.lockService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); @@ -277,9 +268,10 @@ export class Bot { this.removeWindowCoveringService(accessory); this.removeStatefulProgrammableSwitchService(accessory); - // Add switchService - (this.faucetService = accessory.getService(this.platform.Service.Faucet) || accessory.addService(this.platform.Service.Faucet)), - `${accessory.displayName} Faucet`; + // Add faucetService + const faucetService = `${accessory.displayName} Faucet`; + (this.faucetService = accessory.getService(this.platform.Service.Faucet) + || accessory.addService(this.platform.Service.Faucet)), faucetService; this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Faucet`); this.faucetService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); @@ -298,9 +290,10 @@ export class Bot { this.removeWindowCoveringService(accessory); this.removeStatefulProgrammableSwitchService(accessory); - // Add switchService - (this.fanService = accessory.getService(this.platform.Service.Fan) || accessory.addService(this.platform.Service.Fan)), - `${accessory.displayName} Fan`; + // Add fanService + const fanService = `${accessory.displayName} Fan`; + (this.fanService = accessory.getService(this.platform.Service.Fan) + || accessory.addService(this.platform.Service.Fan)), fanService; this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Fan`); this.fanService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); @@ -319,11 +312,10 @@ export class Bot { this.removeGarageDoorService(accessory); this.removeWindowCoveringService(accessory); - // Add switchService - (this.statefulProgrammableSwitchService = - accessory.getService(this.platform.Service.StatefulProgrammableSwitch) || - accessory.addService(this.platform.Service.StatefulProgrammableSwitch)), - `${accessory.displayName} Stateful Programmable Switch`; + // Add statefulProgrammableSwitchService + const statefulProgrammableSwitchService = `${accessory.displayName} Stateful Programmable Switch`; + (this.statefulProgrammableSwitchService = accessory.getService(this.platform.Service.StatefulProgrammableSwitch) || + accessory.addService(this.platform.Service.StatefulProgrammableSwitch)), statefulProgrammableSwitchService; this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Stateful Programmable Switch`); this.statefulProgrammableSwitchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); @@ -345,8 +337,9 @@ export class Bot { this.removeStatefulProgrammableSwitchService(accessory); // Add outletService - (this.outletService = accessory.getService(this.platform.Service.Outlet) || accessory.addService(this.platform.Service.Outlet)), - `${accessory.displayName} Outlet`; + const outletService = `${accessory.displayName} Outlet`; + (this.outletService = accessory.getService(this.platform.Service.Outlet) + || accessory.addService(this.platform.Service.Outlet)), outletService; this.debugWarnLog(`${this.device.deviceType}: ${accessory.displayName} Displaying as Outlet`); this.outletService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); @@ -356,9 +349,10 @@ export class Bot { this.outletService.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this)); } - // Battery Service - (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)), - `${accessory.displayName} Battery`; + // batteryService + const batteryService = `${accessory.displayName} Battery`; + (this.batteryService = this.accessory.getService(this.platform.Service.Battery) + || accessory.addService(this.platform.Service.Battery)), batteryService; this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`); if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -450,7 +444,7 @@ export class Bot { this.BatteryLevel = 100; } this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},` - + ` StatusLowBattery: ${this.StatusLowBattery}`); + + ` StatusLowBattery: ${this.StatusLowBattery}`); } async openAPIparseStatus(): Promise { @@ -477,10 +471,11 @@ export class Bot { this.BatteryLevel = 100; } this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},` - + ` StatusLowBattery: ${this.StatusLowBattery}`); + + ` StatusLowBattery: ${this.StatusLowBattery}`); // FirmwareRevision this.FirmwareRevision = this.OpenAPI_FirmwareRevision!; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; } /** @@ -1042,36 +1037,6 @@ export class Bot { this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery); this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`); } - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.batteryService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - if (this.botDeviceType === 'garagedoor') { - this.garageDoorService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } else if (this.botDeviceType === 'door') { - this.doorService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } else if (this.botDeviceType === 'window') { - this.windowService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } else if (this.botDeviceType === 'windowcovering') { - this.windowCoveringService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } else if (this.botDeviceType === 'lock') { - this.lockService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } else if (this.botDeviceType === 'faucet') { - this.faucetService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } else if (this.botDeviceType === 'fan') { - this.fanService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } else if (this.botDeviceType === 'stateful') { - this.statefulProgrammableSwitchService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } else if (this.botDeviceType === 'switch') { - this.switchService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } else { - this.outletService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } } async removeOutletService(accessory: PlatformAccessory): Promise { @@ -1363,32 +1328,6 @@ export class Bot { this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e); } - async setFirmwareRevision(accessory: PlatformAccessory, device: device & devicesConfig) { - await this.refreshStatus(); - if (device.firmware) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else if (device.version) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`); - accessory.context.FirmwareRevision = device.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - async deviceType(device: device & devicesConfig): Promise { if (!device.bot?.deviceType && this.accessory.context.deviceType) { this.botDeviceType = this.accessory.context.deviceType; @@ -1423,6 +1362,10 @@ export class Bot { } else { this.StatusLowBattery = this.accessory.context.StatusLowBattery; } + if (this.FirmwareRevision === undefined) { + this.FirmwareRevision = this.platform.version; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; + } } async refreshRate(device: device & devicesConfig): Promise { diff --git a/src/device/ceilinglight.ts b/src/device/ceilinglight.ts index 9af8403c..492fae9d 100644 --- a/src/device/ceilinglight.ts +++ b/src/device/ceilinglight.ts @@ -1,5 +1,3 @@ -/* eslint-disable brace-style */ -import { Context } from 'vm'; import { request } from 'undici'; import { sleep } from '../utils'; import { interval, Subject } from 'rxjs'; @@ -88,25 +86,14 @@ export class CeilingLight { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, this.model(device)) - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // get the Lightbulb service if it exists, otherwise create a new Lightbulb service // you can create multiple services for each accessory - (this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)), - `${accessory.displayName} ${device.deviceType}`; + const lightBulbService = `${accessory.displayName} ${device.deviceType}`; + (this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) + || accessory.addService(this.platform.Service.Lightbulb)), lightBulbService; if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) { this.accessory.removeService(this.lightBulbService); @@ -242,7 +229,7 @@ export class CeilingLight { } /*if (this.BLE) { await this.BLEparseStatus(); - } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) { + } else*/ if (this.OpenAPI && this.platform.config.credentials?.token) { await this.openAPIparseStatus(); } else { await this.offlineOff(); @@ -315,6 +302,7 @@ export class CeilingLight { // FirmwareRevision this.FirmwareRevision = this.OpenAPI_FirmwareRevision!; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; } /** @@ -323,9 +311,9 @@ export class CeilingLight { async refreshStatus(): Promise { if (!this.device.enableCloudService && this.OpenAPI) { this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`); - } /*if (this.BLE) { - await this.BLERefreshStatus(); - } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) { + /*} else if (this.BLE) { + await this.BLERefreshStatus();*/ + } else if (this.OpenAPI && this.platform.config.credentials?.token) { await this.openAPIRefreshStatus(); } else { await this.offlineOff(); @@ -454,9 +442,9 @@ export class CeilingLight { async pushChanges(): Promise { if (!this.device.enableCloudService && this.OpenAPI) { this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`); - } /*if (this.BLE) { - await this.BLEpushChanges(); - } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) { + /*} else if (this.BLE) { + await this.BLEpushChanges();*/ + } else if (this.OpenAPI && this.platform.config.credentials?.token) { await this.openAPIpushChanges(); } else { await this.offlineOff(); @@ -856,16 +844,6 @@ export class CeilingLight { this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation); this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`); } - - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.lightBulbService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } } async adaptiveLighting(device: device & devicesConfig): Promise { @@ -1022,32 +1000,6 @@ export class CeilingLight { this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, e); } - async setFirmwareRevision(accessory: PlatformAccessory, device: device & devicesConfig) { - await this.refreshStatus(); - if (device.firmware) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else if (device.version) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`); - accessory.context.FirmwareRevision = device.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - async context() { if (this.On === undefined) { this.On = false; @@ -1076,6 +1028,10 @@ export class CeilingLight { } this.minKelvin = 2000; this.maxKelvin = 9000; + if (this.FirmwareRevision === undefined) { + this.FirmwareRevision = this.platform.version; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; + } } async refreshRate(device: device & devicesConfig): Promise { diff --git a/src/device/colorbulb.ts b/src/device/colorbulb.ts index 43f6b5de..988d9c03 100644 --- a/src/device/colorbulb.ts +++ b/src/device/colorbulb.ts @@ -1,5 +1,3 @@ -/* eslint-disable brace-style */ -import { Context } from 'vm'; import { request } from 'undici'; import { sleep } from '../utils'; import { interval, Subject } from 'rxjs'; @@ -94,25 +92,14 @@ export class ColorBulb { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, 'W1401400') - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // get the Lightbulb service if it exists, otherwise create a new Lightbulb service // you can create multiple services for each accessory - (this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)), - `${accessory.displayName} ${device.deviceType}`; + const lightBulbService = `${accessory.displayName} ${device.deviceType}`; + (this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) + || accessory.addService(this.platform.Service.Lightbulb)), lightBulbService; if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) { this.accessory.removeService(this.lightBulbService); @@ -341,6 +328,7 @@ export class ColorBulb { // FirmwareRevision this.FirmwareRevision = this.OpenAPI_FirmwareRevision!; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; } /** @@ -481,9 +469,9 @@ export class ColorBulb { async pushChanges(): Promise { if (!this.device.enableCloudService && this.OpenAPI) { this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`); - } /* if (this.BLE) { - await this.BLEpushChanges(); - } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) { + /*} else if (this.BLE) { + await this.BLEpushChanges();*/ + } else if (this.OpenAPI && this.platform.config.credentials?.token) { await this.openAPIpushChanges(); } else { await this.offlineOff(); @@ -1024,15 +1012,6 @@ export class ColorBulb { this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation); this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`); } - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.lightBulbService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } } async adaptiveLighting(device: device & devicesConfig): Promise { @@ -1189,32 +1168,6 @@ export class ColorBulb { this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, e); } - async setFirmwareRevision(accessory: PlatformAccessory, device: device & devicesConfig) { - await this.refreshStatus(); - if (device.firmware) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else if (device.version) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`); - accessory.context.FirmwareRevision = device.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - async context() { if (this.On === undefined) { this.On = false; @@ -1243,6 +1196,10 @@ export class ColorBulb { } this.minKelvin = 2000; this.maxKelvin = 9000; + if (this.FirmwareRevision === undefined) { + this.FirmwareRevision = this.platform.version; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; + } } async refreshRate(device: device & devicesConfig): Promise { diff --git a/src/device/contact.ts b/src/device/contact.ts index 2d814a00..f69e2012 100644 --- a/src/device/contact.ts +++ b/src/device/contact.ts @@ -1,4 +1,3 @@ -import { Context } from 'vm'; import { request } from 'undici'; import { sleep } from '../utils'; import { interval, Subject } from 'rxjs'; @@ -83,26 +82,14 @@ export class Contact { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, 'W1201500') - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // get the Contact service if it exists, otherwise create a new Contact service // you can create multiple services for each accessory - (this.contactSensorservice = - accessory.getService(this.platform.Service.ContactSensor) || accessory.addService(this.platform.Service.ContactSensor)), - `${accessory.displayName} Contact Sensor`; + const contactSensorservice = `${accessory.displayName} Contact Sensor`; + (this.contactSensorservice = accessory.getService(this.platform.Service.ContactSensor) + || accessory.addService(this.platform.Service.ContactSensor)), contactSensorservice; this.contactSensorservice.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); if (!this.contactSensorservice.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -116,9 +103,9 @@ export class Contact { accessory.removeService(this.motionService!); } else if (!this.motionService) { this.debugLog(`${this.device.deviceType}: ${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`; + const motionService = `${accessory.displayName} Motion Sensor`; + (this.motionService = this.accessory.getService(this.platform.Service.MotionSensor) + || this.accessory.addService(this.platform.Service.MotionSensor)), motionService; this.motionService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Motion Sensor`); this.motionService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Motion Sensor`); @@ -133,9 +120,10 @@ export class Contact { accessory.removeService(this.lightSensorService!); } else if (!this.lightSensorService) { this.debugLog(`${this.device.deviceType}: ${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`; + + const lightSensorService = `${accessory.displayName} Light Sensor`; + (this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor) + || this.accessory.addService(this.platform.Service.LightSensor)), lightSensorService; this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`); this.lightSensorService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Light Sensor`); @@ -144,8 +132,9 @@ export class Contact { } // Battery Service - (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)), - `${accessory.displayName} Battery`; + const batteryService = `${accessory.displayName} Battery`; + (this.batteryService = this.accessory.getService(this.platform.Service.Battery) + || accessory.addService(this.platform.Service.Battery)), batteryService; this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`); if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -293,6 +282,7 @@ export class Contact { // FirmwareRevision this.FirmwareRevision = this.OpenAPI_FirmwareRevision!; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; } /** @@ -464,23 +454,6 @@ export class Contact { this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery); this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`); } - - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.batteryService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - this.contactSensorservice.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - if (!this.device.contact?.hide_motionsensor) { - this.motionService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } - if (!this.device.contact?.hide_lightsensor) { - this.lightSensorService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } } async stopScanning(switchbot: any) { @@ -612,32 +585,6 @@ export class Contact { this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e); } - async setFirmwareRevision(accessory: PlatformAccessory, device: device & devicesConfig) { - await this.refreshStatus(); - if (device.firmware) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else if (device.version) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`); - accessory.context.FirmwareRevision = device.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - async context() { if (this.MotionDetected === undefined) { this.MotionDetected = false; @@ -649,6 +596,10 @@ export class Contact { } else { this.ContactSensorState = this.accessory.context.ContactSensorState; } + if (this.FirmwareRevision === undefined) { + this.FirmwareRevision = this.platform.version; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; + } } async refreshRate(device: device & devicesConfig): Promise { diff --git a/src/device/curtain.ts b/src/device/curtain.ts index 47fbbadc..e90285fe 100644 --- a/src/device/curtain.ts +++ b/src/device/curtain.ts @@ -1,4 +1,3 @@ -import { Context } from 'vm'; import { request } from 'undici'; import { sleep } from '../utils'; import { MqttClient } from 'mqtt'; @@ -102,26 +101,14 @@ export class Curtain { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, 'W0701600') - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // get the WindowCovering service if it exists, otherwise create a new WindowCovering service // you can create multiple services for each accessory - (this.windowCoveringService = - accessory.getService(this.platform.Service.WindowCovering) || accessory.addService(this.platform.Service.WindowCovering)), - `${device.deviceName} ${device.deviceType}`; + const windowCoveringService = `${accessory.displayName} ${device.deviceType}`; + (this.windowCoveringService = accessory.getService(this.platform.Service.WindowCovering) + || accessory.addService(this.platform.Service.WindowCovering)), windowCoveringService; this.windowCoveringService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); if (!this.windowCoveringService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -163,9 +150,9 @@ export class Curtain { accessory.removeService(this.lightSensorService!); } else if (!this.lightSensorService) { this.debugLog(`${this.device.deviceType}: ${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`; + const lightSensorService = `${accessory.displayName} Light Sensor`; + (this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor) + || this.accessory.addService(this.platform.Service.LightSensor)), lightSensorService; this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`); if (!this.lightSensorService?.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -176,8 +163,9 @@ export class Curtain { } // Battery Service - (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)), - `${accessory.displayName} Battery`; + const batteryService = `${accessory.displayName} Battery`; + (this.batteryService = this.accessory.getService(this.platform.Service.Battery) + || accessory.addService(this.platform.Service.Battery)), batteryService; this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`); if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -478,10 +466,11 @@ export class Curtain { this.BatteryLevel = 100; } this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},` - + ` StatusLowBattery: ${this.StatusLowBattery}`); + + ` StatusLowBattery: ${this.StatusLowBattery}`); // FirmwareRevision this.FirmwareRevision = this.OpenAPI_FirmwareRevision!; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; } async refreshStatus(): Promise { @@ -875,22 +864,6 @@ export class Curtain { this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery); this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`); } - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - if (this.device.mqttURL) { - this.mqttPublish('FirmwareRevision', this.FirmwareRevision); - } - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.batteryService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - if (this.device.curtain?.hide_lightsensor) { - this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } } /* @@ -1122,32 +1095,6 @@ export class Curtain { //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE); } - async setFirmwareRevision(accessory: PlatformAccessory, device: device & devicesConfig) { - await this.refreshStatus(); - if (device.firmware) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else if (device.version) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`); - accessory.context.FirmwareRevision = device.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - async context() { if (this.accessory.context.CurrentPosition === undefined) { this.CurrentPosition = 0; @@ -1193,6 +1140,10 @@ export class Curtain { // removes cached values if history is turned off delete this.accessory.context.lastActivation; } + if (this.FirmwareRevision === undefined) { + this.FirmwareRevision = this.platform.version; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; + } } async refreshRate(device: device & devicesConfig): Promise { diff --git a/src/device/hub.ts b/src/device/hub.ts index 443b1edb..8f1cbed5 100644 --- a/src/device/hub.ts +++ b/src/device/hub.ts @@ -4,7 +4,6 @@ import { MqttClient } from 'mqtt'; import { hostname } from 'os'; import { interval } from 'rxjs'; import { request } from 'undici'; -import { Context } from 'vm'; import { SwitchBotPlatform } from '../platform'; import { Devices, device, deviceStatus, devicesConfig } from '../settings'; @@ -56,7 +55,7 @@ export class Hub { // default placeholders this.logs(device); this.refreshRate(device); - this.context(accessory, device); + this.context(); this.setupHistoryService(device); this.setupMqtt(device); this.config(device); @@ -72,20 +71,8 @@ export class Hub { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, accessory.context.model) - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // Temperature Sensor Service if (device.hub?.hide_temperature) { @@ -94,9 +81,9 @@ export class Hub { accessory.removeService(this.temperatureService!); } else if (!this.temperatureService) { this.debugLog(`${this.device.deviceType}: ${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`; + const temperatureService = `${accessory.displayName} Temperature Sensor`; + (this.temperatureService = this.accessory.getService(this.platform.Service.TemperatureSensor) + || this.accessory.addService(this.platform.Service.TemperatureSensor)), temperatureService; this.temperatureService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Temperature Sensor`); if (!this.temperatureService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -125,9 +112,9 @@ export class Hub { accessory.removeService(this.humidityService!); } else if (!this.humidityService) { this.debugLog(`${this.device.deviceType}: ${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`; + const humidityService = `${accessory.displayName} Humidity Sensor`; + (this.humidityService = this.accessory.getService(this.platform.Service.HumiditySensor) + || this.accessory.addService(this.platform.Service.HumiditySensor)), humidityService; this.humidityService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Humidity Sensor`); if (!this.humidityService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -152,9 +139,9 @@ export class Hub { accessory.removeService(this.lightSensorService!); } else if (!this.lightSensorService) { this.debugLog(`${this.device.deviceType}: ${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`; + const lightSensorService = `${accessory.displayName} Light Sensor`; + (this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor) + || this.accessory.addService(this.platform.Service.LightSensor)), lightSensorService; this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`); this.lightSensorService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Light Sensor`); @@ -303,6 +290,7 @@ export class Hub { // FirmwareRevision this.FirmwareRevision = this.OpenAPI_FirmwareRevision!; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; } async refreshStatus(): Promise { @@ -412,25 +400,6 @@ export class Hub { } } - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - - if (!this.device.hub?.hide_humidity) { - this.humidityService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } - if (!this.device.hub?.hide_temperature) { - this.temperatureService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } - if (!this.device.hub?.hide_lightsensor) { - this.lightSensorService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } - // MQTT if (this.device.mqttURL) { this.mqttPublish(`{${mqttmessage.join(',')}}`); @@ -536,7 +505,7 @@ export class Hub { async offlineOff(): Promise { if (this.device.offline) { - await this.context(this.accessory, this.device); + await this.context(); await this.updateHomeKitCharacteristics(); } } @@ -571,28 +540,7 @@ export class Hub { return this.set_maxLux; } - async setFirmwareRevision(accessory: PlatformAccessory, device: device & devicesConfig) { - await this.refreshStatus(); - if (device.firmware) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`); - accessory.context.FirmwareRevision = device.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - - async context(accessory, device) { + async context() { if (this.CurrentRelativeHumidity === undefined) { this.CurrentRelativeHumidity = 0; } else { @@ -610,9 +558,7 @@ export class Hub { } if (this.FirmwareRevision === undefined) { this.FirmwareRevision = this.platform.version; - } else { - this.setFirmwareRevision(accessory, device); - this.FirmwareRevision = this.accessory.context.FirmwareRevision; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; } } diff --git a/src/device/humidifier.ts b/src/device/humidifier.ts index bc240f18..4d9324ec 100644 --- a/src/device/humidifier.ts +++ b/src/device/humidifier.ts @@ -1,5 +1,3 @@ -/* eslint-disable brace-style */ -import { Context } from 'vm'; import { request } from 'undici'; import { sleep } from '../utils'; import { interval, Subject } from 'rxjs'; @@ -81,26 +79,14 @@ export class Humidifier { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, 'W0801800') - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // get the service if it exists, otherwise create a new service // you can create multiple services for each accessory - (this.humidifierService = - accessory.getService(this.platform.Service.HumidifierDehumidifier) || accessory.addService(this.platform.Service.HumidifierDehumidifier)), - `${accessory.displayName} Humidifier`; + const humidifierService = `${accessory.displayName} Humidifier`; + (this.humidifierService = accessory.getService(this.platform.Service.HumidifierDehumidifier) + || accessory.addService(this.platform.Service.HumidifierDehumidifier)), humidifierService; this.humidifierService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); if (!this.humidifierService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -145,9 +131,9 @@ export class Humidifier { accessory.removeService(this.temperatureservice!); } else if (!this.temperatureservice && !this.BLE) { this.debugLog(`${this.device.deviceType}: ${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`; + const temperatureservice = `${accessory.displayName} Temperature Sensor`; + (this.temperatureservice = this.accessory.getService(this.platform.Service.TemperatureSensor) + || this.accessory.addService(this.platform.Service.TemperatureSensor)), temperatureservice; this.temperatureservice.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Temperature Sensor`); if (!this.temperatureservice.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -294,6 +280,7 @@ export class Humidifier { // FirmwareRevision this.FirmwareRevision = this.OpenAPI_FirmwareRevision!; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; } /** @@ -421,9 +408,9 @@ export class Humidifier { async pushChanges(): Promise { if (!this.device.enableCloudService && this.OpenAPI) { this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`); - } /*if (this.BLE) { - await this.BLEpushChanges(); - } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) { + /*} else if (this.BLE) { + await this.BLEpushChanges();*/ + } else if (this.OpenAPI && this.platform.config.credentials?.token) { await this.openAPIpushChanges(); } else { await this.offlineOff(); @@ -747,19 +734,6 @@ export class Humidifier { this.accessory.context.CurrentTemperature = this.CurrentTemperature; } } - - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.humidifierService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - if (!this.device.humidifier?.hide_temperature) { - this.temperatureservice!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } } async stopScanning(switchbot: any) { @@ -895,32 +869,6 @@ export class Humidifier { } } - async setFirmwareRevision(accessory: PlatformAccessory, device: device & devicesConfig) { - await this.refreshStatus(); - if (device.firmware) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else if (device.version) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`); - accessory.context.FirmwareRevision = device.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - async context() { if (this.Active === undefined) { this.Active = this.platform.Characteristic.Active.ACTIVE; @@ -961,6 +909,10 @@ export class Humidifier { } else { this.WaterLevel = this.accessory.context.WaterLevel; } + if (this.FirmwareRevision === undefined) { + this.FirmwareRevision = this.platform.version; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; + } } async refreshRate(device: device & devicesConfig): Promise { diff --git a/src/device/iosensor.ts b/src/device/iosensor.ts index 45f67206..5c58b69e 100644 --- a/src/device/iosensor.ts +++ b/src/device/iosensor.ts @@ -1,4 +1,3 @@ -import { Context } from 'vm'; import { hostname } from 'os'; import { request } from 'undici'; import { sleep } from '../utils'; @@ -89,20 +88,8 @@ export class IOSensor { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, 'WoIOSensor') - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // Temperature Sensor Service if (device.meter?.hide_temperature) { @@ -111,9 +98,9 @@ export class IOSensor { accessory.removeService(this.temperatureservice!); } else if (!this.temperatureservice) { this.debugLog(`${this.device.deviceType}: ${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`; + const temperatureservice = `${accessory.displayName} Temperature Sensor`; + (this.temperatureservice = this.accessory.getService(this.platform.Service.TemperatureSensor) + || this.accessory.addService(this.platform.Service.TemperatureSensor)), temperatureservice; this.temperatureservice.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Temperature Sensor`); if (!this.temperatureservice.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -142,9 +129,9 @@ export class IOSensor { accessory.removeService(this.humidityservice!); } else if (!this.humidityservice) { this.debugLog(`${this.device.deviceType}: ${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`; + const humidityservice = `${accessory.displayName} Humidity Sensor`; + (this.humidityservice = this.accessory.getService(this.platform.Service.HumiditySensor) + || this.accessory.addService(this.platform.Service.HumiditySensor)), humidityservice; this.humidityservice.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Humidity Sensor`); if (!this.humidityservice.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -163,8 +150,9 @@ export class IOSensor { } // Battery Service - (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)), - `${accessory.displayName} Battery`; + const batteryService = `${accessory.displayName} Battery`; + (this.batteryService = this.accessory.getService(this.platform.Service.Battery) + || accessory.addService(this.platform.Service.Battery)), batteryService; this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`); if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -261,10 +249,11 @@ export class IOSensor { this.BatteryLevel = 100; } this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},` - + ` StatusLowBattery: ${this.StatusLowBattery}`); + + ` StatusLowBattery: ${this.StatusLowBattery}`); // FirmwareRevision this.FirmwareRevision = this.OpenAPI_FirmwareRevision!; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; } /** @@ -457,22 +446,6 @@ export class IOSensor { this.historyService?.addEntry(entry); } } - - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.batteryService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - if (this.device.meter?.hide_humidity) { - this.humidityservice!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } - if (this.device.meter?.hide_temperature) { - this.temperatureservice!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } } /* @@ -634,32 +607,6 @@ export class IOSensor { this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e); } - async setFirmwareRevision(accessory: PlatformAccessory, device: device & devicesConfig) { - await this.refreshStatus(); - if (device.firmware) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else if (device.version) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`); - accessory.context.FirmwareRevision = device.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - async context() { if (this.CurrentRelativeHumidity === undefined) { this.CurrentRelativeHumidity = 0; @@ -682,6 +629,10 @@ export class IOSensor { } else { this.StatusLowBattery = this.accessory.context.StatusLowBattery; } + if (this.FirmwareRevision === undefined) { + this.FirmwareRevision = this.platform.version; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; + } } async refreshRate(device: device & devicesConfig): Promise { diff --git a/src/device/lightstrip.ts b/src/device/lightstrip.ts index 7fa6f5f5..7c31b65e 100644 --- a/src/device/lightstrip.ts +++ b/src/device/lightstrip.ts @@ -1,5 +1,3 @@ -/* eslint-disable brace-style */ -import { Context } from 'vm'; import { request } from 'undici'; import { sleep } from '../utils'; import { interval, Subject } from 'rxjs'; @@ -86,25 +84,14 @@ export class StripLight { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, 'W1701100') - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // get the Lightbulb service if it exists, otherwise create a new Lightbulb service // you can create multiple services for each accessory - (this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)), - `${accessory.displayName} ${device.deviceType}`; + const lightBulbService = `${accessory.displayName} ${device.deviceType}`; + (this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) + || accessory.addService(this.platform.Service.Lightbulb)), lightBulbService; if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) { this.accessory.removeService(this.lightBulbService); @@ -289,6 +276,7 @@ export class StripLight { // FirmwareRevision this.FirmwareRevision = this.OpenAPI_FirmwareRevision!; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; } /** @@ -419,9 +407,9 @@ export class StripLight { async pushChanges(): Promise { if (!this.device.enableCloudService && this.OpenAPI) { this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`); - } /*if (this.BLE) { - await this.BLEpushChanges(); - } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) { + /* }else if (this.BLE) { + await this.BLEpushChanges();*/ + } else if (this.OpenAPI && this.platform.config.credentials?.token) { await this.openAPIpushChanges(); } else { await this.offlineOff(); @@ -870,15 +858,6 @@ export class StripLight { this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation); this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`); } - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.lightBulbService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } } async stopScanning(switchbot: any) { @@ -1034,32 +1013,6 @@ export class StripLight { this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, e); } - async setFirmwareRevision(accessory: PlatformAccessory, device: device & devicesConfig) { - await this.refreshStatus(); - if (device.firmware) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else if (device.version) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`); - accessory.context.FirmwareRevision = device.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - async context() { if (this.On === undefined) { this.On = false; @@ -1088,6 +1041,10 @@ export class StripLight { } this.minKelvin = 2000; this.maxKelvin = 9000; + if (this.FirmwareRevision === undefined) { + this.FirmwareRevision = this.platform.version; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; + } } async refreshRate(device: device & devicesConfig): Promise { diff --git a/src/device/lock.ts b/src/device/lock.ts index 91022f0e..547290bc 100644 --- a/src/device/lock.ts +++ b/src/device/lock.ts @@ -1,5 +1,3 @@ -/* eslint-disable brace-style */ -import { Context } from 'vm'; import { request } from 'undici'; import { sleep } from '../utils'; import { interval, Subject } from 'rxjs'; @@ -74,25 +72,14 @@ export class Lock { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, 'W1601700') - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // get the LockMechanism service if it exists, otherwise create a new LockMechanism service // you can create multiple services for each accessory - (this.lockService = accessory.getService(this.platform.Service.LockMechanism) || accessory.addService(this.platform.Service.LockMechanism)), - `${device.deviceName} ${device.deviceType}`; + const lockService = `${accessory.displayName} ${device.deviceType}`; + (this.lockService = accessory.getService(this.platform.Service.LockMechanism) + || accessory.addService(this.platform.Service.LockMechanism)), lockService; this.lockService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); if (!this.lockService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -112,9 +99,9 @@ export class Lock { accessory.removeService(this.contactSensorService!); } else if (!this.contactSensorService) { this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Contact Sensor Service`); - (this.contactSensorService = - this.accessory.getService(this.platform.Service.ContactSensor) || this.accessory.addService(this.platform.Service.ContactSensor)), - `${accessory.displayName} Contact Sensor`; + const contactSensorService = `${accessory.displayName} Contact Sensor`; + (this.contactSensorService = this.accessory.getService(this.platform.Service.ContactSensor) + || this.accessory.addService(this.platform.Service.ContactSensor)), contactSensorService; this.contactSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Contact Sensor`); if (!this.contactSensorService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -125,8 +112,9 @@ export class Lock { } // Battery Service - (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)), - `${accessory.displayName} Battery`; + const batteryService = `${accessory.displayName} Battery`; + (this.batteryService = this.accessory.getService(this.platform.Service.Battery) + || accessory.addService(this.platform.Service.Battery)), batteryService; this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`); if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -173,9 +161,9 @@ export class Lock { async parseStatus(): Promise { if (!this.device.enableCloudService && this.OpenAPI) { this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`); - } /*if (this.BLE) { - await this.BLEparseStatus(); - } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) { + /* } else if (this.BLE) { + await this.BLEparseStatus();*/ + } else if (this.OpenAPI && this.platform.config.credentials?.token) { await this.openAPIparseStatus(); } else { await this.offlineOff(); @@ -251,6 +239,7 @@ export class Lock { // FirmwareRevision this.FirmwareRevision = this.OpenAPI_FirmwareRevision!; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; } /** @@ -380,9 +369,9 @@ export class Lock { async pushChanges(): Promise { if (!this.device.enableCloudService && this.OpenAPI) { this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`); - } /*if (this.BLE) { - await this.BLEpushChanges(); - } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) { + /*} else if (this.BLE) { + await this.BLEpushChanges();*/ + } else if (this.OpenAPI && this.platform.config.credentials?.token) { await this.openAPIpushChanges(); } else { await this.offlineOff(); @@ -542,20 +531,6 @@ export class Lock { this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery); this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`); } - - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.lockService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - this.batteryService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - if (this.device.lock?.hide_contactsensor) { - this.contactSensorService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } } async stopScanning(switchbot: any) { @@ -672,38 +647,16 @@ export class Lock { this.lockService.updateCharacteristic(this.platform.Characteristic.LockCurrentState, e); } - async setFirmwareRevision(accessory: PlatformAccessory, device: device & devicesConfig) { - await this.refreshStatus(); - if (device.firmware) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else if (device.version) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`); - accessory.context.FirmwareRevision = device.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - async context() { if (this.LockTargetState === undefined) { this.LockTargetState = false; } else { this.LockTargetState = this.accessory.context.On; } + if (this.FirmwareRevision === undefined) { + this.FirmwareRevision = this.platform.version; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; + } } async refreshRate(device: device & devicesConfig): Promise { diff --git a/src/device/meter.ts b/src/device/meter.ts index 54a35fd1..954d4f9a 100644 --- a/src/device/meter.ts +++ b/src/device/meter.ts @@ -4,7 +4,6 @@ import { MqttClient } from 'mqtt'; import { hostname } from 'os'; import { interval } from 'rxjs'; import { request } from 'undici'; -import { Context } from 'vm'; import { SwitchBotPlatform } from '../platform'; import { Devices, ad, device, deviceStatus, devicesConfig, serviceData, temperature } from '../settings'; import { sleep } from '../utils'; @@ -78,20 +77,8 @@ export class Meter { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, 'METERTH-S1') - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // Temperature Sensor Service if (device.meter?.hide_temperature) { @@ -100,9 +87,9 @@ export class Meter { accessory.removeService(this.temperatureService!); } else if (!this.temperatureService) { this.debugLog(`${this.device.deviceType}: ${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`; + const temperatureService = `${accessory.displayName} Temperature Sensor`; + (this.temperatureService = this.accessory.getService(this.platform.Service.TemperatureSensor) + || this.accessory.addService(this.platform.Service.TemperatureSensor)), temperatureService; this.temperatureService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Temperature Sensor`); if (!this.temperatureService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -131,9 +118,9 @@ export class Meter { accessory.removeService(this.humidityService!); } else if (!this.humidityService) { this.debugLog(`${this.device.deviceType}: ${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`; + const humidityService = `${accessory.displayName} Humidity Sensor`; + (this.humidityService = this.accessory.getService(this.platform.Service.HumiditySensor) + || this.accessory.addService(this.platform.Service.HumiditySensor)), humidityService; this.humidityService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Humidity Sensor`); if (!this.humidityService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -152,8 +139,9 @@ export class Meter { } // Battery Service - (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)), - `${accessory.displayName} Battery`; + const batteryService = `${accessory.displayName} Battery`; + (this.batteryService = this.accessory.getService(this.platform.Service.Battery) + || accessory.addService(this.platform.Service.Battery)), batteryService; this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`); if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -250,10 +238,11 @@ export class Meter { this.BatteryLevel = 100; } this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},` - + ` StatusLowBattery: ${this.StatusLowBattery}`); + + ` StatusLowBattery: ${this.StatusLowBattery}`); // FirmwareRevision this.FirmwareRevision = this.OpenAPI_FirmwareRevision!; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; } /** @@ -399,7 +388,7 @@ export class Meter { this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity; this.humidityService?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity); this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` - + `updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`); + + `updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`); } } // CurrentTemperature @@ -439,24 +428,6 @@ export class Meter { this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery); this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`); } - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - if (this.device.mqttURL) { - mqttmessage.push(`"FirmwareRevision": ${this.FirmwareRevision}`); - } - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.batteryService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - if (!this.device.meter?.hide_humidity) { - this.humidityService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } - if (!this.device.meter?.hide_temperature) { - this.temperatureService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } // MQTT if (this.device.mqttURL) { @@ -629,32 +600,6 @@ export class Meter { this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e); } - async setFirmwareRevision(accessory: PlatformAccessory, device: device & devicesConfig) { - await this.refreshStatus(); - if (device.firmware) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else if (device.version) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`); - accessory.context.FirmwareRevision = device.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - async context() { if (this.CurrentRelativeHumidity === undefined) { this.CurrentRelativeHumidity = 0; @@ -677,6 +622,10 @@ export class Meter { } else { this.StatusLowBattery = this.accessory.context.StatusLowBattery; } + if (this.FirmwareRevision === undefined) { + this.FirmwareRevision = this.platform.version; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; + } } async refreshRate(device: device & devicesConfig): Promise { diff --git a/src/device/meterplus.ts b/src/device/meterplus.ts index 75e01673..607599a2 100644 --- a/src/device/meterplus.ts +++ b/src/device/meterplus.ts @@ -4,7 +4,6 @@ import { MqttClient } from 'mqtt'; import { hostname } from 'os'; import { interval } from 'rxjs'; import { request } from 'undici'; -import { Context } from 'vm'; import { SwitchBotPlatform } from '../platform'; import { Devices, ad, device, deviceStatus, devicesConfig, serviceData, temperature } from '../settings'; import { sleep } from '../utils'; @@ -67,7 +66,7 @@ export class MeterPlus { this.logs(device); this.scan(device); this.refreshRate(device); - this.context(accessory, device); + this.context(); this.setupHistoryService(device); this.setupMqtt(device); this.config(device); @@ -80,20 +79,8 @@ export class MeterPlus { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, this.model(device)) - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // Temperature Sensor Service if (device.meter?.hide_temperature) { @@ -102,9 +89,9 @@ export class MeterPlus { accessory.removeService(this.temperatureService!); } else if (!this.temperatureService) { this.debugLog(`${this.device.deviceType}: ${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`; + const temperatureService = `${accessory.displayName} Temperature Sensor`; + (this.temperatureService = this.accessory.getService(this.platform.Service.TemperatureSensor) + || this.accessory.addService(this.platform.Service.TemperatureSensor)), temperatureService; this.temperatureService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Temperature Sensor`); if (!this.temperatureService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -133,9 +120,9 @@ export class MeterPlus { accessory.removeService(this.humidityService!); } else if (!this.humidityService) { this.debugLog(`${this.device.deviceType}: ${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`; + const humidityService = `${accessory.displayName} Humidity Sensor`; + (this.humidityService = this.accessory.getService(this.platform.Service.HumiditySensor) + || this.accessory.addService(this.platform.Service.HumiditySensor)), humidityService; this.humidityService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Humidity Sensor`); if (!this.humidityService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -154,8 +141,9 @@ export class MeterPlus { } // Battery Service - (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)), - `${accessory.displayName} Battery`; + const batteryService = `${accessory.displayName} Battery`; + (this.batteryService = this.accessory.getService(this.platform.Service.Battery) + || accessory.addService(this.platform.Service.Battery)), batteryService; this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`); if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -252,10 +240,11 @@ export class MeterPlus { this.BatteryLevel = 100; } this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},` - + ` StatusLowBattery: ${this.StatusLowBattery}`); + + ` StatusLowBattery: ${this.StatusLowBattery}`); // FirmwareRevision this.FirmwareRevision = this.OpenAPI_FirmwareRevision!; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; } /** @@ -444,25 +433,6 @@ export class MeterPlus { this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery); this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`); } - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - if (this.device.mqttURL) { - mqttmessage.push(`"FirmwareRevision": ${this.FirmwareRevision}`); - } - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - - this.batteryService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - if (!this.device.meter?.hide_humidity) { - this.humidityService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } - if (!this.device.meter?.hide_temperature) { - this.temperatureService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } // MQTT if (this.device.mqttURL) { @@ -629,7 +599,7 @@ export class MeterPlus { async offlineOff(): Promise { if (this.device.offline) { - await this.context(this.accessory, this.device); + await this.context(); await this.updateHomeKitCharacteristics(); } } @@ -645,28 +615,7 @@ export class MeterPlus { this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e); } - async setFirmwareRevision(accessory: PlatformAccessory, device: device & devicesConfig) { - await this.refreshStatus(); - if (device.firmware) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`); - accessory.context.FirmwareRevision = device.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - - async context(accessory, device) { + async context() { if (this.CurrentRelativeHumidity === undefined) { this.CurrentRelativeHumidity = 0; } else { @@ -690,9 +639,7 @@ export class MeterPlus { } if (this.FirmwareRevision === undefined) { this.FirmwareRevision = this.platform.version; - } else { - this.setFirmwareRevision(accessory, device); - this.FirmwareRevision = this.accessory.context.FirmwareRevision; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; } } diff --git a/src/device/motion.ts b/src/device/motion.ts index f364aca2..2d000192 100644 --- a/src/device/motion.ts +++ b/src/device/motion.ts @@ -1,4 +1,3 @@ -import { Context } from 'vm'; import { request } from 'undici'; import { sleep } from '../utils'; import { interval, Subject } from 'rxjs'; @@ -79,25 +78,14 @@ export class Motion { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, 'W1101500') - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // get the Battery service if it exists, otherwise create a new Motion service // you can create multiple services for each accessory - (this.motionSensorService = accessory.getService(this.platform.Service.MotionSensor) || accessory.addService(this.platform.Service.MotionSensor)), - `${accessory.displayName} Motion Sensor`; + const motionSensorService = `${accessory.displayName} Motion Sensor`; + (this.motionSensorService = accessory.getService(this.platform.Service.MotionSensor) + || accessory.addService(this.platform.Service.MotionSensor)), motionSensorService; this.motionSensorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); if (!this.motionSensorService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -113,9 +101,9 @@ export class Motion { accessory.removeService(this.lightSensorService!); } else if (!this.lightSensorService) { this.debugLog(`${this.device.deviceType}: ${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`; + const lightSensorService = `${accessory.displayName} Light Sensor`; + (this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor) + || this.accessory.addService(this.platform.Service.LightSensor)), lightSensorService; this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`); this.lightSensorService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Light Sensor`); @@ -124,8 +112,9 @@ export class Motion { } // Battery Service - (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)), - `${accessory.displayName} Battery`; + const batteryService = `${accessory.displayName} Battery`; + (this.batteryService = this.accessory.getService(this.platform.Service.Battery) + || accessory.addService(this.platform.Service.Battery)), batteryService; this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`); if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -236,10 +225,11 @@ export class Motion { this.BatteryLevel = 100; } this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},` - + ` StatusLowBattery: ${this.StatusLowBattery}`); + + ` StatusLowBattery: ${this.StatusLowBattery}`); // FirmwareRevision this.FirmwareRevision = this.OpenAPI_FirmwareRevision!; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; } /** @@ -412,19 +402,6 @@ export class Motion { ); } } - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.motionSensorService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - this.batteryService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - if (!this.device.motion?.hide_lightsensor) { - this.lightSensorService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - } - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } } async stopScanning(switchbot: any) { @@ -573,32 +550,6 @@ export class Motion { } } - async setFirmwareRevision(accessory: PlatformAccessory, device: device & devicesConfig) { - await this.refreshStatus(); - if (device.firmware) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else if (device.version) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`); - accessory.context.FirmwareRevision = device.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - async context() { if (this.MotionDetected === undefined) { this.MotionDetected = false; diff --git a/src/device/plug.ts b/src/device/plug.ts index 0c4d785b..53883af7 100644 --- a/src/device/plug.ts +++ b/src/device/plug.ts @@ -1,4 +1,3 @@ -import { Context } from 'vm'; import { request } from 'undici'; import { sleep } from '../utils'; import { interval, Subject } from 'rxjs'; @@ -60,25 +59,14 @@ export class Plug { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, this.model(device)) - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // get the Outlet service if it exists, otherwise create a new Outlet service // you can create multiple services for each accessory - (this.outletService = accessory.getService(this.platform.Service.Outlet) || accessory.addService(this.platform.Service.Outlet)), - `${device.deviceName} ${device.deviceType}`; + const outletService = `${accessory.displayName} ${device.deviceType}`; + (this.outletService = accessory.getService(this.platform.Service.Outlet) + || accessory.addService(this.platform.Service.Outlet)), outletService; this.outletService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); if (!this.outletService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -167,6 +155,7 @@ export class Plug { // FirmwareRevision this.FirmwareRevision = this.OpenAPI_FirmwareRevision!; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; } /** @@ -435,15 +424,6 @@ export class Plug { this.outletService.updateCharacteristic(this.platform.Characteristic.On, this.On); this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`); } - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.outletService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } } async stopScanning(switchbot: any) { @@ -597,32 +577,6 @@ export class Plug { this.outletService.updateCharacteristic(this.platform.Characteristic.On, e); } - async setFirmwareRevision(accessory: PlatformAccessory, device: device & devicesConfig) { - await this.refreshStatus(); - if (device.firmware) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else if (device.version) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`); - accessory.context.FirmwareRevision = device.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - async context() { if (this.On === undefined) { this.On = false; diff --git a/src/device/robotvacuumcleaner.ts b/src/device/robotvacuumcleaner.ts index a1f4e575..0c90c9f6 100644 --- a/src/device/robotvacuumcleaner.ts +++ b/src/device/robotvacuumcleaner.ts @@ -1,5 +1,3 @@ -/* eslint-disable brace-style */ -import { Context } from 'vm'; import { request } from 'undici'; import { sleep } from '../utils'; import { interval, Subject } from 'rxjs'; @@ -68,25 +66,14 @@ export class RobotVacuumCleaner { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, this.model(device)) - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // get the Lightbulb service if it exists, otherwise create a new Lightbulb service // you can create multiple services for each accessory - (this.robotVacuumCleanerService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)), - `${device.deviceName} ${device.deviceType}`; + const robotVacuumCleanerService = `${accessory.displayName} ${device.deviceType}`; + (this.robotVacuumCleanerService = accessory.getService(this.platform.Service.Lightbulb) + || accessory.addService(this.platform.Service.Lightbulb)), robotVacuumCleanerService; this.robotVacuumCleanerService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); if (!this.robotVacuumCleanerService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -114,8 +101,9 @@ export class RobotVacuumCleaner { .onSet(this.BrightnessSet.bind(this)); // Battery Service - (this.batteryService = this.accessory.getService(this.platform.Service.Battery) || accessory.addService(this.platform.Service.Battery)), - `${accessory.displayName} Battery`; + const batteryService = `${accessory.displayName} Battery`; + (this.batteryService = this.accessory.getService(this.platform.Service.Battery) + || accessory.addService(this.platform.Service.Battery)), batteryService; this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`); if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -166,9 +154,9 @@ export class RobotVacuumCleaner { async parseStatus(): Promise { if (!this.device.enableCloudService && this.OpenAPI) { this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`); - } /*if (this.BLE) { - await this.BLEparseStatus(); - } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) { + /*} else if (this.BLE) { + await this.BLEparseStatus();*/ + } else if (this.OpenAPI && this.platform.config.credentials?.token) { await this.openAPIparseStatus(); } else { await this.offlineOff(); @@ -213,6 +201,7 @@ export class RobotVacuumCleaner { // FirmwareRevision this.FirmwareRevision = this.OpenAPI_FirmwareRevision!; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; } /** @@ -221,9 +210,9 @@ export class RobotVacuumCleaner { async refreshStatus(): Promise { if (!this.device.enableCloudService && this.OpenAPI) { this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`); - } /*if (this.BLE) { - await this.BLERefreshStatus(); - } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) { + /*} else if (this.BLE) { + await this.BLERefreshStatus();*/ + } else if (this.OpenAPI && this.platform.config.credentials?.token) { await this.openAPIRefreshStatus(); } else { await this.offlineOff(); @@ -341,9 +330,9 @@ export class RobotVacuumCleaner { async pushChanges(): Promise { if (!this.device.enableCloudService && this.OpenAPI) { this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges enableCloudService: ${this.device.enableCloudService}`); - } /* if (this.BLE) { - await this.BLEpushChanges(); - } else*/ else if (this.OpenAPI && this.platform.config.credentials?.token) { + /*} else if (this.BLE) { + await this.BLEpushChanges();*/ + } else if (this.OpenAPI && this.platform.config.credentials?.token) { await this.openAPIpushChanges(); } else { await this.offlineOff(); @@ -599,16 +588,6 @@ export class RobotVacuumCleaner { this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery); this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`); } - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.batteryService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - this.robotVacuumCleanerService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } } async stopScanning(switchbot: any) { @@ -761,32 +740,6 @@ export class RobotVacuumCleaner { this.robotVacuumCleanerService.updateCharacteristic(this.platform.Characteristic.On, e); } - async setFirmwareRevision(accessory: PlatformAccessory, device: device & devicesConfig) { - await this.refreshStatus(); - if (device.firmware) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else if (device.version) { - this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`); - accessory.context.FirmwareRevision = device.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - async context() { if (this.On === undefined) { this.On = false; diff --git a/src/irdevice/airconditioner.ts b/src/irdevice/airconditioner.ts index bfdbbb81..16659599 100644 --- a/src/irdevice/airconditioner.ts +++ b/src/irdevice/airconditioner.ts @@ -62,25 +62,14 @@ export class AirConditioner { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, device.remoteType) - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // get the Television service if it exists, otherwise create a new Television service // you can create multiple services for each accessory - (this.coolerService = accessory.getService(this.platform.Service.HeaterCooler) || accessory.addService(this.platform.Service.HeaterCooler)), - `${accessory.displayName} ${device.remoteType}`; + const coolerService = `${accessory.displayName} ${device.remoteType}`; + (this.coolerService = accessory.getService(this.platform.Service.HeaterCooler) + || accessory.addService(this.platform.Service.HeaterCooler)), coolerService; this.coolerService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); if (!this.coolerService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -524,16 +513,6 @@ export class AirConditioner { `${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic ThresholdTemperature: ${this.ThresholdTemperature}`, ); } - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.accessory.getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } } async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise { @@ -641,26 +620,6 @@ export class AirConditioner { this.coolerService.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, e); } - async setFirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig) { - if (device.firmware) { - this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - async context(): Promise { if (this.Active === undefined) { this.Active = this.platform.Characteristic.Active.INACTIVE; @@ -703,6 +662,10 @@ export class AirConditioner { this.CurrentRelativeHumidity = this.CurrentRelativeHumidity || this.accessory.context.CurrentRelativeHumidity; } } + if (this.FirmwareRevision === undefined) { + this.FirmwareRevision = this.platform.version; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; + } } async config(device: irdevice & irDevicesConfig): Promise { diff --git a/src/irdevice/airpurifier.ts b/src/irdevice/airpurifier.ts index ba3749f7..8cefb865 100644 --- a/src/irdevice/airpurifier.ts +++ b/src/irdevice/airpurifier.ts @@ -56,25 +56,14 @@ export class AirPurifier { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, device.remoteType) - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // get the Television service if it exists, otherwise create a new Television service // you can create multiple services for each accessory - (this.airPurifierService = accessory.getService(this.platform.Service.AirPurifier) || accessory.addService(this.platform.Service.AirPurifier)), - `${accessory.displayName} Air Purifier`; + const airPurifierService = `${accessory.displayName} Air Purifier`; + (this.airPurifierService = accessory.getService(this.platform.Service.AirPurifier) + || accessory.addService(this.platform.Service.AirPurifier)), airPurifierService; this.airPurifierService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); if (!this.airPurifierService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -283,16 +272,6 @@ export class AirPurifier { ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`, ); } - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.accessory.getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } } async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise { @@ -388,28 +367,6 @@ export class AirPurifier { this.airPurifierService.updateCharacteristic(this.platform.Characteristic.Active, e); } - - - async setFirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig) { - if (device.firmware) { - this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - private context() { if (this.Active === undefined) { this.Active = this.platform.Characteristic.Active.INACTIVE; @@ -421,6 +378,10 @@ export class AirPurifier { } else { this.CurrentTemperature = this.accessory.context.CurrentTemperature; } + if (this.FirmwareRevision === undefined) { + this.FirmwareRevision = this.platform.version; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; + } } async config(device: irdevice & irDevicesConfig): Promise { diff --git a/src/irdevice/camera.ts b/src/irdevice/camera.ts index 30ee550a..0f73c38c 100644 --- a/src/irdevice/camera.ts +++ b/src/irdevice/camera.ts @@ -38,25 +38,14 @@ export class Camera { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, device.remoteType) - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // get the Television service if it exists, otherwise create a new Television service // you can create multiple services for each accessory - (this.switchService = accessory.getService(this.platform.Service.Switch) || accessory.addService(this.platform.Service.Switch)), - `${accessory.displayName} Camera`; + const switchService = `${accessory.displayName} Camera`; + (this.switchService = accessory.getService(this.platform.Service.Switch) + || accessory.addService(this.platform.Service.Switch)), switchService; this.switchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); if (!this.switchService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -167,16 +156,6 @@ export class Camera { this.switchService?.updateCharacteristic(this.platform.Characteristic.On, this.On); this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`); } - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.accessory.getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } } async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise { @@ -269,34 +248,16 @@ export class Camera { this.switchService.updateCharacteristic(this.platform.Characteristic.On, e); } - - - async setFirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig) { - if (device.firmware) { - this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - async context() { if (this.On === undefined) { this.On = false; } else { this.On = this.accessory.context.On; } + if (this.FirmwareRevision === undefined) { + this.FirmwareRevision = this.platform.version; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; + } } async config(device: irdevice & irDevicesConfig): Promise { diff --git a/src/irdevice/fan.ts b/src/irdevice/fan.ts index 53635307..fb92d320 100644 --- a/src/irdevice/fan.ts +++ b/src/irdevice/fan.ts @@ -45,25 +45,14 @@ export class Fan { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, device.remoteType) - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // get the Television service if it exists, otherwise create a new Television service // you can create multiple services for each accessory - (this.fanService = accessory.getService(this.platform.Service.Fanv2) || accessory.addService(this.platform.Service.Fanv2)), - `${accessory.displayName} Fan`; + const fanService = `${accessory.displayName} Fan`; + (this.fanService = accessory.getService(this.platform.Service.Fanv2) + || accessory.addService(this.platform.Service.Fanv2)), fanService; this.fanService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); if (!this.fanService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -297,16 +286,6 @@ export class Fan { this.fanService?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed); this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`); } - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.accessory.getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } } async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise { @@ -401,34 +380,16 @@ export class Fan { this.fanService.updateCharacteristic(this.platform.Characteristic.SwingMode, e); } - - - async setFirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig) { - if (device.firmware) { - this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - async context() { if (this.Active === undefined) { this.Active = this.platform.Characteristic.Active.INACTIVE; } else { this.Active = this.accessory.context.Active; } + if (this.FirmwareRevision === undefined) { + this.FirmwareRevision = this.platform.version; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; + } } async config(device: irdevice & irDevicesConfig): Promise { diff --git a/src/irdevice/light.ts b/src/irdevice/light.ts index 4c64015f..7a33c2b6 100644 --- a/src/irdevice/light.ts +++ b/src/irdevice/light.ts @@ -38,25 +38,14 @@ export class Light { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, device.remoteType) - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // get the Light service if it exists, otherwise create a new Light service // you can create multiple services for each accessory - (this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)), - `${accessory.displayName} ${device.remoteType}`; + const lightBulbService = `${accessory.displayName} ${device.remoteType}`; + (this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) + || accessory.addService(this.platform.Service.Lightbulb)), lightBulbService; this.lightBulbService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); if (!this.lightBulbService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -192,16 +181,6 @@ export class Light { this.lightBulbService?.updateCharacteristic(this.platform.Characteristic.On, this.On); this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`); } - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.accessory.getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } } async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise { @@ -294,34 +273,16 @@ export class Light { this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, e); } - - - async setFirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig) { - if (device.firmware) { - this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - async context() { if (this.On === undefined) { this.On = false; } else { this.On = this.accessory.context.On; } + if (this.FirmwareRevision === undefined) { + this.FirmwareRevision = this.platform.version; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; + } } async config(device: irdevice & irDevicesConfig): Promise { diff --git a/src/irdevice/other.ts b/src/irdevice/other.ts index c705abca..eb438c03 100644 --- a/src/irdevice/other.ts +++ b/src/irdevice/other.ts @@ -49,20 +49,8 @@ export class Others { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, device.remoteType) - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // deviceType if (this.otherDeviceType === 'switch') { @@ -77,8 +65,9 @@ export class Others { this.removeStatefulProgrammableSwitchService(accessory); // Add switchService - (this.switchService = accessory.getService(this.platform.Service.Switch) || accessory.addService(this.platform.Service.Switch)), - `${accessory.displayName} Switch`; + const switchService = `${accessory.displayName} Switch`; + (this.switchService = accessory.getService(this.platform.Service.Switch) + || accessory.addService(this.platform.Service.Switch)), switchService; this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Switch`); this.switchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); @@ -97,10 +86,10 @@ export class Others { this.removeWindowCoveringService(accessory); this.removeStatefulProgrammableSwitchService(accessory); - // Add switchService - (this.garageDoorService = - accessory.getService(this.platform.Service.GarageDoorOpener) || accessory.addService(this.platform.Service.GarageDoorOpener)), - `${accessory.displayName} Garage Door Opener`; + // Add garageDoorService + const garageDoorService = `${accessory.displayName} Garage Door Opener`; + (this.garageDoorService = accessory.getService(this.platform.Service.GarageDoorOpener) + || accessory.addService(this.platform.Service.GarageDoorOpener)), garageDoorService; this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Garage Door Opener`); this.garageDoorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); @@ -120,9 +109,10 @@ export class Others { this.removeWindowCoveringService(accessory); this.removeStatefulProgrammableSwitchService(accessory); - // Add switchService - (this.doorService = accessory.getService(this.platform.Service.Door) || accessory.addService(this.platform.Service.Door)), - `${accessory.displayName} Door`; + // Add doorService + const doorService = `${accessory.displayName} Door`; + (this.doorService = accessory.getService(this.platform.Service.Door) + || accessory.addService(this.platform.Service.Door)), doorService; this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Door`); this.doorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); @@ -150,9 +140,10 @@ export class Others { this.removeWindowCoveringService(accessory); this.removeStatefulProgrammableSwitchService(accessory); - // Add switchService - (this.windowService = accessory.getService(this.platform.Service.Window) || accessory.addService(this.platform.Service.Window)), - `${accessory.displayName} Window`; + // Add windowService + const windowService = `${accessory.displayName} Window`; + (this.windowService = accessory.getService(this.platform.Service.Window) + || accessory.addService(this.platform.Service.Window)), windowService; this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Window`); this.windowService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); @@ -180,10 +171,10 @@ export class Others { this.removeGarageDoorService(accessory); this.removeStatefulProgrammableSwitchService(accessory); - // Add switchService - (this.windowCoveringService = - accessory.getService(this.platform.Service.WindowCovering) || accessory.addService(this.platform.Service.WindowCovering)), - `${accessory.displayName} Window Covering`; + // Add windowCoveringService + const windowCoveringService = `${accessory.displayName} Window Covering`; + (this.windowCoveringService = accessory.getService(this.platform.Service.WindowCovering) + || accessory.addService(this.platform.Service.WindowCovering)), windowCoveringService; this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Window Covering`); this.windowCoveringService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); @@ -211,9 +202,10 @@ export class Others { this.removeWindowCoveringService(accessory); this.removeStatefulProgrammableSwitchService(accessory); - // Add switchService - (this.lockService = accessory.getService(this.platform.Service.LockMechanism) || accessory.addService(this.platform.Service.LockMechanism)), - `${accessory.displayName} Lock`; + // Add lockService + const lockService = `${accessory.displayName} Lock`; + (this.lockService = accessory.getService(this.platform.Service.LockMechanism) + || accessory.addService(this.platform.Service.LockMechanism)), lockService; this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Lock`); this.lockService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); @@ -232,9 +224,10 @@ export class Others { this.removeWindowCoveringService(accessory); this.removeStatefulProgrammableSwitchService(accessory); - // Add switchService - (this.faucetService = accessory.getService(this.platform.Service.Faucet) || accessory.addService(this.platform.Service.Faucet)), - `${accessory.displayName} Faucet`; + // Add faucetService + const faucetService = `${accessory.displayName} Faucet`; + (this.faucetService = accessory.getService(this.platform.Service.Faucet) + || accessory.addService(this.platform.Service.Faucet)), faucetService; this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Faucet`); this.faucetService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); @@ -253,9 +246,10 @@ export class Others { this.removeWindowCoveringService(accessory); this.removeStatefulProgrammableSwitchService(accessory); - // Add switchService - (this.fanService = accessory.getService(this.platform.Service.Fan) || accessory.addService(this.platform.Service.Fan)), - `${accessory.displayName} Fan`; + // Add fanService + const fanService = `${accessory.displayName} Fan`; + (this.fanService = accessory.getService(this.platform.Service.Fan) + || accessory.addService(this.platform.Service.Fan)), fanService; this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Fan`); this.fanService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); @@ -274,11 +268,10 @@ export class Others { this.removeGarageDoorService(accessory); this.removeWindowCoveringService(accessory); - // Add switchService - (this.statefulProgrammableSwitchService = - accessory.getService(this.platform.Service.StatefulProgrammableSwitch) || - accessory.addService(this.platform.Service.StatefulProgrammableSwitch)), - `${accessory.displayName} Stateful Programmable Switch`; + // Add statefulProgrammableSwitchService + const statefulProgrammableSwitchService = `${accessory.displayName} Stateful Programmable Switch`; + (this.statefulProgrammableSwitchService = accessory.getService(this.platform.Service.StatefulProgrammableSwitch) + || accessory.addService(this.platform.Service.StatefulProgrammableSwitch)), statefulProgrammableSwitchService; this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Stateful Programmable Switch`); this.statefulProgrammableSwitchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); @@ -300,8 +293,9 @@ export class Others { this.removeStatefulProgrammableSwitchService(accessory); // Add outletService - (this.outletService = accessory.getService(this.platform.Service.Outlet) || accessory.addService(this.platform.Service.Outlet)), - `${accessory.displayName} Outlet`; + const outletService = `${accessory.displayName} Outlet`; + (this.outletService = accessory.getService(this.platform.Service.Outlet) + || accessory.addService(this.platform.Service.Outlet)), outletService; this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Outlet`); this.outletService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); @@ -646,16 +640,6 @@ export class Others { this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`); } } - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.accessory.getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } } async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise { @@ -885,34 +869,16 @@ export class Others { } } - - - async setFirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig) { - if (device.firmware) { - this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - async context() { if (this.On === undefined) { this.On = true; } else { this.On = this.accessory.context.On; } + if (this.FirmwareRevision === undefined) { + this.FirmwareRevision = this.platform.version; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; + } } async config(device: irdevice & irDevicesConfig): Promise { diff --git a/src/irdevice/tv.ts b/src/irdevice/tv.ts index aa645868..0b259b1b 100644 --- a/src/irdevice/tv.ts +++ b/src/irdevice/tv.ts @@ -43,50 +43,39 @@ export class TV { .setCharacteristic(this.platform.Characteristic.Name, `${device.deviceName} ${device.remoteType}`) .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, device.remoteType) - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // set the accessory category + const tvServiceCategory = `${accessory.displayName} ${device.remoteType}`; switch (device.remoteType) { case 'Speaker': case 'DIY Speaker': accessory.category = this.platform.api.hap.Categories.SPEAKER; - (this.tvService = accessory.getService(this.platform.Service.Television) || accessory.addService(this.platform.Service.Television)), - `${accessory.displayName} ${device.remoteType}`; + (this.tvService = accessory.getService(this.platform.Service.Television) + || accessory.addService(this.platform.Service.Television)), tvServiceCategory; break; case 'IPTV': case 'DIY IPTV': accessory.category = this.platform.api.hap.Categories.TV_STREAMING_STICK; - (this.tvService = accessory.getService(this.platform.Service.Television) || accessory.addService(this.platform.Service.Television)), - `${accessory.displayName} ${device.remoteType}`; + (this.tvService = accessory.getService(this.platform.Service.Television) + || accessory.addService(this.platform.Service.Television)), tvServiceCategory; break; case 'DVD': case 'DIY DVD': case 'Set Top Box': case 'DIY Set Top Box': accessory.category = this.platform.api.hap.Categories.TV_SET_TOP_BOX; - (this.tvService = accessory.getService(this.platform.Service.Television) || accessory.addService(this.platform.Service.Television)), - `${accessory.displayName} ${device.remoteType}`; + (this.tvService = accessory.getService(this.platform.Service.Television) + || accessory.addService(this.platform.Service.Television)), tvServiceCategory; break; default: accessory.category = this.platform.api.hap.Categories.TELEVISION; // get the Television service if it exists, otherwise create a new Television service // you can create multiple services for each accessory - (this.tvService = accessory.getService(this.platform.Service.Television) || accessory.addService(this.platform.Service.Television)), - `${accessory.displayName} ${device.remoteType}`; + (this.tvService = accessory.getService(this.platform.Service.Television) + || accessory.addService(this.platform.Service.Television)), tvServiceCategory; } this.tvService.getCharacteristic(this.platform.Characteristic.ConfiguredName); @@ -112,9 +101,9 @@ export class TV { * Create a speaker service to allow volume control */ // create a new Television Speaker service - (this.speakerService = - accessory.getService(this.platform.Service.TelevisionSpeaker) || accessory.addService(this.platform.Service.TelevisionSpeaker)), - `${accessory.displayName} Speaker`; + const speakerService = `${accessory.displayName} Speaker`; + (this.speakerService = accessory.getService(this.platform.Service.TelevisionSpeaker) + || accessory.addService(this.platform.Service.TelevisionSpeaker)), speakerService; this.speakerService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Speaker`); if (!this.speakerService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -424,16 +413,6 @@ export class TV { this.tvService?.updateCharacteristic(this.platform.Characteristic.ActiveIdentifier, this.ActiveIdentifier); this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic ActiveIdentifier: ${this.ActiveIdentifier}`); } - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.accessory.getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } } async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise { @@ -535,28 +514,6 @@ export class TV { this.tvService.updateCharacteristic(this.platform.Characteristic.ActiveIdentifier, e); } - - - async setFirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig) { - if (device.firmware) { - this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - async context() { if (this.Active === undefined) { this.Active = this.platform.Characteristic.Active.INACTIVE; @@ -568,6 +525,10 @@ export class TV { } else { this.ActiveIdentifier = this.accessory.context.ActiveIdentifier; } + if (this.FirmwareRevision === undefined) { + this.FirmwareRevision = this.platform.version; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; + } } async config(device: irdevice & irDevicesConfig): Promise { diff --git a/src/irdevice/vacuumcleaner.ts b/src/irdevice/vacuumcleaner.ts index b9ca55da..8b5a9099 100644 --- a/src/irdevice/vacuumcleaner.ts +++ b/src/irdevice/vacuumcleaner.ts @@ -38,25 +38,14 @@ export class VacuumCleaner { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, device.remoteType) - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // get the Television service if it exists, otherwise create a new Television service // you can create multiple services for each accessory - (this.switchService = accessory.getService(this.platform.Service.Switch) || accessory.addService(this.platform.Service.Switch)), - `${accessory.displayName} ${device.remoteType}`; + const switchService = `${accessory.displayName} ${device.remoteType}`; + (this.switchService = accessory.getService(this.platform.Service.Switch) + || accessory.addService(this.platform.Service.Switch)), switchService; this.switchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); if (!this.switchService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -163,16 +152,6 @@ export class VacuumCleaner { this.switchService?.updateCharacteristic(this.platform.Characteristic.On, this.On); this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`); } - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.accessory.getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } } async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise { @@ -265,34 +244,16 @@ export class VacuumCleaner { this.switchService.updateCharacteristic(this.platform.Characteristic.On, e); } - - - async setFirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig) { - if (device.firmware) { - this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - async context() { if (this.On === undefined) { this.On = false; } else { this.On = this.accessory.context.On; } + if (this.FirmwareRevision === undefined) { + this.FirmwareRevision = this.platform.version; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; + } } async config(device: irdevice & irDevicesConfig): Promise { diff --git a/src/irdevice/waterheater.ts b/src/irdevice/waterheater.ts index 1997c641..46ea58c7 100644 --- a/src/irdevice/waterheater.ts +++ b/src/irdevice/waterheater.ts @@ -38,25 +38,14 @@ export class WaterHeater { .getService(this.platform.Service.AccessoryInformation)! .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot') .setCharacteristic(this.platform.Characteristic.Model, device.remoteType) - .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!); - - if (accessory.context.FirmwareRevision) { - this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName}` - + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(accessory.context.FirmwareRevision); - } else { - this.setFirmwareRevision(accessory, device); - } + .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId) + .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision); // get the Television service if it exists, otherwise create a new Television service // you can create multiple services for each accessory - (this.valveService = accessory.getService(this.platform.Service.Valve) || accessory.addService(this.platform.Service.Valve)), - `${accessory.displayName} ${device.remoteType}`; + const valveService = `${accessory.displayName} ${device.remoteType}`; + (this.valveService = accessory.getService(this.platform.Service.Valve) + || accessory.addService(this.platform.Service.Valve)), valveService; this.valveService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); if (!this.valveService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) { @@ -172,16 +161,6 @@ export class WaterHeater { this.valveService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active); this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`); } - // FirmwareRevision - if (this.FirmwareRevision === undefined) { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.accessory.context.FirmwareRevision = this.FirmwareRevision; - this.accessory.getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision); - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ` - + `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`); - } } async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise { @@ -274,34 +253,16 @@ export class WaterHeater { this.valveService.updateCharacteristic(this.platform.Characteristic.Active, e); } - - - async setFirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig) { - if (device.firmware) { - this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`); - accessory.context.FirmwareRevision = device.firmware; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`); - } else { - this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`); - accessory.context.FirmwareRevision = this.platform.version; - this.FirmwareRevision = accessory.context.FirmwareRevision; - this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`); - } - this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`); - accessory - .getService(this.platform.Service.AccessoryInformation)! - .updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision) - .getCharacteristic(this.platform.Characteristic.FirmwareRevision) - .updateValue(this.FirmwareRevision); - } - async context(): Promise { if (this.Active === undefined) { this.Active = this.platform.Characteristic.Active.INACTIVE; } else { this.Active = this.accessory.context.Active; } + if (this.FirmwareRevision === undefined) { + this.FirmwareRevision = this.platform.version; + this.accessory.context.FirmwareRevision = this.FirmwareRevision; + } } async config(device: irdevice & irDevicesConfig): Promise { diff --git a/src/platform.ts b/src/platform.ts index 1ec64955..68b06cb3 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -46,7 +46,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { // this is used to track restored cached accessories public readonly accessories: PlatformAccessory[] = []; - version = process.env.npm_package_version || '2.1.1'; + version = process.env.npm_package_version || '2.9.0'; debugMode!: boolean; platformLogging?: string; @@ -347,6 +347,10 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { const devices = mergeBydeviceId(deviceLists, deviceConfigs); this.debugLog(`SwitchBot Devices: ${JSON.stringify(devices)}`); for (const device of devices) { + if (!device.deviceType) { + device.deviceType = device.configDeviceType; + this.errorLog(`API has displaying no deviceType: ${device.deviceType}, So using configDeviceType: ${device.configDeviceType}`); + } if (device.deviceType) { if (device.configDeviceName) { device.deviceName = device.configDeviceName; @@ -415,10 +419,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { for (const device of devices) { device.deviceType = device.configDeviceType; device.deviceName = device.configDeviceName; - if (!device.deviceType) { - device.deviceType = device.configDeviceType; - this.errorLog(`API has displaying no deviceType: ${device.deviceType}, So using configDeviceType: ${device.configDeviceType}`); - } if (device.deviceType) { this.createDevice(device); } @@ -604,7 +604,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.deviceType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = await this.connectionType(device); @@ -630,7 +632,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.deviceType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `SwitchBot: ${device.deviceType}`; accessory.context.connectionType = await this.connectionType(device); // create the accessory handler for the newly create accessory @@ -660,7 +664,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.deviceType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = await this.connectionType(device); @@ -686,10 +692,12 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.deviceType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `SwitchBot: ${device.deviceType}`; accessory.context.connectionType = await this.connectionType(device); - // accessory.context.firmwareRevision = findaccessories.accessoryAttribute.softwareRevision; + // accessory.context.FirmwareRevision = findaccessories.accessoryAttribute.softwareRevision; // create the accessory handler for the newly create accessory // this is imported from `platformAccessory.ts` new Bot(this, accessory, device); @@ -717,7 +725,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.deviceType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = await this.connectionType(device); @@ -743,7 +753,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.deviceType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `SwitchBot: ${device.deviceType}`; accessory.context.connectionType = await this.connectionType(device); // create the accessory handler for the newly create accessory @@ -774,7 +786,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.deviceType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = await this.connectionType(device); @@ -800,7 +814,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.deviceType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `SwitchBot: ${device.deviceType}`; accessory.context.connectionType = await this.connectionType(device); // create the accessory handler for the newly create accessory @@ -831,7 +847,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.deviceType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = await this.connectionType(device); @@ -857,7 +875,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.deviceType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `SwitchBot: ${device.deviceType}`; accessory.context.connectionType = await this.connectionType(device); // create the accessory handler for the newly create accessory @@ -887,7 +907,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.deviceType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = await this.connectionType(device); @@ -913,7 +935,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.deviceType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `SwitchBot: ${device.deviceType}`; accessory.context.connectionType = await this.connectionType(device); // create the accessory handler for the newly create accessory @@ -943,7 +967,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.deviceType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = await this.connectionType(device); @@ -969,7 +995,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.deviceType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `SwitchBot: ${device.deviceType}`; accessory.context.connectionType = await this.connectionType(device); // create the accessory handler for the newly create accessory @@ -999,7 +1027,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.deviceType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = await this.connectionType(device); @@ -1025,7 +1055,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.deviceType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `SwitchBot: ${device.deviceType}`; accessory.context.connectionType = await this.connectionType(device); // create the accessory handler for the newly create accessory @@ -1055,7 +1087,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.deviceType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = await this.connectionType(device); @@ -1094,7 +1128,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.deviceType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `SwitchBot: ${device.deviceType}`; accessory.context.connectionType = await this.connectionType(device); // create the accessory handler for the newly create accessory @@ -1124,7 +1160,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.deviceType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = await this.connectionType(device); @@ -1163,7 +1201,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.deviceType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `SwitchBot: ${device.deviceType}`; accessory.context.connectionType = await this.connectionType(device); // create the accessory handler for the newly create accessory @@ -1193,7 +1233,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.deviceType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = await this.connectionType(device); @@ -1219,7 +1261,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.deviceType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `SwitchBot: ${device.deviceType}`; accessory.context.connectionType = await this.connectionType(device); // create the accessory handler for the newly create accessory @@ -1249,7 +1293,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.deviceType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = await this.connectionType(device); @@ -1275,7 +1321,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.deviceType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `SwitchBot: ${device.deviceType}`; accessory.context.connectionType = await this.connectionType(device); // create the accessory handler for the newly create accessory @@ -1305,7 +1353,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.deviceType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = await this.connectionType(device); @@ -1331,7 +1381,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.deviceType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `SwitchBot: ${device.deviceType}`; accessory.context.connectionType = await this.connectionType(device); // create the accessory handler for the newly create accessory @@ -1361,7 +1413,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.deviceType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = await this.connectionType(device); @@ -1387,7 +1441,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.deviceType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `SwitchBot: ${device.deviceType}`; accessory.context.connectionType = await this.connectionType(device); // create the accessory handler for the newly create accessory @@ -1417,7 +1473,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.deviceType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = await this.connectionType(device); @@ -1443,7 +1501,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.deviceType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `SwitchBot: ${device.deviceType}`; accessory.context.connectionType = await this.connectionType(device); // create the accessory handler for the newly create accessory @@ -1473,7 +1533,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.deviceType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `SwitchBot: ${device.deviceType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = await this.connectionType(device); @@ -1499,7 +1561,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.deviceType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `SwitchBot: ${device.deviceType}`; accessory.context.connectionType = await this.connectionType(device); // create the accessory handler for the newly create accessory @@ -1527,7 +1591,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.remoteType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + existingAccessory.context.FirmwareRevision = device.firmware; existingAccessory.context.deviceType = `IR: ${device.remoteType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = device.connectionType; @@ -1550,7 +1614,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.remoteType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `IR: ${device.remoteType}`; accessory.context.connectionType = device.connectionType; // create the accessory handler for the newly create accessory @@ -1579,7 +1645,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.remoteType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `IR: ${device.remoteType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = device.connectionType; @@ -1605,7 +1673,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.remoteType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `IR: ${device.remoteType}`; accessory.context.connectionType = device.connectionType; // create the accessory handler for the newly create accessory @@ -1635,7 +1705,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.remoteType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `IR: ${device.remoteType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = device.connectionType; @@ -1661,7 +1733,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.remoteType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `IR: ${device.remoteType}`; accessory.context.connectionType = device.connectionType; // create the accessory handler for the newly create accessory @@ -1691,7 +1765,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.remoteType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `IR: ${device.remoteType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = device.connectionType; @@ -1717,7 +1793,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.remoteType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `IR: ${device.remoteType}`; accessory.context.connectionType = device.connectionType; // create the accessory handler for the newly create accessory @@ -1747,7 +1825,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.remoteType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `IR: ${device.remoteType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = device.connectionType; @@ -1773,7 +1853,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.remoteType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `IR: ${device.remoteType}`; accessory.context.connectionType = device.connectionType; // create the accessory handler for the newly create accessory @@ -1803,7 +1885,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.remoteType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `IR: ${device.remoteType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = device.connectionType; @@ -1829,7 +1913,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.remoteType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `IR: ${device.remoteType}`; accessory.context.connectionType = device.connectionType; // create the accessory handler for the newly create accessory @@ -1859,7 +1945,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.remoteType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `IR: ${device.remoteType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = device.connectionType; @@ -1885,7 +1973,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.remoteType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `IR: ${device.remoteType}`; accessory.context.connectionType = device.connectionType; // create the accessory handler for the newly create accessory @@ -1915,7 +2005,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.remoteType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `IR: ${device.remoteType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = device.connectionType; @@ -1941,7 +2033,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.remoteType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `IR: ${device.remoteType}`; accessory.context.connectionType = device.connectionType; // create the accessory handler for the newly create accessory @@ -1971,7 +2065,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { existingAccessory.context.model = device.remoteType; existingAccessory.context.deviceID = device.deviceId; existingAccessory.displayName = device.configDeviceName || device.deviceName; - existingAccessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + existingAccessory.context.FirmwareRevision = device.firmware; + } existingAccessory.context.deviceType = `IR: ${device.remoteType}`; this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} DeviceID: ${device.deviceId}`); existingAccessory.context.connectionType = device.connectionType; @@ -1997,7 +2093,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin { accessory.context.device = device; accessory.context.model = device.remoteType; accessory.context.deviceID = device.deviceId; - accessory.context.firmwareRevision = device.firmware; + if (device.firmware) { + accessory.context.FirmwareRevision = device.firmware; + } accessory.context.deviceType = `IR: ${device.remoteType}`; accessory.context.connectionType = device.connectionType; // create the accessory handler for the newly create accessory diff --git a/tsconfig.json b/tsconfig.json index 41b030fc..a08cd3c5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,15 @@ "compilerOptions": { "target": "ES2021", "module": "commonjs", - "lib": ["ES2015", "ES2016", "ES2017", "ES2018", "ES2019", "ES2020", "ES2021"], + "lib": [ + "ES2015", + "ES2016", + "ES2017", + "ES2018", + "ES2019", + "ES2020", + "ES2021" + ], "declaration": true, "declarationMap": true, "sourceMap": true, @@ -12,6 +20,10 @@ "esModuleInterop": true, "noImplicitAny": false }, - "include": ["src/"], - "exclude": ["**/*.spec.ts"] -} + "include": [ + "src/" + ], + "exclude": [ + "**/*.spec.ts" + ] +} \ No newline at end of file