Skip to content

Commit

Permalink
Merge pull request #164 from aivus/next-v0.9.x
Browse files Browse the repository at this point in the history
Next v0.9.x changes
  • Loading branch information
aivus authored Sep 23, 2024
2 parents e166385 + a9d6518 commit a2e20c8
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 19 deletions.
10 changes: 5 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -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 }]
}
}
}
33 changes: 32 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "com.gree",
"version": "0.8.2",
"version": "0.9.0",
"compatibility": ">=12.0.1",
"sdk": 3,
"brandColor": "#ff732e",
Expand Down Expand Up @@ -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": {
Expand Down
32 changes: 29 additions & 3 deletions drivers/gree_cooper_hunter_hvac/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -97,6 +98,7 @@ class GreeHVACDevice extends Homey.Device {
host: hvac.remoteInfo.address,
pollingInterval: POLLING_INTERVAL,
pollingTimeout: POLLING_TIMEOUT,
encryptionVersion,
});

this._registerClientListeners();
Expand Down Expand Up @@ -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;
2 changes: 1 addition & 1 deletion drivers/gree_cooper_hunter_hvac/network/finder.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
14 changes: 6 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit a2e20c8

Please sign in to comment.