Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Quantity to QuantityType conversion after upgrade to 4.1 #313

Closed
jlaur opened this issue Dec 23, 2023 · 1 comment · Fixed by openhab/openhab-addons#16106
Closed
Labels
bug Something isn't working

Comments

@jlaur
Copy link

jlaur commented Dec 23, 2023

After upgrading my production system to 4.1 I have run into an issue related to QuantityType and JavaScript Scripting.

I don't know if the issue is in openhab-js or in the Energi Data Service thing action. The thing action code was not changed recently, so if the problem lies here, it's probably still related to openhab-js changes, perhaps an existing bug in the thing action being exposed by stricter checks on openhab-js side. Anyway, I hope you'll be able to assist figuring out the culprit.

Expected Behavior

No error, the call should produce a correct result like in 4.0.

Current Behavior

This rule code:

var edsActions = actions.get("energidataservice", "energidataservice:service:energidataservice");
var price = edsActions.calculatePrice(time.Instant.now(), time.Instant.now().plusSeconds(360600), Quantity("150 W"));

Results in:

2023-12-23 16:01:15.535 [ERROR] [enhab.automation.script.file.test.js] - Failed to execute rule Test-JavaScript-8553ef2d-9a4e-484f-ba06-81ada6e26649: TypeError: invokeMember (calculatePrice) on org.openhab.binding.energidataservice.internal.action.EnergiDataServiceActions@11d3737 failed due to: Cannot convert '[object Object]'(language: JavaScript, type: A) to Java type 'org.openhab.core.library.types.QuantityType': Unsupported target type.: TypeError: invokeMember (calculatePrice) on org.openhab.binding.energidataservice.internal.action.EnergiDataServiceActions@11d3737 failed due to: Cannot convert '[object Object]'(language: JavaScript, type: A) to Java type 'org.openhab.core.library.types.QuantityType': Unsupported target type.
	at <program> (test.js:18)
	at _run (@openhab-globals.js:2)
	at execute (@openhab-globals.js:2)
	at execute (@openhab-globals.js:2)
2023-12-23 16:01:15.541 [ERROR] [e.automation.internal.RuleEngineImpl] - Failed to execute rule 'Test-JavaScript-8553ef2d-9a4e-484f-ba06-81ada6e26649': Failed to execute action: 1(Error: Failed to execute rule Test-JavaScript-8553ef2d-9a4e-484f-ba06-81ada6e26649: TypeError: invokeMember (calculatePrice) on org.openhab.binding.energidataservice.internal.action.EnergiDataServiceActions@11d3737 failed due to: Cannot convert '[object Object]'(language: JavaScript, type: A) to Java type 'org.openhab.core.library.types.QuantityType': Unsupported target type.: TypeError: invokeMember (calculatePrice) on org.openhab.binding.energidataservice.internal.action.EnergiDataServiceActions@11d3737 failed due to: Cannot convert '[object Object]'(language: JavaScript, type: A) to Java type 'org.openhab.core.library.types.QuantityType': Unsupported target type.
	at <program> (test.js:18)
	at _run (@openhab-globals.js:2)
	at execute (@openhab-globals.js:2)
	at execute (@openhab-globals.js:2))

The thing action code is here:

https://github.com/openhab/openhab-addons/blob/dc187c9eec267cd4c6fa57d883db48b281f8fad8/bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/action/EnergiDataServiceActions.java#L138-L151

Third parameter, which I suspect is related to the issue, is defined as:

@ActionInput(name = "power", type = "QuantityType<Power>") QuantityType<Power> power

Possible Solution

Currently none.

Steps to Reproduce

  • Install Energi Data Service binding.
  • Configure price area DK1 (no other configuration is needed).
  • Run the rule code.

Context

Unfortunately most EDS thing actions are broken, thus automations for optimizing electricity usage.

Your Environment

  • Version used: openHAB 4.1 with built-in/bundled JS Scripting add-on (cached injection).
@jlaur jlaur added the bug Something isn't working label Dec 23, 2023
@florian-h05
Copy link
Contributor

The issue is in the Addon code, but it is caused by a recent change to openhab-js, that was required to fix an issue.
I had to rename a private property, which broke the conversion inside the add-on.

As a work-around, you can use Quantity(…).rawQtyType, but I’ve already created a PR to fix that: openhab/openhab-addons#16106

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants