Skip to content

Commit

Permalink
Suport fakegato-history
Browse files Browse the repository at this point in the history
Add fakegato-history
  • Loading branch information
geovaneferreira committed Jul 4, 2021
1 parent 057601a commit 516371d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 33 deletions.
Binary file added .DS_Store
Binary file not shown.
61 changes: 34 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
var ds18b20 = require("ds18b20-raspi");
var Service, Characteristic, FakeGatoHistoryService, loggingService;
var Service, Characteristic, FakeGatoHistoryService;
var Logger = require("mcuiot-logger").logger;
const moment = require('moment');
var os = require("os");
var hostname = os.hostname();
var fs = require('fs');

module.exports = function(homebridge) {
Service = homebridge.hap.Service;
Expand All @@ -24,17 +25,13 @@ function TemperatureAccessory(log, config) {
this.pollInterval = config["pollInterval"] || "60000";// Every minute
this.offsetC = config["offsetC"] || 0;
this.spreadsheetId = config['spreadsheetId'];
this.log_event_counter = 59;
this.storage = config['storage'] || "fs";
this.service = config.service || "DS18B20";

this.log_event_counter = 59;
if (this.spreadsheetId) {
this.logger = new Logger(this.spreadsheetId);
}

this.service = new Service.TemperatureSensor(this.name);
this.service
.getCharacteristic(Characteristic.CurrentTemperature)
.setProps({ minValue: -100, maxValue: 125 })
.on("get", this.getState.bind(this));
}

TemperatureAccessory.prototype = {
Expand All @@ -46,7 +43,7 @@ TemperatureAccessory.prototype = {
this.log_event_counter = this.log_event_counter + 1;
if (this.log_event_counter > 59) {
if (this.spreadsheetId) {
this.logger.storeDS(this.name, roundInt(value + this.offsetC));
this.logger.storeDHT(this.name, 0, roundInt(value + this.offsetC), 0);
}
this.log_event_counter = 0;
}
Expand Down Expand Up @@ -80,25 +77,35 @@ TemperatureAccessory.prototype = {
.setCharacteristic(Characteristic.SerialNumber, hostname + "-" + this.name)
.setCharacteristic(Characteristic.FirmwareRevision, require('./package.json').version);

this.service.log = this.log;
this.loggingService = new FakeGatoHistoryService("weather", this.service, {
//size:4600, // optional - if you still need to specify the length
storage:'fs',
path:'/home/pi/homebridgedb/', // if empty it will be used the -U homebridge option if present, or .homebridge in the user's home folder
minutes: ((this.pollInterval/1000) * 10 / 60)
});
switch (this.service) {
case "DS18B20":
this.dsservice = new Service.TemperatureSensor(this.name);
this.dsservice
.getCharacteristic(Characteristic.CurrentTemperature)
.setProps({ minValue: -100, maxValue: 125 })
;
//.on("get", this.getState.bind(this));

setInterval(function() {
this.getState(function(err, value) {
if (!err) {
this.service
.getCharacteristic(Characteristic.CurrentTemperature)
.updateValue(value + this.offsetC);
}
}.bind(this));
}.bind(this), this.pollInterval * 1);

return [this.service, informationService, loggingService];
this.dsservice.log = this.log;
this.loggingService = new FakeGatoHistoryService("weather", this.dsservice, {
//size:4600, // optional - if you still need to specify the length
storage:'fs',
//path:'/home/pi/homebridgedb/', // if empty it will be used the -U homebridge option if present, or .homebridge in the user's home folder
minutes: ((this.pollInterval/1000) * 10 / 60)
});

setInterval(function() {
this.getState(function(err, value) {
if (!err) {
this.dsservice
.getCharacteristic(Characteristic.CurrentTemperature)
.updateValue(value + this.offsetC);
}
}.bind(this));
}.bind(this), this.pollInterval * 1);

return [this.dsservice, informationService, this.loggingService];
}
}
};

Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "homebridge-ds18b20",
"version": "1.2.1",
"version": "1.2.0",
"description": "A HomeBridge plugin for DS18B20 temperature sensors.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/geovaneferreira/homebridge-ds18b20.git"
"url": "git+https://github.com/DanTheMan827/homebridge-ds18b20.git"
},
"files": [
"index.js",
Expand All @@ -21,16 +21,16 @@
"node": ">=0.12.0",
"homebridge": ">=0.2.0"
},
"author": "Geovane Ferreira",
"author": "Daniel Radtke",
"license": "MIT",
"bugs": {
"url": "https://github.com/geovaneferreira/homebridge-ds18b20/issues"
"url": "https://github.com/DanTheMan827/homebridge-ds18b20/issues"
},
"homepage": "https://github.com/geovaneferreira/homebridge-ds18b20#readme",
"homepage": "https://github.com/DanTheMan827/homebridge-ds18b20#readme",
"dependencies": {
"ds18b20-raspi": "^0.3.4",
"mcuiot-logger": ">0.0.6",
"moment": ">2.20.1",
"fakegato-history": "^0.6.1"
}
}
}

0 comments on commit 516371d

Please sign in to comment.