modified api and methods
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
package com.zoblak.farmalarm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by senadu on 11/15/16.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class AlarmResponseHandler {
|
||||||
|
}
|
||||||
@@ -44,13 +44,19 @@ Api.addRoute('alarm/:id/phonePing', {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
var state = stateOrDefault(this.urlParams.id).state;
|
var state = stateOrDefault(this.urlParams.id).state;
|
||||||
return {
|
|
||||||
'alarmTriggered': state['alarmTriggered'],
|
if(state.alarmTriggered) {
|
||||||
'tooHot': state['alarmReasons']['tooHot'],
|
return {
|
||||||
'tooCold': state['alarmReasons']['tooCold'],
|
'alarmTriggered': state.alarmTriggered,
|
||||||
'phoneSilent': state['alarmReasons']['phoneSilent'],
|
'tooHot': state.alarmReasons.tooHot,
|
||||||
'boxSilent': state['alarmReasons']['boxSilent']
|
'tooCold': state.alarmReasons.tooCold,
|
||||||
|
'phoneSilent': state.alarmReasons.phoneSilent,
|
||||||
|
'boxSilent': state.alarmReasons.boxSilent
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -178,7 +184,14 @@ function stateOrDefault(id) {
|
|||||||
controller_id: id,
|
controller_id: id,
|
||||||
state: {
|
state: {
|
||||||
out_valve: 'closed',
|
out_valve: 'closed',
|
||||||
in_valve: 'closed'
|
in_valve: 'closed',
|
||||||
|
alarmTriggered: false,
|
||||||
|
alarmReasons: {
|
||||||
|
tooHot: false,
|
||||||
|
tooCold: false,
|
||||||
|
boxSilent: false,
|
||||||
|
phoneSilent: false
|
||||||
|
}
|
||||||
},
|
},
|
||||||
time: new Date(),
|
time: new Date(),
|
||||||
config: {
|
config: {
|
||||||
|
|||||||
@@ -170,6 +170,8 @@ function saveAlarmSettings(controller_id, minTemperature, maxTemperature, timeou
|
|||||||
reactToAlarmData(controller_id);
|
reactToAlarmData(controller_id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
reactToAlarmData(controller_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -178,13 +180,13 @@ function saveAlarmSettings(controller_id, minTemperature, maxTemperature, timeou
|
|||||||
// 2. triggered ( state.alarmTriggered: true, state.alarmStopped: null )
|
// 2. triggered ( state.alarmTriggered: true, state.alarmStopped: null )
|
||||||
// 3. silenced ( state.alarmTriggered: false, state.alarmStopped: (sometime) )
|
// 3. silenced ( state.alarmTriggered: false, state.alarmStopped: (sometime) )
|
||||||
|
|
||||||
function reactToAlarmData(controller_id) {
|
reactToAlarmData = function(controller_id) {
|
||||||
var reading = last_sensor_reading(controller_id);
|
var reading = last_sensor_reading(controller_id);
|
||||||
var state = Meteor.zoblak.server.controller_state(controller_id);
|
var state = Meteor.zoblak.server.controller_state(controller_id);
|
||||||
var config = state.config;
|
var config = state.config;
|
||||||
|
|
||||||
var minTemperature = function(temperatures) {
|
var minTemperature = function(temperatures) {
|
||||||
// if it gets a lot colder than absolute zero we will
|
// if it gets a lot colder than absolute zero
|
||||||
// we will have more problems than the bug in this code
|
// we will have more problems than the bug in this code
|
||||||
if (temperatures.length <= 0) return -1000;
|
if (temperatures.length <= 0) return -1000;
|
||||||
var minimal = parseFloat(temperatures[0]);
|
var minimal = parseFloat(temperatures[0]);
|
||||||
@@ -218,6 +220,7 @@ function reactToAlarmData(controller_id) {
|
|||||||
var minutesSinceLastPhoneContact = state.lastPhoneContact ? moment(new Date()).diff(moment(state.lastPhoneContact), 'minutes') : -1;
|
var minutesSinceLastPhoneContact = state.lastPhoneContact ? moment(new Date()).diff(moment(state.lastPhoneContact), 'minutes') : -1;
|
||||||
var phoneSilent = config.timeoutPhone && minutesSinceLastPhoneContact > config.timeoutPhone;
|
var phoneSilent = config.timeoutPhone && minutesSinceLastPhoneContact > config.timeoutPhone;
|
||||||
|
|
||||||
|
console.log("too ", tooCold, tooHot, boxSilent, phoneSilent);
|
||||||
console.log("lpc", state.lastPhoneContact);
|
console.log("lpc", state.lastPhoneContact);
|
||||||
console.log("mslpc", minutesSinceLastPhoneContact);
|
console.log("mslpc", minutesSinceLastPhoneContact);
|
||||||
console.log("phoneSilent", phoneSilent);
|
console.log("phoneSilent", phoneSilent);
|
||||||
|
|||||||
Reference in New Issue
Block a user