this problem is annoying. Here a snippet from my code:
logInfo("Venting","Current Venting Duration: " + venting_duration.toString)
if (current_vent_timer < venting_duration) {
var Number new_venting_duration = Math::floor(venting_duration)
}
The annoying thing is, that logging of the venting_duration_value returns a value but calling Math::floor() says, that value is null. How is this even possible
2018-07-11 18:35:37.476 [INFO ] [g.openhab.model.script.Venting] - Current Venting Duration: 2.88
2018-07-11 18:35:37.481 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Venting GF Bath - Set Venting Duration': Could not invoke method: java.lang.Math.floor(double) on instance: null
If venting_duration is a Number or DecimalType then I would expect this error. Math::floor requires a primitive.
If venting_duration were a primitive (e.g. float) then I would expect this error on the venting_duration.toString line because primitives are not Objects and therefore do not have a toString method.
Iâm going to guess this will work, given the lack of knowing what venting_duration actually is:
But I think, this is a bug. I understand your explanation why it throws this exception, but a framework shouldnât expect from its users how it works on the underground. So I would expect a ânot a float valueâ. Otherwise it could also write âan error occuredâ. This would help me in the same way the null value messages helps me - absolutely not.
If you are working with Rules DSL classes and Objects then you donât need to know about this stuff. If you want to use Java classes and Objects, and Math is a Java class, then you may have to know about this stuff. Itâs a limitation of making available libraries from one language (Java) in another language (Rules DSL). It canât be helped except to either forbid such access (in which case there wouldnât be any way for you to get the floor of a floating point number).
It is not ideal, but it canât be helped.
In Rules DSL, when you see Could not invoke method: some method(argument) on instance: null it always means you have a type problem. In this case, you were trying to pass a Number object to a method that expects a double primitive.