To convert a QuantityType Item (Dimensionless) to an integer I use the following statement in a rule:
val int CurrentCO2level = (LR_NHC_CO2.state as QuantityType<Dimensionless>).intValue
The rule works fine and gives the right result, but the validator in VS Code Extension flags it as an error, stating Dimensionless cannot be resolved to a type. [org.eclipse.xtext.diagnostics.Diagnostic.Linking].
Is there a better way of converting it, that does not give an error in VS Code?
It shows I was trained in programming when strongly typed was the norm and type casting considered dangerous because of different processor types…
Meanwhile I’ve been reading up on types in Xtend/DSL and I understand that QuantityTypes (and DecimalTypes) are derived from the Number type.
BTW: If I comment-out the line with the type error, it is still shown in VS Code as an error.
..., "QuantityType value={}", (LR_NHC_CO2.state as QuantityType<Dimensionless>).intValue...
It shows:
...QuantityType value=1011
The same value as produced by:
val int CurrentCO2level = (LR_NHC_CO2.state as Number).intValue
It looks like there is no conversion involved for Dimensionless other than removing the unit symbol (ppm in my case). Since there are 3 different dimensions that are represented by Dimensionless according to the docs, I would expect that no unit conversion can take place for this QuantityType as it can be different things.
In case of percentage, that would mean that the receiving end of a percentage value just ‘knows’ it is a percentage (like Dimmer or RollerShutter).
< offtopic>
There are, again, intermittent errors reaching the API service of Netatmo
2019-01-05 08:16:40.735 [ERROR] [nternal.handler.NetatmoDeviceHandler] - Unable to connect Netatmo API : 404 Not Found
When trying to reproduce this (after VS Code was restarted this morning), the issue did not occur anymore, so I’ll wait and see if something similar occurs.