Skip to content

Commit

Permalink
changed interface for accessing Schedule class
Browse files Browse the repository at this point in the history
  • Loading branch information
tobekas committed Nov 28, 2019
1 parent d1fd894 commit 28149bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 6 additions & 9 deletions fakegato-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}


Expand Down Expand Up @@ -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';
Expand Down
8 changes: 3 additions & 5 deletions fakegato-schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 : () => {};
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -454,7 +452,7 @@ module.exports = function (pHomebridge) {
}
}

if (setVacationMode != null) {
if (setVacationMode !== null) {
this.setVacationMode(setVacationMode);
}
else if (setEnableSchedule === true) {
Expand Down

0 comments on commit 28149bd

Please sign in to comment.