I recently upgraded from openHAB3.0 to openHAB 3.1 and suddenly several Jython scripts stopped working.
After debugging a rule, I noticed that the event is no longer parsed into an object but stays a string (as reported in events.log
:
Here’s the rule:
@rule(
rulePrefix + "Update machine state when automation parameters have been updated",
description="""When the roller shutter automation settings have been modified, the machine state may have to ba recomputed."""
+ ruleTimeStamp,
tags=["roller shutter automation", ruleTimeStamp],
)
@when(
"Item {item} changed".format(
item=my_ir_items.AUTOMATION_TEMPERATURE_HYSTERESIS
)
)
@when(
"Item {item} changed".format(
item=my_ir_items.COLD_DAY_TEMPERATURE_THRESHOLD_ITEM
)
)
@when(
"Item {item} changed".format(
item=my_ir_items.WARM_DAY_TEMPERATURE_THRESHOLD_ITEM
)
)
@when(
"Item {item} changed".format(
item=my_ir_items.HOT_DAY_TEMPERATURE_THRESHOLD_ITEM
)
)
def Rule_UpdateMachineStateAfterAutomationSettingsChanged(event):
global logTitle
logPrefix = "Rule_UpdateMachineStateAfterAutomationSettingsChanged(): "
if event is None or isinstance(event, UnDefType):
# Event not defined or instance of UnDefType - nothing to do
return
LogAction.logInfo(
logTitle,
logPrefix
+ "[ XXX ] event := " + pp.pformat(event)
)
'''
# This no longer works when upgrading from openHAB3.0 to openHAB3.1
if event['itemCommand'] and event.itemCommand == "REFRESH":
# Skip processing of Z-Wave REFRESH commands (by cron rule or otherwise)
return
LogAction.logInfo(
logTitle,
logPrefix
+ "Item '{name}' received command '{cmd}'".format(
name=event.itemName, cmd=event.itemCommand
),
)
'''
Here's the resulting `openhab-cli showlogs` output:
==> /var/log/openhab/events.log <==
2021-07-30 11:35:24.816 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'ShutterAutomation_Roof_TemperatureThreshold_Warm' received command 22.5
2021-07-30 11:35:24.838 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ShutterAutomation_Roof_TemperatureThreshold_Warm' changed from 22 °C to 22.5 °C
==> /var/log/openhab/openhab.log <==
2021-07-30 11:35:24.842 [INFO ] [tters.py@2021-07-30T09:34:57.709427Z] - Rule_UpdateMachineStateAfterAutomationSettingsChanged(): [ XXX ] **event := Item 'ShutterAutomation_Roof_TemperatureThreshold_Warm' changed from 22 °C to 22.5 °C**
If I remove the block comment, I get the following error:
2021-07-30 11:32:40.457 [WARN ] [jsr223.jython ] - Traceback (most recent call last):
File “/etc/openhab/automation/lib/python/core/log.py”, line 96, in wrapper
return function(*args, **kwargs)
File “/etc/openhab/automation/lib/python/core/rules.py”, line 108, in execute
self.callback(inputs.get(‘event’))
File “/etc/openhab/automation/jsr223/python/personal/roller_shutters.py”, line 2372, in Rule_UpdateMachineStateAfterAutomationSettingsChanged
if event[‘itemCommand’] and event.itemCommand == “REFRESH”:
TypeError: ‘org.openhab.core.items.events.ItemStateChangedEvent’ object is unsubscriptable
Is it possible that the upgrade to OH3.1 wiped the Jython helper library?