Subversion Repositories HomeAutomation

Rev

Rev 1652 | Rev 1998 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1652 Rev 1657
Line 6... Line 6...
6
IRIn_Remotes        = function() { return get_keys(Storage_GetParameters("RemoteList")); };
6
IRIn_Remotes        = function() { return get_keys(Storage_GetParameters("RemoteList")); };
7
 
7
 
8
IRIn_RecordRemoteName = null;
8
IRIn_RecordRemoteName = null;
9
IRIn_RecordAliasData = null;
9
IRIn_RecordAliasData = null;
10
IRIn_RecordLast = null;
10
IRIn_RecordLast = null;
-
 
11
IRIn_RecordClientId = null;
11
 
12
 
12
function IRIn_CodeToName(data, protocol, remote_name)
13
function IRIn_CodeToName(data, protocol, remote_name)
13
{
14
{
14
    var remote_storage_name = Storage_GetParameter("RemoteList", remote_name);
15
    var remote_storage_name = Storage_GetParameter("RemoteList", remote_name);
15
 
16
 
Line 37... Line 38...
37
    return "";
38
    return "";
38
}
39
}
39
 
40
 
40
function IRIn_Record(alias_name, remote_name)
41
function IRIn_Record(alias_name, remote_name)
41
{
42
{
42
   
-
 
43
    if (arguments.length < 2)
43
    if (arguments.length < 2)
44
    {
44
    {
45
        Log("\033[31mNot enough parameters given.\033[0m\n");
45
        Log("\033[31mNot enough parameters given.\033[0m\n");
46
        return false;
46
        return false;
47
    }
47
    }
48
   
48
   
49
    IRIn_RecordRemoteName = Storage_GetParameter("RemoteList", remote_name);
49
    IRIn_RecordRemoteName = Storage_GetParameter("RemoteList", remote_name);
50
   
50
   
51
    if (!IRIn_RecordRemoteName)
51
    if (!IRIn_RecordRemoteName)
52
    {
52
    {
53
        IRIn_RecordRemoteName = "Remote_" + remote_name;
53
        IRIn_RecordRemoteName = "Remote_" + remote_name;
54
       
54
       
55
        Log("\033[32mNo such remote name in list, " + remote_name + ", creating...\033[0m\n");
55
        Log("\033[32mNo such remote name in list, " + remote_name + ", creating...\033[0m\n");
56
       
56
       
57
        Storage_SetParameter("RemoteList", remote_name, IRIn_RecordRemoteName);
57
        Storage_SetParameter("RemoteList", remote_name, IRIn_RecordRemoteName);
58
    }
58
    }
59
   
59
   
60
    var aliases_data = Module_ResolveAlias(alias_name, IRIn_ModuleNames);
60
    var aliases_data = Module_ResolveAlias(alias_name, IRIn_ModuleNames);
61
   
61
   
62
    for (var name in aliases_data)
62
    for (var name in aliases_data)
63
    {
63
    {
64
        if (aliases_data[name]["group"])
64
        if (aliases_data[name]["group"])
65
        {
65
        {
66
            Log("\033[31mAlias must not be an alias group.\033[0m\n");
66
            Log("\033[31mAlias must not be an alias group.\033[0m\n");
67
            return false;
67
            return false;
68
        }
68
        }
-
 
69
       
-
 
70
        IRIn_RecordClientId = Console_GetClientId();
69
       
71
       
70
        IRIn_RecordAliasData = aliases_data[name];
72
        IRIn_RecordAliasData = aliases_data[name];
71
        Log("Enter a single dot to finish.\n");
73
        Log("Enter a single dot to finish.\n");
72
       
74
       
73
        Log("\033[29mPress a button on you remote...\033[0m\n");
75
        Log("\033[29mPress a button on you remote...\033[0m\n");
74
        Console_PreventDefaultPrompt();
76
        Console_PreventDefaultPrompt();
75
   
77
   
76
        Module_RegisterToOnMessage(alias_name, IRIn_RecordOnIrMessage);
78
        Module_RegisterToOnMessage(alias_name, IRIn_RecordOnIrMessage);
77
        return true;
79
        return true;
78
    }
80
    }
79
   
81
   
80
    Log("\033[31mNo such alias name found, " + alias_name + ".\033[0m\n");
82
    Log("\033[31mNo such alias name found, " + alias_name + ".\033[0m\n");
81
    return false;
83
    return false;
82
   
84
   
83
}
85
}
Line 85... Line 87...
85
 
87
 
86
function IRIn_RecordOnResponse(response)
88
function IRIn_RecordOnResponse(response)
87
{
89
{
88
    if (response == ".")
90
    if (response == ".")
89
    {
91
    {
-
 
92
        IRIn_RecordClientId = null;
90
        return true;
93
        return true;
91
    }
94
    }
92
   
95
   
93
    Storage_SetParameter(IRIn_RecordRemoteName, response, JSON.stringify(IRIn_RecordLast));
96
    Storage_SetParameter(IRIn_RecordRemoteName, response, JSON.stringify(IRIn_RecordLast));
94
    IRIn_RecordLast = null;
97
    IRIn_RecordLast = null;
Line 104... Line 107...
104
    if (variables["Status"] != "Pressed" || IRIn_RecordLast != null)
107
    if (variables["Status"] != "Pressed" || IRIn_RecordLast != null)
105
    {
108
    {
106
        return;
109
        return;
107
    }
110
    }
108
   
111
   
109
    Log("\033[32mGot code " + variables["IRdata"] + " on protocol " + variables["Protocol"] + ".\033[0m\n");
112
    ConsoleExport_LogToClient(IRIn_RecordClientId, "\033[32mGot code " + variables["IRdata"] + " on protocol " + variables["Protocol"] + ".\033[0m\n");
110
   
113
   
111
    IRIn_RecordLast = { "protocol" : variables["Protocol"], "data" : variables["IRdata"] };
114
    IRIn_RecordLast = { "protocol" : variables["Protocol"], "data" : variables["IRdata"] };
112
   
115
   
113
    Console_PromptRequest("\033[29mEnter name: \033[0m", IRIn_RecordOnResponse);
116
    Console_PromptRequest("\033[29mEnter name: \033[0m", IRIn_RecordOnResponse);
114
   
117
   
115
    return true;
118
    return true;
116
}
119
}
117
 
-
 
118
 
-
 
119
 
-