diff --git a/app.json b/app.json index db19762..71cc4fb 100644 --- a/app.json +++ b/app.json @@ -1221,15 +1221,41 @@ } ], "settings": [ + { + "id": "polling_interval", + "type": "number", + "value": 3500, + "min": 100, + "units": { "en": "ms" }, + "label": { + "en": "Polling interval" + }, + "hint": { + "en": "Interval between polling status from HVAC. Default value 3500" + } + }, + { + "id": "polling_timeout", + "type": "number", + "value": 3000, + "min": 100, + "units": { "en": "ms" }, + "label": { + "en": "Polling timeout" + }, + "hint": { + "en": "Timeout for the response from the HVAC during polling process. Default value 3000" + } + }, { "id": "enable_debug", "type": "checkbox", "value": false, "label": { - "en": "Debug" + "en": "Verbose logging" }, "hint": { - "en": "Enable debug in case the application is crashing. It allows developer to investigate the issue" + "en": "Enable verbose logging in case the application is crashing. It allows developer to investigate the issue" } } ], diff --git a/drivers/gree_cooper_hunter_hvac/device.js b/drivers/gree_cooper_hunter_hvac/device.js index 021e7c7..18e4f07 100644 --- a/drivers/gree_cooper_hunter_hvac/device.js +++ b/drivers/gree_cooper_hunter_hvac/device.js @@ -8,12 +8,6 @@ const { compareBoolProperties } = require('../../utils'); // Interval between trying to found HVAC in network (ms) const LOOKING_FOR_DEVICE_TIME_INTERVAL = 5000; -// Interval between polling status from HVAC (ms) -const POLLING_INTERVAL = 3500; - -// Timeout for response from the HVAC during polling process (ms) -const POLLING_TIMEOUT = 3000; - class GreeHVACDevice extends Homey.Device { /** @@ -85,15 +79,15 @@ class GreeHVACDevice extends Homey.Device { return; } - this.log('[find devices]', 'Connecting to device with mac:', hvac.message.mac); + this.log('[find devices]', 'Connecting to device with mac:', hvac.message.mac, 'using next settings:', settings); this._stopLookingForDevice(); this._client = new HVAC.Client({ debug: settings.enable_debug, host: hvac.remoteInfo.address, - pollingInterval: POLLING_INTERVAL, - pollingTimeout: POLLING_TIMEOUT, + pollingInterval: settings.polling_interval, + pollingTimeout: settings.polling_timeout, }); this._registerClientListeners(); @@ -511,6 +505,24 @@ class GreeHVACDevice extends Homey.Device { } } + if (changedKeys.indexOf('polling_interval') > -1) { + console.log('Changing the "polling_interval" settings from', oldSettings.polling_interval, 'to', newSettings.polling_interval); + if (this._client) { + this._markOffline(); + this._tryToDisconnect(); + this._startLookingForDevice(); + } + } + + if (changedKeys.indexOf('polling_timeout') > -1) { + console.log('Changing the "polling_timeout" settings from', oldSettings.polling_timeout, 'to', newSettings.polling_timeout); + if (this._client) { + this._markOffline(); + this._tryToDisconnect(); + this._startLookingForDevice(); + } + } + return Promise.resolve(); }