sky201503 / openhab

Automatically exported from code.google.com/p/openhab
GNU General Public License v3.0
0 stars 0 forks source link

Persistence: changedSince() gives false results #297

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
See: http://knx-user-forum.de/openhab/26722-persistence-regeln.html#post313603

1. I have the following statement in a rule:
if(!Steckdose_Arbeiten_Schalten.changedSince(now.minusMinutes(10))) {
logInfo("Test rules", "Steckdose_Arbeiten_Schalten seems to be on for more than 
10 minutes")
}       

2. Switch off the Item " Steckdose_Arbeiten_Schalten" and wait for 15min 
(waiting time must be longer than the argument of 
changedSince(now.minusMinutes(10))

3. Switch on the Item, the log message "Steckdose_Arbeiten_Schalten seems to be 
on for more than 10 minutes" is printed immediately 

What is the expected output? What do you see instead?
The log message should be printed only when the Item is on for more than 10min.

What version of the product are you using? On what operating system?
The latest stable (1.2.0 with Bindings 1.2.1) on OS X Mountain Lion Server

I have done some debugging:

1. The function changedSince() from the file PersistenceExtensions.java has the 
follwoing call: 
result = getAllStatesSince(item, timestamp, serviceName);

2. The returned list does only contain the ON event from switching the item on 
in step 3, the OFF events are missing when they are older than the argument 
time in the changedSince(now.minusMinutes()) call.  This is probably because 
they are filtered in the function getAllStatesSince()

The proposed fix is to change the function changedSince() so that the state is 
not initialised to NULL but to the historic state at the beginning of the time 
in the changedSince() call (see the attached diff):
...
 Iterator<HistoricItem> it = result.iterator();
State state = historicState(item, timestamp);
 while(it.hasNext()) {
 ...

Original issue reported on code.google.com by estan...@gmx.de on 12 May 2013 at 1:31

Attachments:

GoogleCodeExporter commented 8 years ago

Original comment by kai.openhab on 12 May 2013 at 2:30

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago

Original comment by teichsta on 13 Aug 2013 at 4:08

GoogleCodeExporter commented 8 years ago
Fixed with 
https://code.google.com/p/openhab/source/detail?r=89296ad411a084a221a69fb05670c7
fa458a9f2a
Thanks for your patience!

Original comment by kai.openhab on 6 Sep 2013 at 2:11