diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..ab212bb --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,45 @@ +# This is a basic workflow to help you get started with Actions +name: Publish to NPM + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the master branch +on: + push: + branches: + - master + - dev + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1.1.0 + with: + node-version: 12.15 + registry-url: https://registry.npmjs.org/ + + - name: Install npm dependencies + run: npm i + + - name: Publish release + run: npm publish --access public + if: github.ref == 'refs/heads/master' + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + + - name: Update the package version + if: github.ref == 'refs/heads/dev' + run: node scripts/update-package-version.js $GITHUB_RUN_ID + + - name: Publish beta release + run: npm publish --tag next --access public + if: github.ref == 'refs/heads/dev' + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b5519e0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +node_modules/ +dist +debug + +.DS_Store \ No newline at end of file diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..8a7c738 --- /dev/null +++ b/.npmignore @@ -0,0 +1,7 @@ +node_modules +src +scripts + +.DS_Store +.gitignore +tsconfig.json \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..4dc68c6 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,2 @@ +# Changelog + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..27ed765 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Elio Struyf + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..b336939 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# Presence switch connected to Microsoft Graph + +*To be added* + +## Local development + +``` +nvm use v12 +cd ~/.nvm/versions/node/v12.15.0/bin/ + +homebridge -D -I -U ~/nodejs/homebridge/homebridge-presence-switch-msgraph/debug -P ~/nodejs/homebridge/homebridge-presence-switch-msgraph +``` + +## Config + +- AppId +- API URL to call +- Light states + - Available + - Away + - Bussy +- Light settings + - type: none, blink, ... + - brightness: 0.4 - 1 \ No newline at end of file diff --git a/config.schema.json b/config.schema.json new file mode 100644 index 0000000..0b3275e --- /dev/null +++ b/config.schema.json @@ -0,0 +1,125 @@ +{ + "pluginAlias": "presence-switch", + "pluginType": "accessory", + "singular": false, + "headerDisplay": "Microsoft Graph Presence Switch", + "footerDisplay": "Plugin which allows you retrieve your presence via the Microsoft Graph and call your busy light API.", + "schema": { + "type": "object", + "properties": { + "name": { + "title": "Name", + "type": "string", + "default": "Presence Indicator", + "required": true + }, + "appId": { + "title": "Azure AD application ID", + "description": "The GUID of the Azure AD app.", + "type": "string", + "required": true + }, + "interval": { + "title": "Interval", + "description": "Polling interval.", + "type": "integer", + "default": 1 + }, + "setColorApi": { + "title": "Set color API", + "description": "API to set the color", + "type": "string", + "required": true + }, + "offApi": { + "title": "Off API", + "description": "API to turn off your device", + "type": "string", + "required": true + }, + "onApi": { + "title": "On API", + "description": "API to turn on your device", + "type": "string", + "required": true + }, + "startTime": { + "title": "Start time", + "description": "Define the time when you start your working day (ex: 8:30).", + "type": "string", + "default": "" + }, + "endTime": { + "title": "End time", + "description": "Define the time when you end your working day (ex: 18:00).", + "type": "string", + "default": "" + }, + "weekend": { + "title": "Weekend checks", + "description": "Do you want to check in the weekends", + "type": "boolean", + "default": false + }, + "statusColors": { + "title": "Status color", + "description": "Define the color values for the following states: 'available', 'busy', and 'away'.", + "type": "object", + "properties": { + "available": { + "type": "object", + "properties": { + "red": "string", + "green": "string", + "blue": "string" + } + }, + "busy": { + "type": "object", + "properties": { + "red": "string", + "green": "string", + "blue": "string" + } + }, + "away": { + "type": "object" , + "properties": { + "red": "string", + "green": "string", + "blue": "string" + } + } + } + }, + "lightType": { + "title": "Light type", + "description": "Define the type of light you want to show.", + "type": "string", + "default": "switch", + "oneOf": [ + { + "title": "Always on", + "enum": [ "on" ] + }, + { + "title": "Blink", + "enum": [ "blink" ] + }, + { + "title": "Hearthbeat", + "enum": [ "hearthbeat" ] + } + ] + }, + "debug": { + "title": "Debug", + "type": "boolean", + "default": false, + "required": false + } + } + }, + "form": null, + "display": null +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..13d7f15 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,1019 @@ +{ + "name": "homebridge-presence-switch-msgraph", + "version": "0.0.1", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@types/color-name": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", + "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==" + }, + "@types/node": { + "version": "13.11.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-13.11.0.tgz", + "integrity": "sha512-uM4mnmsIIPK/yeO+42F2RQhGUIs39K2RFmugcJANppXe6J1nvH87PvzPZYpza7Xhhs8Yn9yIAVdLZ84z61+0xQ==", + "dev": true + }, + "@types/node-fetch": { + "version": "2.5.5", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.5.tgz", + "integrity": "sha512-IWwjsyYjGw+em3xTvWVQi5MgYKbRs0du57klfTaZkv/B24AEQ/p/IopNeqIYNy3EsfHOpg8ieQSDomPcsYMHpA==", + "dev": true, + "requires": { + "@types/node": "*", + "form-data": "^3.0.0" + }, + "dependencies": { + "form-data": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.0.tgz", + "integrity": "sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==", + "dev": true, + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + } + } + }, + "@types/node-persist": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@types/node-persist/-/node-persist-3.0.0.tgz", + "integrity": "sha512-kCeCaLJvPGVMB9gwFbf37k3e+MV/ZBjp3c7BepfTdggRU7Wdijbce+fIhcZmpnQw4o9PV8jGizGSz/vlbwikow==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, + "adal-node": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/adal-node/-/adal-node-0.2.1.tgz", + "integrity": "sha512-C/oasZuTy0NIqh5wPWjG/09XaG+zS7elC8upf1ZVExt9lSRncme4Ejbx8CKYk+wsGgj609y84txtRAXQVvqApg==", + "requires": { + "@types/node": "^8.0.47", + "async": "^2.6.3", + "date-utils": "*", + "jws": "3.x.x", + "request": "^2.88.0", + "underscore": ">= 1.3.1", + "uuid": "^3.1.0", + "xmldom": ">= 0.1.x", + "xpath.js": "~1.1.0" + }, + "dependencies": { + "@types/node": { + "version": "8.10.59", + "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.59.tgz", + "integrity": "sha512-8RkBivJrDCyPpBXhVZcjh7cQxVBSmRk9QM7hOketZzp6Tg79c0N8kkpAIito9bnJ3HCVCHVYz+KHTEbfQNfeVQ==" + } + } + }, + "ajv": { + "version": "6.12.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.0.tgz", + "integrity": "sha512-D6gFiFA0RRLyUbvijN74DWAjXSFxWKaWP7mldxkVhyhAV3+SWA9HEJPHQ2c9soIeTFJqcSdFDGFgdqs1iUU2Hw==", + "requires": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + } + }, + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "dev": true + }, + "ansi-styles": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", + "dev": true + }, + "array-flatten": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-2.1.2.tgz", + "integrity": "sha512-hNfzcOV8W4NdualtqBFPyVO+54DSJuZGY9qT4pRroB6S9e3iiido2ISIC5h9R2sPJ8H3FHCIiEnsv1lPXO3KtQ==" + }, + "asn1": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", + "integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==", + "requires": { + "safer-buffer": "~2.1.0" + } + }, + "assert-plus": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" + }, + "async": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz", + "integrity": "sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==", + "requires": { + "lodash": "^4.17.14" + } + }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" + }, + "aws-sign2": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", + "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=" + }, + "aws4": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.9.1.tgz", + "integrity": "sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug==" + }, + "bcrypt-pbkdf": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", + "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=", + "requires": { + "tweetnacl": "^0.14.3" + }, + "dependencies": { + "tweetnacl": { + "version": "0.14.5", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", + "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" + } + } + }, + "bonjour-hap": { + "version": "3.5.4", + "resolved": "https://registry.npmjs.org/bonjour-hap/-/bonjour-hap-3.5.4.tgz", + "integrity": "sha512-MgU27SEZYQ09Skm71Xa7SZoAg259V4IlAJNWaloFVMlYDn1OjJy3nkwSixRHnDzrcLWocVI84f9exI1ObZChBw==", + "requires": { + "array-flatten": "^2.1.0", + "deep-equal": "^1.0.1", + "dns-equal": "^1.0.0", + "dns-txt": "^2.0.2", + "multicast-dns": "^7.2.0", + "multicast-dns-service-types": "^1.1.0" + } + }, + "buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk=" + }, + "buffer-indexof": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/buffer-indexof/-/buffer-indexof-1.1.1.tgz", + "integrity": "sha512-4/rOEg86jivtPTeOUUT61jJO1Ya1TrR/OkqCSZDyq84WJh3LuuiphBYJN+fm5xufIk4XAFcEwte/8WzC8If/1g==" + }, + "buffer-shims": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/buffer-shims/-/buffer-shims-1.0.0.tgz", + "integrity": "sha1-mXjOMXOIxkmth5MCjDR37wRKi1E=", + "dev": true + }, + "caseless": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", + "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" + }, + "chalk": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", + "dev": true, + "requires": { + "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" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "requires": { + "delayed-stream": "~1.0.0" + } + }, + "commander": { + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.8.1.tgz", + "integrity": "sha1-Br42f+v9oMMwqh4qBy09yXYkJdQ=", + "dev": true, + "requires": { + "graceful-readlink": ">= 1.0.0" + } + }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" + }, + "dashdash": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", + "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", + "requires": { + "assert-plus": "^1.0.0" + } + }, + "date-utils": { + "version": "1.2.21", + "resolved": "https://registry.npmjs.org/date-utils/-/date-utils-1.2.21.tgz", + "integrity": "sha1-YfsWzcEnSzyayq/+n8ad+HIKK2Q=" + }, + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "decimal.js": { + "version": "7.5.1", + "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-7.5.1.tgz", + "integrity": "sha512-1K5Y6MykxQYfHBcFfAj2uBaLmwreq4MsjsvrlgcEOvg+X82IeeXlIVIVkBMiypksu+yo9vcYP6lfU3qTedofSQ==", + "dev": true + }, + "deep-equal": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.1.1.tgz", + "integrity": "sha512-yd9c5AdiqVcR+JjcwUQb9DkhJc8ngNr0MahEBGvDiJw8puWab2yZlh+nkasOnZP+EGTAP6rRp2JzJhJZzvNF8g==", + "requires": { + "is-arguments": "^1.0.4", + "is-date-object": "^1.0.1", + "is-regex": "^1.0.4", + "object-is": "^1.0.1", + "object-keys": "^1.1.1", + "regexp.prototype.flags": "^1.2.0" + } + }, + "define-properties": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", + "integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==", + "requires": { + "object-keys": "^1.0.12" + } + }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" + }, + "dns-equal": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/dns-equal/-/dns-equal-1.0.0.tgz", + "integrity": "sha1-s55/HabrCnW6nBcySzR1PEfgZU0=" + }, + "dns-packet": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/dns-packet/-/dns-packet-4.2.0.tgz", + "integrity": "sha512-bn1AKpfkFbm0MIioOMHZ5qJzl2uypdBwI4nYNsqvhjsegBhcKJUlCrMPWLx6JEezRjxZmxhtIz/FkBEur2l8Cw==", + "requires": { + "ip": "^1.1.5", + "safe-buffer": "^5.1.1" + } + }, + "dns-txt": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/dns-txt/-/dns-txt-2.0.2.tgz", + "integrity": "sha1-uR2Ab10nGI5Ks+fRB9iBocxGQrY=", + "requires": { + "buffer-indexof": "^1.0.0" + } + }, + "ecc-jsbn": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", + "integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=", + "requires": { + "jsbn": "~0.1.0", + "safer-buffer": "^2.1.0" + } + }, + "ecdsa-sig-formatter": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", + "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", + "requires": { + "safe-buffer": "^5.0.1" + } + }, + "es-abstract": { + "version": "1.17.5", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.5.tgz", + "integrity": "sha512-BR9auzDbySxOcfog0tLECW8l28eRGpDpU3Dm3Hp4q/N+VtLTmyj4EUN088XZWQDW/hzj6sYRDXeOFsaAODKvpg==", + "requires": { + "es-to-primitive": "^1.2.1", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1", + "is-callable": "^1.1.5", + "is-regex": "^1.0.5", + "object-inspect": "^1.7.0", + "object-keys": "^1.1.1", + "object.assign": "^4.1.0", + "string.prototype.trimleft": "^2.1.1", + "string.prototype.trimright": "^2.1.1" + } + }, + "es-to-primitive": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", + "integrity": "sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==", + "requires": { + "is-callable": "^1.1.4", + "is-date-object": "^1.0.1", + "is-symbol": "^1.0.2" + } + }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "dev": true + }, + "extend": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", + "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==" + }, + "extsprintf": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", + "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=" + }, + "fast-deep-equal": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz", + "integrity": "sha512-8UEa58QDLauDNfpbrX55Q9jrGHThw2ZMdOky5Gl1CDtVeJDPVrG4Jxx1N8jw2gkWaff5UUuX1KJd+9zGe2B+ZA==" + }, + "fast-json-stable-stringify": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==" + }, + "fast-srp-hap": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/fast-srp-hap/-/fast-srp-hap-1.0.1.tgz", + "integrity": "sha1-N3Ek0Za8alFXquWze/X6NbtK0tk=", + "dev": true + }, + "forever-agent": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", + "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=" + }, + "form-data": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", + "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.6", + "mime-types": "^2.1.12" + } + }, + "function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + }, + "getpass": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", + "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", + "requires": { + "assert-plus": "^1.0.0" + } + }, + "graceful-readlink": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/graceful-readlink/-/graceful-readlink-1.0.1.tgz", + "integrity": "sha1-TK+tdrxi8C+gObL5Tpo906ORpyU=", + "dev": true + }, + "hap-nodejs": { + "version": "0.4.51", + "resolved": "https://registry.npmjs.org/hap-nodejs/-/hap-nodejs-0.4.51.tgz", + "integrity": "sha512-d+b0KsakGRC5IgYBBCuqkAFzj8iKAHVw0bKreT8vmhK4b43FTVWiSwi5MWXApoYQUkbPux+xnVYqwMo+Zviieg==", + "dev": true, + "requires": { + "bonjour-hap": "^3.5.1", + "buffer-shims": "^1.0.0", + "debug": "^2.2.0", + "decimal.js": "^7.2.3", + "fast-srp-hap": "^1.0.1", + "ip": "^1.1.3", + "node-persist": "^0.0.11", + "tweetnacl": "^1.0.1" + }, + "dependencies": { + "node-persist": { + "version": "0.0.11", + "resolved": "https://registry.npmjs.org/node-persist/-/node-persist-0.0.11.tgz", + "integrity": "sha1-1m66Pr72IPB5Uw+nsTB2qQZmWHQ=", + "dev": true, + "requires": { + "mkdirp": "~0.5.1", + "q": "~1.1.1" + } + } + } + }, + "har-schema": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", + "integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=" + }, + "har-validator": { + "version": "5.1.3", + "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.3.tgz", + "integrity": "sha512-sNvOCzEQNr/qrvJgc3UG/kD4QtlHycrzwS+6mfTrrSq97BvaYcPZZI1ZSqGSPR73Cxn4LKTD4PttRwfU7jWq5g==", + "requires": { + "ajv": "^6.5.5", + "har-schema": "^2.0.0" + } + }, + "has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "requires": { + "function-bind": "^1.1.1" + } + }, + "has-ansi": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", + "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" + }, + "has-symbols": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz", + "integrity": "sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg==" + }, + "homebridge": { + "version": "0.4.53", + "resolved": "https://registry.npmjs.org/homebridge/-/homebridge-0.4.53.tgz", + "integrity": "sha512-yi8GEKVEkQWeOE9CPmZiu+7dZzeiqzVX/P8suTd2h1hjXHiuots3UdZunEY4MOwNNPc8w62m47T9pbK6RZM4WA==", + "dev": true, + "requires": { + "chalk": "^1.1.1", + "commander": "2.8.1", + "hap-nodejs": "0.4.51", + "node-persist": "^0.0.8", + "qrcode-terminal": "^0.11.0", + "semver": "5.0.3" + }, + "dependencies": { + "mkdirp": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.5.tgz", + "integrity": "sha1-3j5fiWHIjHh+4TaN+EmsRBPsqNc=", + "dev": true + }, + "node-persist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/node-persist/-/node-persist-0.0.8.tgz", + "integrity": "sha1-pWxzm8b/2c7vGcDo2JWXkX8Ikkk=", + "dev": true, + "requires": { + "mkdirp": "~0.3.5", + "q": "~1.1.1" + } + } + } + }, + "homebridge-lib": { + "version": "4.5.6", + "resolved": "https://registry.npmjs.org/homebridge-lib/-/homebridge-lib-4.5.6.tgz", + "integrity": "sha512-L5i2f18JFJLEhNCRJz3EO+zDhdvT7D/J6iYo/3y21OmfC+9UtMEpOcA5TpJsrSHZ63FztPkooBlmIQcvY8FgLw==", + "requires": { + "bonjour-hap": "~3.5.4", + "chalk": "~3.0.0", + "debug": "~4.1.1", + "moment": "~2.24.0", + "semver": "~7.1.3" + }, + "dependencies": { + "ansi-styles": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", + "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", + "requires": { + "@types/color-name": "^1.1.1", + "color-convert": "^2.0.1" + } + }, + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "requires": { + "ms": "^2.1.1" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, + "semver": { + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.1.3.tgz", + "integrity": "sha512-ekM0zfiA9SCBlsKa2X1hxyxiI4L3B6EbVJkkdgQXnSEEaHlGdvyodMruTiulSRWMMB4NeIuYNMC9rTKTz97GxA==" + }, + "supports-color": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", + "integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==", + "requires": { + "has-flag": "^4.0.0" + } + } + } + }, + "http-signature": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", + "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=", + "requires": { + "assert-plus": "^1.0.0", + "jsprim": "^1.2.2", + "sshpk": "^1.7.0" + } + }, + "ip": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/ip/-/ip-1.1.5.tgz", + "integrity": "sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo=" + }, + "is-arguments": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.0.4.tgz", + "integrity": "sha512-xPh0Rmt8NE65sNzvyUmWgI1tz3mKq74lGA0mL8LYZcoIzKOzDh6HmrYm3d18k60nHerC8A9Km8kYu87zfSFnLA==" + }, + "is-callable": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.5.tgz", + "integrity": "sha512-ESKv5sMCJB2jnHTWZ3O5itG+O128Hsus4K4Qh1h2/cgn2vbgnLSVqfV46AeJA9D5EeeLa9w81KUXMtn34zhX+Q==" + }, + "is-date-object": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.2.tgz", + "integrity": "sha512-USlDT524woQ08aoZFzh3/Z6ch9Y/EWXEHQ/AaRN0SkKq4t2Jw2R2339tSXmwuVoY7LLlBCbOIlx2myP/L5zk0g==" + }, + "is-regex": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.5.tgz", + "integrity": "sha512-vlKW17SNq44owv5AQR3Cq0bQPEb8+kF3UKZ2fiZNOWtztYE5i0CzCZxFDwO58qAOWtxdBRVO/V5Qin1wjCqFYQ==", + "requires": { + "has": "^1.0.3" + } + }, + "is-symbol": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.3.tgz", + "integrity": "sha512-OwijhaRSgqvhm/0ZdAcXNZt9lYdKFpcRDT5ULUuYXPoT794UNOdU+gpT6Rzo7b4V2HUl/op6GqY894AZwv9faQ==", + "requires": { + "has-symbols": "^1.0.1" + } + }, + "is-typedarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", + "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=" + }, + "isstream": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", + "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" + }, + "jsbn": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", + "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" + }, + "json-schema": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", + "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=" + }, + "json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" + }, + "json-stringify-safe": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", + "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=" + }, + "jsprim": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", + "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", + "requires": { + "assert-plus": "1.0.0", + "extsprintf": "1.3.0", + "json-schema": "0.2.3", + "verror": "1.10.0" + } + }, + "jwa": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz", + "integrity": "sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==", + "requires": { + "buffer-equal-constant-time": "1.0.1", + "ecdsa-sig-formatter": "1.0.11", + "safe-buffer": "^5.0.1" + } + }, + "jws": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz", + "integrity": "sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==", + "requires": { + "jwa": "^1.4.1", + "safe-buffer": "^5.0.1" + } + }, + "lodash": { + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" + }, + "mime-db": { + "version": "1.43.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.43.0.tgz", + "integrity": "sha512-+5dsGEEovYbT8UY9yD7eE4XTc4UwJ1jBYlgaQQF38ENsKR3wj/8q8RFZrF9WIZpB2V1ArTVFUva8sAul1NzRzQ==" + }, + "mime-types": { + "version": "2.1.26", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.26.tgz", + "integrity": "sha512-01paPWYgLrkqAyrlDorC1uDwl2p3qZT7yl806vW7DvDoxwXi46jsjFbg+WdwotBIk6/MbEhO/dh5aZ5sNj/dWQ==", + "requires": { + "mime-db": "1.43.0" + } + }, + "minimist": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" + }, + "mkdirp": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", + "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", + "requires": { + "minimist": "^1.2.5" + } + }, + "moment": { + "version": "2.24.0", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz", + "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==" + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true + }, + "multicast-dns": { + "version": "7.2.2", + "resolved": "https://registry.npmjs.org/multicast-dns/-/multicast-dns-7.2.2.tgz", + "integrity": "sha512-XqSMeO8EWV/nOXOpPV8ztIpNweVfE1dSpz6SQvDPp71HD74lMXjt4m/mWB1YBMG0kHtOodxRWc5WOb/UNN1A5g==", + "requires": { + "dns-packet": "^4.0.0", + "thunky": "^1.0.2" + } + }, + "multicast-dns-service-types": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/multicast-dns-service-types/-/multicast-dns-service-types-1.1.0.tgz", + "integrity": "sha1-iZ8R2WhuXgXLkbNdXw5jt3PPyQE=" + }, + "node-fetch": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", + "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==" + }, + "node-persist": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/node-persist/-/node-persist-3.0.5.tgz", + "integrity": "sha512-zJmBA58kI9QAxXLMc4NLswgzXVIqKfsfQtiySMF6eEQ3kVvoM3YHzcP0//L9u30Fqx3cYe1FL/a+fyB3VwO/oQ==", + "requires": { + "mkdirp": "~0.5.1" + } + }, + "oauth-sign": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", + "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==" + }, + "object-inspect": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.7.0.tgz", + "integrity": "sha512-a7pEHdh1xKIAgTySUGgLMx/xwDZskN1Ud6egYYN3EdRW4ZMPNEDUTF+hwy2LUC+Bl+SyLXANnwz/jyh/qutKUw==" + }, + "object-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/object-is/-/object-is-1.0.2.tgz", + "integrity": "sha512-Epah+btZd5wrrfjkJZq1AOB9O6OxUQto45hzFd7lXGrpHPGE0W1k+426yrZV+k6NJOzLNNW/nVsmZdIWsAqoOQ==" + }, + "object-keys": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", + "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==" + }, + "object.assign": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.0.tgz", + "integrity": "sha512-exHJeq6kBKj58mqGyTQ9DFvrZC/eR6OwxzoM9YRoGBqrXYonaFyGiFMuc9VZrXf7DarreEwMpurG3dd+CNyW5w==", + "requires": { + "define-properties": "^1.1.2", + "function-bind": "^1.1.1", + "has-symbols": "^1.0.0", + "object-keys": "^1.0.11" + } + }, + "performance-now": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", + "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" + }, + "psl": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", + "integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ==" + }, + "punycode": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" + }, + "q": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/q/-/q-1.1.2.tgz", + "integrity": "sha1-Y1fikSBnAdmfGXq4TlforRlvKok=", + "dev": true + }, + "qrcode-terminal": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/qrcode-terminal/-/qrcode-terminal-0.11.0.tgz", + "integrity": "sha1-/8bCii/Av7RwUrR+I/T0RqX7254=", + "dev": true + }, + "qs": { + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", + "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==" + }, + "regexp.prototype.flags": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.3.0.tgz", + "integrity": "sha512-2+Q0C5g951OlYlJz6yu5/M33IcsESLlLfsyIaLJaG4FA2r4yP8MvVMJUUP/fVBkSpbbbZlS5gynbEWLipiiXiQ==", + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.17.0-next.1" + } + }, + "request": { + "version": "2.88.2", + "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz", + "integrity": "sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==", + "requires": { + "aws-sign2": "~0.7.0", + "aws4": "^1.8.0", + "caseless": "~0.12.0", + "combined-stream": "~1.0.6", + "extend": "~3.0.2", + "forever-agent": "~0.6.1", + "form-data": "~2.3.2", + "har-validator": "~5.1.3", + "http-signature": "~1.2.0", + "is-typedarray": "~1.0.0", + "isstream": "~0.1.2", + "json-stringify-safe": "~5.0.1", + "mime-types": "~2.1.19", + "oauth-sign": "~0.9.0", + "performance-now": "^2.1.0", + "qs": "~6.5.2", + "safe-buffer": "^5.1.2", + "tough-cookie": "~2.5.0", + "tunnel-agent": "^0.6.0", + "uuid": "^3.3.2" + } + }, + "safe-buffer": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz", + "integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==" + }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, + "semver": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.0.3.tgz", + "integrity": "sha1-d0Zt5YnNXTyV8TiqeLxWmjy10no=", + "dev": true + }, + "sshpk": { + "version": "1.16.1", + "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", + "integrity": "sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg==", + "requires": { + "asn1": "~0.2.3", + "assert-plus": "^1.0.0", + "bcrypt-pbkdf": "^1.0.0", + "dashdash": "^1.12.0", + "ecc-jsbn": "~0.1.1", + "getpass": "^0.1.1", + "jsbn": "~0.1.0", + "safer-buffer": "^2.0.2", + "tweetnacl": "~0.14.0" + }, + "dependencies": { + "tweetnacl": { + "version": "0.14.5", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", + "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" + } + } + }, + "string.prototype.trimend": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/string.prototype.trimend/-/string.prototype.trimend-1.0.0.tgz", + "integrity": "sha512-EEJnGqa/xNfIg05SxiPSqRS7S9qwDhYts1TSLR1BQfYUfPe1stofgGKvwERK9+9yf+PpfBMlpBaCHucXGPQfUA==", + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.17.5" + } + }, + "string.prototype.trimleft": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/string.prototype.trimleft/-/string.prototype.trimleft-2.1.2.tgz", + "integrity": "sha512-gCA0tza1JBvqr3bfAIFJGqfdRTyPae82+KTnm3coDXkZN9wnuW3HjGgN386D7hfv5CHQYCI022/rJPVlqXyHSw==", + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.17.5", + "string.prototype.trimstart": "^1.0.0" + } + }, + "string.prototype.trimright": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/string.prototype.trimright/-/string.prototype.trimright-2.1.2.tgz", + "integrity": "sha512-ZNRQ7sY3KroTaYjRS6EbNiiHrOkjihL9aQE/8gfQ4DtAC/aEBRHFJa44OmoWxGGqXuJlfKkZW4WcXErGr+9ZFg==", + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.17.5", + "string.prototype.trimend": "^1.0.0" + } + }, + "string.prototype.trimstart": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/string.prototype.trimstart/-/string.prototype.trimstart-1.0.0.tgz", + "integrity": "sha512-iCP8g01NFYiiBOnwG1Xc3WZLyoo+RuBymwIlWncShXDDJYWN6DbnM3odslBJdgCdRlq94B5s63NWAZlcn2CS4w==", + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.17.5" + } + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, + "supports-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", + "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", + "dev": true + }, + "thunky": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/thunky/-/thunky-1.1.0.tgz", + "integrity": "sha512-eHY7nBftgThBqOyHGVN+l8gF0BucP09fMo0oO/Lb0w1OF80dJv+lDVpXG60WMQvkcxAkNybKsrEIE3ZtKGmPrA==" + }, + "tough-cookie": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", + "integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==", + "requires": { + "psl": "^1.1.28", + "punycode": "^2.1.1" + } + }, + "tunnel-agent": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", + "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", + "requires": { + "safe-buffer": "^5.0.1" + } + }, + "tweetnacl": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==", + "dev": true + }, + "typescript": { + "version": "3.8.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz", + "integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==", + "dev": true + }, + "underscore": { + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.10.2.tgz", + "integrity": "sha512-N4P+Q/BuyuEKFJ43B9gYuOj4TQUHXX+j2FqguVOpjkssLUUrnJofCcBccJSCoeturDoZU6GorDTHSvUDlSQbTg==" + }, + "uri-js": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", + "integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==", + "requires": { + "punycode": "^2.1.0" + } + }, + "uuid": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", + "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==" + }, + "verror": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", + "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", + "requires": { + "assert-plus": "^1.0.0", + "core-util-is": "1.0.2", + "extsprintf": "^1.2.0" + } + }, + "xmldom": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.3.0.tgz", + "integrity": "sha512-z9s6k3wxE+aZHgXYxSTpGDo7BYOUfJsIRyoZiX6HTjwpwfS2wpQBQKa2fD+ShLyPkqDYo5ud7KitmLZ2Cd6r0g==" + }, + "xpath.js": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/xpath.js/-/xpath.js-1.1.0.tgz", + "integrity": "sha512-jg+qkfS4K8E7965sqaUl8mRngXiKb3WZGfONgE18pr03FUQiuSV6G+Ej4tS55B+rIQSFEIw3phdVAQ4pPqNWfQ==" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..32f007b --- /dev/null +++ b/package.json @@ -0,0 +1,38 @@ +{ + "name": "homebridge-presence-switch-msgraph", + "version": "0.0.1", + "description": "Switch for Microsoft Graph presence status", + "license": "MIT", + "keywords": [ + "homebridge-plugin" + ], + "author": "Elio Struyf", + "main": "dist/index.js", + "scripts": { + "prepublish": "tsc", + "start": "tsc", + "publish:next": "npm publish --tag next" + }, + "repository": { + "type": "git", + "url": "" + }, + "bugs": {}, + "engines": { + "node": ">=0.12.0", + "homebridge": ">=0.2.0" + }, + "dependencies": { + "adal-node": "0.2.1", + "homebridge-lib": "4.5.6", + "node-fetch": "2.6.0", + "node-persist": "3.0.5" + }, + "devDependencies": { + "@types/node-fetch": "2.5.5", + "@types/node-persist": "3.0.0", + "hap-nodejs": "0.4.51", + "homebridge": "0.4.53", + "typescript": "3.8.3" + } +} diff --git a/scripts/update-package-version.js b/scripts/update-package-version.js new file mode 100644 index 0000000..a16825e --- /dev/null +++ b/scripts/update-package-version.js @@ -0,0 +1,6 @@ +const fs = require('fs'); +const path = require('path'); +const packageJson = require('../package.json'); +packageJson.version += `-beta.${process.argv[process.argv.length-1].substr(0, 7)}`; +console.log(packageJson.version); +fs.writeFileSync(path.join(path.resolve('.'), 'package.json'), JSON.stringify(packageJson, null, 2)); diff --git a/src/accessories/PresenceAccessory.ts b/src/accessories/PresenceAccessory.ts new file mode 100644 index 0000000..c6e5616 --- /dev/null +++ b/src/accessories/PresenceAccessory.ts @@ -0,0 +1,205 @@ +import { Homebridge, HomebridgeAccessory, PresenceConfig, Logger, Presence, Availability, StatusColors, RGB } from '../models'; +import 'hap-nodejs'; +import persist from 'node-persist'; +import { Auth, splitHours } from '../helpers'; +import { MsGraphService, BusyLightService } from '../services'; +import { Characteristic } from 'hap-nodejs'; + +const MSGRAPH_URL = `https://graph.microsoft.com`; +const MSGRAPH_PRESENCE_PATH = `beta/me/presence`; + +export class PresenceAccessory implements HomebridgeAccessory { + private static api: Homebridge = null; + private static service: HAPNodeJS.Service = null; + private static characteristic: HAPNodeJS.Characteristic = null; + private static version: string = null; + + private accessoryService: HAPNodeJS.Service = null; + private storage: typeof persist; + private auth: Auth = null; + + private readonly defaultColors: StatusColors = { + available: { + red: 0, + green: 144, + blue: 0 + }, + away: { + red: 255, + green: 191, + blue: 0 + }, + busy: { + red: 179, + green: 0, + blue: 0 + } + }; + + private config: PresenceConfig = { + name: null, + accessory: null, + appId: null, + interval: 1, // Every minute + setColorApi: null, + offApi: null, + onApi: null, + startTime: null, + endTime: null, + lightType: null, + statusColors: this.defaultColors, + weekend: false, + debug: false + }; + + /** + * Initialize the accessory registration + * + * @param homebridge + * @param packageJSON + * @param platformName + */ + public static register(homebridge: Homebridge, packageJSON: any, platformName: string) { + console.log(`The ${packageJSON.name} plugin version is: ${packageJSON.version}. Installed on Homebridge version: ${homebridge.version}.`); + + this.api = homebridge; + this.service = homebridge.hap.Service; + this.characteristic = homebridge.hap.Characteristic; + this.version = packageJSON.version; + + homebridge.registerAccessory(packageJSON.name, platformName, PresenceAccessory); + } + + constructor(private log: Logger, options: PresenceConfig, private api: Homebridge) { + // Overwrite the default config + this.config = Object.assign({}, this.config, options); + + // Register new switch + this.accessoryService = new PresenceAccessory.service.Switch(this.config.name, null); + this.accessoryService.getCharacteristic(Characteristic.On).updateValue(false); + + // Initialize the accessory + this.init(); + } + + /** + * Return the new accessory service + */ + public getServices() { + const informationService = new (PresenceAccessory.service as any).AccessoryInformation(); + const characteristic = PresenceAccessory.characteristic; + informationService.setCharacteristic(characteristic.Manufacturer, 'Elio Struyf') + .setCharacteristic(characteristic.Model, 'Presence Indicator') + .setCharacteristic(characteristic.SerialNumber, 'PI_01') + .setCharacteristic(characteristic.FirmwareRevision, PresenceAccessory.version); + return [informationService, this.accessoryService]; + } + + /** + * Initialize the button + */ + private async init() { + const storePath = PresenceAccessory.api.user.persistPath(); + this.storage = persist; + await this.storage.init({ + dir: storePath, + forgiveParseErrors: true + }); + + this.auth = new Auth(this.config.appId, this.storage); + this.auth.ensureAccessToken(MSGRAPH_URL, this.log, true).then(async (accessToken) => { + await BusyLightService.get(this.config.onApi, this.log, this.config.debug); + + if (accessToken) { + this.presencePolling(); + } + }); + } + + /** + * Presence polling + */ + private presencePolling = async () => { + const accessToken = await this.auth.ensureAccessToken(MSGRAPH_URL, this.log, this.config.debug); + if (accessToken) { + const shouldFetch = this.shouldCheckPresence(); + + if (shouldFetch) { + const presence: Presence = await MsGraphService.get(`${MSGRAPH_URL}/${MSGRAPH_PRESENCE_PATH}`, accessToken, this.log, this.config.debug); + if (presence && presence.availability) { + const availability = this.getAvailability(presence.availability); + let color: RGB = this.config.statusColors[availability.toLowerCase()]; + if (!color || (!color.red && !color.green && !color.blue)) { + color = this.defaultColors[availability.toLowerCase()]; + } + await BusyLightService.post(this.config.setColorApi, color, this.log, this.config.debug); + } + } else { + await BusyLightService.get(this.config.offApi, this.log, this.config.debug); + } + } + + setTimeout(() => { + this.presencePolling(); + }, (this.config.interval >= 1 ? this.config.interval : 1) * 60 * 1000); + } + + /** + * Retrieve the availability status + * + * @param presence + */ + private getAvailability(presence: Availability) { + switch(presence) { + case Availability.Available: + case Availability.AvailableIdle: + return Availability.Available; + case Availability.Away: + case Availability.BeRightBack: + return Availability.Away; + case Availability.Busy: + case Availability.BusyIdle: + case Availability.DoNotDisturb: + return Availability.Busy; + case Availability.Offline: + case Availability.PresenceUnknown: + default: + return Availability.Offline; + } + } + + /** + * Should the accessory check the presence + */ + private shouldCheckPresence() { + // Check if switch is on or off + const state = (this.accessoryService.getCharacteristic(Characteristic.On) as any).value; + if (this.config.debug) { + this.log.info(`Current accessory state is: ${JSON.stringify(state)}`); + } + if (!state) { + return false; + } + + const startTimeSplit = splitHours(this.config.startTime); + const endTimeSplit = splitHours(this.config.endTime); + const crntDate = new Date(); + + if(!this.config.weekend && (crntDate.getDay() == 6 || crntDate.getDay() == 0)) { + if (this.config.debug) { + this.log.info(`It's weekend, accessory will not set the busy light.`); + } + return false; + } + + if (startTimeSplit && (crntDate.getHours() < startTimeSplit.hour || crntDate.getHours() === startTimeSplit.hour && crntDate.getMinutes() < startTimeSplit.minutes)) { + return false; + } + + if (endTimeSplit && (crntDate.getHours() > endTimeSplit.hour || crntDate.getHours() === endTimeSplit.hour && crntDate.getMinutes() > endTimeSplit.minutes)) { + return false; + } + + return true; + } +} diff --git a/src/accessories/index.ts b/src/accessories/index.ts new file mode 100644 index 0000000..49d5f72 --- /dev/null +++ b/src/accessories/index.ts @@ -0,0 +1 @@ +export * from './PresenceAccessory'; diff --git a/src/helpers/Auth.ts b/src/helpers/Auth.ts new file mode 100644 index 0000000..1028d38 --- /dev/null +++ b/src/helpers/Auth.ts @@ -0,0 +1,197 @@ +import { AuthenticationContext, TokenResponse, ErrorResponse, UserCodeInfo, Logging, LoggingLevel } from 'adal-node'; +import { Logger, AccessToken } from '../models'; +import persist from 'node-persist'; + +const MS_LOGIN_URL = "https://login.microsoftonline.com"; + +export interface Hash { + [key: string]: TValue; +} + +class AuthService { + connected: boolean = false; + refreshToken?: string; + accessTokens: Hash; + tenantId?: string; + + constructor() { + this.accessTokens = {}; + } + + public logout(): void { + this.connected = false; + this.accessTokens = {}; + this.refreshToken = undefined; + this.tenantId = undefined; + } +} + +export class Auth { + private authCtx: AuthenticationContext = null; + private service: AuthService = null; + private userCodeInfo?: UserCodeInfo; + + constructor(private appId: string, private storage: typeof persist) { + this.service = new AuthService(); + this.authCtx = new AuthenticationContext(`${MS_LOGIN_URL}/common`) + } + + /** + * Retrieve an accessToken + * + * @param resource + * @param log + * @param debug + * @param fetchNew + */ + public async ensureAccessToken(resource: string, log: Logger, debug: boolean = false, fetchNew: boolean = false): Promise { + try { + const now: Date = new Date(); + const accessToken: AccessToken | undefined = this.service.accessTokens[resource]; + const expiresOn: Date = accessToken ? new Date(accessToken.expiresOn) : new Date(0); + + // Check if there is still an accessToken available + if (!fetchNew && accessToken && expiresOn > now) { + if (debug) { + log.info(`Existing access token ${accessToken.value} still valid. Returning...`); + } + return accessToken.value; + } else { + if (debug) { + if (!accessToken) { + log.warn(`No token found for resource ${resource}`); + } else { + log.warn(`Access token expired. Token: ${accessToken.value}, ExpiresAt: ${accessToken.expiresOn}`); + } + } + } + + let getTokenPromise = this.ensureAccessTokenWithDeviceCode; + if (this.service.refreshToken) { + getTokenPromise = this.ensureAccessTokenWithRefreshToken; + } + + const tokenResponse = await getTokenPromise(resource, log, debug); + if (!tokenResponse) { + return null; + } + + this.service.accessTokens[resource] = { + expiresOn: tokenResponse.expiresOn as string, + value: tokenResponse.accessToken + }; + this.service.refreshToken = tokenResponse.refreshToken; + this.service.connected = true; + + await this.storeConnectionInfo(resource); + + return this.service.accessTokens[resource].value; + } catch (error) { + log.error(`Failed to retrieve an accessToken: ${error.message}`); + return null; + } + } + + /** + * Cancel the device token flow + */ + public cancel(): void { + if (this.userCodeInfo) { + this.authCtx.cancelRequestToGetTokenWithDeviceCode(this.userCodeInfo as UserCodeInfo, (error: Error, response: TokenResponse | ErrorResponse): void => { }); + } + } + + /** + * Retrieve a new accessToken via the device flow + * + * @param resource + * @param log + * @param debug + */ + private ensureAccessTokenWithDeviceCode = (resource: string, log: Logger, debug: boolean): Promise => { + if (debug) { + log.info(`Starting Auth.ensureAccessTokenWithDeviceCode. resource: ${resource}, debug: ${debug}`); + } + + return new Promise((resolve: (tokenResponse: TokenResponse) => void, reject: (err: any) => void) => { + if (debug) { + log.info('No existing refresh token. Starting new device code flow...'); + } + + this.authCtx.acquireUserCode(resource, this.appId as string, 'en-us', + (error: Error, response: UserCodeInfo): void => { + if (debug) { + log.info('Response:'); + log.info(response); + log.info(''); + } + + if (error) { + reject((response && (response as any).error_description) || error.message); + return; + } + + log.info(response.message); + + this.userCodeInfo = response; + this.authCtx.acquireTokenWithDeviceCode(resource, this.appId as string, response, + (error: Error, response: TokenResponse | ErrorResponse): void => { + if (debug) { + log.info('Response:'); + log.info(response); + log.info(''); + } + + if (error) { + reject((response && (response as any).error_description) || error.message || (error as any).error_description); + return; + } + + this.userCodeInfo = undefined; + resolve(response); + }); + }); + }); + } + + /** + * Retrieve a new accessToken via the refresh token + * + * @param resource + * @param log + * @param debug + */ + private ensureAccessTokenWithRefreshToken(resource: string, log: Logger, debug: boolean): Promise { + return new Promise((resolve: (tokenResponse: TokenResponse) => void, reject: (error: any) => void): void => { + if (debug) { + log.info(`Retrieving new access token using existing refresh token ${this.service.refreshToken}`); + } + + this.authCtx.acquireTokenWithRefreshToken( + this.service.refreshToken as string, + this.appId as string, + resource, + (error: Error, response: TokenResponse | ErrorResponse): void => { + if (debug) { + log.info('Response:'); + log.info(response); + log.info(''); + } + + if (error) { + reject((response && (response as any).error_description) || error.message); + return; + } + + resolve(response); + }); + }); + } + + /** + * Store the connection information + */ + private storeConnectionInfo = async (resource: string): Promise => { + await this.storage.set(`${this.appId}-${resource}`, JSON.stringify(this.service)); + } +} \ No newline at end of file diff --git a/src/helpers/TimeHelpers.ts b/src/helpers/TimeHelpers.ts new file mode 100644 index 0000000..7d7fcf4 --- /dev/null +++ b/src/helpers/TimeHelpers.ts @@ -0,0 +1,12 @@ + +export const splitHours = (time: string): { hour: number, minutes: number} | null => { + if (time && time.includes(":")) { + const daySplit = time.split(":"); + return { + hour: parseInt(daySplit[0]), + minutes: parseInt(daySplit[1]) + } + } + + return null; +} \ No newline at end of file diff --git a/src/helpers/index.ts b/src/helpers/index.ts new file mode 100644 index 0000000..f471df4 --- /dev/null +++ b/src/helpers/index.ts @@ -0,0 +1,2 @@ +export * from './Auth'; +export * from './TimeHelpers'; diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..465a799 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,9 @@ +import { PresenceAccessory } from './accessories'; +import { Homebridge } from './models'; +const packageJSON = require('../package.json'); + +const HOMEBRIDGE_PLATFORM_NAME = "presence-switch"; + +export default function (homebridge: Homebridge) { + PresenceAccessory.register(homebridge, packageJSON, HOMEBRIDGE_PLATFORM_NAME); +}; \ No newline at end of file diff --git a/src/models/AccessToken.ts b/src/models/AccessToken.ts new file mode 100644 index 0000000..37aa3a8 --- /dev/null +++ b/src/models/AccessToken.ts @@ -0,0 +1,4 @@ +export interface AccessToken { + expiresOn: string; + value: string; +} \ No newline at end of file diff --git a/src/models/Availability.ts b/src/models/Availability.ts new file mode 100644 index 0000000..8c4e4e1 --- /dev/null +++ b/src/models/Availability.ts @@ -0,0 +1,11 @@ +export enum Availability { + Available = "Available", + AvailableIdle = "AvailableIdle", + Away = "Away", + BeRightBack = "BeRightBack", + Busy = "Busy", + BusyIdle = "BusyIdle", + DoNotDisturb = "DoNotDisturb", + Offline = "Offline", + PresenceUnknown = "PresenceUnknown" +} \ No newline at end of file diff --git a/src/models/Homebridge.ts b/src/models/Homebridge.ts new file mode 100644 index 0000000..33ff116 --- /dev/null +++ b/src/models/Homebridge.ts @@ -0,0 +1,126 @@ +export interface Homebridge { + _accessories: Accessories; + _platforms: Accessories; + _configurableAccessories: Accessories; + _dynamicPlatforms: Accessories; + version: number; + serverVersion: string; + hap: Hap; + user: User; + hapLegacyTypes: HapLegacyTypes; + platformAccessory: any; + _events: Accessories; + _eventsCount: number; + + registerAccessory: (pluginName: string, platformName: string, constructor: any) => void; + registerPlatform: (pluginName: string, platformName: string, constructor: any, dynamic: boolean) => void; + registerPlatformAccessories: (pluginName: string, platformName: string, accessories: Accessories) => void; + + updatePlatformAccessories: (accessories: Accessories) => void; + + unregisterPlatformAccessories: (pluginName: string, platformName: string, accessories: Accessories) => void; + + on: (eventName: string, callback: () => void) => void; +} + +export interface HapLegacyTypes { + OTHER_TCTYPE: number; + FAN_TCTYPE: number; + GARAGE_DOOR_OPENER_TCTYPE: number; + LIGHTBULB_TCTYPE: number; + DOOR_LOCK_TCTYPE: number; + OUTLET_TCTYPE: number; + SWITCH_TCTYPE: number; + THERMOSTAT_TCTYPE: number; + SENSOR_TCTYPE: number; + ALARM_SYSTEM_TCTYPE: number; + DOOR_TCTYPE: number; + WINDOW_TCTYPE: number; + WINDOW_COVERING_TCTYPE: number; + PROGRAMMABLE_SWITCH_TCTYPE: number; + LIGHTBULB_STYPE: string; + SWITCH_STYPE: string; + THERMOSTAT_STYPE: string; + GARAGE_DOOR_OPENER_STYPE: string; + ACCESSORY_INFORMATION_STYPE: string; + FAN_STYPE: string; + OUTLET_STYPE: string; + LOCK_MECHANISM_STYPE: string; + LOCK_MANAGEMENT_STYPE: string; + ALARM_STYPE: string; + WINDOW_COVERING_STYPE: string; + OCCUPANCY_SENSOR_STYPE: string; + CONTACT_SENSOR_STYPE: string; + MOTION_SENSOR_STYPE: string; + HUMIDITY_SENSOR_STYPE: string; + TEMPERATURE_SENSOR_STYPE: string; + ALARM_CURRENT_STATE_CTYPE: string; + ALARM_TARGET_STATE_CTYPE: string; + ADMIN_ONLY_ACCESS_CTYPE: string; + AUDIO_FEEDBACK_CTYPE: string; + BRIGHTNESS_CTYPE: string; + BATTERY_LEVEL_CTYPE: string; + COOLING_THRESHOLD_CTYPE: string; + CONTACT_SENSOR_STATE_CTYPE: string; + CURRENT_DOOR_STATE_CTYPE: string; + CURRENT_LOCK_MECHANISM_STATE_CTYPE: string; + CURRENT_RELATIVE_HUMIDITY_CTYPE: string; + CURRENT_TEMPERATURE_CTYPE: string; + HEATING_THRESHOLD_CTYPE: string; + HUE_CTYPE: string; + IDENTIFY_CTYPE: string; + LOCK_MANAGEMENT_AUTO_SECURE_TIMEOUT_CTYPE: string; + LOCK_MANAGEMENT_CONTROL_POINT_CTYPE: string; + LOCK_MECHANISM_LAST_KNOWN_ACTION_CTYPE: string; + LOGS_CTYPE: string; + MANUFACTURER_CTYPE: string; + MODEL_CTYPE: string; + MOTION_DETECTED_CTYPE: string; + NAME_CTYPE: string; + OBSTRUCTION_DETECTED_CTYPE: string; + OUTLET_IN_USE_CTYPE: string; + OCCUPANCY_DETECTED_CTYPE: string; + POWER_STATE_CTYPE: string; + PROGRAMMABLE_SWITCH_SWITCH_EVENT_CTYPE: string; + PROGRAMMABLE_SWITCH_OUTPUT_STATE_CTYPE: string; + ROTATION_DIRECTION_CTYPE: string; + ROTATION_SPEED_CTYPE: string; + SATURATION_CTYPE: string; + SERIAL_NUMBER_CTYPE: string; + STATUS_LOW_BATTERY_CTYPE: string; + STATUS_FAULT_CTYPE: string; + TARGET_DOORSTATE_CTYPE: string; + TARGET_LOCK_MECHANISM_STATE_CTYPE: string; + TARGET_RELATIVE_HUMIDITY_CTYPE: string; + TARGET_TEMPERATURE_CTYPE: string; + TEMPERATURE_UNITS_CTYPE: string; + VERSION_CTYPE: string; + WINDOW_COVERING_TARGET_POSITION_CTYPE: string; + WINDOW_COVERING_CURRENT_POSITION_CTYPE: string; + WINDOW_COVERING_OPERATION_STATE_CTYPE: string; + CURRENTHEATINGCOOLING_CTYPE: string; + TARGETHEATINGCOOLING_CTYPE: string; +} + +export interface Hap { + uuid: HAPNodeJS.uuid; + AccessoryLoader: Accessories; + Characteristic: HAPNodeJS.Characteristic; + Service: HAPNodeJS.Service; +} + +export interface Accessories { +} + +export interface Accessory { + displayName: string; +} + +export interface User { + config: () => any; + storagePath: () => string; + configPath: () => string; + persistPath: () => string; + cachedAccessoryPath: () => string; + setStoragePath: (storagePath: string) => void; +} \ No newline at end of file diff --git a/src/models/HomebridgeAccessory.ts b/src/models/HomebridgeAccessory.ts new file mode 100644 index 0000000..f0f66cb --- /dev/null +++ b/src/models/HomebridgeAccessory.ts @@ -0,0 +1,5 @@ + + +export interface HomebridgeAccessory { + getServices: () => HAPNodeJS.Service[]; +} \ No newline at end of file diff --git a/src/models/Logger.ts b/src/models/Logger.ts new file mode 100644 index 0000000..45e89a4 --- /dev/null +++ b/src/models/Logger.ts @@ -0,0 +1,8 @@ + + +export interface Logger { + debug: (msg: any) => void; + info: (msg: any) => void; + warn: (msg: any) => void; + error: (msg: any) => void; +} \ No newline at end of file diff --git a/src/models/Presence.ts b/src/models/Presence.ts new file mode 100644 index 0000000..b163cbd --- /dev/null +++ b/src/models/Presence.ts @@ -0,0 +1,7 @@ +import { Availability } from "."; + +export interface Presence { + id: string; + availability: Availability; + activity: string; +} \ No newline at end of file diff --git a/src/models/PresenceConfig.ts b/src/models/PresenceConfig.ts new file mode 100644 index 0000000..05503d3 --- /dev/null +++ b/src/models/PresenceConfig.ts @@ -0,0 +1,17 @@ +import { StatusColors } from "."; + +export interface PresenceConfig { + name: string; + accessory: string; + appId: string; + interval: number; + setColorApi: string; + offApi: string; + onApi: string; + startTime: string; + endTime: string; + lightType: string; + statusColors: StatusColors; + weekend: boolean; + debug: boolean; +} \ No newline at end of file diff --git a/src/models/StatusColors.ts b/src/models/StatusColors.ts new file mode 100644 index 0000000..7d1a62c --- /dev/null +++ b/src/models/StatusColors.ts @@ -0,0 +1,12 @@ + +export interface StatusColors { + available: RGB; + away: RGB; + busy: RGB; +} + +export interface RGB { + red: number; + green: number; + blue: number; +} \ No newline at end of file diff --git a/src/models/index.ts b/src/models/index.ts new file mode 100644 index 0000000..bd3ae14 --- /dev/null +++ b/src/models/index.ts @@ -0,0 +1,8 @@ +export * from './AccessToken'; +export * from './Availability'; +export * from './Homebridge'; +export * from './HomebridgeAccessory'; +export * from './Logger'; +export * from './Presence'; +export * from './PresenceConfig'; +export * from './StatusColors'; diff --git a/src/services/busyLightService.ts b/src/services/busyLightService.ts new file mode 100644 index 0000000..586eebe --- /dev/null +++ b/src/services/busyLightService.ts @@ -0,0 +1,50 @@ +import { Logger } from "../models"; +import fetch from 'node-fetch'; + + +export class BusyLightService { + + /** + * Do a get request to the busy light + * + * @param url + */ + public static async get(url: string, log: Logger, debug: boolean = false) { + try { + if (debug) { + log.info(`Calling the busy light API: ${url}`); + } + const data = await fetch(url); + if (debug) { + log.info(`Call was: ${data.ok}`); + } + } catch (error) { + log.warn(`Seems to be the busy light API was offline`); + } + } + + /** + * Do a post request to the busy light + * + * @param url + */ + public static async post(url: string, body: any, log: Logger, debug: boolean = false) { + try { + if (debug) { + log.info(`Calling the busy light API: ${url} - ${JSON.stringify(body)}`); + } + const data = await fetch(url, { + method: "POST", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify(body) + }); + if (debug) { + log.info(`Call was: ${data.ok}`); + } + } catch (error) { + log.warn(`Seems to be the busy light API was offline`); + } + } +} \ No newline at end of file diff --git a/src/services/index.ts b/src/services/index.ts new file mode 100644 index 0000000..0b99f00 --- /dev/null +++ b/src/services/index.ts @@ -0,0 +1,2 @@ +export * from './busyLightService'; +export * from './msGraphService'; diff --git a/src/services/msGraphService.ts b/src/services/msGraphService.ts new file mode 100644 index 0000000..4d106e3 --- /dev/null +++ b/src/services/msGraphService.ts @@ -0,0 +1,32 @@ +import fetch from 'node-fetch'; +import { Logger } from '../models'; + +export class MsGraphService { + + /** + * Perform a get request against the MS Graph + * + * @param url + * @param accessToken + */ + public static async get(url: string, accessToken: string, log: Logger, debug: boolean = false) { + if (debug) { + log.info(`Calling the MS Graph.`); + } + + const response = await fetch(url, { + headers: { + Authorization: `Bearer ${accessToken}`, + 'Content-Type': `application/json`, + 'Accept': `application/json` + } + }); + + const data = await response.json(); + if (debug) { + log.info(`MS Graph response: ${JSON.stringify(data)}`); + } + + return data; + } +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..189ac02 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "target": "es2017", + "forceConsistentCasingInFileNames": true, + "module": "commonjs", + "moduleResolution": "node", + "resolveJsonModule": true, + "esModuleInterop": true, + "declaration": true, + "sourceMap": true, + "skipLibCheck": true, + "outDir": "dist", + "typeRoots": [ + "./node_modules/@types" + ], + "lib": ["es2017"] + }, + "exclude": [ + "node_modules", + "dist" + ], + "include": [ + "src/**/*.ts", + ] +}