Skip to content

Commit

Permalink
Improve log messages in ItemStateConditionHandler (openhab#3535)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan N. Klug <[email protected]>
  • Loading branch information
J-N-K authored Apr 9, 2023
1 parent 26daabc commit 643fe49
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ public boolean isSatisfied(Map<String, Object> inputs) {
String state = (String) module.getConfiguration().get(STATE);
String operator = (String) module.getConfiguration().get(OPERATOR);
if (operator == null || state == null || itemName == null) {
logger.error("Module is not well configured: itemName={} operator={} state = {}", itemName, operator,
state);
logger.error("Module is not well configured: itemName={} operator={} state = {} for rule {}", itemName,
operator, state, ruleUID);
return false;
}
try {
logger.debug("ItemStateCondition '{}' checking if {} {} {}", module.getId(), itemName, operator, state);
logger.debug("ItemStateCondition '{}' checking if {} {} {} for rule {}", module.getId(), itemName, operator,
state, ruleUID);
switch (operator) {
case "=":
return equalsToItemState(itemName, state);
Expand All @@ -149,7 +150,7 @@ public boolean isSatisfied(Map<String, Object> inputs) {
return greaterThanOrEqualsToItemState(itemName, state);
}
} catch (ItemNotFoundException e) {
logger.error("Item with name {} not found in ItemRegistry.", itemName);
logger.error("Item with name {} not found in ItemRegistry for condition of rule {}.", itemName, ruleUID);
}
return false;
}
Expand All @@ -170,8 +171,8 @@ private boolean lessThanOrEqualsToItemState(String itemName, String state) throw
// state, but warn the user
if (!Units.ONE.equals(qtState.getUnit())) {
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.",
qtState, itemName, state);
"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 for rule {}.",
qtState, itemName, state, ruleUID);
}
return qtState.compareTo(
new QuantityType<>(((DecimalType) compareState).toBigDecimal(), qtState.getUnit())) <= 0;
Expand Down Expand Up @@ -209,8 +210,8 @@ private boolean greaterThanOrEqualsToItemState(String itemName, String state) th
// state, but warn the user
if (!Units.ONE.equals(qtState.getUnit())) {
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.",
qtState, itemName, state);
"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 for rule {}.",
qtState, itemName, state, ruleUID);
}
return qtState.compareTo(
new QuantityType<>(((DecimalType) compareState).toBigDecimal(), qtState.getUnit())) >= 0;
Expand Down Expand Up @@ -245,8 +246,8 @@ private boolean equalsToItemState(String itemName, String state) throws ItemNotF
} else {
// log a warning if the unit of the state differs from ONE
logger.warn(
"Received a QuantityType state '{}' with unit for item {}, but the condition is defined as a plain number without unit ({}), comparison will fail unless a unit is added to the condition.",
itemState, itemName, state);
"Received a QuantityType state '{}' with unit for item {}, but the condition is defined as a plain number without unit ({}), comparison will fail unless a unit is added to the condition for rule {}.",
itemState, itemName, state, ruleUID);
return false;
}
}
Expand Down

0 comments on commit 643fe49

Please sign in to comment.