Closed miwok72 closed 2 years ago
This appears to only affect QuantityType
1) Create an Item using %unit% in the label:
Number:Dimensionless Test_Item "Test Item [%.1f %unit%]"
2) Post a value to the Item through the console:
smarthome:update Test_Item 5
3) Note the state of the Item does not include the unit:
smarthome:status Test_Item
4) Change the Item to not use %unit%:
Number:Dimensionless Test_Item "Test Item [%.1f %%]"
5) Update the Item and check the state:
smarthome:update Test_Item 55
smarthome:status Test_Item
Seems to be related to https://github.com/openhab/openhab-core/issues/986#issuecomment-536337499.
I guess the root cause is when one updates the state of an Item having a dimension by a DecimalType
(or sends a non quantized command) - even if it expects a QuantityType
.
// Edit: The DecimalType
will not be converted internally to a QuantityType
...
It is correct that when comparing 50
to 55 %
(which is 0.55
) the result is "50 is bigger". The confusion comes from the fact that the ItemStateEvent
does not reflect the internal state of the item but is used to update the item's state. In most cases, this is the same, but not always.
If no unit is given (%unit%
) IMO the unit should be considered to be ONE
, so again the comparison is correct. This is also reflected by the item state which shows no unit in this case.
In the second case where the unit is fixed to %
, the item's state is internally 50 %
while the ItemStateEvent
carries 50
as state.
The solution here is to either query the item's state from the registry or introduce a proper event like proposed in #2956.
A more detailed description of the problem can be found at: OH community
Item definition:
Jython Rule:
openhab.log extract
OH 2.5.3, Jython 2.7.2, OpenJDK Runtime Environment (Zulu 8.44.0.11-CA-linux64) (build 1.8.0_242-b20)