Skip to content

Commit

Permalink
v0.1.2
Browse files Browse the repository at this point in the history
Change Last Activation Logic.
Remove node-persist.
  • Loading branch information
stickpin committed Jan 11, 2020
1 parent 2239f5f commit da5715e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ If you use the EVE.app you can also see the presence history of every person-sen
{
"platform": "PeopleARP",
"threshold" : 3,
"cacheDirectory": "./.node-persist/storage",
"checkInterval": 10000,
"people" : [
{
Expand All @@ -43,7 +42,6 @@ If you use the EVE.app you can also see the presence history of every person-sen
| Parameter | Note |
|----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `threshold` | optional, in minutes, default: 3 |
| `cacheDirectory` | optional, default: "./.node-persist/storage" |
| `checkInterval` | optional, in milliseconds, default: 10000. minimal value: 10000 |
| `target` | may be either a hostname or IP address |
| `macAddress` | mac address of the device |
Expand Down
18 changes: 6 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
var ping = require('ping');
var arp = require('arp-a-x');
var moment = require('moment');
var FakeGatoHistoryService;

var Service, Characteristic, HomebridgeAPI;
var Service, Characteristic, HomebridgeAPI, FakeGatoHistoryService;
module.exports = function(homebridge) {
Service = homebridge.hap.Service;
Characteristic = homebridge.hap.Characteristic;
Expand All @@ -21,11 +20,8 @@ module.exports = function(homebridge) {
function PeoplePlatform(log, config){
this.log = log;
this.threshold = config['threshold'] || 3;
this.cacheDirectory = config["cacheDirectory"] || HomebridgeAPI.user.persistPath();
this.checkInterval = config["checkInterval"] || 10000;
this.people = config['people'];
this.storage = require('node-persist');
this.storage.initSync({dir:this.cacheDirectory});
}

PeoplePlatform.prototype = {
Expand Down Expand Up @@ -156,7 +152,9 @@ function PeopleAccessory(log, config, platform) {
},
{
storage: 'fs',
disableTimer: true
disableTimer: true,
path: HomebridgeAPI.user.storagePath() + '/accessories',
filename: 'history_' + "hps-" + this.name.toLowerCase() + '.json'
});

this.historyService.addCharacteristic(ResetTotalCharacteristic);
Expand All @@ -181,11 +179,8 @@ PeopleAccessory.prototype.getState = function(callback) {
}

PeopleAccessory.prototype.getLastActivation = function(callback) {
var lastSeenUnix = this.platform.storage.getItemSync('lastConnectionLoss_' + this.target);
if (lastSeenUnix) {
var lastSeenMoment = moment(lastSeenUnix).unix();
callback(null, lastSeenMoment - this.historyService.getInitialTime());
}
var lastActivation = now - this.historyService.getInitialTime();
callback(null, lastActivation);
}

PeopleAccessory.prototype.identify = function(callback) {
Expand All @@ -208,7 +203,6 @@ PeopleAccessory.prototype.arp = function() {
if (entry.mac == this.macAddress.toLowerCase()) {
if(entry.flag == "0x0") {
newState = false;
this.platform.storage.setItemSync('lastConnectionLoss_' + this.target, Date.now());
}
this.setNewState(newState);
setTimeout(PeopleAccessory.prototype.arp.bind(this), this.checkInterval);
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-people-arp",
"version": "0.1.1",
"version": "0.1.2",
"description": "Homebridge plugin that provides details of who is in a Home + History (powered by fakegato) based on IP and MAC Address",
"keywords": [
"homebridge-plugin"
Expand All @@ -15,7 +15,6 @@
},
"dependencies": {
"moment": "^2.11.2",
"node-persist": "2.1.0",
"ping": "^0.1.10",
"arp-a-x": "^0.5.3",
"fakegato-history": "^0.5.0"
Expand Down

0 comments on commit da5715e

Please sign in to comment.