Rev 2138 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1602 | runge | 1 | |
| 1644 | runge | 2 | Require("plugin/storage.js"); |
| 1603 | runge | 3 | |
| 1649 | runge | 4 | function Module_CreateAliasAutoComplete(arg_index, args) |
| 1647 | runge | 5 | { |
| 6 | if (arg_index == 0) |
||
| 7 | { |
||
| 8 | return Module_GetAliasNames(); |
||
| 9 | } |
||
| 10 | else if (arg_index == 1) |
||
| 11 | { |
||
| 12 | return Module_GetNames(); |
||
| 13 | } |
||
| 14 | else if (arg_index == 2) |
||
| 15 | { |
||
| 1649 | runge | 16 | return Module_GetAvailableIds([ args[1] ]) |
| 1647 | runge | 17 | } |
| 2075 | runge | 18 | |
| 1647 | runge | 19 | return []; |
| 20 | } |
||
| 21 | |||
| 22 | function Module_CreateAlias(alias_name, module_name, module_id, specific) |
||
| 23 | { |
||
| 1649 | runge | 24 | if (arguments.length < 3) |
| 25 | { |
||
| 26 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 27 | return false; |
||
| 28 | } |
||
| 2075 | runge | 29 | |
| 1649 | runge | 30 | if (alias_name == "all") |
| 31 | { |
||
| 32 | Log("\033[31m\"all\" is not allowed as alias name.\033[0m\n"); |
||
| 33 | return false; |
||
| 34 | } |
||
| 2075 | runge | 35 | |
| 1647 | runge | 36 | var specific_list = {}; |
| 2075 | runge | 37 | |
| 1647 | runge | 38 | if (specific) |
| 39 | { |
||
| 1649 | runge | 40 | var specific_parts = specific.split(","); |
| 2075 | runge | 41 | |
| 1647 | runge | 42 | // TODO: Check length |
| 2075 | runge | 43 | |
| 1647 | runge | 44 | for (var index in specific_parts) |
| 45 | { |
||
| 1649 | runge | 46 | var parts = specific_parts[index].split("="); |
| 2075 | runge | 47 | |
| 1647 | runge | 48 | // TODO: Check length |
| 2075 | runge | 49 | |
| 1647 | runge | 50 | specific_list[parts[0]] = parts[1]; |
| 51 | } |
||
| 52 | } |
||
| 2075 | runge | 53 | |
| 1647 | runge | 54 | var alias_data = { |
| 55 | "group" : false, |
||
| 56 | "name" : alias_name, |
||
| 57 | "module_name" : module_name, |
||
| 58 | "module_id" : module_id, |
||
| 59 | "specific" : specific_list |
||
| 60 | }; |
||
| 2075 | runge | 61 | |
| 1647 | runge | 62 | return Storage_SetParameter("alias", alias_name, JSON.stringify(alias_data)); |
| 63 | } |
||
| 64 | Console_RegisterCommand(Module_CreateAlias, Module_CreateAliasAutoComplete); |
||
| 65 | |||
| 1649 | runge | 66 | function Module_CreateAliasGroupAutoComplete(arg_index, args) |
| 1624 | runge | 67 | { |
| 1644 | runge | 68 | if (arg_index == 0) |
| 1603 | runge | 69 | { |
| 1644 | runge | 70 | return Module_GetAliasNames(); |
| 1603 | runge | 71 | } |
| 1644 | runge | 72 | else if (arg_index == 1) |
| 73 | { |
||
| 1647 | runge | 74 | return Module_GetNames(); |
| 1644 | runge | 75 | } |
| 76 | else if (arg_index >= 2) |
||
| 77 | { |
||
| 1649 | runge | 78 | return Module_GetAliasNames([ args[1] ]) |
| 1644 | runge | 79 | } |
| 2075 | runge | 80 | |
| 1644 | runge | 81 | return []; |
| 1603 | runge | 82 | } |
| 83 | |||
| 1644 | runge | 84 | function Module_CreateAliasGroup(alias_group_name, module_type, alias_name1, alias_name2) |
| 1602 | runge | 85 | { |
| 1644 | runge | 86 | if (arguments.length < 3) |
| 1604 | runge | 87 | { |
| 1649 | runge | 88 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
| 89 | return false; |
||
| 1604 | runge | 90 | } |
| 2075 | runge | 91 | |
| 1649 | runge | 92 | if (alias_group_name == "all") |
| 93 | { |
||
| 94 | Log("\033[31m\"all\" is not allowed as alias name.\033[0m\n"); |
||
| 95 | return false; |
||
| 96 | } |
||
| 2075 | runge | 97 | |
| 1644 | runge | 98 | alias_group_name = arguments[0]; |
| 99 | module_type = arguments[1]; |
||
| 100 | var aliases = []; |
||
| 2075 | runge | 101 | |
| 1644 | runge | 102 | for (var n = 2; n < arguments.length; n++) |
| 1603 | runge | 103 | { |
| 1644 | runge | 104 | if (arguments[n].length > 0) |
| 105 | { |
||
| 106 | var aliases_data = Module_ResolveAlias(arguments[n]); |
||
| 107 | aliases.push(arguments[n]); |
||
| 108 | } |
||
| 1603 | runge | 109 | } |
| 2075 | runge | 110 | |
| 1644 | runge | 111 | if (aliases.length == 0) |
| 1604 | runge | 112 | { |
| 1649 | runge | 113 | Log("\033[31mNo valid aliases were found, aborting creation of group alias.\033[0m\n"); |
| 114 | return false; |
||
| 1604 | runge | 115 | } |
| 2075 | runge | 116 | |
| 1644 | runge | 117 | var alias_data = { |
| 118 | "group" : true, |
||
| 119 | "name" : alias_group_name, |
||
| 120 | "module_name" : module_type, |
||
| 121 | "aliases" : aliases |
||
| 122 | }; |
||
| 2075 | runge | 123 | |
| 1644 | runge | 124 | return Storage_SetParameter("alias", alias_group_name, JSON.stringify(alias_data)); |
| 1602 | runge | 125 | } |
| 1644 | runge | 126 | Console_RegisterCommand(Module_CreateAliasGroup, Module_CreateAliasGroupAutoComplete); |
| 1602 | runge | 127 | |
| 1644 | runge | 128 | function Module_ResolveAlias(alias_name, filter_module_names) |
| 1602 | runge | 129 | { |
| 1644 | runge | 130 | var aliases_data = {}; |
| 131 | var alias_data_string = Storage_GetParameter("alias", alias_name); |
||
| 2075 | runge | 132 | |
| 1644 | runge | 133 | if (alias_data_string) |
| 1602 | runge | 134 | { |
| 1644 | runge | 135 | var alias_data = eval("(" + alias_data_string + ")"); |
| 2075 | runge | 136 | |
| 1644 | runge | 137 | if (alias_data["group"]) |
| 1603 | runge | 138 | { |
| 1644 | runge | 139 | for (var n in alias_data["aliases"]) |
| 140 | { |
||
| 1646 | runge | 141 | var aliases_data_sub = Module_ResolveAlias(alias_data["aliases"][n], filter_module_names); |
| 2075 | runge | 142 | |
| 1644 | runge | 143 | for (var name in aliases_data_sub) |
| 144 | { |
||
| 145 | aliases_data[name] = aliases_data_sub[name]; |
||
| 146 | } |
||
| 147 | } |
||
| 1603 | runge | 148 | } |
| 1644 | runge | 149 | else |
| 150 | { |
||
| 1650 | runge | 151 | if (!filter_module_names || in_array(filter_module_names, alias_data["module_name"])) |
| 1644 | runge | 152 | { |
| 153 | aliases_data[alias_name] = alias_data; |
||
| 154 | } |
||
| 155 | } |
||
| 1602 | runge | 156 | } |
| 2075 | runge | 157 | |
| 1644 | runge | 158 | return aliases_data; |
| 1602 | runge | 159 | } |
| 1603 | runge | 160 | |
| 1644 | runge | 161 | function Module_LookupAliases(match_filter) |
| 1603 | runge | 162 | { |
| 1644 | runge | 163 | var aliases_data_filtered = {}; |
| 164 | var aliases_data = Storage_GetParameters("alias"); |
||
| 2075 | runge | 165 | |
| 1644 | runge | 166 | for (var name in aliases_data) |
| 167 | { |
||
| 168 | var alias_data = eval("(" + aliases_data[name] + ")"); |
||
| 2075 | runge | 169 | |
| 1644 | runge | 170 | var valid = true; |
| 2075 | runge | 171 | |
| 1644 | runge | 172 | for (var key in match_filter) |
| 173 | { |
||
| 174 | if (alias_data[key] != match_filter[key]) |
||
| 175 | { |
||
| 176 | valid = false; |
||
| 177 | break; |
||
| 178 | } |
||
| 179 | } |
||
| 2075 | runge | 180 | |
| 1644 | runge | 181 | if (valid) |
| 182 | { |
||
| 183 | aliases_data_filtered[name] = alias_data; |
||
| 184 | } |
||
| 185 | } |
||
| 2075 | runge | 186 | |
| 1644 | runge | 187 | return aliases_data_filtered; |
| 1603 | runge | 188 | } |
| 189 | |||
| 1644 | runge | 190 | function Module_GetAliasNames(filter_module_names) |
| 1603 | runge | 191 | { |
| 1644 | runge | 192 | var aliases_name_filtered = []; |
| 193 | var aliases_data = Storage_GetParameters("alias"); |
||
| 2075 | runge | 194 | |
| 1644 | runge | 195 | for (var name in aliases_data) |
| 1603 | runge | 196 | { |
| 1644 | runge | 197 | var alias_data = eval("(" + aliases_data[name] + ")"); |
| 2075 | runge | 198 | |
| 1644 | runge | 199 | if (!filter_module_names || in_array(filter_module_names, alias_data["module_name"])) |
| 200 | { |
||
| 201 | aliases_name_filtered.push(name) |
||
| 202 | } |
||
| 1603 | runge | 203 | } |
| 2075 | runge | 204 | |
| 1644 | runge | 205 | return aliases_name_filtered; |
| 1603 | runge | 206 | } |
| 207 | |||
| 1644 | runge | 208 | function Module_GetAvailableIds(filter_module_names) |
| 1603 | runge | 209 | { |
| 1644 | runge | 210 | var result_list = []; |
| 211 | var available_modules = ModuleExport_GetAvailableModules(); |
||
| 2075 | runge | 212 | |
| 1644 | runge | 213 | for (var n in available_modules) |
| 1603 | runge | 214 | { |
| 1644 | runge | 215 | var id_parts = available_modules[n].split(":", 2); |
| 2075 | runge | 216 | |
| 1644 | runge | 217 | if (in_array(filter_module_names, id_parts[0])) |
| 1603 | runge | 218 | { |
| 1644 | runge | 219 | result_list.push(id_parts[1]); |
| 1603 | runge | 220 | } |
| 221 | } |
||
| 2075 | runge | 222 | |
| 1644 | runge | 223 | return result_list; |
| 1603 | runge | 224 | } |
| 225 | |||
| 1647 | runge | 226 | function Module_GetNames() |
| 227 | { |
||
| 2169 | arune | 228 | return [ "Dimmer230", "irTransmit", "irReceive", "SimpleDTMF", "BusVoltage", "DS18x20", "FOST02", "HD44789", "Rotary", "RotaryHex", "Touch", "power", "input", "output", "softPWM", "counter", "rfTransceive", "hwPWM", "KS0108", "heatPower", "water"]; |
| 1647 | runge | 229 | } |
| 230 | |||
| 1644 | runge | 231 | function Module_SendMessage(module_name, module_id, command, variables) |
| 1614 | runge | 232 | { |
| 1644 | runge | 233 | var args = []; |
| 2075 | runge | 234 | |
| 1644 | runge | 235 | args.push(module_name + ":" + module_id); |
| 236 | args.push(command); |
||
| 2075 | runge | 237 | |
| 1644 | runge | 238 | var length = 0; |
| 239 | for (var key in variables) |
||
| 1614 | runge | 240 | { |
| 1644 | runge | 241 | length++; |
| 1614 | runge | 242 | } |
| 2075 | runge | 243 | |
| 1644 | runge | 244 | args.push(length); |
| 2075 | runge | 245 | |
| 1644 | runge | 246 | for (var key in variables) |
| 247 | { |
||
| 248 | args.push(key); |
||
| 249 | args.push(variables[key]); |
||
| 250 | } |
||
| 2075 | runge | 251 | |
| 1644 | runge | 252 | return ModuleExport_SendMessage.apply(null, Array.prototype.slice.call(args, 0)); |
| 1614 | runge | 253 | } |
| 254 | |||
| 1644 | runge | 255 | var Module_OnChangeFunctions = {}; |
| 256 | var Module_OnMessageFunctions = {}; |
||
| 257 | |||
| 258 | function Module_RegisterToOnChange(alias_name, callback) |
||
| 259 | { |
||
| 260 | if (!Module_OnChangeFunctions[alias_name]) |
||
| 1603 | runge | 261 | { |
| 1644 | runge | 262 | Module_OnChangeFunctions[alias_name] = []; |
| 1603 | runge | 263 | } |
| 2075 | runge | 264 | |
| 1644 | runge | 265 | Module_OnChangeFunctions[alias_name].push(callback); |
| 1603 | runge | 266 | } |
| 267 | |||
| 1644 | runge | 268 | function Module_RegisterToOnMessage(alias_name, callback) |
| 1603 | runge | 269 | { |
| 1644 | runge | 270 | if (!Module_OnMessageFunctions[alias_name]) |
| 1603 | runge | 271 | { |
| 1644 | runge | 272 | Module_OnMessageFunctions[alias_name] = []; |
| 1603 | runge | 273 | } |
| 2075 | runge | 274 | |
| 1644 | runge | 275 | Module_OnMessageFunctions[alias_name].push(callback); |
| 1603 | runge | 276 | } |
| 1609 | runge | 277 | |
| 1644 | runge | 278 | function Module_OnMessage(full_id, command, variables) |
| 1609 | runge | 279 | { |
| 1644 | runge | 280 | var id_parts = full_id.split(":", 2); |
| 281 | var aliases_data = {}; |
||
| 1647 | runge | 282 | |
| 283 | var aliases_data = Module_LookupAliases({ |
||
| 284 | "module_name" : id_parts[0], |
||
| 285 | "module_id" : id_parts[1], |
||
| 286 | "group" : false |
||
| 287 | }); |
||
| 2075 | runge | 288 | |
| 1647 | runge | 289 | for (var alias_name in aliases_data) |
| 1609 | runge | 290 | { |
| 1647 | runge | 291 | var ok = true; |
| 292 | |||
| 293 | if (aliases_data[alias_name]["specific"]) |
||
| 1644 | runge | 294 | { |
| 1647 | runge | 295 | var ok = true; |
| 2075 | runge | 296 | |
| 1647 | runge | 297 | for (var name in variables) |
| 298 | { |
||
| 299 | if (aliases_data[alias_name]["specific"][name] && aliases_data[alias_name]["specific"][name] != variables[name]) |
||
| 300 | { |
||
| 301 | ok = false; |
||
| 302 | break; |
||
| 303 | } |
||
| 304 | } |
||
| 305 | } |
||
| 2075 | runge | 306 | |
| 1647 | runge | 307 | if (Module_OnMessageFunctions[alias_name] && ok) |
| 308 | { |
||
| 1644 | runge | 309 | for (var n in Module_OnMessageFunctions[alias_name]) |
| 310 | { |
||
| 311 | Module_OnMessageFunctions[alias_name][n](alias_name, command, variables); |
||
| 312 | } |
||
| 313 | } |
||
| 314 | } |
||
| 2075 | runge | 315 | |
| 1649 | runge | 316 | if (Module_OnMessageFunctions["all"]) |
| 317 | { |
||
| 318 | for (var n in Module_OnMessageFunctions["all"]) |
||
| 319 | { |
||
| 320 | Module_OnMessageFunctions["all"][n](id_parts[0], id_parts[1], command, variables); |
||
| 321 | } |
||
| 322 | } |
||
| 1609 | runge | 323 | } |
| 324 | |||
| 1644 | runge | 325 | function Module_OnChange(full_id, available) |
| 1642 | runge | 326 | { |
| 1644 | runge | 327 | var id_parts = full_id.split(":", 2); |
| 1647 | runge | 328 | var aliases_data = {}; |
| 2075 | runge | 329 | |
| 1765 | linlun | 330 | aliases_data = Module_LookupAliases({ |
| 1644 | runge | 331 | "module_name" : id_parts[0], |
| 332 | "module_id" : id_parts[1], |
||
| 1647 | runge | 333 | "group" : false |
| 1644 | runge | 334 | }); |
| 1647 | runge | 335 | for (var alias_name in aliases_data) |
| 1644 | runge | 336 | { |
| 1647 | runge | 337 | var ok = true; |
| 2075 | runge | 338 | |
| 1765 | linlun | 339 | if (Module_OnChangeFunctions[alias_name]) |
| 1644 | runge | 340 | { |
| 341 | for (var n in Module_OnChangeFunctions[alias_name]) |
||
| 342 | { |
||
| 343 | Module_OnChangeFunctions[alias_name][n](alias_name, available); |
||
| 344 | } |
||
| 345 | } |
||
| 346 | } |
||
| 2075 | runge | 347 | |
| 1649 | runge | 348 | if (Module_OnChangeFunctions["all"]) |
| 349 | { |
||
| 350 | for (var n in Module_OnChangeFunctions["all"]) |
||
| 351 | { |
||
| 352 | Module_OnChangeFunctions["all"][n](id_parts[0], id_parts[1], available); |
||
| 353 | } |
||
| 354 | } |
||
| 1642 | runge | 355 | } |
| 1650 | runge | 356 | |
| 357 | function Module_GetLastValue(alias_name) |
||
| 358 | { |
||
| 359 | if (arguments.length < 1) |
||
| 360 | { |
||
| 361 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 362 | return false; |
||
| 363 | } |
||
| 2075 | runge | 364 | |
| 1650 | runge | 365 | var aliases_data = Module_ResolveAlias(alias_name); |
| 366 | var found = false; |
||
| 2075 | runge | 367 | |
| 1650 | runge | 368 | for (var name in aliases_data) |
| 369 | { |
||
| 1673 | runge | 370 | var last_value_string = Storage_GetParameter("LastValues", name); |
| 2075 | runge | 371 | |
| 1650 | runge | 372 | if (last_value_string) |
| 373 | { |
||
| 1673 | runge | 374 | Log("\033[0;1mStored values for " + name + ":\033[0m\n"); |
| 1650 | runge | 375 | var last_value = eval("(" + last_value_string + ")"); |
| 2075 | runge | 376 | |
| 1650 | runge | 377 | for (var type_name in last_value) |
| 378 | { |
||
| 379 | var date = new Date(last_value[type_name]["timestamp"] * 1000); |
||
| 2075 | runge | 380 | |
| 1650 | runge | 381 | Log("\033[96m" + type_name + ": \033[0;1m" + last_value[type_name]["value"] + "\033[0m at " + date.toString() + "\n"); |
| 382 | } |
||
| 383 | } |
||
| 384 | else |
||
| 385 | { |
||
| 386 | Log("\033[32mNo value is stored for " + name + ".\033[0m\n"); |
||
| 387 | } |
||
| 2075 | runge | 388 | |
| 1650 | runge | 389 | found = true; |
| 390 | } |
||
| 2075 | runge | 391 | |
| 1650 | runge | 392 | if (!found) |
| 393 | { |
||
| 394 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 395 | return false; |
||
| 396 | } |
||
| 2075 | runge | 397 | |
| 1650 | runge | 398 | return true; |
| 399 | } |
||
| 400 | Console_RegisterCommand(Module_GetLastValue, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Module_GetAliasNames()); }); |
||
| 1657 | runge | 401 | |
| 402 | function Module_ListAvailable() |
||
| 403 | { |
||
| 404 | var available_modules = ModuleExport_GetAvailableModules(); |
||
| 2075 | runge | 405 | |
| 1660 | runge | 406 | var lines = [["Id", "Name", "Aliases"]]; |
| 2075 | runge | 407 | |
| 1657 | runge | 408 | for (var n in available_modules) |
| 409 | { |
||
| 410 | var id_parts = available_modules[n].split(":", 2); |
||
| 1660 | runge | 411 | var alias = "<none>"; |
| 2075 | runge | 412 | |
| 1660 | runge | 413 | var alias_names = get_keys(Module_LookupAliases({ |
| 1657 | runge | 414 | "module_name" : id_parts[0], |
| 415 | "module_id" : id_parts[1], |
||
| 416 | "group" : false |
||
| 1660 | runge | 417 | })); |
| 2075 | runge | 418 | |
| 1660 | runge | 419 | if (alias_names.length > 0) |
| 1657 | runge | 420 | { |
| 1660 | runge | 421 | alias = alias_names.join(", "); |
| 1657 | runge | 422 | } |
| 2075 | runge | 423 | |
| 1660 | runge | 424 | lines.push([id_parts[1], id_parts[0], alias]); |
| 1657 | runge | 425 | } |
| 2075 | runge | 426 | |
| 1660 | runge | 427 | var table_lines = create_table(lines); |
| 2075 | runge | 428 | |
| 1660 | runge | 429 | Log("\033[29;1m" + table_lines[0] + "\033[0m\n"); |
| 2075 | runge | 430 | |
| 1660 | runge | 431 | for (var n = 1; n < table_lines.length; n++) |
| 432 | { |
||
| 433 | Log(table_lines[n] + "\n"); |
||
| 434 | } |
||
| 2075 | runge | 435 | |
| 1657 | runge | 436 | return true; |
| 437 | } |
||
| 438 | Console_RegisterCommand(Module_ListAvailable); |
||
| 2049 | linlun | 439 | |
| 440 | function Module_GetLastData(alias_name) |
||
| 441 | { |
||
| 442 | if (arguments.length < 1) |
||
| 443 | { |
||
| 444 | Log("\033[31mNot enough parameters given.\033[0m\n"); |
||
| 445 | return false; |
||
| 446 | } |
||
| 2075 | runge | 447 | |
| 2049 | linlun | 448 | var aliases_data = Module_ResolveAlias(alias_name); |
| 449 | var found = false; |
||
| 2075 | runge | 450 | |
| 2049 | linlun | 451 | for (var name in aliases_data) |
| 452 | { |
||
| 453 | var last_value_string = Storage_GetParameter("LastValues", name); |
||
| 2075 | runge | 454 | |
| 2049 | linlun | 455 | if (last_value_string) |
| 456 | { |
||
| 457 | Log("\033[0;1mStored values for " + name + ":\033[0m\n"); |
||
| 2075 | runge | 458 | var last_value = eval("(" + last_value_string + ")"); |
| 2049 | linlun | 459 | for (var type_name in last_value) |
| 460 | { |
||
| 461 | var date = new Date(last_value[type_name]["timestamp"] * 1000); |
||
| 462 | var text = ""; |
||
| 463 | for (var data in last_value[type_name]) |
||
| 464 | { |
||
| 465 | if (data != "timestamp"){ |
||
| 2138 | linlun | 466 | if (typeof last_value[type_name][data] == "string") |
| 467 | { |
||
| 468 | text += data+"="+last_value[type_name][data]+" "; |
||
| 469 | } |
||
| 470 | else |
||
| 471 | { |
||
| 472 | for (var name2 in last_value[type_name][data]) |
||
| 473 | { |
||
| 474 | text += name2 + "=" + last_value[type_name][data][name2] + " "; |
||
| 475 | } |
||
| 476 | } |
||
| 2049 | linlun | 477 | } |
| 2138 | linlun | 478 | |
| 2049 | linlun | 479 | } |
| 480 | Log("\033[96m" + type_name + ": \033[0;1m" + text + "\033[0m at " + date.toString() + "\n"); |
||
| 2138 | linlun | 481 | |
| 482 | |||
| 483 | /* Check if the value is simple or complex */ |
||
| 484 | |||
| 485 | |||
| 486 | |||
| 487 | |||
| 488 | |||
| 2049 | linlun | 489 | } |
| 490 | } |
||
| 491 | else |
||
| 492 | { |
||
| 493 | Log("\033[32mNo value is stored for " + name + ".\033[0m\n"); |
||
| 494 | } |
||
| 2075 | runge | 495 | |
| 2049 | linlun | 496 | found = true; |
| 497 | } |
||
| 2075 | runge | 498 | |
| 2049 | linlun | 499 | if (!found) |
| 500 | { |
||
| 501 | Log("\033[31mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n"); |
||
| 502 | return false; |
||
| 503 | } |
||
| 2075 | runge | 504 | |
| 2049 | linlun | 505 | return true; |
| 506 | } |
||
| 507 | Console_RegisterCommand(Module_GetLastData, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Module_GetAliasNames()); }); |
||
| 2052 | linlun | 508 | |
| 2110 | runge | 509 | function Module_GetLastDataNative(alias_name) |
| 510 | { |
||
| 511 | var result = { }; |
||
| 512 | |||
| 513 | for (var n = 0; n < arguments.length; n++) |
||
| 514 | { |
||
| 515 | var aliases_data = Module_ResolveAlias(arguments[n]); |
||
| 516 | |||
| 2113 | runge | 517 | result[arguments[n]] = {}; |
| 518 | |||
| 2110 | runge | 519 | for (var name in aliases_data) |
| 520 | { |
||
| 521 | var last_value_string = Storage_GetParameter("LastValues", name); |
||
| 522 | |||
| 523 | if (last_value_string) |
||
| 524 | { |
||
| 525 | result[name] = JSON.parse(last_value_string); |
||
| 2113 | runge | 526 | result[arguments[n]] = result[name]; |
| 2110 | runge | 527 | } |
| 528 | else |
||
| 529 | { |
||
| 530 | result[name] = {}; |
||
| 531 | } |
||
| 532 | } |
||
| 533 | } |
||
| 534 | |||
| 535 | return result; |
||
| 536 | } |
||
| 537 | |||
| 2052 | linlun | 538 | function Module_GetLastDataRaw(alias_name) |
| 539 | { |
||
| 2067 | runge | 540 | var result = { results : {} }; |
| 541 | |||
| 542 | for (var n = 0; n < arguments.length; n++) |
||
| 2052 | linlun | 543 | { |
| 2067 | runge | 544 | var aliases_data = Module_ResolveAlias(arguments[n]); |
| 2075 | runge | 545 | |
| 2052 | linlun | 546 | for (var name in aliases_data) |
| 547 | { |
||
| 2067 | runge | 548 | var last_value_string = Storage_GetParameter("LastValues", name); |
| 2075 | runge | 549 | |
| 2113 | runge | 550 | result[arguments[n]] = {}; |
| 551 | |||
| 2067 | runge | 552 | if (last_value_string) |
| 553 | { |
||
| 554 | result.results[name] = JSON.parse(last_value_string); |
||
| 2113 | runge | 555 | result[arguments[n]] = result[name]; |
| 2067 | runge | 556 | } |
| 557 | else |
||
| 558 | { |
||
| 559 | result.results[name] = {}; |
||
| 560 | } |
||
| 561 | } |
||
| 2052 | linlun | 562 | } |
| 2075 | runge | 563 | |
| 2052 | linlun | 564 | Log(JSON.stringify(result)+'\n'); |
| 565 | return true; |
||
| 566 | } |
||
| 567 | Console_RegisterCommand(Module_GetLastDataRaw, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Module_GetAliasNames()); }); |
||
| 568 |