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

UoM QuantityType<Time> doesn't work #2281

Closed
mstormi opened this issue Apr 8, 2021 · 4 comments
Closed

UoM QuantityType<Time> doesn't work #2281

mstormi opened this issue Apr 8, 2021 · 4 comments
Labels
DSL rules Domain-Specific Language rules UoM Units of Measurement

Comments

@mstormi
Copy link

mstormi commented Apr 8, 2021

QuantityType<Time> does not work in rules DSL, an expression like
(myItem.state as QuantityType<Time>).toUnit("s") results in
Configuration model 'Test.rules' has errors, therefore ignoring it: [94,75]: no viable alternative at input 'Time'
(myItem is defined and can be properly used as Number:Time)

Strange: If I use DateTime instead of Time it's actually working. The LSP server is (properly) complaining that it cannot resolve DateTime, though.

@cweitkamp cweitkamp added the UoM Units of Measurement label Apr 10, 2021
@lolodomo
Copy link
Contributor

lolodomo commented May 4, 2021

Did you import the correct path to Time in your script (ftom the package javax.measure.quantity) ?

@mstormi
Copy link
Author

mstormi commented May 4, 2021

I tried but failed. How exactly would I need to specify the import ?
On 'import javax.measure.quantity.Time', VSC complains about 'javax'

@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/counting-on-time-for-heater/133087/8

@J-N-K J-N-K added the DSL rules Domain-Specific Language rules label Apr 27, 2022
@J-N-K
Copy link
Member

J-N-K commented Jun 18, 2022

Works fine:

val time = (TimeItem.state as QuantityType).toUnit("s")
logInfo("test", time.toString)

TimeItem is a Number:Time item where I posted a state of 10 min. When executing the rule, the log showed:

20:16:03.310 | INFO  | qtp1859993897-590    | org.openhab.core.model.script.test   | 197 | 600 s

@J-N-K J-N-K closed this as completed Jun 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DSL rules Domain-Specific Language rules UoM Units of Measurement
Projects
None yet
Development

No branches or pull requests

5 participants