44$ new_value = (float )$ params ['NEW_VALUE ' ];
55$ old_value = (float )$ params ['OLD_VALUE ' ];
66
7+ $ timer_name = $ ot . '_counter_update_h ' ;
8+ clearTimeOut ($ timer_name );
9+
10+ $ timer_name = $ ot . '_counter_update_d ' ;
11+ clearTimeOut ($ timer_name );
12+
13+ $ timer_name = $ ot . '_counter_update_m ' ;
14+ clearTimeOut ($ timer_name );
15+
16+ if ($ new_value != $ old_value ) {
17+
18+ // HOUR
19+ $ timer_name = $ ot . '_counter_update_h ' ;
20+ $ when_start = strtotime (date ('Y-m-d H:59:59 ' )) + 1 ;
21+ $ timeout = $ when_start - time () + 1 ;
22+ setTimeOut ($ timer_name , "DebMes('H: Updating $ ot.value to $ new_value','counter_update');setGlobal(' $ ot.value', ' " . $ new_value . "'); " , $ timeout );
23+ $ prev_timeout = $ timeout ;
24+
25+ // DAY
26+ $ timer_name = $ ot . '_counter_update_d ' ;
27+ $ when_start = strtotime (date ('Y-m-d 23:59:59 ' )) + 1 ;
28+ $ timeout = $ when_start - time () + 1 ;
29+ if ($ prev_timeout != $ timeout ) {
30+ setTimeOut ($ timer_name , "DebMes('D: Updating $ ot.value to $ new_value','counter_update');setGlobal(' $ ot.value', ' " . $ new_value . "'); " , $ timeout );
31+ $ prev_timeout = $ timeout ;
32+ }
33+
34+ // MONTH
35+ $ timer_name = $ ot . '_counter_update_m ' ;
36+ $ when_start = strtotime (date ('Y-m-t 23:59:59 ' )) + 1 ;
37+ $ timeout = $ when_start - time () + 1 ;
38+ if ($ prev_timeout != $ timeout ) {
39+ setTimeOut ($ timer_name , "DebMes('M: Updating $ ot.value to $ new_value','counter_update');setGlobal(' $ ot.value', ' " . $ new_value . "'); " , $ timeout );
40+ }
41+
42+ }
43+
744$ this ->callMethodSafe ('keepAlive ' );
845$ this ->callMethodSafe ('statusUpdated ' );
946$ this ->callMethodSafe ('logicAction ' );
1047
1148$ history_values = array (
12- 'valueHour ' => date ('Y-m-d H:00:00 ' ),
13- 'valueDay ' => date ('Y-m-d 00:00:00 ' ),
14- 'valueMonth ' => date ('Y-m-01 00:00:00 ' )
49+ 'valueHour ' => date ('Y-m-d H:00:00 ' ),
50+ 'valueDay ' => date ('Y-m-d 00:00:00 ' ),
51+ 'valueMonth ' => date ('Y-m-01 00:00:00 ' )
1552);
1653
17- foreach ($ history_values as $ history_value=> $ time ) {
18- $ value_id = (int )getHistoryValueId ($ ot . '. ' . $ history_value );
19- if (defined ('SEPARATE_HISTORY_STORAGE ' ) && SEPARATE_HISTORY_STORAGE == 1 ) {
20- $ table_name = createHistoryTable ($ value_id );
21- } else {
22- $ table_name = 'phistory ' ;
23- }
24- $ val1 = SQLSelectOne ("SELECT ID, VALUE FROM pvalues WHERE ID=' " . $ value_id . "' AND UPDATED>=(' " . $ time . "') " );
25- if ($ val1 ['ID ' ]) {
26- SQLExec ("DELETE FROM $ table_name WHERE VALUE_ID= $ value_id AND ADDED>=(' " . $ time . "') " );
27- $ set_value = $ val1 ['VALUE ' ] + ($ new_value - $ old_value );
28- $ set_value = round ($ set_value , 3 );
29- $ this ->setProperty ($ history_value , $ set_value );
30- } else {
31- $ set_value = $ new_value - $ old_value ;
32- $ set_value = round ($ set_value , 3 );
33- $ this ->setProperty ($ history_value , $ set_value );
34- //DebMes($history_value . ' ' . $time . ' - id - ' . $value_id . ' - new - ' . $new_value . ' - old - ' . $old_value, $ot);
35- }
54+ foreach ($ history_values as $ history_value => $ time ) {
55+ $ value_id = (int )getHistoryValueId ($ ot . '. ' . $ history_value );
56+ if (defined ('SEPARATE_HISTORY_STORAGE ' ) && SEPARATE_HISTORY_STORAGE == 1 ) {
57+ $ table_name = createHistoryTable ($ value_id );
58+ } else {
59+ $ table_name = 'phistory ' ;
60+ }
61+ $ val1 = SQLSelectOne ("SELECT ID, VALUE FROM pvalues WHERE ID=' " . $ value_id . "' AND UPDATED>=(' " . $ time . "') " );
62+ if ($ val1 ['ID ' ]) {
63+ SQLExec ("DELETE FROM $ table_name WHERE VALUE_ID= $ value_id AND ADDED>=(' " . $ time . "') " );
64+ $ set_value = $ val1 ['VALUE ' ] + ($ new_value - $ old_value );
65+ $ set_value = round ($ set_value , 2 );
66+ $ this ->setProperty ($ history_value , $ set_value );
67+ } else {
68+ $ set_value = $ new_value - $ old_value ;
69+ $ set_value = round ($ set_value , 2 );
70+ $ this ->setProperty ($ history_value , $ set_value );
71+ //DebMes($history_value . ' ' . $time . ' - id - ' . $value_id . ' - new - ' . $new_value . ' - old - ' . $old_value, $ot);
72+ }
3673}
3774
38- include_once (dirname (__FILE__ ). '/devices.class.php ' );
39- $ dv= new devices ();
75+ include_once (dirname (__FILE__ ) . '/devices.class.php ' );
76+ $ dv = new devices ();
4077$ dv ->checkLinkedDevicesAction ($ this ->object_title , $ new_value );
0 commit comments