modified api and methods
This commit is contained in:
@@ -44,13 +44,19 @@ Api.addRoute('alarm/:id/phonePing', {
|
||||
}
|
||||
});
|
||||
var state = stateOrDefault(this.urlParams.id).state;
|
||||
return {
|
||||
'alarmTriggered': state['alarmTriggered'],
|
||||
'tooHot': state['alarmReasons']['tooHot'],
|
||||
'tooCold': state['alarmReasons']['tooCold'],
|
||||
'phoneSilent': state['alarmReasons']['phoneSilent'],
|
||||
'boxSilent': state['alarmReasons']['boxSilent']
|
||||
|
||||
if(state.alarmTriggered) {
|
||||
return {
|
||||
'alarmTriggered': state.alarmTriggered,
|
||||
'tooHot': state.alarmReasons.tooHot,
|
||||
'tooCold': state.alarmReasons.tooCold,
|
||||
'phoneSilent': state.alarmReasons.phoneSilent,
|
||||
'boxSilent': state.alarmReasons.boxSilent
|
||||
};
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
@@ -178,7 +184,14 @@ function stateOrDefault(id) {
|
||||
controller_id: id,
|
||||
state: {
|
||||
out_valve: 'closed',
|
||||
in_valve: 'closed'
|
||||
in_valve: 'closed',
|
||||
alarmTriggered: false,
|
||||
alarmReasons: {
|
||||
tooHot: false,
|
||||
tooCold: false,
|
||||
boxSilent: false,
|
||||
phoneSilent: false
|
||||
}
|
||||
},
|
||||
time: new Date(),
|
||||
config: {
|
||||
|
||||
@@ -170,6 +170,8 @@ function saveAlarmSettings(controller_id, minTemperature, maxTemperature, timeou
|
||||
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 )
|
||||
// 3. silenced ( state.alarmTriggered: false, state.alarmStopped: (sometime) )
|
||||
|
||||
function reactToAlarmData(controller_id) {
|
||||
reactToAlarmData = function(controller_id) {
|
||||
var reading = last_sensor_reading(controller_id);
|
||||
var state = Meteor.zoblak.server.controller_state(controller_id);
|
||||
var config = state.config;
|
||||
|
||||
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
|
||||
if (temperatures.length <= 0) return -1000;
|
||||
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 phoneSilent = config.timeoutPhone && minutesSinceLastPhoneContact > config.timeoutPhone;
|
||||
|
||||
console.log("too ", tooCold, tooHot, boxSilent, phoneSilent);
|
||||
console.log("lpc", state.lastPhoneContact);
|
||||
console.log("mslpc", minutesSinceLastPhoneContact);
|
||||
console.log("phoneSilent", phoneSilent);
|
||||
|
||||
Reference in New Issue
Block a user