UoM support in rules

Hi.

How is this supposed to work. I currently have two “errors”, not sure if those are bugs or mis-use.

First:

var Number CurrentValue = (Bad_temp.state as QuantityType<Temperature>).doubleValue()

shows as Temperature cannot be resolved to a type. in Visual Studio Code, but works. I assume something is missing in ESH, because QuantityType<Density> can be resolved.

Second:

if ((Aussen_hum_abs.state instanceof QuantityType<Density>) && (Bad_hum_abs.state instanceof QuantityType<Density>)) {
[...]
}

shows no error in Visual Studio, but the log shows

12:07:25.753 [INFO ] [del.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'bad.rules', using it anyway:
Cannot perform instanceof check against parameterized type QuantityType<Density>
Cannot perform instanceof check against parameterized type QuantityType<Density>

If I change to generic type

if ((Aussen_hum_abs.state instanceof QuantityType) && (Bad_hum_abs.state instanceof QuantityType)) {
[...]
}

the log switches to

12:08:53.376 [INFO ] [del.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'bad.rules', using it anyway:
QuantityType is a raw type. References to generic type QuantityType<T> should be parameterized
QuantityType is a raw type. References to generic type QuantityType<T> should be parameterized

So what is the correct way to check if that item state is of QuantityType?

Regards,

Jan

I recently ran into something similar trying to use a value in a string without the unit, and used this…

val String testTemp = gTemperatureUpstairs.state.format("%.0f")

Which means these could also be used…

val Integer testTemp1 = Integer::parseInt(gTemperatureUpstairs.state.format("%.0f"))
val Double testTemp2 = Double::parseDouble(gTemperatureUpstairs.state.format("%.3f"))

To do this the way you were trying, it would need to be like this…

var Number CurrentValue = (Bad_temp.state as QuantityType<Number>).doubleValue

I don’t know the answer to this one, but could you describe why you would need it? Since you’ve defined the item, then wouldn’t you already know this?

I use it to check if the item has a valid value. On intialization, before the first value is posted to the item that check fails. If I cast the value and the item’s state is undefined (because no value was ever posted) this leads to an exception.

Items are initialized with NULL so you can just use

if(MyItem.state != NULL) // it has a value