Deprecated imports

Since the latest updates i receive feedback to the configuration models:

The use of wildcard imports is deprecated.
The method toDateMidnight() from the type DateTime is deprecated

Is there anyone who is facing the same issue?

the successor of “toDateMidnight()” is: “toDateTimeAtStartOfDay()

But how can i avoid the wildcard import message, or how do i only import the nessecary stuff.

In openHAB2 there is very little you should need to import any more. Joda is imported by default, though Designer sometimes has a hard time recognizing that fact so you can get around that by just importing

import org.joda.datetime.DateTime

I think.

For everything else, just import the specific classes you are actually using. For example, if you have a lambda use:

import org.eclipse.xtext.xbase.lib.Functions

instead of

import org.eclipse.xtext.xbase.lib.*

I just did a grep of my entire ruleset and I now have a grand total of 4 import statements. I would expect you to have a similarly small number of imports.

1 Like

I too am having issues after upgrading:

2017-02-07 23:22:51.190 [ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘Test Rule’: An error occured during the script execution: Could not invoke method: org.joda.time.base.AbstractInstant.isBefore(long) on instance: 2017-02-07T23:22:51.188-05:00

obviously this is deprecated now:
import org.joda.time.*

so what do i need to import to get that to work?

rule "Test Rule"
when
Item TestRule received command ON
then

if (now.isBefore(Sunrise_Time.state as DateTimeType).calendar.timeInMillis){
	postUpdate(IsSunset, ON)
	sendMail("test@gmail.com", "DeterminSunRiseSet", "Path 1")
}
if (now.isAfter(Sunrise_Time.state as DateTimeType).calendar.timeInMillis){
	if (now.isBefore(Sunset_Time.state as DateTimeType).calendar.timeInMillis){
		postUpdate(IsSunset, OFF)
		sendMail("test@gmail.com", "DeterminSunRiseSet", "Path 2")
	}
	if (now.isAfter(Sunset_Time.state as DateTimeType).calendar.timeInMillis){
		postUpdate(IsSunset, ON)
		sendMail("test@gmail.com", "DeterminSunRiseSet", "Path 3")
	}
}

Here is another:

2017-02-07 23:30:06.448 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule Turn Dining Room Light Off: An error occured during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(org.eclipse.smarthome.core.items.Item,java.lang.String) on instance: null

rule “Turn lights off"
when
Time cron “0 00 23 * * ?” or
Time cron “00 00 01 * * ?” or
Time cron “00 00 03 * * ?” /or
Time cron “0 0 3 * * ?”
/
then
sendMail("test@gmail.com”, “2:Light:Pre:Light:TurnLightsOff”, “Current State: GuestRoom_PowerStrip:” + GuestRoom_PowerStrip.state + " LivingRoom_PowerStrip: " + LivingRoom_PowerStrip.state + " DiningRoom_Light: " + DiningRoom_Light.state)
if (PowerStripTimerToggles.state == ON) {
sendCommand(GuestRoom_PowerStrip, OFF)
sendCommand(LivingRoom_PowerStrip, OFF)
if (PowerStripEmailToggles.state == ON) {
sendMail("test@gmail.com", “2:Light:Post:Light:TurnLightsOff”, “Current State: GuestRoom_PowerStrip:” + GuestRoom_PowerStrip.state + " LivingRoom_PowerStrip: " + LivingRoom_PowerStrip.state + " DiningRoom_Light: " + DiningRoom_Light.state)
}
}
end

Try:

GuestRoom_PowerStrip.sendCommand(OFF)
LivingRoom_PowerStrip.sendCommand(OFF)

I actually gave the wrong rule, but I implemented your change and am still seeing the error:
2017-02-08 10:11:08.208 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule Test Cron: An error occured during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(org.eclipse.smarthome.core.items.Item,java.lang.String) on instance: null

rule “Test Cron”
when
Time cron “0 11 10 * * ?” //or
//Time cron “0 0 1 * * ?” or
//Time cron “0 0 2 * * ?” or
//Time cron “0 0 3 * * ?” or
//Time cron “0 0 4 * * ?” or
//Time cron “0 0 5 * * ?” or
//Time cron “0 0 6 * * ?”
then
sendMail(“test@gmail.com”, “Dining Room PRE Email”, "Dining room light Cron Has Been Reached. Current state = " + DiningRoom_Light.state)
if (DiningRoom_Light.state != 0) {
//sendCommand(DiningRoomLight, 0)
DiningRoom_Light.sendCommand(0)
DiningRoomLightRuleTriggered.sendCommand(ON)
//sendCommand(DiningRoomLightRuleTriggered, ON)
sendMail(“test@gmail.com”, “Dining Room Off Conditional if”, "Dining room light Cron Has Been Reached. Current state = " + DiningRoom_Light.state)
if (DiningRoomLightEmailToggle.state == ON) {
sendMail(“test@gmail.com”, “2:Light:Cron:1:00:DiningRoom Light Off”, “Dining Room Light was turned off at 1:00 AM timer” + now)
}
//sendCommand(DimLevel, DiningRoom_Light.state)
DimLevel.sendCommand(DiningRoom_Light.state)
Thread::sleep(5000)
//sendCommand(DiningRoomLightRuleTriggered, OFF)
DiningRoomLightRuleTriggered.sendCommand(OFF)
}

end

I’ve tracked it down to this line:

DimLevel.sendCommand(DiningRoom_Light.state)

It errors when i try to pass the state of the light into the item anymore.
So dimlevel is a Number item
Number DimLevel “”

The state of the light should be a number ie, 0, 100 etc)

I had the same issue and just defined a int variable to pass the state to first and used that variable in my sendCommand.

I think you can define the state using a (DiningRoom_Light.state as DecimalType) (or something similar) appended to it but haven’t had time to play with it yet to test.

I changed DimLevel to a string item…still errors out in the log.

Still nothing i stripped it down to this:
rule "Test Cron"
when
Time cron "0 54 10 * * ?“
then
var int intDimLevel
intDimLevel = DiningRoom_Light.state
sendMail("miltyzwave@gmail.com”, “Dining Room PRE Email”, "Dining room light Cron Has Been Reached. Current state = " + DiningRoom_Light.state + " " + intDimLevel)
DimLevel = intDimLevel

end

I still get the null errors and still parsing errors on loading the rule file

2017-02-08 10:53:57.797 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'CronTest.rules’
2017-02-08 10:53:57.804 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘CronTest.rules’ is either empty or cannot be parsed correctly!
2017-02-08 10:53:58.621 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'CronTest.rules’
2017-02-08 10:54:02.140 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule Test Cron: An error occured during the script execution: Cannot assign a value in null context.

I think i figured this out.
DImLevel was being set from another rule as well…possible race condition.
I’m going to remove it from this one.

I still can’t figure out why on load, the rule file doesn’t parse correctly

2017-02-08 11:09:04.773 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'CronTest.rules’
2017-02-08 11:09:04.787 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘CronTest.rules’ is either empty or cannot be parsed correctly!
2017-02-08 11:09:07.217 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘CronTest.rules’

rule “Test Cron”

when
Time cron "0 10 11 * * ?“
then
if (DiningRoom_Light.state != 0) {
//sendCommand(DiningRoomLight, 0)
DiningRoom_Light.sendCommand(0)
DiningRoomLightRuleTriggered.sendCommand(ON)
//sendCommand(DiningRoomLightRuleTriggered, ON)
sendMail("miltyzwave@gmail.com”, “Dining Room Off Conditional if”, “Dining room light Cron Has Been Reached. Current state = " + DiningRoom_Light.state)
if (DiningRoomLightEmailToggle.state == ON) {
sendMail("miltyzwave@gmail.com”, “2:Light:Cron:1:00:DiningRoom Light Off”, “Dining Room Light was turned off at 1:00 AM timer” + now)
}
Thread::sleep(5000)
//sendCommand(DiningRoomLightRuleTriggered, OFF)
DiningRoomLightRuleTriggered.sendCommand(OFF)
}

I’m seeing those same error codes about cannot be parsed correctly but so far it doesn’t seem to be impacting my rules running. Haven’t yet looked around to see if others are having the same issue.

I assume the underlying rule is now running correctly?

Yeah it runs now. Only remaining error are parsing issues…but i see that across many rules now after updating last night.

Thanks for the help.