diff --git a/README.md b/README.md index e81d446..170588c 100644 --- a/README.md +++ b/README.md @@ -142,10 +142,17 @@ For the setup of Google Drive, please follow the Google Drive Quickstart for Nod * Pay attention so that your plugin does not issue multiple addEntry calls for the same accessory at the same time (this may results in improper behaviour of Google Drive to the its asynchronous nature) ### Schedules -For Eve Thermo you can also enable the schedule feature. You must pass your Thermostat service to the `addThermoSchedule` function: +For Eve Thermo you can also enable the schedule feature. You must pass your Thermostat service to the `registerScheduleEvents` function: ``` -this.loggingService = new FakeGatoHistoryService('thermo', accessoryObject, historyOptions); -let thermoScheduler = this.loggingService.addThermoSchedule(this.thermostatService); +// in your includes: +var fakegatoHistory = require('fakegato-history'); +... +// in your module.exports: +Schedule = fakegatoHistory.Schedule(homebridge); +... +// in your code: +let thermoScheduler = new Schedule('thermo', log); +thermoScheduler.registerScheduleEvents(thermostatService); ``` This will add the custom characteristics `E863F12F` (ProgramData), `E863F12C` (ProgramCommand) and `E863F11E`(FirmwareInfo) to your Termostat service. The schedule is executed in the background and will fire set calls to TargetTemperature and TargetHeatingCoolingState at the specified times. You does not have to return the 'thermoScheduler' instance, but you can play around with vacation mode and open window mode from your plugin: diff --git a/fakegato-history.js b/fakegato-history.js index 553dbae..744070f 100644 --- a/fakegato-history.js +++ b/fakegato-history.js @@ -4,6 +4,7 @@ const Format = require('util').format; const FakeGatoTimer = require('./fakegato-timer').FakeGatoTimer; const FakeGatoStorage = require('./fakegato-storage').FakeGatoStorage; +const FakeGatoSchedule = require('./fakegato-schedule'); const moment = require('moment'); const EPOCH_OFFSET = 978307200; @@ -19,15 +20,17 @@ const TYPE_ENERGY = 'energy', var homebridge; var Characteristic, Service; -var FakeGatoSchedule; -module.exports = function (pHomebridge) { +module.exports = createFakeGatoHistory; // default export +module.exports.Schedule = FakeGatoSchedule; + + +function createFakeGatoHistory(pHomebridge) { if (pHomebridge && !homebridge) { homebridge = pHomebridge; Characteristic = homebridge.hap.Characteristic; Service = homebridge.hap.Service; - FakeGatoSchedule = require('./fakegato-schedule')(homebridge); } @@ -846,12 +849,6 @@ module.exports = function (pHomebridge) { callback(null, val); } - addThermoSchedule(service) { - let scheduler = new FakeGatoSchedule('thermo', this.log); - scheduler.registerScheduleEvents(service); - return scheduler; - } - } FakeGatoHistoryService.UUID = 'E863F007-079E-48FF-8F27-9C2605A29F52'; diff --git a/fakegato-schedule.js b/fakegato-schedule.js index 6454071..81651a3 100644 --- a/fakegato-schedule.js +++ b/fakegato-schedule.js @@ -74,8 +74,6 @@ module.exports = function (pHomebridge) { for (let i = 0; i < 3; i++) { let str = buf.readUInt8(ofs); let end = buf.readUInt8(ofs+1); - //let str = parseInt(hexVal.substring(ofs, ofs+2), 16); - //let end = parseInt(hexVal.substring(ofs+2, ofs+4), 16); if (str != 0xFF) { str = str * 10; end = end * 10; @@ -143,7 +141,7 @@ module.exports = function (pHomebridge) { class FakeGatoSchedule { constructor(type, logger) { - this.scheduleModeType = type || 'unknown'; + this.scheduleType = type || 'unknown'; this.log = logger || {}; if (!this.log.debug) { this.log.debug = DEBUG ? console.log : () => {}; @@ -187,7 +185,7 @@ module.exports = function (pHomebridge) { return; } - if (this.scheduleModeType === 'thermo') { + if (this.scheduleType === 'thermo') { service.addCharacteristic(ProgramData) .on('get', this.cb_getProgramData.bind(this)); @@ -454,7 +452,7 @@ module.exports = function (pHomebridge) { } } - if (setVacationMode != null) { + if (setVacationMode !== null) { this.setVacationMode(setVacationMode); } else if (setEnableSchedule === true) {