Subversion Repositories HomeAutomation

Rev

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

Rev 2205 Rev 2207
Line 50... Line 50...
50
    Sensor_OnNewPhonenumberFunctions[alias_name] = [];
50
    Sensor_OnNewPhonenumberFunctions[alias_name] = [];
51
  }
51
  }
52
 
52
 
53
  Sensor_OnNewPhonenumberFunctions[alias_name].push(callback);
53
  Sensor_OnNewPhonenumberFunctions[alias_name].push(callback);
54
}
54
}
-
 
55
 
-
 
56
Sensor_OnDeviceStateChangeFunctions = [];
-
 
57
 
-
 
58
function Sensor_RegisterToDeviceStateChange(alias_name, callback)
-
 
59
{
-
 
60
  if (!Sensor_OnDeviceStateChangeFunctions[alias_name])
-
 
61
  {
-
 
62
    Sensor_OnDeviceStateChangeFunctions[alias_name] = [];
-
 
63
  }
-
 
64
 
-
 
65
  Sensor_OnDeviceStateChangeFunctions[alias_name].push(callback);
-
 
66
}
-
 
67
 
55
 
68
 
56
function Sensor_OnMessage(module_name, module_id, command, variables)
69
function Sensor_OnMessage(module_name, module_id, command, variables)
57
{
70
{
58
  if (in_array(Sensor_ModuleNames, module_name))
71
  if (in_array(Sensor_ModuleNames, module_name))
59
  {
72
  {
Line 110... Line 123...
110
          {
123
          {
111
            /* Secret/protected number */
124
            /* Secret/protected number */
112
            number = "Protected";
125
            number = "Protected";
113
            incommingCall = true;
126
            incommingCall = true;
114
            checkName = false;
127
            checkName = false;
115
          }
128
          }
116
          else
129
          else
117
          {
130
          {
118
            Log("DTMF decoded number is to short, number: \"" + number + "\", length: " + number.length);
131
            Log("DTMF decoded number is to short, number: \"" + number + "\", length: " + number.length);
119
            return;
132
            return;
120
          }
133
          }
121
         
134
         
122
          /* Adding area code prefix if needed */
135
          /* Adding area code prefix if needed */
123
          if (number.charAt(0) != '0' && checkName)
136
          if (number.charAt(0) != '0' && checkName)
124
          {
137
          {
125
            if (typeof sensorDefaultPhoneAreaCode === 'undefined')
138
            if (typeof sensorDefaultPhoneAreaCode === 'undefined')
126
            {
139
            {
Line 130... Line 143...
130
            else
143
            else
131
            {
144
            {
132
                number = sensorDefaultPhoneAreaCode + number;
145
                number = sensorDefaultPhoneAreaCode + number;
133
            }
146
            }
134
          }
147
          }
135
 
148
 
136
          /* Store number and direction in last values */
149
          /* Store number and direction in last values */
137
          var lastValue = {};
150
          var lastValue = {};
138
          var lastValueString = Storage_GetParameter("LastValues", alias_name);
151
          var lastValueString = Storage_GetParameter("LastValues", alias_name);
139
 
152
 
140
          if (lastValueString)
153
          if (lastValueString)
141
          {
154
          {
142
            lastValue = JSON.parse(lastValueString);
155
            lastValue = JSON.parse(lastValueString);
143
          }
156
          }
144
 
157
 
145
          var timestamp = get_time();
158
          var timestamp = get_time();
146
 
159
 
147
          lastValue["Phonenumber"] = { "value" : number, "timestamp" : timestamp };
160
          lastValue["Phonenumber"] = { "value" : number, "timestamp" : timestamp };
148
          lastValue["Direction"] = { "value" : incommingCall ? "in" : "out", "timestamp" : timestamp };
161
          lastValue["Direction"] = { "value" : incommingCall ? "in" : "out", "timestamp" : timestamp };
149
 
162
 
150
          Storage_SetParameter("LastValues", alias_name, JSON.stringify(lastValue));
163
          Storage_SetParameter("LastValues", alias_name, JSON.stringify(lastValue));
Line 197... Line 210...
197
        for (var alias_name in aliases_data)
210
        for (var alias_name in aliases_data)
198
        {
211
        {
199
          if (aliases_data[alias_name]["specific"]["SensorId"] != variables["SensorId"])
212
          if (aliases_data[alias_name]["specific"]["SensorId"] != variables["SensorId"])
200
          {
213
          {
201
            continue;
214
            continue;
202
          }
215
          }
203
 
216
 
204
          var last_value = {};
217
          var last_value = {};
205
          var last_value_string = Storage_GetParameter("LastValues", alias_name);
218
          var last_value_string = Storage_GetParameter("LastValues", alias_name);
206
 
219
 
207
          if (last_value_string)
220
          if (last_value_string)
208
          {
221
          {
209
            last_value = eval("(" + last_value_string + ")");
222
            last_value = eval("(" + last_value_string + ")");
210
          }
223
          }
Line 233... Line 246...
233
        var VikingSuccess = "NoVikingSensor";
246
        var VikingSuccess = "NoVikingSensor";
234
        loopAliases:    /* Label to break nested */
247
        loopAliases:    /* Label to break nested */
235
        for (var alias_name in aliases_data)
248
        for (var alias_name in aliases_data)
236
        {
249
        {
237
            if (aliases_data[alias_name]["specific"]["Channel"] == variables["Channel"] &&
250
            if (aliases_data[alias_name]["specific"]["Channel"] == variables["Channel"] &&
238
                variables["Status"] == "Burst" &&
-
 
239
                aliases_data[alias_name]["specific"]["Proto"] == variables["Protocol"])
251
                aliases_data[alias_name]["specific"]["Proto"] == variables["Protocol"])
240
            {
252
            {
241
                switch (variables["Protocol"])
253
                switch (variables["Protocol"])
242
                {
254
                {
243
                    case "Viking":
255
                    case "Viking":
244
                    {
-
 
-
 
256
                    {   /* Add alias with these specifics: Channel=0,Proto=Viking,Address=<address of sensor> */
245
                        VikingSuccess = "VikingNotFound";
257
                        VikingSuccess = "VikingNotFound";
246
                        /*
258
                        /*
247
                                          ??? aaaaaaaa sttttttttttt hhhhhhhh cccccccc
259
                                          ??? aaaaaaaa sttttttttttt hhhhhhhh cccccccc
248
                        341731651126    0b100 11111001 000011001011 00101110 00110110   20.3 46%
260
                        341731651126    0b100 11111001 000011001011 00101110 00110110   20.3 46%
249
                        a = address, s = sign, t = temperature, h = humidity, c = crc
261
                        a = address, s = sign, t = temperature, h = humidity, c = crc
Line 291... Line 303...
291
                            last_value["Humidity_Percent"] = { "value" : humidity.toString(), "timestamp" : timestamp };
303
                            last_value["Humidity_Percent"] = { "value" : humidity.toString(), "timestamp" : timestamp };
292
 
304
 
293
                            Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
305
                            Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
294
                           
306
                           
295
                            break loopAliases;
307
                            break loopAliases;
-
 
308
                        }
-
 
309
                        break;
-
 
310
                    }
-
 
311
                    case "Nexa2":
-
 
312
                    {   /* Add alias with these specifics: Channel=0,Proto=Nexa,OnData=<data for on>,OffData=<data for off> */
-
 
313
                        var deviceStateCommand = "";
-
 
314
                        if (variables["IRdata"] == aliases_data[alias_name]["specific"]["OnData"] && variables["Status"] == "Pressed")
-
 
315
                        {
-
 
316
                            deviceStateCommand = "On";
-
 
317
                        }
-
 
318
                        else if (variables["IRdata"] == aliases_data[alias_name]["specific"]["OffData"] && variables["Status"] == "Pressed")
-
 
319
                        {
-
 
320
                            deviceStateCommand = "Off";
-
 
321
                        }
-
 
322
                        else
-
 
323
                        {
-
 
324
                            break;
-
 
325
                        }
-
 
326
                       
-
 
327
                        var last_value = {};
-
 
328
                        var last_value_string = Storage_GetParameter("LastValues", alias_name);
-
 
329
 
-
 
330
                        if (last_value_string)
-
 
331
                        {
-
 
332
                            last_value = eval("(" + last_value_string + ")");
-
 
333
                        }
-
 
334
                       
-
 
335
                        if (( typeof(last_value["State"]) == "undefined" ) ||
-
 
336
                            ( deviceStateCommand == "Off" && last_value["State"]["value"] == "On" ) ||
-
 
337
                            ( deviceStateCommand == "On" && last_value["State"]["value"] == "Off" ))
-
 
338
                        {
-
 
339
                            last_value["State"] = { "value" : deviceStateCommand, "timestamp" : get_time() };
-
 
340
 
-
 
341
                            Storage_SetParameter("LastValues", alias_name, JSON.stringify(last_value));
-
 
342
 
-
 
343
                            /* Call any potential subscribers */
-
 
344
                            if (Sensor_OnDeviceStateChangeFunctions[alias_name])
-
 
345
                            {
-
 
346
                                for (var n in Sensor_OnDeviceStateChangeFunctions[alias_name])
-
 
347
                                {
-
 
348
                                    /* Call callback with arguments alias, state */
-
 
349
                                    Sensor_OnDeviceStateChangeFunctions[alias_name][n](alias_name, deviceStateCommand);
-
 
350
                                }
-
 
351
                            }
296
                        }
352
                        }
297
                        break;
353
                        break;
298
                    }
354
                    }
299
                }
355
                }
300
            }
356
            }