Skip to content

Commit

Permalink
Log item name in warnings of ItemStateConditionHandler (openhab#2540)
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
GitOrigin-RevId: f694535
  • Loading branch information
cweitkamp authored and splatch committed Jul 12, 2023
1 parent 18bf26e commit 83d463a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
*/
package org.openhab.core.automation.internal.module.factory;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import org.openhab.core.automation.Action;
import org.openhab.core.automation.Condition;
Expand Down Expand Up @@ -59,7 +59,7 @@ public class CoreModuleHandlerFactory extends BaseModuleHandlerFactory implement

private final Logger logger = LoggerFactory.getLogger(CoreModuleHandlerFactory.class);

private static final Collection<String> TYPES = Arrays.asList(ItemCommandTriggerHandler.MODULE_TYPE_ID,
private static final Collection<String> TYPES = List.of(ItemCommandTriggerHandler.MODULE_TYPE_ID,
GroupCommandTriggerHandler.MODULE_TYPE_ID, ItemStateTriggerHandler.UPDATE_MODULE_TYPE_ID,
ItemStateTriggerHandler.CHANGE_MODULE_TYPE_ID, GroupStateTriggerHandler.UPDATE_MODULE_TYPE_ID,
GroupStateTriggerHandler.CHANGE_MODULE_TYPE_ID, ThingStatusTriggerHandler.UPDATE_MODULE_TYPE_ID,
Expand Down Expand Up @@ -219,7 +219,7 @@ protected synchronized ModuleHandler internalCreate(final Module module, final S
}
}

logger.error("The ModuleHandler is not supported:{}", moduleTypeUID);
logger.error("The ModuleHandler is not supported: {}", moduleTypeUID);
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void dispose() {
itemRegistry = null;
}

@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({ "rawtypes", "unchecked", "null" })
@Override
public boolean isSatisfied(Map<String, Object> inputs) {
String itemName = (String) module.getConfiguration().get(ITEM_NAME);
Expand All @@ -96,7 +96,7 @@ public boolean isSatisfied(Map<String, Object> inputs) {
Item item = itemRegistry.getItem(itemName);
State compareState = TypeParser.parseState(item.getAcceptedDataTypes(), state);
State itemState = item.getState();
logger.debug("ItemStateCondition '{}'checking if {} (State={}) {} {}", module.getId(), itemName, itemState,
logger.debug("ItemStateCondition '{}' checking if {} (State={}) {} {}", module.getId(), itemName, itemState,
operator, compareState);
switch (operator) {
case "=":
Expand All @@ -110,16 +110,16 @@ public boolean isSatisfied(Map<String, Object> inputs) {
// allow compareState without unit -> implicitly assume its the same as the one from the
// state, but warn the user
logger.warn(
"Received a QuantityType state '{}' with unit, but the condition is defined as a plain number without unit ({}), please consider adding a unit to the condition.",
qtState, 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.",
qtState, itemName, state);
return qtState.compareTo(new QuantityType<>(((DecimalType) compareState).toBigDecimal(),
qtState.getUnit())) < 0;
} else if (compareState instanceof QuantityType) {
return qtState.compareTo((QuantityType) compareState) < 0;
} else {
logger.warn(
"Condition '{}' cannot be compared to the incompatible state '{}' from the item.",
state, qtState);
"Condition '{}' cannot be compared to the incompatible state '{}' from item {}.",
state, qtState, itemName);
}
} else if (itemState instanceof DecimalType && null != compareState) {
DecimalType decimalState = compareState.as(DecimalType.class);
Expand All @@ -136,16 +136,16 @@ public boolean isSatisfied(Map<String, Object> inputs) {
// allow compareState without unit -> implicitly assume its the same as the one from the
// state, but warn the user
logger.warn(
"Received a QuantityType state '{}' with unit, but the condition is defined as a plain number without unit ({}), please consider adding a unit to the condition.",
qtState, 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.",
qtState, itemName, state);
return qtState.compareTo(new QuantityType<>(((DecimalType) compareState).toBigDecimal(),
qtState.getUnit())) <= 0;
} else if (compareState instanceof QuantityType) {
return qtState.compareTo((QuantityType) compareState) <= 0;
} else {
logger.warn(
"Condition '{}' cannot be compared to the incompatible state '{}' from the item.",
state, qtState);
"Condition '{}' cannot be compared to the incompatible state '{}' from item {}.",
state, qtState, itemName);
}
} else if (itemState instanceof DecimalType && null != compareState) {
DecimalType decimalState = compareState.as(DecimalType.class);
Expand All @@ -161,16 +161,16 @@ public boolean isSatisfied(Map<String, Object> inputs) {
// allow compareState without unit -> implicitly assume its the same as the one from the
// state, but warn the user
logger.warn(
"Received a QuantityType state '{}' with unit, but the condition is defined as a plain number without unit ({}), please consider adding a unit to the condition.",
qtState, 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.",
qtState, itemName, state);
return qtState.compareTo(new QuantityType<>(((DecimalType) compareState).toBigDecimal(),
qtState.getUnit())) > 0;
} else if (compareState instanceof QuantityType) {
return qtState.compareTo((QuantityType) compareState) > 0;
} else {
logger.warn(
"Condition '{}' cannot be compared to the incompatible state '{}' from the item.",
state, qtState);
"Condition '{}' cannot be compared to the incompatible state '{}' from item {}.",
state, qtState, itemName);
}
} else if (itemState instanceof DecimalType && null != compareState) {
DecimalType decimalState = compareState.as(DecimalType.class);
Expand All @@ -187,16 +187,16 @@ public boolean isSatisfied(Map<String, Object> inputs) {
// allow compareState without unit -> implicitly assume its the same as the one from the
// state, but warn the user
logger.warn(
"Received a QuantityType state '{}' with unit, but the condition is defined as a plain number without unit ({}), please consider adding a unit to the condition.",
qtState, 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.",
qtState, itemName, state);
return qtState.compareTo(new QuantityType<>(((DecimalType) compareState).toBigDecimal(),
qtState.getUnit())) >= 0;
} else if (compareState instanceof QuantityType) {
return qtState.compareTo((QuantityType) compareState) >= 0;
} else {
logger.warn(
"Condition '{}' cannot be compared to the incompatible state '{}' from the item.",
state, qtState);
"Condition '{}' cannot be compared to the incompatible state '{}' from item {}.",
state, qtState, itemName);
}
} else if (itemState instanceof DecimalType && null != compareState) {
DecimalType decimalState = compareState.as(DecimalType.class);
Expand All @@ -207,7 +207,7 @@ public boolean isSatisfied(Map<String, Object> inputs) {
break;
}
} catch (ItemNotFoundException e) {
logger.error("Item with Name {} not found in itemRegistry", itemName);
logger.error("Item with name {} not found in ItemRegistry.", itemName);
}
return false;
}
Expand Down

0 comments on commit 83d463a

Please sign in to comment.