Skip to content

Commit

Permalink
add Event to report on API errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chas-iot committed Aug 7, 2020
1 parent ea14344 commit c472a13
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ const HOUR = 60 * 60 * 1000;
const manifest = require('../manifest.json');
const {
Adapter,
Database,
Device,
Event,
Property,
Database,
} = require('gateway-addon');
const getAPIdates = require('./holidayAPI');

Expand Down Expand Up @@ -151,6 +152,10 @@ class CalendarDevice extends Device {
type: 'string',
readOnly: true,
}));
this.addEvent('APIerror',
{title: 'API error',
description: 'Details of an error encountered while using the Holiday API',
type: 'string'});
}
}

Expand All @@ -162,6 +167,7 @@ class CalendarAdapter extends Adapter {

const device = new CalendarDevice(this, manifest.id);
this.handleDeviceAdded(device);
this.device = device;

this.holiday = device.findProperty('isHoliday');
this.workingDay = device.findProperty('isWorkingDay');
Expand Down Expand Up @@ -297,9 +303,7 @@ class CalendarAdapter extends Adapter {

// passed to the dates API requester to merge any received dates into the configured dates
merge(apiDates, that) {
if (!that) {
that = this;
}
that = that || this;
normaliseDatesArray(apiDates, getTodayStr());

if (apiDates.length > 0) {
Expand Down Expand Up @@ -394,9 +398,8 @@ class CalendarAdapter extends Adapter {

// passed to the dates API requester to allow it to update the status
setStatus(message, that) {
if (!that) {
that = this;
}
that = that || this;
that.device.eventNotify(new Event(that.device, 'APIerror', message));
that.config.api.status = message;
that.config.changed = true;
}
Expand Down

0 comments on commit c472a13

Please # to comment.