diff --git a/.eslintrc.json b/.eslintrc.json index cd9b30c..dfc8789 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,3 +1,4 @@ { - "extends": "athom/homey-app" -} \ No newline at end of file + "extends": "athom/homey-app", + "strict": "off" +} diff --git a/.homeychangelog.json b/.homeychangelog.json index c257a09..3897bb5 100644 --- a/.homeychangelog.json +++ b/.homeychangelog.json @@ -13,5 +13,8 @@ }, "0.0.5": { "en": "Handle networking errors and add debugging feature" + }, + "0.0.6": { + "en": "Additional debug for pairing, fix reported crashes" } } diff --git a/.homeycompose/app.json b/.homeycompose/app.json index 916ca0f..20f54f1 100644 --- a/.homeycompose/app.json +++ b/.homeycompose/app.json @@ -1,6 +1,6 @@ { "id": "com.christerbeke.remeha-home", - "version": "0.0.5", + "version": "0.0.6", "compatibility": ">=5.0.0", "sdk": 3, "platforms": [ diff --git a/app.json b/app.json index fcd5fb3..f81b67f 100644 --- a/app.json +++ b/app.json @@ -1,7 +1,7 @@ { "_comment": "This file is generated. Please edit .homeycompose/app.json instead.", "id": "com.christerbeke.remeha-home", - "version": "0.0.5", + "version": "0.0.6", "compatibility": ">=5.0.0", "sdk": 3, "platforms": [ diff --git a/app.ts b/app.ts index 3a2dff2..e921f23 100644 --- a/app.ts +++ b/app.ts @@ -3,8 +3,12 @@ sourceMapSupport.install() import { App } from 'homey' +const { Log } = require('homey-log') + class RemehaApp extends App { async onInit() { + // @ts-ignore TS2339 + this.homeyLog = new Log({ homey: this.homey }) this.log('RemehaApp is running...') } } diff --git a/drivers/remeha/device.ts b/drivers/remeha/device.ts index 5b786a3..d7d8abf 100644 --- a/drivers/remeha/device.ts +++ b/drivers/remeha/device.ts @@ -26,10 +26,6 @@ class RemehaThermostatDevice extends Device { this._init() } - async onDeleted(): Promise { - this._uninit() - } - private async _init(): Promise { const { accessToken } = this.getStore() this._client = new RemehaMobileApi(accessToken) @@ -38,7 +34,6 @@ class RemehaThermostatDevice extends Device { } async _uninit(): Promise { - this.setUnavailable() clearInterval(this._syncInterval as NodeJS.Timeout) this._syncInterval = undefined this._client = undefined @@ -70,7 +65,7 @@ class RemehaThermostatDevice extends Device { if (!debugEnabled) return const debug = await this._client.debug() this.setSettings({ apiData: JSON.stringify(debug) }) - } catch (error) {} + } catch (error) { } } private async _setTargetTemperature(value: number): Promise { diff --git a/drivers/remeha/driver.ts b/drivers/remeha/driver.ts index 99641f8..c067329 100644 --- a/drivers/remeha/driver.ts +++ b/drivers/remeha/driver.ts @@ -8,30 +8,21 @@ class RemehaDriver extends Driver { private _tokenData: TokenData | null = null async onPair(session: PairSession) { + session.setHandler('login', this._login.bind(this)) + session.setHandler('list_devices', this._listDevices.bind(this)) + } - const driver = this - - session.setHandler('login', async function (credentials: string): Promise { - const authorizer = new RemehaAuth() - const [email, password] = credentials.split(':') - try { - driver._tokenData = await authorizer.login(email, password) - return true - } catch (error) { - return false - } - }) + private async _login(credentials: string): Promise { + const authorizer = new RemehaAuth() + const [email, password] = credentials.split(':') + this._tokenData = await authorizer.login(email, password) + } - session.setHandler('list_devices', async function (): Promise { - if (!driver._tokenData || !driver._tokenData.accessToken) return [] - const api = new RemehaMobileApi(driver._tokenData.accessToken) - try { - const devices = await api.devices() - return devices.map(driver._mapDevice.bind(driver)) - } catch (error) { - return [] - } - }) + private async _listDevices(): Promise { + if (!this._tokenData || !this._tokenData.accessToken) return [] + const api = new RemehaMobileApi(this._tokenData.accessToken) + const devices = await api.devices() + return devices.map(this._mapDevice.bind(this)) } private _mapDevice(device: DeviceData): any { diff --git a/drivers/remeha/pair/login.html b/drivers/remeha/pair/login.html index bb39425..ad56ffc 100644 --- a/drivers/remeha/pair/login.html +++ b/drivers/remeha/pair/login.html @@ -3,15 +3,10 @@ var email = document.getElementById('email').value var password = document.getElementById('password').value Homey.showLoadingOverlay() - Homey.emit('login', `${email}:${password}`).then((success) => { - if (success) { - Homey.showView('list_devices') - } else { - Homey.alert(Homey.__('pair.login_error'), 'error') - Homey.done() - } + Homey.emit('login', `${email}:${password}`).then(() => { + Homey.showView('list_devices') }).catch(error => { - Homey.alert(Homey.__('pair.login_error'), 'error') + Homey.alert(error.message, 'error') Homey.done() }).finally(() => { Homey.hideLoadingOverlay() diff --git a/package-lock.json b/package-lock.json index 4e1a5cc..c2fe7dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.0.1", "dependencies": { "fetch-cookie": "^3.0.1", + "homey-log": "^2.1.0", "node-fetch": "^2.6.1", "source-map-support": "^0.5.21" }, @@ -922,6 +923,14 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, + "node_modules/charenc": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz", + "integrity": "sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA==", + "engines": { + "node": "*" + } + }, "node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", @@ -964,6 +973,14 @@ "integrity": "sha512-JsPKdmh8ZkmnHxDk55FZ1TqVLvEQTvoByJZRN9jzI0UjxK/QgAmsphz7PGtqgPieQZ/CQcHWXCR7ATDNhGe+YA==", "dev": true }, + "node_modules/cookie": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", + "integrity": "sha512-+IJOX0OqlHCszo2mBUq+SrEbCj6w7Kpffqx60zYbPTFaO4+yYgRjHwcZNpWvaTylDHaV7PPmBHzSecZiMhtPgw==", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", @@ -984,6 +1001,14 @@ "node": ">= 8" } }, + "node_modules/crypt": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz", + "integrity": "sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow==", + "engines": { + "node": "*" + } + }, "node_modules/data-view-buffer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/data-view-buffer/-/data-view-buffer-1.0.1.tgz", @@ -2135,6 +2160,17 @@ "node": ">= 0.4" } }, + "node_modules/homey-log": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/homey-log/-/homey-log-2.1.0.tgz", + "integrity": "sha512-BL4AduSZ1Hlzs3vLmExOzNONp3N5GUpG5Ro/R/6+PpKgG4ME5EIcanCuDUWcdXD8y3hJj2KKYqrr0JaggGG/8g==", + "dependencies": { + "raven": "github:athombv/raven-node" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/ignore": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", @@ -2243,6 +2279,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-buffer": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", + "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==" + }, "node_modules/is-callable": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", @@ -2564,6 +2605,16 @@ "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", "dev": true }, + "node_modules/md5": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/md5/-/md5-2.3.0.tgz", + "integrity": "sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==", + "dependencies": { + "charenc": "0.0.2", + "crypt": "0.0.2", + "is-buffer": "~1.1.6" + } + }, "node_modules/merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", @@ -2918,6 +2969,23 @@ "integrity": "sha512-SbiLPU40JuJniHexQSAgad32hfwd+DRUdwF2PlVuI5RZD0/vahUco7R8vD86J/tcEKKF9vZrUVwgtmGCqlCKyA==", "dev": true }, + "node_modules/raven": { + "version": "2.6.2", + "resolved": "git+ssh://git@github.com/athombv/raven-node.git#b8b2b6e007924a79ba4434240f6dfcf431d7c9a1", + "dependencies": { + "cookie": "0.3.1", + "md5": "^2.2.1", + "stack-trace": "0.0.10", + "timed-out": "5.0.0", + "uuid": "3.0.0" + }, + "bin": { + "raven": "bin/raven" + }, + "engines": { + "node": ">= 4.0.0" + } + }, "node_modules/regexp.prototype.flags": { "version": "1.5.2", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.2.tgz", @@ -3211,6 +3279,14 @@ "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==", "dev": true }, + "node_modules/stack-trace": { + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz", + "integrity": "sha512-KGzahc7puUKkzyMt+IqAep+TVNbKP+k2Lmwhub39m1AsTSkaDutx56aDCo+HLDzf/D26BIHTJWNiTG1KAJiQCg==", + "engines": { + "node": "*" + } + }, "node_modules/string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", @@ -3375,6 +3451,14 @@ "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", "dev": true }, + "node_modules/timed-out": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/timed-out/-/timed-out-5.0.0.tgz", + "integrity": "sha512-+IAmaDqYnVi/HOMCeH4NDzdjTH9EHTC8xbe+PgXMKtovdMjbu25qYxeUj6u/yukMp1wDOhPeh6oTcIVepm5n7Q==", + "engines": { + "node": ">=8" + } + }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -3648,6 +3732,15 @@ "requires-port": "^1.0.0" } }, + "node_modules/uuid": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.0.0.tgz", + "integrity": "sha512-rqE1LoOVLv3QrZMjb4NkF5UWlkurCfPyItVnFPNKDDGkHw4dQUdE4zMcLqx28+0Kcf3+bnUk4PisaiRJT4aiaQ==", + "deprecated": "Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.", + "bin": { + "uuid": "bin/uuid" + } + }, "node_modules/v8-compile-cache": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.4.0.tgz", diff --git a/package.json b/package.json index e4259c4..09f798a 100644 --- a/package.json +++ b/package.json @@ -10,12 +10,13 @@ }, "dependencies": { "fetch-cookie": "^3.0.1", + "homey-log": "^2.1.0", "node-fetch": "^2.6.1", "source-map-support": "^0.5.21" }, "devDependencies": { - "@tsconfig/node16": "^16.1.3", "@tsconfig/node12": "^1.0.11", + "@tsconfig/node16": "^16.1.3", "@types/homey": "npm:homey-apps-sdk-v3-types@^0.3.5", "@types/node": "^20.12.7", "@types/node-fetch": "^2.6.11",