Skip to content

Commit

Permalink
Readd openhab get all items retry logic (#408)
Browse files Browse the repository at this point in the history
Signed-off-by: jsetton <[email protected]>
  • Loading branch information
jsetton authored Nov 10, 2021
1 parent 13ae3ae commit 893aa30
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lambda/openhab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ class OpenHAB {
* @return {Promise}
*/
async getAllItems() {
const items = await this.getItems();
let items;
// Retrieve all items up to 3 tries if not an array
for (let tries = 0; !Array.isArray(items) && tries < 3; tries++) {
items = await this.getItems();
}
// Return all items adding members and expanding groupNames into groups
return items.map(({ groupNames, ...item }) => ({
...item,
Expand Down
11 changes: 10 additions & 1 deletion lambda/test/openhab.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,16 @@ describe('OpenHAB Tests', () => {

it('type error', async () => {
// set environment
nock(baseURL).get('/rest/items').query(qs).reply(200, 'invalid');
nock(baseURL)
.get('/rest/items')
.query(qs)
.reply(200, 'invalid 1')
.get('/rest/items')
.query(qs)
.reply(200, 'invalid 2')
.get('/rest/items')
.query(qs)
.reply(200, 'invalid 3');
// run test
try {
await openhab.getAllItems();
Expand Down

0 comments on commit 893aa30

Please sign in to comment.