Skip to content

Commit

Permalink
Improved error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
klein0r committed May 24, 2023
1 parent f62a4fe commit c270d37
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,15 @@ class AwtrixLight extends utils.Adapter {
this.log.warn(`Unable to perform display action: ${error}`);
});
} else if (idNoNamespace.startsWith('display.moodlight.')) {
this.updateMoodlightByStates().then(async (response) => {
if (response.status === 200 && response.data === 'OK') {
await this.setStateAsync(idNoNamespace, { val: state.val, ack: true });
}
});
this.updateMoodlightByStates()
.then(async (response) => {
if (response.status === 200 && response.data === 'OK') {
await this.setStateAsync(idNoNamespace, { val: state.val, ack: true });
}
})
.catch((error) => {
this.log.warn(`Unable to perform moodlight action: ${error}`);
});
} else if (idNoNamespace === 'device.update') {
this.log.info('performing firmware update');

Expand Down Expand Up @@ -143,11 +147,15 @@ class AwtrixLight extends utils.Adapter {
this.log.debug(`Changed indicator ${indicatorNo} with action ${action}`);

if (indicatorNo && indicatorNo >= 1) {
this.updateIndicatorByStates(indicatorNo).then(async (response) => {
if (response.status === 200 && response.data === 'OK') {
await this.setStateAsync(idNoNamespace, { val: state.val, ack: true });
}
});
this.updateIndicatorByStates(indicatorNo)
.then(async (response) => {
if (response.status === 200 && response.data === 'OK') {
await this.setStateAsync(idNoNamespace, { val: state.val, ack: true });
}
})
.catch((error) => {
this.log.warn(`Unable to perform indicator action: ${error}`);
});
}
}
} else {
Expand Down Expand Up @@ -206,7 +214,9 @@ class AwtrixLight extends utils.Adapter {
this.refreshStateTimeout ||
setTimeout(() => {
this.refreshStateTimeout = null;
this.refreshState();
this.refreshState().catch((error) => {
this.log.debug(`Unable to refresh state: ${error}`);
});
}, 60000);

this.buildRequestAsync('stats', 'GET')
Expand Down

0 comments on commit c270d37

Please sign in to comment.