Subversion Repositories HomeAutomation

Rev

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

Rev 1626 Rev 1644
Line 1... Line 1...
1
 
1
 
2
function Dimmer230(name)
2
Require("plugin/module.js");
-
 
3
 
-
 
4
Dimmer_ModuleName     = "Dimmer230";
-
 
5
Dimmer_SpeedLevels    = function() { return [ 50, 135, 200, 255 ]; };
-
 
6
Dimmer_StrengthLevels = function() { return [ 0, 50, 100, 150, 200, 255 ]; };
-
 
7
Dimmer_StepsLevels    = function() { return [ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90 ]; };
-
 
8
Dimmer_Directions     = function() { return [ "Increase", "Decrease" ]; };
-
 
9
Dimmer_Channels       = function() { return [ 0 ]; };
-
 
10
Dimmer_Aliases        = function() { return Module_GetAliasNames([ Dimmer_ModuleName ]); };
-
 
11
Dimmer_AvailableIds   = function() { return Module_GetAvailableIds([ Dimmer_ModuleName ]); };
-
 
12
 
-
 
13
function Dimmer_MessageAliasLookup(module_id, command, variables)
3
{
14
{
4
    this.Module(name);
15
    var aliases_data = {};
-
 
16
   
-
 
17
    if (command == "Netinfo")
-
 
18
    {
-
 
19
        aliases_data = Module_LookupAliases({
-
 
20
            "module_name" : Dimmer_ModuleName,
-
 
21
            "module_id"   : module_id,
-
 
22
            "channel"     : channel
-
 
23
        });
-
 
24
    }
-
 
25
   
5
    Dimmer230.instance_ = this;
26
    return aliases_data;
6
}
27
}
-
 
28
Module_RegisterMessageAliasLookup(Dimmer_ModuleName, Dimmer_MessageAliasLookup);
7
 
29
 
-
 
30
function Dimmer_CreateAlias(alias_name, module_id, channel)
-
 
31
{
-
 
32
    var alias_data = {
-
 
33
        "group"       : false,
-
 
34
        "name"        : alias_name,
-
 
35
        "module_name" : Dimmer_ModuleName,
8
Extend(Dimmer230, Module);
36
        "module_id"   : module_id,
-
 
37
        "channel"     : channel
-
 
38
    };
-
 
39
 
-
 
40
    return Storage_SetParameter("alias", alias_name, JSON.stringify(alias_data));
-
 
41
}
-
 
42
Console_RegisterCommand(Dimmer_CreateAlias, function(args) { return Console_StandardAutocomplete(args, Dimmer_Aliases(), Dimmer_AvailableIds(), Dimmer_Channels()); });
9
 
43
 
-
 
44
function Dimmer_StartFade(alias_name, speed, direction)
-
 
45
{
-
 
46
    if (arguments.length < 3)
-
 
47
    {
-
 
48
        throw("Not enought parameters given");
-
 
49
    }
-
 
50
   
10
Dimmer230.instance_ = null;
51
    var result_text = "";
-
 
52
    var aliases_data = Module_ResolveAlias(alias_name, [ Dimmer_ModuleName ]);
-
 
53
   
-
 
54
    for (var name in aliases_data)
-
 
55
    {
-
 
56
        var variables = {
-
 
57
            "Channel"   : aliases_data[name]["channel"],
-
 
58
            "Speed"     : speed,
-
 
59
            "Direction" : direction };
-
 
60
   
-
 
61
        if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Start_Fade", variables))
-
 
62
        {
-
 
63
            result_text += "StartFade sent successfully to " + name + "\n";
-
 
64
        }
-
 
65
        else
-
 
66
        {
11
Dimmer230.standard_speeds_ = [ 50, 135, 200, 255 ];
67
            result_text += "StartFade failed to send to " + name + "\n";
-
 
68
        }
-
 
69
    }
-
 
70
   
-
 
71
    if (result_text.length == 0)
-
 
72
    {
-
 
73
        result_text = "No aliases by the name " + alias_name + " were applicable to StartFade.";
-
 
74
    }
-
 
75
   
-
 
76
    return result_text;
-
 
77
}
-
 
78
Console_RegisterCommand(Dimmer_StartFade, function(args) { return Console_StandardAutocomplete(args, Dimmer_Aliases(), Dimmer_SpeedLevels(), Dimmer_Directions()); });
-
 
79
 
-
 
80
function Dimmer_StopFade(alias_name)
-
 
81
{
-
 
82
    if (arguments.length < 1)
-
 
83
    {
-
 
84
        throw("Not enought parameters given");
-
 
85
    }
-
 
86
   
-
 
87
    var result_text = "";
12
Dimmer230.standard_levels_ = [ 0, 50, 100, 150, 200, 255 ];
88
    var aliases_data = Module_ResolveAlias(alias_name, [ Dimmer_ModuleName ]);
-
 
89
   
-
 
90
    for (var name in aliases_data)
-
 
91
    {
-
 
92
        var variables = {
-
 
93
            "Channel" : aliases_data[name]["channel"] };
-
 
94
       
-
 
95
        if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Stop_Fade", variables))
-
 
96
        {
13
Dimmer230.standard_steps_ = [ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90 ];
97
            result_text += "StopFade sent successfully to " + name + "\n";
-
 
98
        }
-
 
99
        else
-
 
100
        {
14
Dimmer230.standard_direction_ = [ "Increase", "Decrease" ];
101
            result_text += "StopFade failed to send to " + name + "\n";
-
 
102
        }
-
 
103
    }
-
 
104
   
-
 
105
    if (result_text.length == 0)
-
 
106
    {
-
 
107
        result_text = "No aliases by the name " + alias_name + " were applicable to StopFade.";
-
 
108
    }
-
 
109
   
-
 
110
    return result_text;
-
 
111
}
-
 
112
Console_RegisterCommand(Dimmer_StopFade, function(args) { return Console_StandardAutocomplete(args, Dimmer_Aliases()); });
15
 
113
 
16
Dimmer230.prototype.ReceiveMessage = function(id, command, variables)
114
function Dimmer_AbsoluteFade(alias_name, speed, level)
17
{
115
{
-
 
116
    if (arguments.length < 3)
-
 
117
    {
-
 
118
        throw("Not enought parameters given");
-
 
119
    }
-
 
120
   
-
 
121
    var result_text = "";
-
 
122
    var aliases_data = Module_ResolveAlias(alias_name, [ Dimmer_ModuleName ]);
-
 
123
   
-
 
124
    for (var name in aliases_data)
-
 
125
    {
-
 
126
        var variables = {
-
 
127
            "Channel"   : aliases_data[name]["channel"],
-
 
128
            "Speed"     : speed,
-
 
129
            "EndValue"  : level };
-
 
130
       
-
 
131
        if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Abs_Fade", variables))
-
 
132
        {
-
 
133
            result_text += "AbsolutFade sent successfully to " + name + "\n";
-
 
134
        }
-
 
135
        else
-
 
136
        {
-
 
137
            result_text += "AbsolutFade failed to send to " + name + "\n";
-
 
138
        }
-
 
139
    }
-
 
140
   
-
 
141
    if (result_text.length == 0)
-
 
142
    {
-
 
143
        result_text = "No aliases by the name " + alias_name + " were applicable to AbsolutFade.";
-
 
144
    }
-
 
145
   
18
    switch (command)
146
    return result_text;
-
 
147
}
-
 
148
Console_RegisterCommand(Dimmer_AbsoluteFade, function(args) { return Console_StandardAutocomplete(args, Dimmer_Aliases(), Dimmer_SpeedLevels(), Dimmer_StrengthLevels()); });
-
 
149
 
-
 
150
function Dimmer_RelativeFade(alias_name, speed, direction, steps)
-
 
151
{
-
 
152
    if (arguments.length < 4)
19
    {
153
    {
-
 
154
        throw("Not enought parameters given");
-
 
155
    }
-
 
156
   
20
        case "Netinfo":
157
    var result_text = "";
-
 
158
    var aliases_data = Module_ResolveAlias(alias_name, [ Dimmer_ModuleName ]);
-
 
159
   
-
 
160
    for (var name in aliases_data)
-
 
161
    {
-
 
162
        var variables = {
-
 
163
            "Channel"   : aliases_data[name]["channel"],
-
 
164
            "Speed"     : speed,
-
 
165
            "Direction" : direction,
-
 
166
            "Steps"     : steps };
-
 
167
       
-
 
168
        if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Rel_Fade", variables))
21
        {
169
        {
-
 
170
            result_text += "RelativeFade sent successfully to " + name + "\n";
-
 
171
        }
22
            break;
172
        else
-
 
173
        {
-
 
174
            result_text += "RelativeFade failed to send to " + name + "\n";
23
        }
175
        }
-
 
176
    }
-
 
177
   
-
 
178
    if (result_text.length == 0)
-
 
179
    {
-
 
180
        result_text = "No aliases by the name " + alias_name + " were applicable to RelativeFade.";
-
 
181
    }
-
 
182
   
-
 
183
    return result_text;
-
 
184
}
-
 
185
Console_RegisterCommand(Dimmer_RelativeFade, function(args) { return Console_StandardAutocomplete(args, Dimmer_Aliases(), Dimmer_SpeedLevels(), Dimmer_Directions(), Dimmer_StepsLevels()); });
-
 
186
 
-
 
187
function Dimmer_Demo(alias_name, speed, steps)
-
 
188
{
-
 
189
    if (arguments.length < 3)
-
 
190
    {
-
 
191
        throw("Not enought parameters given");
24
    }
192
    }
25
   
193
   
-
 
194
    var result_text = "";
26
    this.Module.prototype.ReceiveMessage.call(this, id, command, variables);
195
    var aliases_data = Module_ResolveAlias(alias_name, [ Dimmer_ModuleName ]);
27
}
-
 
28
 
196
   
29
function Dimmer230_StartFade(id, channel, speed, direction)
197
    for (var name in aliases_data)
30
{
198
    {
31
    var variables = [
199
        var variables = {
32
    { "Channel"   : channel },
200
            "Channel"   : aliases_data[name]["channel"],
33
    { "Speed"     : speed },
201
            "Speed"     : speed,
34
    { "Direction" : direction } ];
202
            "Steps"     : steps };
35
   
203
       
36
    Dimmer230.instance_.Module.prototype.SendMessage.call(Dimmer230.instance_, id, "Start_Fade", variables);
204
        if (Module_SendMessage(aliases_data[name]["module_name"], aliases_data[name]["module_id"], "Demo", variables))
37
    return "OK";
-
 
38
}
-
 
39
RegisterConsoleCommand(Dimmer230_StartFade, function(args) { return StandardAutocomplete(args, Dimmer230.instance_.GetAvailableIds(), [ 0 ], Dimmer230.standard_speeds_, Dimmer230.standard_direction_); });
-
 
40
 
-
 
41
 
-
 
42
function Dimmer230_StopFade(id, channel)
-
 
43
{
205
        {
44
    var variables = [
206
            result_text += "Demo sent successfully to " + name + "\n";
-
 
207
        }
45
    { "Channel"  : channel } ];
208
        else
46
   
209
        {
47
    Dimmer230.instance_.Module.prototype.SendMessage.call(Dimmer230.instance_, id, "Stop_Fade", variables);
210
            result_text += "Demo failed to send to " + name + "\n";
48
    return "OK";
211
        }
49
}
212
    }
50
RegisterConsoleCommand(Dimmer230_StopFade, function(args) { return StandardAutocomplete(args, Dimmer230.instance_.GetAvailableIds(), [ 0 ]); });
-
 
51
 
213
   
52
 
-
 
53
function Dimmer230_AbsoluteFade(id, channel, speed, level)
214
    if (result_text.length == 0)
54
{
215
    {
55
    var variables = [
-
 
56
    { "Channel"  : channel },
-
 
57
    { "Speed"    : speed },
-
 
58
    { "EndValue" : level } ];
-
 
59
   
-
 
60
    Dimmer230.instance_.Module.prototype.SendMessage.call(Dimmer230.instance_, id, "Abs_Fade", variables);
216
        result_text = "No aliases by the name " + alias_name + " were applicable to Demo.";
61
    return "OK";
-
 
62
}
217
    }
63
RegisterConsoleCommand(Dimmer230_AbsoluteFade, function(args) { return StandardAutocomplete(args, Dimmer230.instance_.GetAvailableIds(), [ 0 ], Dimmer230.standard_speeds_, Dimmer230.standard_levels_); });
-
 
64
 
-
 
65
 
-
 
66
function Dimmer230_RelativeFade(id, channel, speed, direction, steps)
-
 
67
{
-
 
68
    var variables = [
-
 
69
    { "Channel"   : channel },
-
 
70
    { "Speed"     : speed },
-
 
71
    { "Direction" : direction },
-
 
72
    { "Steps"     : steps } ];
-
 
73
   
-
 
74
    Dimmer230.instance_.Module.prototype.SendMessage.call(Dimmer230.instance_, id, "Rel_Fade", variables);
-
 
75
    return "OK";
-
 
76
}
-
 
77
RegisterConsoleCommand(Dimmer230_RelativeFade, function(args) { return StandardAutocomplete(args, Dimmer230.instance_.GetAvailableIds(), [ 0 ], Dimmer230.standard_speeds_, Dimmer230.standard_direction_, Dimmer230.standard_steps_); });
-
 
78
 
-
 
79
 
-
 
80
function Dimmer230_Demo(id, channel, speed, steps)
-
 
81
{
-
 
82
    var variables = [
-
 
83
    { "Channel"   : channel },
-
 
84
    { "Speed"     : speed },
-
 
85
    { "Steps"     : steps } ];
-
 
86
   
218
   
87
    Dimmer230.instance_.Module.prototype.SendMessage.call(Dimmer230.instance_, id, "Demo", variables);
-
 
88
    return "OK";
219
    return result_text;
89
}
220
}
90
RegisterConsoleCommand(Dimmer230_Demo, function(args) { return StandardAutocomplete(args, Dimmer230.instance_.GetAvailableIds(), [ 0 ], Dimmer230.standard_speeds_, Dimmer230.standard_steps_); });
221
Console_RegisterCommand(Dimmer_Demo, function(args) { return Console_StandardAutocomplete(args, Dimmer_Aliases(), Dimmer_SpeedLevels(), Dimmer_StepsLevels()); });