Rev 2169 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 2169 | Rev 2188 | ||
|---|---|---|---|
| 1 | 1 | ||
| 2 | //Require("plugin/module.js"); |
2 | //Require("plugin/module.js"); |
| 3 | 3 | ||
| 4 | Water_ModuleNames = [ "water" ]; |
4 | Water_ModuleNames = [ "water" ]; |
| 5 | Water_Intervals = function() { return [ 1, 5, 10, 15, 20 ]; }; |
5 | Water_Intervals = function() { return [ 1, 5, 10, 15, 20 ]; }; |
| 6 | Water_Volume = function() { return [ 0, 500, 1000, 5000, 10000 ]; }; |
6 | Water_Volume = function() { return [ 0, 500, 1000, 5000, 10000 ]; }; |
| 7 | Water_Aliases = function() { return Module_GetAliasNames(Water_ModuleNames); }; |
7 | Water_Aliases = function() { return Module_GetAliasNames(Water_ModuleNames); }; |
| 8 | Water_AvailableIds = function() { return Module_GetAvailableIds(Water_ModuleNames); }; |
8 | Water_AvailableIds = function() { return Module_GetAvailableIds(Water_ModuleNames); }; |
| 9 | 9 | ||
| 10 | /* |
10 | |
| 11 | function Water_SetVolume(alias_name, volume) |
11 | function Water_SetVolume(alias_name, volume) |
| 12 | { |
12 | { |
| 13 | if (arguments.length < 2) |
13 | if (arguments.length < 2) |
| 14 | { |
14 | { |
| 15 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
15 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
| 16 | return false; |
16 | return false; |
| 17 | } |
17 | } |
| 18 | |
18 | |
| 19 | var aliases_data = Module_ResolveAlias(alias_name, Water_ModuleNames); |
19 | var aliases_data = Module_ResolveAlias(alias_name, Water_ModuleNames); |
| 20 | var found = false; |
20 | var found = false; |
| 21 | |
21 | |
| 22 | for (var name in aliases_data) |
22 | for (var name in aliases_data) |
| 23 | { |
23 | { |
| 24 | var variables = {"Volume" : volume }; |
24 | var variables = {"Volume" : volume }; |
| 25 | |
25 | |
| 26 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "setVolume", variables)) |
26 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "setVolume", variables)) |
| 27 | { |
27 | { |
| 28 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
28 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
| 29 | } |
29 | } |
| 30 | else |
30 | else |
| 31 | { |
31 | { |
| 32 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
32 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
| 33 | } |
33 | } |
| 34 | |
34 | |
| 35 | found = true; |
35 | found = true; |
| 36 | } |
36 | } |
| 37 | |
37 | |
| 38 | if (!found) |
38 | if (!found) |
| 39 | { |
39 | { |
| 40 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
40 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
| 41 | return false; |
41 | return false; |
| 42 | } |
42 | } |
| 43 | |
43 | |
| 44 | return true; |
44 | return true; |
| 45 | } |
45 | } |
| 46 | Console_RegisterCommand(Water_SetVolume, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Water_Aliases(), Water_Volume()); }); |
46 | Console_RegisterCommand(Water_SetVolume, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Water_Aliases(), Water_Volume()); }); |
| 47 | */ |
47 | |
| 48 | /* |
48 | |
| 49 | function Water_SetReportInterval(alias_name, interval) |
49 | function Water_SetReportInterval(alias_name, interval) |
| 50 | { |
50 | { |
| 51 | if (arguments.length < 2) |
51 | if (arguments.length < 2) |
| 52 | { |
52 | { |
| 53 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
53 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
| 54 | return false; |
54 | return false; |
| 55 | } |
55 | } |
| 56 | |
56 | |
| 57 | var aliases_data = Module_ResolveAlias(alias_name, Water_ModuleNames); |
57 | var aliases_data = Module_ResolveAlias(alias_name, Water_ModuleNames); |
| 58 | var found = false; |
58 | var found = false; |
| 59 | |
59 | |
| 60 | for (var name in aliases_data) |
60 | for (var name in aliases_data) |
| 61 | { |
61 | { |
| 62 | var variables = {"Time" : interval }; |
62 | var variables = {"Time" : interval }; |
| 63 | |
63 | |
| 64 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Report_Interval", variables)) |
64 | if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Report_Interval", variables)) |
| 65 | { |
65 | { |
| 66 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
66 | Log("\033[32mCommand sent successfully to " + name + ".\033[0m\n"); |
| 67 | } |
67 | } |
| 68 | else |
68 | else |
| 69 | { |
69 | { |
| 70 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
70 | Log("\033[31mFailed to send command to " + name + ".\033[0m\n"); |
| 71 | } |
71 | } |
| 72 | |
72 | |
| 73 | found = true; |
73 | found = true; |
| 74 | } |
74 | } |
| 75 | |
75 | |
| 76 | if (!found) |
76 | if (!found) |
| 77 | { |
77 | { |
| 78 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
78 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
| 79 | return false; |
79 | return false; |
| 80 | } |
80 | } |
| 81 | |
81 | |
| 82 | return true; |
82 | return true; |
| 83 | } |
83 | } |
| 84 | Console_RegisterCommand(Water_SetReportInterval, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Water_Aliases(), Water_Intervals()); }); |
84 | Console_RegisterCommand(Water_SetReportInterval, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Water_Aliases(), Water_Intervals()); }); |
| 85 | */ |
- | |
| 86 | 85 | ||
| 87 | function Water_OnMessage(module_name, module_id, command, variables) |
86 | function Water_OnMessage(module_name, module_id, command, variables) |
| 88 | { |
87 | { |
| 89 | if (in_array(Water_ModuleNames, module_name)) |
88 | if (in_array(Water_ModuleNames, module_name)) |
| 90 | { |
89 | { |
| 91 | var aliases_data = Module_LookupAliases({ |
90 | var aliases_data = Module_LookupAliases({ |
| 92 | "module_name" : module_name, |
91 | "module_name" : module_name, |
| 93 | "module_id" : module_id, |
92 | "module_id" : module_id, |
| 94 | "group" : false |
93 | "group" : false |
| 95 | }); |
94 | }); |
| 96 | 95 | ||
| 97 | switch (command) |
96 | switch (command) |
| 98 | { |
97 | { |
| 99 | case "Flow": |
98 | case "Flow": |
| 100 | { |
99 | { |
| 101 | for (var alias_name in aliases_data) |
100 | for (var alias_name in aliases_data) |
| 102 | { |
101 | { |
| 103 | var last_value = {}; |
102 | var last_value = {}; |
| 104 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
103 | var last_value_string = Storage_GetParameter("LastValues", alias_name); |
| 105 | 104 | ||
| 106 | if (last_value_string) |
105 | if (last_value_string) |
| 107 | { |
106 | { |
| 108 | last_value = eval("(" + last_value_string + ")"); |
107 | last_value = eval("(" + last_value_string + ")"); |
| 109 | } |
108 | } |
| 110 | 109 | ||
| 111 | last_value["Flow"] = { "value" : variables["Flow"], "timestamp" : get_time() }; |
110 | last_value["Flow"] = { "value" : variables["Flow"], "timestamp" : get_time() }; |
| 112 | last_value["Volume"] = { "value" : variables["Volume"], "timestamp" : get_time() }; |
111 | last_value["Volume"] = { "value" : variables["Volume"], "timestamp" : get_time() }; |
| 113 | 112 | ||
| 114 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
113 | Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value)); |
| 115 | } |
114 | } |
| 116 | 115 | ||
| 117 | break; |
116 | break; |
| 118 | } |
117 | } |
| 119 | } |
118 | } |
| 120 | } |
119 | } |
| 121 | } |
120 | } |
| 122 | Module_RegisterToOnMessage("all", Water_OnMessage); |
121 | Module_RegisterToOnMessage("all", Water_OnMessage); |
| 123 | 122 | ||