diff --git a/.eslintrc b/.eslintrc index ba9b8ef..5f7846c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -22,7 +22,7 @@ "curly": ["warn", "all"], "brace-style": ["warn"], "prefer-arrow-callback": ["warn"], - "max-len": ["warn", 140], + "max-len": ["warn", 100], "no-console": ["warn"], // use the provided Homebridge log method instead "no-non-null-assertion": ["off"], "comma-spacing": ["error"], diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md index fd51059..1edb406 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.md +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -4,18 +4,20 @@ about: Create a report to help us improve title: '' labels: bug assignees: '' - --- **Describe The Bug:** + **To Reproduce:** + **Expected behavior:** + **Logs:** @@ -31,14 +33,15 @@ Show your Homebridge config.json here, remove any sensitive information. ``` **Screenshots:** + **Environment:** -* **Plugin Version**: -* **Homebridge Version**: -* **Node.js Version**: -* **NPM Version**: -* **Operating System**: +- **Plugin Version**: +- **Homebridge Version**: +- **Node.js Version**: +- **NPM Version**: +- **Operating System**: diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index fe4e429..783e187 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -2,4 +2,4 @@ # contact_links: # - name: Homebridge Discord Community # url: https://discord.gg/kqNCe2D -# about: Ask your questions in the #YOUR_CHANNEL_HERE channel \ No newline at end of file +# about: Ask your questions in the #YOUR_CHANNEL_HERE channel diff --git a/.github/ISSUE_TEMPLATE/feature-request.md b/.github/ISSUE_TEMPLATE/feature-request.md index f974b3b..8b86230 100644 --- a/.github/ISSUE_TEMPLATE/feature-request.md +++ b/.github/ISSUE_TEMPLATE/feature-request.md @@ -4,20 +4,22 @@ about: Suggest an idea for this project title: '' labels: enhancement assignees: '' - --- **Is your feature request related to a problem? Please describe:** + **Describe the solution you'd like:** + **Describe alternatives you've considered:** + **Additional context:** - + diff --git a/.github/ISSUE_TEMPLATE/support-request.md b/.github/ISSUE_TEMPLATE/support-request.md index c64c5ff..187cfd3 100644 --- a/.github/ISSUE_TEMPLATE/support-request.md +++ b/.github/ISSUE_TEMPLATE/support-request.md @@ -4,12 +4,12 @@ about: Need help? title: '' labels: question assignees: '' - --- **Describe Your Problem:** + **Logs:** @@ -25,14 +25,15 @@ Show your Homebridge config.json here, remove any sensitive information. ``` **Screenshots:** + **Environment:** -* **Plugin Version**: -* **Homebridge Version**: -* **Node.js Version**: -* **NPM Version**: -* **Operating System**: +- **Plugin Version**: +- **Homebridge Version**: +- **Node.js Version**: +- **NPM Version**: +- **Operating System**: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f20ccb5..ada9c5c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,7 +15,7 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.node-version }} + - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..7900def --- /dev/null +++ b/.prettierrc @@ -0,0 +1,7 @@ +{ + "semi": true, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "all", + "useTabs": false +} diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index fd1d9bf..0000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "recommendations": [ - "dbaeumer.vscode-eslint" - ] -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 31b20d1..fd69b0a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,11 @@ { + "editor.defaultFormatter": "rvest.vs-code-prettier-eslint", + "editor.formatOnType": false, + "editor.formatOnPaste": true, + "editor.formatOnSave": true, + "editor.formatOnSaveMode": "file", + "editor.rulers": [100], + "files.autoSave": "onFocusChange", "files.eol": "\n", - "editor.codeActionsOnSave": { - "source.fixAll.eslint": true - }, - "editor.rulers": [ 140 ], - "eslint.enable": true -} \ No newline at end of file + "vs-code-prettier-eslint.prettierLast": false +} diff --git a/README.md b/README.md index 427370a..2e0f9f0 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ This template should be used in conjunction with the [developer documentation](h ### Clone As Template -Click the link below to create a new GitHub Repository using this template, or click the *Use This Template* button above. +Click the link below to create a new GitHub Repository using this template, or click the _Use This Template_ button above. @@ -54,7 +54,7 @@ When you are ready to publish the plugin you should set `private` to false, or r Open the [`src/settings.ts`](./src/settings.ts) file and change the default values: - `PLATFORM_NAME` - Set this to be the name of your platform. This is the name of the platform that users will use to register the plugin in the Homebridge `config.json`. -- `PLUGIN_NAME` - Set this to be the same name you set in the [`package.json`](./package.json) file. +- `PLUGIN_NAME` - Set this to be the same name you set in the [`package.json`](./package.json) file. Open the [`config.schema.json`](./config.schema.json) file and change the following attribute: @@ -85,6 +85,7 @@ homebridge -D ### Watch For Changes and Build Automatically If you want to have your code compile automatically as you make changes, and restart Homebridge automatically between changes, you first need to add your plugin as a platform in `~/.homebridge/config.json`: + ``` { ... @@ -152,7 +153,7 @@ If you are publishing a scoped plugin, i.e. `@username/homebridge-xxx` you will #### Publishing Beta Versions -You can publish *beta* versions of your plugin for other users to test before you release it to everyone. +You can publish _beta_ versions of your plugin for other users to test before you release it to everyone. ```shell # create a new pre-release version (eg. 2.1.0-beta.1) @@ -162,13 +163,14 @@ npm version prepatch --preid beta npm publish --tag=beta ``` -Users can then install the *beta* version by appending `@beta` to the install command, for example: +Users can then install the _beta_ version by appending `@beta` to the install command, for example: ```shell sudo npm install -g homebridge-example-plugin@beta ``` ### Best Practices + Consider creating your plugin with the [Homebridge Verified](https://github.com/homebridge/verified) criteria in mind. This will help you to create a plugin that is easy to use and works well with Homebridge. You can then submit your plugin to the Homebridge Verified list for review. The most up-to-date criteria can be found [here](https://github.com/homebridge/verified#requirements). @@ -187,5 +189,7 @@ For reference, the current criteria are: - If the plugin needs to write files to disk (cache, keys, etc.), it must store them inside the Homebridge storage directory. ### Useful Links + Note these links are here for help but are not supported/verified by the Homebridge team + - [Custom Characteristics](https://github.com/homebridge/homebridge-plugin-template/issues/20) diff --git a/config.schema.json b/config.schema.json index 21bd99a..85255df 100644 --- a/config.schema.json +++ b/config.schema.json @@ -1,5 +1,5 @@ { - "pluginAlias": "ExampleHomebridgePlugin", + "pluginAlias": "HomebridgeShortcutsButtons", "pluginType": "platform", "singular": true, "schema": { @@ -13,4 +13,4 @@ } } } -} \ No newline at end of file +} diff --git a/nodemon.json b/nodemon.json index 6dd7df6..0e0e5ba 100644 --- a/nodemon.json +++ b/nodemon.json @@ -1,7 +1,5 @@ { - "watch": [ - "src" - ], + "watch": ["src"], "ext": "ts", "ignore": [], "exec": "tsc && homebridge -I -D", @@ -9,4 +7,4 @@ "env": { "NODE_OPTIONS": "--trace-warnings" } -} \ No newline at end of file +} diff --git a/package-lock.json b/package-lock.json index d9d6534..abbf63b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,20 +1,22 @@ { - "name": "homebridge-plugin-name", - "version": "1.0.0", + "name": "homebridge-shortcuts-buttons", + "version": "0.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "homebridge-plugin-name", - "version": "1.0.0", + "name": "homebridge-shortcuts-buttons", + "version": "0.0.1", "license": "Apache-2.0", "devDependencies": { "@types/node": "^20.12.7", "@typescript-eslint/eslint-plugin": "^7.6.0", - "@typescript-eslint/parser": "^7.6.0", + "@typescript-eslint/parser": "^7.7.0", "eslint": "^8.57.0", "homebridge": "^1.7.0", "nodemon": "^3.1.0", + "prettier": "^3.2.5", + "prettier-eslint": "^16.3.0", "rimraf": "^5.0.5", "ts-node": "^10.9.2", "typescript": "^5.4.5" @@ -273,6 +275,18 @@ "url": "https://github.com/chalk/strip-ansi?sponsor=1" } }, + "node_modules/@jest/schemas": { + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-29.6.3.tgz", + "integrity": "sha512-mo5j5X+jIZmJQveBKeS/clAueipV7KgiX1vMgCxam1RNYiqE1w62n0/tJJnHtjW8ZHcQco5gY85jA3mi0L+nSA==", + "dev": true, + "dependencies": { + "@sinclair/typebox": "^0.27.8" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, "node_modules/@jridgewell/resolve-uri": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", @@ -349,6 +363,12 @@ "node": ">=14" } }, + "node_modules/@sinclair/typebox": { + "version": "0.27.8", + "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", + "integrity": "sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==", + "dev": true + }, "node_modules/@tsconfig/node10": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.11.tgz", @@ -395,16 +415,16 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.6.0.tgz", - "integrity": "sha512-gKmTNwZnblUdnTIJu3e9kmeRRzV2j1a/LUO27KNNAnIC5zjy1aSvXSRp4rVNlmAoHlQ7HzX42NbKpcSr4jF80A==", + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.7.0.tgz", + "integrity": "sha512-GJWR0YnfrKnsRoluVO3PRb9r5aMZriiMMM/RHj5nnTrBy1/wIgk76XCtCKcnXGjpZQJQRFtGV9/0JJ6n30uwpQ==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "7.6.0", - "@typescript-eslint/type-utils": "7.6.0", - "@typescript-eslint/utils": "7.6.0", - "@typescript-eslint/visitor-keys": "7.6.0", + "@typescript-eslint/scope-manager": "7.7.0", + "@typescript-eslint/type-utils": "7.7.0", + "@typescript-eslint/utils": "7.7.0", + "@typescript-eslint/visitor-keys": "7.7.0", "debug": "^4.3.4", "graphemer": "^1.4.0", "ignore": "^5.3.1", @@ -430,15 +450,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.6.0.tgz", - "integrity": "sha512-usPMPHcwX3ZoPWnBnhhorc14NJw9J4HpSXQX4urF2TPKG0au0XhJoZyX62fmvdHONUkmyUe74Hzm1//XA+BoYg==", + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.7.0.tgz", + "integrity": "sha512-fNcDm3wSwVM8QYL4HKVBggdIPAy9Q41vcvC/GtDobw3c4ndVT3K6cqudUmjHPw8EAp4ufax0o58/xvWaP2FmTg==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "7.6.0", - "@typescript-eslint/types": "7.6.0", - "@typescript-eslint/typescript-estree": "7.6.0", - "@typescript-eslint/visitor-keys": "7.6.0", + "@typescript-eslint/scope-manager": "7.7.0", + "@typescript-eslint/types": "7.7.0", + "@typescript-eslint/typescript-estree": "7.7.0", + "@typescript-eslint/visitor-keys": "7.7.0", "debug": "^4.3.4" }, "engines": { @@ -458,13 +478,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.6.0.tgz", - "integrity": "sha512-ngttyfExA5PsHSx0rdFgnADMYQi+Zkeiv4/ZxGYUWd0nLs63Ha0ksmp8VMxAIC0wtCFxMos7Lt3PszJssG/E6w==", + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.7.0.tgz", + "integrity": "sha512-/8INDn0YLInbe9Wt7dK4cXLDYp0fNHP5xKLHvZl3mOT5X17rK/YShXaiNmorl+/U4VKCVIjJnx4Ri5b0y+HClw==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.6.0", - "@typescript-eslint/visitor-keys": "7.6.0" + "@typescript-eslint/types": "7.7.0", + "@typescript-eslint/visitor-keys": "7.7.0" }, "engines": { "node": "^18.18.0 || >=20.0.0" @@ -475,13 +495,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.6.0.tgz", - "integrity": "sha512-NxAfqAPNLG6LTmy7uZgpK8KcuiS2NZD/HlThPXQRGwz6u7MDBWRVliEEl1Gj6U7++kVJTpehkhZzCJLMK66Scw==", + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.7.0.tgz", + "integrity": "sha512-bOp3ejoRYrhAlnT/bozNQi3nio9tIgv3U5C0mVDdZC7cpcQEDZXvq8inrHYghLVwuNABRqrMW5tzAv88Vy77Sg==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "7.6.0", - "@typescript-eslint/utils": "7.6.0", + "@typescript-eslint/typescript-estree": "7.7.0", + "@typescript-eslint/utils": "7.7.0", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, @@ -502,9 +522,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.6.0.tgz", - "integrity": "sha512-h02rYQn8J+MureCvHVVzhl69/GAfQGPQZmOMjG1KfCl7o3HtMSlPaPUAPu6lLctXI5ySRGIYk94clD/AUMCUgQ==", + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.7.0.tgz", + "integrity": "sha512-G01YPZ1Bd2hn+KPpIbrAhEWOn5lQBrjxkzHkWvP6NucMXFtfXoevK82hzQdpfuQYuhkvFDeQYbzXCjR1z9Z03w==", "dev": true, "engines": { "node": "^18.18.0 || >=20.0.0" @@ -515,13 +535,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.6.0.tgz", - "integrity": "sha512-+7Y/GP9VuYibecrCQWSKgl3GvUM5cILRttpWtnAu8GNL9j11e4tbuGZmZjJ8ejnKYyBRb2ddGQ3rEFCq3QjMJw==", + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.7.0.tgz", + "integrity": "sha512-8p71HQPE6CbxIBy2kWHqM1KGrC07pk6RJn40n0DSc6bMOBBREZxSDJ+BmRzc8B5OdaMh1ty3mkuWRg4sCFiDQQ==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.6.0", - "@typescript-eslint/visitor-keys": "7.6.0", + "@typescript-eslint/types": "7.7.0", + "@typescript-eslint/visitor-keys": "7.7.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -543,17 +563,17 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.6.0.tgz", - "integrity": "sha512-x54gaSsRRI+Nwz59TXpCsr6harB98qjXYzsRxGqvA5Ue3kQH+FxS7FYU81g/omn22ML2pZJkisy6Q+ElK8pBCA==", + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.7.0.tgz", + "integrity": "sha512-LKGAXMPQs8U/zMRFXDZOzmMKgFv3COlxUQ+2NMPhbqgVm6R1w+nU1i4836Pmxu9jZAuIeyySNrN/6Rc657ggig==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", "@types/json-schema": "^7.0.15", "@types/semver": "^7.5.8", - "@typescript-eslint/scope-manager": "7.6.0", - "@typescript-eslint/types": "7.6.0", - "@typescript-eslint/typescript-estree": "7.6.0", + "@typescript-eslint/scope-manager": "7.7.0", + "@typescript-eslint/types": "7.7.0", + "@typescript-eslint/typescript-estree": "7.7.0", "semver": "^7.6.0" }, "engines": { @@ -568,12 +588,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.6.0.tgz", - "integrity": "sha512-4eLB7t+LlNUmXzfOu1VAIAdkjbu5xNSerURS9X/S5TUKWFRpXRQZbmtPqgKmYx8bj3J0irtQXSiWAOY82v+cgw==", + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.7.0.tgz", + "integrity": "sha512-h0WHOj8MhdhY8YWkzIF30R379y0NqyOHExI9N9KCzvmu05EgG4FumeYa3ccfKUSphyWkWQE1ybVrgz/Pbam6YA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.6.0", + "@typescript-eslint/types": "7.7.0", "eslint-visitor-keys": "^3.4.3" }, "engines": { @@ -901,6 +921,15 @@ "node": ">= 10" } }, + "node_modules/common-tags": { + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/common-tags/-/common-tags-1.8.2.tgz", + "integrity": "sha512-gk/Z852D2Wtb//0I+kRFNKKE9dIIVirjoqPoA1wJU+XePVXZfGeBpk45+A1rKO4Q43prqWBNY/MiIeRLbPWUaA==", + "dev": true, + "engines": { + "node": ">=4.0.0" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -1037,6 +1066,12 @@ "node": ">=8" } }, + "node_modules/dlv": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/dlv/-/dlv-1.1.3.tgz", + "integrity": "sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA==", + "dev": true + }, "node_modules/dns-packet": { "version": "5.6.1", "resolved": "https://registry.npmjs.org/dns-packet/-/dns-packet-5.6.1.tgz", @@ -1717,6 +1752,27 @@ "node": ">=10.17.0" } }, + "node_modules/has-ansi": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", + "integrity": "sha512-C8vBJ8DwUCx19vhm7urhTuUsr4/IyP6l4VzNQDv+ryHQObW3TTTp9yB68WpYgRe2bbaGuZ/se74IqFeVnMnLZg==", + "dev": true, + "dependencies": { + "ansi-regex": "^2.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/has-ansi/node_modules/ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha512-TIGnTpdo+E3+pCyAluZvtED5p5wCqLdezCyhPZzKPcxvFplEt4i+W7OONCKgeZFT3+y5NZZfOOS/Bdcanm1MYA==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/has-bigints": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz", @@ -1868,6 +1924,15 @@ "node": ">=0.8.19" } }, + "node_modules/indent-string": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", + "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -2282,12 +2347,105 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "dev": true + }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", "dev": true }, + "node_modules/loglevel": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.9.1.tgz", + "integrity": "sha512-hP3I3kCrDIMuRwAwHltphhDM1r8i55H33GgqjXbrisuJhF4kRhW1dNuxsRklp4bXl8DSdLaNLuiL4A/LWRfxvg==", + "dev": true, + "engines": { + "node": ">= 0.6.0" + }, + "funding": { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/loglevel" + } + }, + "node_modules/loglevel-colored-level-prefix": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/loglevel-colored-level-prefix/-/loglevel-colored-level-prefix-1.0.0.tgz", + "integrity": "sha512-u45Wcxxc+SdAlh4yeF/uKlC1SPUPCy0gullSNKXod5I4bmifzk+Q4lSLExNEVn19tGaJipbZ4V4jbFn79/6mVA==", + "dev": true, + "dependencies": { + "chalk": "^1.1.3", + "loglevel": "^1.4.1" + } + }, + "node_modules/loglevel-colored-level-prefix/node_modules/ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha512-TIGnTpdo+E3+pCyAluZvtED5p5wCqLdezCyhPZzKPcxvFplEt4i+W7OONCKgeZFT3+y5NZZfOOS/Bdcanm1MYA==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/loglevel-colored-level-prefix/node_modules/ansi-styles": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", + "integrity": "sha512-kmCevFghRiWM7HB5zTPULl4r9bVFSWjz62MhqizDGUrq2NWuNMQyuv4tHHoKJHs69M/MF64lEcHdYIocrdWQYA==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/loglevel-colored-level-prefix/node_modules/chalk": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "integrity": "sha512-U3lRVLMSlsCfjqYPbLyVv11M9CPW4I728d6TCKMAOJueEeB9/8o+eSsMnxPJD+Q+K909sdESg7C+tIkoH6on1A==", + "dev": true, + "dependencies": { + "ansi-styles": "^2.2.1", + "escape-string-regexp": "^1.0.2", + "has-ansi": "^2.0.0", + "strip-ansi": "^3.0.0", + "supports-color": "^2.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/loglevel-colored-level-prefix/node_modules/escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", + "dev": true, + "engines": { + "node": ">=0.8.0" + } + }, + "node_modules/loglevel-colored-level-prefix/node_modules/strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha512-VhumSSbBqDTP8p2ZLKj40UjBCV4+v8bUSEpUb4KjRgWk9pbqGF4REFj6KEagidb2f/M6AzC0EmFyDNGaw9OCzg==", + "dev": true, + "dependencies": { + "ansi-regex": "^2.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/loglevel-colored-level-prefix/node_modules/supports-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", + "integrity": "sha512-KKNVtd6pCYgPIKU4cp2733HWYCpplQhddZLBUryaAHou723x+FRzQ5Df824Fj+IyyuiQTRoub4SnIFfIcrp70g==", + "dev": true, + "engines": { + "node": ">=0.8.0" + } + }, "node_modules/lru-cache": { "version": "10.2.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.2.0.tgz", @@ -2723,6 +2881,200 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz", + "integrity": "sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, + "node_modules/prettier-eslint": { + "version": "16.3.0", + "resolved": "https://registry.npmjs.org/prettier-eslint/-/prettier-eslint-16.3.0.tgz", + "integrity": "sha512-Lh102TIFCr11PJKUMQ2kwNmxGhTsv/KzUg9QYF2Gkw259g/kPgndZDWavk7/ycbRvj2oz4BPZ1gCU8bhfZH/Xg==", + "dev": true, + "dependencies": { + "@typescript-eslint/parser": "^6.7.5", + "common-tags": "^1.4.0", + "dlv": "^1.1.0", + "eslint": "^8.7.0", + "indent-string": "^4.0.0", + "lodash.merge": "^4.6.0", + "loglevel-colored-level-prefix": "^1.0.0", + "prettier": "^3.0.1", + "pretty-format": "^29.7.0", + "require-relative": "^0.8.7", + "typescript": "^5.2.2", + "vue-eslint-parser": "^9.1.0" + }, + "engines": { + "node": ">=16.10.0" + }, + "peerDependencies": { + "prettier-plugin-svelte": "^3.0.0", + "svelte-eslint-parser": "*" + }, + "peerDependenciesMeta": { + "prettier-plugin-svelte": { + "optional": true + }, + "svelte-eslint-parser": { + "optional": true + } + } + }, + "node_modules/prettier-eslint/node_modules/@typescript-eslint/parser": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.21.0.tgz", + "integrity": "sha512-tbsV1jPne5CkFQCgPBcDOt30ItF7aJoZL997JSF7MhGQqOeT3svWRYxiqlfA5RUdlHN6Fi+EI9bxqbdyAUZjYQ==", + "dev": true, + "dependencies": { + "@typescript-eslint/scope-manager": "6.21.0", + "@typescript-eslint/types": "6.21.0", + "@typescript-eslint/typescript-estree": "6.21.0", + "@typescript-eslint/visitor-keys": "6.21.0", + "debug": "^4.3.4" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/prettier-eslint/node_modules/@typescript-eslint/scope-manager": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.21.0.tgz", + "integrity": "sha512-OwLUIWZJry80O99zvqXVEioyniJMa+d2GrqpUTqi5/v5D5rOrppJVBPa0yKCblcigC0/aYAzxxqQ1B+DS2RYsg==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "6.21.0", + "@typescript-eslint/visitor-keys": "6.21.0" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/prettier-eslint/node_modules/@typescript-eslint/types": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.21.0.tgz", + "integrity": "sha512-1kFmZ1rOm5epu9NZEZm1kckCDGj5UJEf7P1kliH4LKu/RkwpsfqqGmY2OOcUs18lSlQBKLDYBOGxRVtrMN5lpg==", + "dev": true, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/prettier-eslint/node_modules/@typescript-eslint/typescript-estree": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.21.0.tgz", + "integrity": "sha512-6npJTkZcO+y2/kr+z0hc4HwNfrrP4kNYh57ek7yCNlrBjWQ1Y0OS7jiZTkgumrvkX5HkEKXFZkkdFNkaW2wmUQ==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "6.21.0", + "@typescript-eslint/visitor-keys": "6.21.0", + "debug": "^4.3.4", + "globby": "^11.1.0", + "is-glob": "^4.0.3", + "minimatch": "9.0.3", + "semver": "^7.5.4", + "ts-api-utils": "^1.0.1" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/prettier-eslint/node_modules/@typescript-eslint/visitor-keys": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.21.0.tgz", + "integrity": "sha512-JJtkDduxLi9bivAB+cYOVMtbkqdPOhZ+ZI5LC47MIRrDV4Yn2o+ZnW10Nkmr28xRpSpdJ6Sm42Hjf2+REYXm0A==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "6.21.0", + "eslint-visitor-keys": "^3.4.1" + }, + "engines": { + "node": "^16.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/prettier-eslint/node_modules/minimatch": { + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", + "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/pretty-format": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", + "integrity": "sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==", + "dev": true, + "dependencies": { + "@jest/schemas": "^29.6.3", + "ansi-styles": "^5.0.0", + "react-is": "^18.0.0" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, + "node_modules/pretty-format/node_modules/ansi-styles": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz", + "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, "node_modules/pstree.remy": { "version": "1.1.8", "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", @@ -2777,6 +3129,12 @@ } ] }, + "node_modules/react-is": { + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.2.0.tgz", + "integrity": "sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==", + "dev": true + }, "node_modules/readdirp": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", @@ -2807,6 +3165,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/require-relative": { + "version": "0.8.7", + "resolved": "https://registry.npmjs.org/require-relative/-/require-relative-0.8.7.tgz", + "integrity": "sha512-AKGr4qvHiryxRb19m3PsLRGuKVAbJLUD7E6eOaHkfKhwc+vSgVOCY5xNvm9EkolBKTOf0GrQAZKLimOCz81Khg==", + "dev": true + }, "node_modules/resolve-from": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", @@ -3373,6 +3737,30 @@ "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", "dev": true }, + "node_modules/vue-eslint-parser": { + "version": "9.4.2", + "resolved": "https://registry.npmjs.org/vue-eslint-parser/-/vue-eslint-parser-9.4.2.tgz", + "integrity": "sha512-Ry9oiGmCAK91HrKMtCrKFWmSFWvYkpGglCeFAIqDdr9zdXmMMpJOmUJS7WWsW7fX81h6mwHmUZCQQ1E0PkSwYQ==", + "dev": true, + "dependencies": { + "debug": "^4.3.4", + "eslint-scope": "^7.1.1", + "eslint-visitor-keys": "^3.3.0", + "espree": "^9.3.1", + "esquery": "^1.4.0", + "lodash": "^4.17.21", + "semver": "^7.3.6" + }, + "engines": { + "node": "^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/mysticatea" + }, + "peerDependencies": { + "eslint": ">=6.0.0" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/package.json b/package.json index 38783b7..3094a01 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,16 @@ { "private": true, - "displayName": "Plugin Name", - "name": "homebridge-plugin-name", - "version": "1.0.0", - "description": "A short description about what your plugin does.", + "displayName": "Homebridge Shortcuts Buttons", + "name": "homebridge-shortcuts-buttons", + "version": "0.0.1", + "description": "Homebridge Plugin to run any Apple Shortcuts from multiple Stateless Programmable Switches", "license": "Apache-2.0", "repository": { "type": "git", - "url": "git+https://github.com/USERNAME/GITHUB_PROJECT_NAME.git" + "url": "git+https://github.com/duddu/homebridge-shortcuts-buttons.git" }, "bugs": { - "url": "https://github.com/USERNAME/GITHUB_PROJECT_NAME/issues" + "url": "https://github.com/duddu/homebridge-shortcuts-buttons/issues" }, "engines": { "node": "^18.17.0 || ^20.9.0", @@ -18,21 +18,26 @@ }, "main": "dist/index.js", "scripts": { - "lint": "eslint src/**/*.ts --max-warnings=0", + "lint": "eslint src/**/*.ts", + "prettier": "prettier . --write", "watch": "npm run build && npm link && nodemon", "build": "rimraf ./dist && tsc", "prepublishOnly": "npm run lint && npm run build" }, "keywords": [ - "homebridge-plugin" + "homebridge-plugin", + "apple-shortcuts", + "stateless-programmable-switch" ], "devDependencies": { "@types/node": "^20.12.7", "@typescript-eslint/eslint-plugin": "^7.6.0", - "@typescript-eslint/parser": "^7.6.0", + "@typescript-eslint/parser": "^7.7.0", "eslint": "^8.57.0", "homebridge": "^1.7.0", "nodemon": "^3.1.0", + "prettier": "^3.2.5", + "prettier-eslint": "^16.3.0", "rimraf": "^5.0.5", "ts-node": "^10.9.2", "typescript": "^5.4.5" diff --git a/src/platform.ts b/src/platform.ts index 536024f..e746646 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -1,4 +1,12 @@ -import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, PlatformConfig, Service, Characteristic } from 'homebridge'; +import { + API, + DynamicPlatformPlugin, + Logger, + PlatformAccessory, + PlatformConfig, + Service, + Characteristic, +} from 'homebridge'; import { PLATFORM_NAME, PLUGIN_NAME } from './settings'; import { ExamplePlatformAccessory } from './platformAccessory'; @@ -10,7 +18,8 @@ import { ExamplePlatformAccessory } from './platformAccessory'; */ export class ExampleHomebridgePlatform implements DynamicPlatformPlugin { public readonly Service: typeof Service = this.api.hap.Service; - public readonly Characteristic: typeof Characteristic = this.api.hap.Characteristic; + public readonly Characteristic: typeof Characteristic = + this.api.hap.Characteristic; // this is used to track restored cached accessories public readonly accessories: PlatformAccessory[] = []; @@ -40,7 +49,8 @@ export class ExampleHomebridgePlatform implements DynamicPlatformPlugin { configureAccessory(accessory: PlatformAccessory) { this.log.info('Loading accessory from cache:', accessory.displayName); - // add the restored accessory to the accessories cache so we can track if it has already been registered + // add the restored accessory to the accessories cache so we can track if it has already + // been registered this.accessories.push(accessory); } @@ -50,7 +60,6 @@ export class ExampleHomebridgePlatform implements DynamicPlatformPlugin { * must not be registered again to prevent "duplicate UUID" errors. */ discoverDevices() { - // EXAMPLE ONLY // A real plugin you would discover accessories from the local network, cloud services // or a user-defined array in the platform config. @@ -67,7 +76,6 @@ export class ExampleHomebridgePlatform implements DynamicPlatformPlugin { // loop over the discovered devices and register each one if it has not already been registered for (const device of exampleDevices) { - // generate a unique id for the accessory this should be generated from // something globally unique, but constant, for example, the device serial // number or MAC address @@ -75,13 +83,19 @@ export class ExampleHomebridgePlatform implements DynamicPlatformPlugin { // see if an accessory with the same uuid has already been registered and restored from // the cached devices we stored in the `configureAccessory` method above - const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid); + const existingAccessory = this.accessories.find( + (accessory) => accessory.UUID === uuid, + ); if (existingAccessory) { // the accessory already exists - this.log.info('Restoring existing accessory from cache:', existingAccessory.displayName); + this.log.info( + 'Restoring existing accessory from cache:', + existingAccessory.displayName, + ); - // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.: + // if you need to update the accessory.context then you should run + // `api.updatePlatformAccessories`. eg.: // existingAccessory.context.device = device; // this.api.updatePlatformAccessories([existingAccessory]); @@ -89,7 +103,8 @@ export class ExampleHomebridgePlatform implements DynamicPlatformPlugin { // this is imported from `platformAccessory.ts` new ExamplePlatformAccessory(this, existingAccessory); - // it is possible to remove platform accessories at any time using `api.unregisterPlatformAccessories`, eg.: + // it is possible to remove platform accessories at any time using + // `api.unregisterPlatformAccessories`, eg.: // remove platform accessories when no longer present // this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [existingAccessory]); // this.log.info('Removing existing accessory from cache:', existingAccessory.displayName); @@ -98,7 +113,10 @@ export class ExampleHomebridgePlatform implements DynamicPlatformPlugin { this.log.info('Adding new accessory:', device.exampleDisplayName); // create a new accessory - const accessory = new this.api.platformAccessory(device.exampleDisplayName, uuid); + const accessory = new this.api.platformAccessory( + device.exampleDisplayName, + uuid, + ); // store a copy of the device object in the `accessory.context` // the `context` property can be used to store any data about the accessory you may need @@ -109,7 +127,9 @@ export class ExampleHomebridgePlatform implements DynamicPlatformPlugin { new ExamplePlatformAccessory(this, accessory); // link the accessory to your platform - this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]); + this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [ + accessory, + ]); } } } diff --git a/src/platformAccessory.ts b/src/platformAccessory.ts index d885377..f9081f8 100644 --- a/src/platformAccessory.ts +++ b/src/platformAccessory.ts @@ -23,50 +23,78 @@ export class ExamplePlatformAccessory { private readonly platform: ExampleHomebridgePlatform, private readonly accessory: PlatformAccessory, ) { - // set accessory information - this.accessory.getService(this.platform.Service.AccessoryInformation)! - .setCharacteristic(this.platform.Characteristic.Manufacturer, 'Default-Manufacturer') + this.accessory + .getService(this.platform.Service.AccessoryInformation)! + .setCharacteristic( + this.platform.Characteristic.Manufacturer, + 'Default-Manufacturer', + ) .setCharacteristic(this.platform.Characteristic.Model, 'Default-Model') - .setCharacteristic(this.platform.Characteristic.SerialNumber, 'Default-Serial'); + .setCharacteristic( + this.platform.Characteristic.SerialNumber, + 'Default-Serial', + ); // get the LightBulb service if it exists, otherwise create a new LightBulb service // you can create multiple services for each accessory - this.service = this.accessory.getService(this.platform.Service.Lightbulb) || this.accessory.addService(this.platform.Service.Lightbulb); + this.service = + this.accessory.getService(this.platform.Service.Lightbulb) || + this.accessory.addService(this.platform.Service.Lightbulb); // set the service name, this is what is displayed as the default name on the Home app - // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method. - this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.context.device.exampleDisplayName); + // in this example we are using the name we stored in the `accessory.context` + // in the `discoverDevices` method. + this.service.setCharacteristic( + this.platform.Characteristic.Name, + accessory.context.device.exampleDisplayName, + ); - // each service must implement at-minimum the "required characteristics" for the given service type - // see https://developers.homebridge.io/#/service/Lightbulb + // each service must implement at-minimum the "required characteristics" for the given service + // type see https://developers.homebridge.io/#/service/Lightbulb // register handlers for the On/Off Characteristic - this.service.getCharacteristic(this.platform.Characteristic.On) - .onSet(this.setOn.bind(this)) // SET - bind to the `setOn` method below - .onGet(this.getOn.bind(this)); // GET - bind to the `getOn` method below + this.service + .getCharacteristic(this.platform.Characteristic.On) + .onSet(this.setOn.bind(this)) // SET - bind to the `setOn` method below + .onGet(this.getOn.bind(this)); // GET - bind to the `getOn` method below // register handlers for the Brightness Characteristic - this.service.getCharacteristic(this.platform.Characteristic.Brightness) - .onSet(this.setBrightness.bind(this)); // SET - bind to the 'setBrightness` method below + this.service + .getCharacteristic(this.platform.Characteristic.Brightness) + .onSet(this.setBrightness.bind(this)); /** * Creating multiple services of the same type. * - * To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error, - * when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id: - * this.accessory.getService('NAME') || this.accessory.addService(this.platform.Service.Lightbulb, 'NAME', 'USER_DEFINED_SUBTYPE_ID'); + * To avoid "Cannot add a Service with the same UUID another Service without also defining a + * unique 'subtype' property." error, when creating multiple services of the same type, you + * need to use the following syntax to specify a name and subtype id: + * this.accessory.getService('NAME') || + * this.accessory.addService( + * this.platform.Service.Lightbulb, 'NAME', 'USER_DEFINED_SUBTYPE_ID' + * ); * - * The USER_DEFINED_SUBTYPE must be unique to the platform accessory (if you platform exposes multiple accessories, each accessory - * can use the same sub type id.) + * The USER_DEFINED_SUBTYPE must be unique to the platform accessory (if you platform exposes + * multiple accessories, each accessory can use the same sub type id.) */ // Example: add two "motion sensor" services to the accessory - const motionSensorOneService = this.accessory.getService('Motion Sensor One Name') || - this.accessory.addService(this.platform.Service.MotionSensor, 'Motion Sensor One Name', 'YourUniqueIdentifier-1'); - - const motionSensorTwoService = this.accessory.getService('Motion Sensor Two Name') || - this.accessory.addService(this.platform.Service.MotionSensor, 'Motion Sensor Two Name', 'YourUniqueIdentifier-2'); + const motionSensorOneService = + this.accessory.getService('Motion Sensor One Name') || + this.accessory.addService( + this.platform.Service.MotionSensor, + 'Motion Sensor One Name', + 'YourUniqueIdentifier-1', + ); + + const motionSensorTwoService = + this.accessory.getService('Motion Sensor Two Name') || + this.accessory.addService( + this.platform.Service.MotionSensor, + 'Motion Sensor Two Name', + 'YourUniqueIdentifier-2', + ); /** * Updating characteristics values asynchronously. @@ -83,17 +111,29 @@ export class ExamplePlatformAccessory { motionDetected = !motionDetected; // push the new value to HomeKit - motionSensorOneService.updateCharacteristic(this.platform.Characteristic.MotionDetected, motionDetected); - motionSensorTwoService.updateCharacteristic(this.platform.Characteristic.MotionDetected, !motionDetected); - - this.platform.log.debug('Triggering motionSensorOneService:', motionDetected); - this.platform.log.debug('Triggering motionSensorTwoService:', !motionDetected); + motionSensorOneService.updateCharacteristic( + this.platform.Characteristic.MotionDetected, + motionDetected, + ); + motionSensorTwoService.updateCharacteristic( + this.platform.Characteristic.MotionDetected, + !motionDetected, + ); + + this.platform.log.debug( + 'Triggering motionSensorOneService:', + motionDetected, + ); + this.platform.log.debug( + 'Triggering motionSensorTwoService:', + !motionDetected, + ); }, 10000); } /** * Handle "SET" requests from HomeKit - * These are sent when the user changes the state of an accessory, for example, turning on a Light bulb. + * These are sent when the user changes the state of an accessory, e.g. turning on a Light bulb. */ async setOn(value: CharacteristicValue) { // implement your own code to turn your device on/off @@ -104,7 +144,8 @@ export class ExamplePlatformAccessory { /** * Handle the "GET" requests from HomeKit - * These are sent when HomeKit wants to know the current state of the accessory, for example, checking if a Light bulb is on. + * These are sent when HomeKit wants to know the current state of the accessory, for example, + * checking if a Light bulb is on. * * GET requests should return as fast as possbile. A long delay here will result in * HomeKit being unresponsive and a bad user experience in general. @@ -122,14 +163,17 @@ export class ExamplePlatformAccessory { this.platform.log.debug('Get Characteristic On ->', isOn); // if you need to return an error to show the device as "Not Responding" in the Home app: - // throw new this.platform.api.hap.HapStatusError(this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE); + // throw new this.platform.api.hap.HapStatusError( + // this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE + // ); return isOn; } /** * Handle "SET" requests from HomeKit - * These are sent when the user changes the state of an accessory, for example, changing the Brightness + * These are sent when the user changes the state of an accessory, for example, changing + * the Brightness */ async setBrightness(value: CharacteristicValue) { // implement your own code to set the brightness @@ -137,5 +181,4 @@ export class ExamplePlatformAccessory { this.platform.log.debug('Set Characteristic Brightness -> ', value); } - } diff --git a/src/settings.ts b/src/settings.ts index 8684475..a20bc1a 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1,9 +1,10 @@ /** - * This is the name of the platform that users will use to register the plugin in the Homebridge config.json + * This is the name of the platform that users will use to register the plugin in the + * Homebridge config.json */ -export const PLATFORM_NAME = 'ExampleHomebridgePlugin'; +export const PLATFORM_NAME = 'HomebridgeShortcutsButtons'; /** * This must match the name of your plugin as defined the package.json */ -export const PLUGIN_NAME = 'homebridge-plugin-name'; \ No newline at end of file +export const PLUGIN_NAME = 'homebridge-shortcuts-buttons'; diff --git a/tsconfig.json b/tsconfig.json index bf07099..97b06b2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,12 +2,7 @@ "compilerOptions": { "target": "ES2018", // ~node10 "module": "commonjs", - "lib": [ - "es2015", - "es2016", - "es2017", - "es2018" - ], + "lib": ["es2015", "es2016", "es2017", "es2018"], "declaration": true, "declarationMap": true, "sourceMap": true, @@ -17,10 +12,6 @@ "esModuleInterop": true, "noImplicitAny": false }, - "include": [ - "src/" - ], - "exclude": [ - "**/*.spec.ts" - ] + "include": ["src/"], + "exclude": ["**/*.spec.ts"] }