diff --git a/.eslintrc.json b/.eslintrc.json index 5a37580..8863857 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,9 +1,9 @@ { "extends": "athom", "rules": { - "no-use-before-define": ["error", { "functions": false }], - "no-console": "off", - "node/no-unpublished-require": ["error", { "allowModules": ["homey"]}], - "indent": ["error", 4] + "no-use-before-define": ["error", { "functions": false }], + "no-console": "off", + "node/no-unpublished-require": ["error", { "allowModules": ["homey"]}], + "indent": ["error", 4, { "SwitchCase": 1 }] } -} \ No newline at end of file +} diff --git a/app.json b/app.json index 878353f..5e6f25a 100644 --- a/app.json +++ b/app.json @@ -1,6 +1,6 @@ { "id": "com.gree", - "version": "0.8.2", + "version": "0.9.0", "compatibility": ">=12.0.1", "sdk": 3, "brandColor": "#ff732e", @@ -1713,6 +1713,37 @@ "hint": { "en": "Enable debug in case the application is crashing. It allows developer to investigate the issue" } + }, + { + "id": "encryption_mode", + "type": "dropdown", + "value": "auto", + "label": { + "en": "Encryption mode" + }, + "hint": { + "en": "Encryption mode used by the HVAC. Most recent firmwares use V2" + }, + "values": [ + { + "id": "auto", + "label": { + "en": "Autodetect (not implemented yet, V1 used instead)" + } + }, + { + "id": "v1", + "label": { + "en": "V1 (HVAC Firmware versions <1.21)" + } + }, + { + "id": "v2", + "label": { + "en": "V2 (HVAC Firmware versions >=1.21)" + } + } + ] } ], "images": { diff --git a/drivers/gree_cooper_hunter_hvac/device.js b/drivers/gree_cooper_hunter_hvac/device.js index 931bde4..e87c207 100644 --- a/drivers/gree_cooper_hunter_hvac/device.js +++ b/drivers/gree_cooper_hunter_hvac/device.js @@ -78,6 +78,7 @@ class GreeHVACDevice extends Homey.Device { const deviceData = this.getData(); const settings = this.getSettings(); + const encryptionVersion = this.mapEncryptionModeSetting(settings.encryption_mode); this.log('[find devices]', 'Finding device with mac:', deviceData.mac); @@ -97,6 +98,7 @@ class GreeHVACDevice extends Homey.Device { host: hvac.remoteInfo.address, pollingInterval: POLLING_INTERVAL, pollingTimeout: POLLING_TIMEOUT, + encryptionVersion, }); this._registerClientListeners(); @@ -638,17 +640,41 @@ class GreeHVACDevice extends Homey.Device { async onSettings({ oldSettings, newSettings, changedKeys }) { if (changedKeys.indexOf('enable_debug') > -1) { - console.log('Changing the debug settings from', oldSettings.enable_debug, 'to', newSettings.enable_debug); + this.log('Changing the debug setting from', oldSettings.enable_debug, 'to', newSettings.enable_debug); if (this._client) { this._client.setDebug(newSettings.enable_debug); - } else { - return Promise.reject(); } } + if (changedKeys.indexOf('encryption_mode') > -1) { + this.log('Changing the encryption mode setting from', oldSettings.encryption_mode, 'to', newSettings.encryption_mode); + this.homey.setTimeout(this.reconnect, 1000); + } + return Promise.resolve(); } + mapEncryptionModeSetting(encryptionMode) { + switch (encryptionMode) { + // not implemented yet + case 'auto': + case 'v1': + default: + // AES-ECB + return 1; + case 'v2': + // AES-GCM + return 2; + } + } + + reconnect() { + this.log('Reconnecting to the HVAC'); + this._markOffline(); + this._tryToDisconnect(); + this._startLookingForDevice(); + } + } module.exports = GreeHVACDevice; diff --git a/drivers/gree_cooper_hunter_hvac/network/finder.js b/drivers/gree_cooper_hunter_hvac/network/finder.js index 214b491..6060939 100644 --- a/drivers/gree_cooper_hunter_hvac/network/finder.js +++ b/drivers/gree_cooper_hunter_hvac/network/finder.js @@ -1,7 +1,7 @@ 'use strict'; const dgram = require('dgram'); -const { EncryptionService } = require('gree-hvac-client/lib/encryption-service'); +const { EncryptionService } = require('gree-hvac-client/src/encryption-service'); const SCAN_MESSAGE = Buffer.from('{"t": "scan"}'); const THIRTY_SECONDS = 30 * 1000; diff --git a/package-lock.json b/package-lock.json index a3dbce6..3d5a8c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "": { "license": "GPL-3.0-or-later", "dependencies": { - "gree-hvac-client": "git+https://github.com/aivus/gree-hvac-client.git#com.gree/master", + "gree-hvac-client": "github:aivus/gree-hvac-client#com.gree/encryption", "homey-log": "^2.1.0" }, "devDependencies": { @@ -3198,10 +3198,9 @@ "dev": true }, "node_modules/gree-hvac-client": { - "version": "1.3.1", - "resolved": "git+ssh://git@github.com/aivus/gree-hvac-client.git#0a83781903fad1fc54f1f2fa87d4c6af21e75641", - "integrity": "sha512-L3Zp1BVPBVLpKxul5L9NnW0XC7oy73vmURAcMa1Srw/BauIPlqiwKj7TYwUtl35iF8bVhptNaz/zpnVSm6oxBQ==", - "license": "MIT", + "version": "0.0.0-development", + "resolved": "git+ssh://git@github.com/aivus/gree-hvac-client.git#7d51627adb76ba50b48fa4f9cd494741c3f2e409", + "license": "GPL-3.0", "dependencies": { "clone": "^2.1.2", "object-diff": "^0.0.4" @@ -9738,9 +9737,8 @@ "dev": true }, "gree-hvac-client": { - "version": "git+ssh://git@github.com/aivus/gree-hvac-client.git#0a83781903fad1fc54f1f2fa87d4c6af21e75641", - "integrity": "sha512-L3Zp1BVPBVLpKxul5L9NnW0XC7oy73vmURAcMa1Srw/BauIPlqiwKj7TYwUtl35iF8bVhptNaz/zpnVSm6oxBQ==", - "from": "gree-hvac-client@git+https://github.com/aivus/gree-hvac-client.git#com.gree/master", + "version": "git+ssh://git@github.com/aivus/gree-hvac-client.git#7d51627adb76ba50b48fa4f9cd494741c3f2e409", + "from": "gree-hvac-client@github:aivus/gree-hvac-client#com.gree/encryption", "requires": { "clone": "^2.1.2", "object-diff": "^0.0.4" diff --git a/package.json b/package.json index 7af2827..6c6ce72 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ }, "homepage": "https://github.com/aivus/com.gree#readme", "dependencies": { - "gree-hvac-client": "git+https://github.com/aivus/gree-hvac-client.git#com.gree/master", + "gree-hvac-client": "github:aivus/gree-hvac-client#com.gree/encryption", "homey-log": "^2.1.0" }, "devDependencies": {