var Boolean OK = transform("JSONPATH", "$.ok", json)
if (OK=true) {
var Boolean WholeDay= transform ("JSONPATH", "$.station.wholeDay", json)
logInfo("OpeningTimes Lambda", "WholeDay = {}", WholeDay)
if (WholeDay) {
//Open the whole day! Create times that show that.
Open.postUpdate((now.withTimeAtStartOfDay).toString)
logInfo("OpeningTimes Lambda", "Open: {}", Open)
but I donāt get the one inside the āif (WholeDay)ā. I tried it with WholeDay=true, (WholeDay=true) and WholeDay==true also!
I restarted OH2 and also rebooted my raspi. It was working until last nigth as expected!!!
If there was a problem with the Open.postUpdate, you wouldnāt see the second log line. OTOH, I assume you looked for related exceptions or errors in the log file. Just in case there an error thatās not being logged, you could try putting a log message before the postUpdate.
Thanks for the reply, as usual my statement was to short.
The rules runs over tha posted part and executes the Else branch. So the rule didnāt run into an eror there.
I think Iāve checked the obvious reasons/causes already.
Spent to whole evening on it, canāt figure out where the problem is coming from. The behaviour switched in between and did the True branch even if the statement was false. More over the postupdate didnāt work in some cases.
The diversity of the false behaviour seems to be pointing on a general system problem, could that be a problem with the SD Card?
Tomorrow Iāl do some tests without lambda expressions, just in case.
WholeDay is declared two lines above the If statement (as in the first post), so it is local to that rule and known within that statement.
The logInfo, which is just after the declaration, states WholeDay: true and in the next step the If statement treats it as not true! Where should WholeDay be interfered with?
[Edit:] didsome more detailed cheks.
Using āif (WholeDay=true) {ā¦ā ,will run the true branch IN ANY CASE, since WholeDay is set to true that way!
Using āif (WholeDay==true) {ā¦ā raises an error:
09:01:01.376 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule āOpeningTimesā: Could not invoke method: org.eclipse.xtext.xbase.lib.BooleanExtensions.operator_equals(boolean,boolean) on instance: null
Using āif WholeDay {ā¦ā does NOT run into the true branch although WholeDay is true!
Thanks for the reply and No, Iām not in similar circumstances. The above discribed behaviour has nothing to do with StartUp, nor with the fact that I initially saw in a lambda expression.
I do also understand the error in this way, however what part would you expect to be null, the āfalseā or the variable which was declared two lines above and which was positvely logged in the line just above???
In a nadditional test I used those lines:
var Boolean WholeDay= transform (āJSONPATHā, ā$.station.wholeDayā, json)
logInfo(āOpeningTimes Lambdaā, āWholeDay: {}ā,WholeDay)
WholeDay=true
if WholeDay { .
logInfo(āOpeningTimes Lambdaā, āWholeDay: {}ā,WholeDay)
This time I get the two expected logInfos, but not if I do not set WholeDay manually to true!!
Iāll use a work-around by reading the expected boolean from the json-string into a string and while checking afterwards if the string contains(ātrueā) I set the boolean. Not nice but working!!
I was curious enough to have a play (OH 1.8.3)
I think this has something to do with Java primitives under Rules DSL and type casting.
Replicating your issue
var Boolean testB = "true" // casting a String to boolean (primitive I reckon)
logInfo ("playtime", "B " + testB) // displays true
logInfo ("playtime", "B {}", testB) // displays true
if(testB == true) { // gives the " ... BooleanExtensions... on instance: null" error
logInfo ("playtime", "B comparison true")
}
Note the error from BooleanExtensions with a B
I do not think var Boolean = is producing a Java Boolean object at all. I suspect it is producing a primitive boolean with a small b and no extensions.
At least, testing with var boolean = produces exactly the same results.
On second thoughts, maybe it does produce a Java Boolean ā¦ but what the Rules DSL specific
if() requires is a rules DSL specific Boolean.
Anyways, fixing the issue is as easy as -
var testA = new Boolean("true") // casting the string as a Boolean (object)
logInfo ("playtime", "A " + testA) // displays 'true'
logInfo ("playtime", "A {}", testA) // displays 'true'
if( true == testA) {
logInfo ("playtime", "A comparison true") // displays
}
if(testA) {
logInfo ("playtime", "A defaults true") // displays
}
Thank you for that lengthy explanation.
That difference between primitive and object Boolean is new to me. My above posted work around can be shortend with this knowledge.
var OK= new Boolean(transform("JSONPATH", "$.ok", json))
For the ātypoā, in my eyes that was OK, but as Iām coming from basic Iām blind on that.topic.
I think this is a bug.
There is a philosophical debate whether a Boolean could ever be equal to a boolean, even if they were both true (or false) seeing as they are different kinds of things.
But, something as simple as
var B/boolean myTest = "some value"
if (myTest) { logInfo("here","true") }
should not break with an error, whatever path you expect the if to take.
We are OH1, so who cares it wonāt be fixed.
Can anyone please test on OH2 and see if this issue is present ?