Subversion Repositories HomeAutomation

Rev

Blame | Last modification | View Log | SVN | RSS feed

  1.  
  2. Sensor_ModuleNames    = [ "DS18x20", "FOST02", "BusVoltage" ];
  3. Sensor_Intervals      = function() { return [ 1, 5, 10, 15, 20 ]; };
  4. Sensor_Aliases        = function() { return Module_GetAliasNames(Sensor_ModuleNames); };
  5. Sensor_AvailableIds   = function() { return Module_GetAvailableIds(Sensor_ModuleNames); };
  6.  
  7. function Sensor_SetReportInterval(alias_name, interval)
  8. {
  9.     if (arguments.length < 2)
  10.     {
  11.         Log("\033[31;1mNot enough parameters given.\033[0m\n");
  12.         return false;
  13.     }
  14.    
  15.     var aliases_data = Module_ResolveAlias(alias_name, Sensor_ModuleNames);
  16.     var found = false;
  17.    
  18.     for (var name in aliases_data)
  19.     {
  20.         var variables = {
  21.             "SensorId" : aliases_data[name]["specific"]["SensorId"],
  22.             "time"     : interval };
  23.            
  24.             if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Report_Interval", variables))
  25.             {
  26.                 Log("\033[32;1mCommand sent successfully to " + name + ".\033[0m\n");
  27.             }
  28.             else
  29.             {
  30.                 Log("\033[31;1mFailed to send command to " + name + ".\033[0m\n");
  31.             }
  32.            
  33.             found = true;
  34.     }
  35.    
  36.     if (!found)
  37.     {
  38.         Log("\033[31;1mNo aliases by the name " + alias_name + " were applicable for this command.\033[0m\n");
  39.         return false;
  40.     }
  41.    
  42.     return true;
  43. }
  44. Console_RegisterCommand(Sensor_SetReportInterval, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Sensor_Aliases(), Sensor_Intervals()); });
  45.