alarm triggering / silencing works
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
function setOutValveTo(controller_id, nextState) {
|
||||
var state = Meteor.zoblak.server.controller_state(controller_id);
|
||||
ControllerState.update(state._id, {
|
||||
@@ -173,6 +172,12 @@ function saveAlarmSettings(controller_id, minTemperature, maxTemperature, timeou
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// there are three states of alarm:
|
||||
// 1. normal ( state.alarmTriggered: false, state.alarmStopped: null )
|
||||
// 2. triggered ( state.alarmTriggered: true, state.alarmStopped: null )
|
||||
// 3. silenced ( state.alarmTriggered: false, state.alarmStopped: (sometime) )
|
||||
|
||||
function reactToAlarmData(controller_id) {
|
||||
var reading = last_sensor_reading(controller_id);
|
||||
var state = Meteor.zoblak.server.controller_state(controller_id);
|
||||
@@ -181,7 +186,7 @@ function reactToAlarmData(controller_id) {
|
||||
var minTemperature = function(temperatures) {
|
||||
// if it gets a lot colder than absolute zero we will
|
||||
// we will have more problems than the bug in this code
|
||||
if(size(temperatures) <= 0) return -1000;
|
||||
if (temperatures.length <= 0) return -1000;
|
||||
var minimal = parseFloat(temperatures[0]);
|
||||
for (var i in temperatures) {
|
||||
if (parseFloat(temperatures[i]) < minimal) {
|
||||
@@ -193,7 +198,7 @@ function reactToAlarmData(controller_id) {
|
||||
|
||||
var maxTemperature = function(temperatures) {
|
||||
// obviously - hell is not supported in this version
|
||||
if(size(temperatures) <= 0) return 1000;
|
||||
if (temperatures.length <= 0) return 1000;
|
||||
var maximal = parseFloat(temperatures[0]);
|
||||
for (var i in temperatures) {
|
||||
if (parseFloat(temperatures[i]) > maximal) {
|
||||
@@ -213,12 +218,17 @@ function reactToAlarmData(controller_id) {
|
||||
var minutesSinceLastPhoneContact = state.lastPhoneContact ? moment(state.lastPhoneContact).diff(moment(new Date()), 'minutes') : -1;
|
||||
var phoneSilent = config.timeoutPhone && minutesSinceLastPhoneContact > config.timeoutPhone;
|
||||
|
||||
|
||||
|
||||
if (tooCold || tooHot || boxSilent || phoneSilent) {
|
||||
soundTheAlarm(tooCold, tooHot, boxSilent, phoneSilent);
|
||||
var alarmSilenced = !!state.state.alarmStopped;
|
||||
if (!alarmSilenced) soundTheAlarm(controller_id, tooCold, tooHot, boxSilent, phoneSilent);
|
||||
} else {
|
||||
stopTheAlarm(controller_id, true);
|
||||
}
|
||||
}
|
||||
|
||||
function soundTheAlarm(tooCold, tooHot, boxSilent, phoneSilent) {
|
||||
function soundTheAlarm(controller_id, tooCold, tooHot, boxSilent, phoneSilent) {
|
||||
var state = Meteor.zoblak.server.controller_state(controller_id);
|
||||
var reason = {
|
||||
tooHot: tooHot,
|
||||
@@ -262,7 +272,18 @@ function sendAlarmingSms(reason, numbers) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function stopTheAlarm(controller_id, everythingIsBackToNormal = false) {
|
||||
// time of alarm stopped is reset so that scheduled job can raise the alarm
|
||||
// again
|
||||
var timeOfStopping = (everythingIsBackToNormal) ? null : new Date();
|
||||
var state = Meteor.zoblak.server.controller_state(controller_id);
|
||||
ControllerState.update(state._id, {
|
||||
'$set': {
|
||||
'state.alarmTriggered': false,
|
||||
'state.alarmStopped': timeOfStopping
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function last_sensor_reading(controller_id) {
|
||||
var result = null;
|
||||
@@ -293,5 +314,6 @@ Meteor.methods({
|
||||
clearLog: clearLog,
|
||||
saveControllerConfig: saveControllerConfig,
|
||||
requestNewPicture: requestNewPicture,
|
||||
saveAlarmSettings: saveAlarmSettings
|
||||
saveAlarmSettings: saveAlarmSettings,
|
||||
stopTheAlarm: stopTheAlarm
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user