-
-
Notifications
You must be signed in to change notification settings - Fork 429
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
[automation] Log warning for equals condition for DecimalTypes and QuantityTypes #2653
Conversation
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the real issue about #2624 that TypeParser.parseState(item.getAcceptedDataTypes(), state)
returns a DecimalType
instead of a QuantityType
? Shouldn't item.getAcceptedDataTypes()
return QuantityType
before DecimalType
in case the number item has a dimension?
@@ -65,9 +65,9 @@ public ParameterSet(String comparisonState, State itemState, boolean expectedRes | |||
{ new ParameterSet("5", new DecimalType(23), false) }, // | |||
{ new ParameterSet("5", new DecimalType(5), true) }, // | |||
{ new ParameterSet("5 °C", new DecimalType(23), false) }, // | |||
{ new ParameterSet("5 °C", new DecimalType(5), false) }, // | |||
{ new ParameterSet("5 °C", new DecimalType(5), true) }, // |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would claim that this change is not correct.
The unit test was just right before: 5 is NOT the same as 5 °C as it is lacking any unit and could thus well also be 5 °F.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping this in mind we should adopt the remaining comparisons too and add a conversion to a base unit before. I will have a look.
From my pov the roit cause of #2624 is that the user did not configuration a comparison value including a unit. And additionally the framework did not inform him about his mistake. IIRC we cannot change the order of accepted data types for I will revert my changes partially to just log a warning if the item state is a |
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
State itemState = item.getState(); | ||
if (itemState instanceof QuantityType && compareState instanceof DecimalType) { | ||
logger.warn( | ||
"Received a QuantityType state '{}' with unit for item {}, but the condition is defined as a plain number without unit ({}), please consider adding a unit to the condition.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"please consider adding" sounds as if it is optional and will work nonetheless without.
Shouldn't we maybe use some stronger formulation to make it clear that the current configuration is invalid and the comparison is simply not done (always returns false)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reformulated the warning to be more precise.
Additionally I added a check to deal with dimensionless QuantityType
s without unit (internally AbstractUnit.ONE
) because for them it is not possible to define a unit in the compare condition as the unit symbol is an empty string.
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/bug-or-why-rule-working-with-temperature/130944/6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
…antityTypes (openhab#2653) * Allow equals comparison for DecimalTypes and QuantityTypes Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de> GitOrigin-RevId: 0709933
DecimalType
s andQuantityType
sCloses #2624
Signed-off-by: Christoph Weitkamp github@christophweitkamp.de