Skip to content

Commit

Permalink
clean up events and properties
Browse files Browse the repository at this point in the history
  • Loading branch information
chas-iot committed Aug 10, 2020
1 parent 54572bc commit 45b57a3
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,10 @@ class CalendarAdapter extends Adapter {
}
, getOffsetToHour());
})
.catch((e) => console.error(e));
.catch((e) => {
console.error(e);
this.device.eventNotify(new Event(this.device, 'APIerror', e.message));
});
}


Expand All @@ -259,7 +262,10 @@ class CalendarAdapter extends Adapter {
delete this.config.changed;
this.db.saveConfig(this.config)
.then(() => console.log('updateCalendar changed config'))
.catch((e) => console.error(e));
.catch((e) => {
console.error(e);
this.device.eventNotify(new Event(this.device, 'APIerror', e.message));
});
}

// we don't need to wait for the database save to complete before updating the gateway
Expand All @@ -277,30 +283,24 @@ class CalendarAdapter extends Adapter {

let i = 0;
while (i < this.dateList.length && dateStr === this.dateList[i].date) {
reason = reason ||
this.dateList[i].reason;

tag = tag ||
this.dateList[i].tag;

source = source ||
this.dateList[i].source;
reason = reason || this.dateList[i].reason;
tag = tag || this.dateList[i].tag;
source = source || this.dateList[i].source;
i++;
}

if ((reason || tag) && !source) {
source = 'added locally';
}
if (!reason) {
reason = this.getDayName();
source = 'manual input';
}
} else {
this.holiday.set(false);
this.workingDay.set(this.workWeek[new Date().getDay()]);
}
if (!reason) {
reason = this.getDayName();
}
this.tag.set(tag);
this.reason.set(reason);
this.tag.set(tag);
this.source.set(source);
}

Expand Down Expand Up @@ -381,9 +381,11 @@ class CalendarAdapter extends Adapter {

// not a good place to be
} else {
that.config.api.status = 'merge from API failed due to programming error';
const message = 'merge from API failed due to programming error';
console.error(message);
that.config.api.status = message;
that.device.eventNotify(new Event(that.device, 'APIerror', message));
that.config.changed = true;
console.error('merge from API failed due to programming error');
holPos = holidays.length;
apiPos = apiDates.length;
}
Expand All @@ -395,7 +397,10 @@ class CalendarAdapter extends Adapter {
delete that.config.changed;
that.db.saveConfig(that.config)
.then(() => console.log('merge/getAPIdates changed config'))
.catch((e) => console.error(e));
.catch((e) => {
console.error(e);
that.device.eventNotify(new Event(that.device, 'APIerror', e.message));
});
}
}

Expand Down

0 comments on commit 45b57a3

Please # to comment.