Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move polling interval and polling timeout values from constants to settings #97

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
],
Expand Down
30 changes: 21 additions & 9 deletions drivers/gree_cooper_hunter_hvac/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}

Expand Down
Loading