Skip to content

Commit

Permalink
tweak timers for history service
Browse files Browse the repository at this point in the history
  • Loading branch information
mihailescu2m committed Dec 3, 2019
1 parent 68333c8 commit 63669f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ AirtouchAPI.prototype.connect = function(address) {
// request information from Airtouch after connection
setTimeout(this.GET_AC_STATUS.bind(this), 0);
setTimeout(this.GET_GROUP_STATUS.bind(this), 2000);
// schedule group status every 5 minutes to get updates for FakeGato history service
setInterval(this.GET_GROUP_STATUS.bind(this), 300000);
// schedule group status every 4.75 minutes to get updates for FakeGato history service
setInterval(this.GET_GROUP_STATUS.bind(this), 285000);
});
this.device.on("close", () => {
this.log("API | Disconnected from Airtouch");
Expand Down
17 changes: 11 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ Airtouch.prototype.setupACAccessory = function(accessory) {
thermostat.isPrimaryService = true;

accessory.historyService = new FakeGatoHistoryService("thermo", accessory, { storage: "fs" });
accessory.historyUpdate = 0;

this.log("Finished creating accessory [" + accessory.displayName + "]");
};
Expand Down Expand Up @@ -259,12 +260,16 @@ Airtouch.prototype.updateACAccessory = function(accessory, status) {
thermostat.setCharacteristic(Characteristic.RotationSpeed, accessory.context.rotationSpeed);

// save history as Eve Thermo
accessory.historyService.addEntry({
time: new Date().getTime() / 1000,
currentTemp: accessory.context.currentTemperature,
setTemp: accessory.context.targetTemperature,
valvePosition: accessory.context.rotationSpeed
});
let now = new Date().getTime() / 1000;
if (now - accessory.historyUpdate > 285) { // 285s = 4.75 min update intervals
accessory.historyService.addEntry({
time: now,
currentTemp: accessory.context.currentTemperature,
setTemp: accessory.context.targetTemperature,
valvePosition: accessory.context.rotationSpeed
});
accessory.historyUpdate = now;
}

accessory.context.statusFault = status.ac_error_code;
thermostat.setCharacteristic(Characteristic.StatusFault, accessory.context.statusFault);
Expand Down

0 comments on commit 63669f3

Please sign in to comment.