Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
86 lines (72 loc) · 2.84 KB
/
Copy pathapp.js
File metadata and controls
86 lines (72 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"use strict";
var fs = require('fs');
var variableManager = require('./lib/variablemanagement/variablemanagement.js');
var util = require('./lib/util/util.js');
var autoCompleteActions = require('./lib/autocomplete/actions.js');
var autoCompleteConditions = require('./lib/autocomplete/conditions.js');
var autoCompleteTriggers = require('./lib/autocomplete/triggers.js');
var flowActions = require('./lib/flow/actions.js');
var flowConditions = require('./lib/flow/conditions.js');
//var flowTriggers = require('./lib/flow/triggers.js');
var self = {
init: function() {
Homey.log("CountUp started");
variableManager.init();
autoCompleteActions.createAutocompleteActions();
autoCompleteConditions.createAutocompleteConditions();
autoCompleteTriggers.createAutocompleteTriggers();
flowActions.createActions();
flowConditions.createConditions();
Homey.manager('flow').on('trigger.countup_to_zero', function (callback,args,state) {
if ( args.variable.name == state.variable ) {
callback(null,true);
return;
} else {
callback(null, false); // true to make the flow continue, or false to abort
}
});
Homey.manager('flow').on('trigger.countup_started', function (callback,args,state) {
if (args.variable.name == state.variable) {
callback(null,true);
return;
} else {
callback(null, false); // true to make the flow continue, or false to abort
}
});
Homey.manager('flow').on('trigger.countup_stopped', function (callback,args,state) {
if ( args.variable.name == state.variable ) {
callback(null,true);
return;
} else {
callback(null, false); // true to make the flow continue, or false to abort
}
});
Homey.manager('flow').on('trigger.countup_timer_changed', function (callback,args,state) {
if ( args.variable.name == state.variable ) {
//Homey.log(args);
callback(null,true);
return;
} else {
callback(null, false); // true to make the flow continue, or false to abort
}
});
var currentVariables= variableManager.getvariables();
Homey.log(currentVariables.length);
setInterval(timers_update,1000);
function timers_update() {
var currentVariables= variableManager.getvariables();
//Homey.log(currentVariables);
currentVariables.forEach(function( obj) {
//Homey.log(obj.name);
//Homey.log(obj.value);
var tokens = { 'variable' : obj.name, 'value' : obj.value };
var state = { 'variable' : obj.name };
if (obj.value != -1) {
variableManager.updatevariable(obj.name, parseInt(obj.value) + 1, 'number','');
Homey.manager('flow').trigger('countup_timer_changed', tokens, state);
}
});
};
}
}
module.exports = self;