Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR enhances timeout handling by retrying transient errors in the API module, cleans up unused dependencies, updates test defaults, and sets up Mocha as the test runner.
- Added
_requestwrapper inopen_garage_api.jsto retry onECONNRESETandETIMEDOUT - Updated test defaults to use
*Secs * 1000for poll frequency and open/close duration - Removed unused
request-promise-nativeimport inopen_garage.jsand changed the npmtestscript to run Mocha
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| test/open_garage_test.js | Adjusted default timing values to use seconds-based settings × 1000 |
| package.json | Updated "test" script to invoke mocha |
| lib/open_garage_api.js | Introduced http.Agent and retry logic for transient timeout errors |
| lib/open_garage.js | Removed unused request-promise-native import comment |
| let pollFrequencyMs = OpenGarageModule.defaults.pollFrequencyMs | ||
| var openDurationMs = OpenGarageModule.defaults.openDurationMs | ||
| let pollFrequencyMs = OpenGarageModule.defaults.pollFrequencySecs * 1000 | ||
| var openDurationMs = OpenGarageModule.defaults.openCloseDurationSecs * 1000 |
There was a problem hiding this comment.
[nitpick] The declaration uses var while pollFrequencyMs uses let. Consider using let or const for consistency and block scoping.
| var openDurationMs = OpenGarageModule.defaults.openCloseDurationSecs * 1000 | |
| let openDurationMs = OpenGarageModule.defaults.openCloseDurationSecs * 1000 |
| @@ -1,4 +1,4 @@ | |||
| const request = require("request-promise-native") | |||
| // request-promise-native was previously required here but never used | |||
There was a problem hiding this comment.
[nitpick] Remove this commented-out import to clean up the code and avoid confusion, as it's no longer used.
| // request-promise-native was previously required here but never used |
| if (retries > 0 && err.cause) { | ||
| if (err.cause.code === 'ECONNRESET' || err.cause.code === 'ETIMEDOUT') { | ||
| log(`Transient ${err.cause.code} error, retrying request`) | ||
| return this._request(options, retries - 1) |
There was a problem hiding this comment.
[nitpick] Retries occur immediately without delay. Consider adding a short delay (e.g., using setTimeout) between retries to avoid rapid-fire requests.
| return this._request(options, retries - 1) | |
| return new Promise((resolve) => { | |
| setTimeout(() => resolve(this._request(options, retries - 1)), 100); | |
| }); |
Summary
OpenGarageApiopen_garage.jsnpm testTesting
npm test(fails: Service.OccupancySensor is not a constructor)https://chatgpt.com/codex/tasks/task_e_684380276384832cb099697ad6529ff7