forked from gadget-monk/homebridge-poolcontroller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tempAccessory.js
executable file
·69 lines (50 loc) · 2.24 KB
/
tempAccessory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var Accessory, Service, Characteristic, UUIDGen;
//var debug = false;
var utils = require('./utils.js')
// var moment = require('moment');
var PoolTempAccessory = function (log, accessory, tempData, homebridge, platform) {
Accessory = homebridge.platformAccessory;
Service = homebridge.hap.Service;
Characteristic = homebridge.hap.Characteristic;
UUIDGen = homebridge.hap.uuid;
Homebridge = homebridge;
this.accessory = accessory;
this.log = log;
this.accessory.log = log
var customtypes = require('./customTypes.js')
var CustomTypes = new customtypes(Homebridge)
var FakeGatoHistoryService = require('fakegato-history')(homebridge);
this.loggingService = new FakeGatoHistoryService("weather", this.accessory, { size: 11520, disableTimer: true, storage: 'fs' });
this.tempData = tempData
this.platform = platform
this.debug = platform.debug;
this.service = accessory.getService(Service.TemperatureSensor);
if (this.service) {
this.service
.getCharacteristic(Characteristic.CurrentTemperature)
.on('get', this.getCurrTemp.bind(this));
}
this.updateState(tempData)
// not needed/used with latest HomeKit API's
// accessory.updateReachability(true);
}
PoolTempAccessory.prototype.getCurrTemp = function (callback) {
callback(null, utils.F2C(this.tempData));
};
// For when state is changed elsewhere.
PoolTempAccessory.prototype.updateState = function (newtempData) {
var customtypes = require('./customTypes.js')
var CustomTypes = new customtypes(Homebridge)
this.tempData = newtempData;
if (this.platform.LogLevel >= 4) this.log('Updating temp to ', this.tempData)
this.accessory.getService(Service.TemperatureSensor).getCharacteristic(Characteristic.CurrentTemperature)
.updateValue(utils.F2C(this.tempData));
this.loggingService.addEntry({ time: Math.round(new Date().valueOf() / 1000), temp: utils.F2C(this.tempData) });
var interval = 10 * 60 * 1000
clearTimeout(this.tempUpdateTimer)
this.tempUpdateTimer = setInterval(function (platform, loggingService, tempData) {
loggingService.addEntry({ time: Math.round(new Date().valueOf() / 1000), temp: utils.F2C(tempData) })
}, interval, this.platform, this.loggingService, this.tempData)
return
}
module.exports = PoolTempAccessory;