Subversion Repositories HomeAutomation

Rev

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

  1.  
  2. function fadeto(alias, level, speed)
  3. {
  4.     var alias_data = resolvealias(alias);
  5.    
  6.     if (alias_data == null)
  7.     {
  8.         return "No such module name found";
  9.     }
  10.    
  11.     if (alias_data["is_group"])
  12.     {
  13.         var result = "";
  14.        
  15.         for (var n = 0; n < alias_data["aliases"].length; n++)
  16.         {
  17.             result += fadeto(alias_data["aliases"][n], level, speed) + "\n";
  18.         }
  19.        
  20.         return result;
  21.     }
  22.    
  23.     if (alias_data["module_name"] != "Dimmer230")
  24.     {
  25.         return "Module type " + alias_data["module_name"] + " is not valid for this action, valid are Dimmer230";
  26.     }
  27.    
  28.     if (typeof alias_data["module_id"] == 'undefined' || typeof alias_data["extra"] == 'undefined')
  29.     {
  30.         return "Alias is corrupt";
  31.     }
  32.    
  33.     if (!speed)
  34.     {
  35.         speed = 135;
  36.     }
  37.    
  38.     return Dimmer230_AbsoluteFade(alias_data["module_id"], alias_data["extra"], speed, level);
  39. }
  40. RegisterConsoleCommand(fadeto, function(args) { return StandardAutocomplete(args, Dimmer230.instance_.GetAvailableNames(), Dimmer230.standard_levels_ , Dimmer230.standard_speeds_ ); });
  41.  
  42. function irsend_autocomplete(args)
  43. {
  44.     // args[0] == command name
  45.     var arg_index = args.length - 2;
  46.    
  47.     if (arg_index == 0)
  48.     {
  49.         return irTransmit.instance_.GetAvailableNames();
  50.     }
  51.     else if (arg_index == 1)
  52.     {
  53.         var remotes = Storage_GetParameters("RemoteList");
  54.        
  55.         var result = new Array();
  56.        
  57.         for (var name in remotes)
  58.         {
  59.             result.push(name);
  60.         }
  61.        
  62.         return result;
  63.     }
  64.     else if (arg_index == 2)
  65.     {
  66.         var remote_storage_name = Storage_GetParameter("RemoteList", args[arg_index]);
  67.        
  68.         var buttons = Storage_GetParameters(remote_storage_name);
  69.        
  70.         var result = new Array();
  71.        
  72.         for (var name in buttons)
  73.         {
  74.             result.push(name);
  75.         }
  76.        
  77.         return result;
  78.     }
  79.    
  80.     return new Array();
  81. }
  82.  
  83. function irsend(alias, remote, button)
  84. {
  85.     var alias_data = resolvealias(alias);
  86.    
  87.     if (alias_data == null)
  88.     {
  89.         return "No such module name found";
  90.     }
  91.    
  92.     if (alias_data["is_group"])
  93.     {
  94.         var result = "";
  95.        
  96.         for (var n = 0; n < alias_data["aliases"].length; n++)
  97.         {
  98.             result += irsend(alias_data["aliases"][n], remote, button) + "\n";
  99.         }
  100.        
  101.         return result;
  102.     }
  103.    
  104.     if (alias_data["module_name"] != "irTransmit")
  105.     {
  106.         return "Module type " + alias_data["module_name"] + " is not valid for this action, valid are irTransmit";
  107.     }
  108.    
  109.     if (typeof alias_data["module_id"] == 'undefined' || typeof alias_data["extra"] == 'undefined')
  110.     {
  111.         return "Alias is corrupt";
  112.     }
  113.    
  114.     var remote_storage_name = Storage_GetParameter("RemoteList", remote);
  115.    
  116.     if (!remote_storage_name)
  117.     {
  118.         return "No such remote name in list, " + remote;
  119.     }
  120.    
  121.     var button_string = Storage_GetParameter(remote_storage_name, button);
  122.    
  123.     if (!button_string)
  124.     {
  125.         return "No such button " + button + " found on remote " + remote;
  126.     }
  127.    
  128.     var button = eval("(" + button_string + ")");
  129.    
  130.     if (typeof button["protocol"] == 'undefined' || typeof button["data"] == 'undefined')
  131.     {
  132.         return "Button is corrupt";
  133.     }
  134.    
  135.     return irTransmit_SendCode(alias_data["module_id"], alias_data["extra"], "Burst", button["protocol"], button["data"]);
  136. }
  137. RegisterConsoleCommand(irsend, irsend_autocomplete);
  138.