From f694535598ab51ca1546dcd8059d72fcd9fa5ced Mon Sep 17 00:00:00 2001 From: Christoph Weitkamp Date: Mon, 25 Oct 2021 22:14:06 +0200 Subject: [PATCH] Log item name in warnings of ItemStateConditionHandler (#2540) Signed-off-by: Christoph Weitkamp --- .../factory/CoreModuleHandlerFactory.java | 6 +-- .../handler/ItemStateConditionHandler.java | 38 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/factory/CoreModuleHandlerFactory.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/factory/CoreModuleHandlerFactory.java index 49707aca3..d218a9f91 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/factory/CoreModuleHandlerFactory.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/factory/CoreModuleHandlerFactory.java @@ -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; @@ -59,7 +59,7 @@ public class CoreModuleHandlerFactory extends BaseModuleHandlerFactory implement private final Logger logger = LoggerFactory.getLogger(CoreModuleHandlerFactory.class); - private static final Collection TYPES = Arrays.asList(ItemCommandTriggerHandler.MODULE_TYPE_ID, + private static final Collection 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, @@ -219,7 +219,7 @@ public class CoreModuleHandlerFactory extends BaseModuleHandlerFactory implement } } - logger.error("The ModuleHandler is not supported:{}", moduleTypeUID); + logger.error("The ModuleHandler is not supported: {}", moduleTypeUID); return null; } } diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/ItemStateConditionHandler.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/ItemStateConditionHandler.java index bbc459f62..713114b23 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/ItemStateConditionHandler.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/ItemStateConditionHandler.java @@ -77,7 +77,7 @@ public class ItemStateConditionHandler extends BaseConditionModuleHandler { itemRegistry = null; } - @SuppressWarnings({ "rawtypes", "unchecked" }) + @SuppressWarnings({ "rawtypes", "unchecked", "null" }) @Override public boolean isSatisfied(Map inputs) { String itemName = (String) module.getConfiguration().get(ITEM_NAME); @@ -96,7 +96,7 @@ public class ItemStateConditionHandler extends BaseConditionModuleHandler { 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 "=": @@ -110,16 +110,16 @@ public class ItemStateConditionHandler extends BaseConditionModuleHandler { // 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); @@ -136,16 +136,16 @@ public class ItemStateConditionHandler extends BaseConditionModuleHandler { // 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); @@ -161,16 +161,16 @@ public class ItemStateConditionHandler extends BaseConditionModuleHandler { // 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); @@ -187,16 +187,16 @@ public class ItemStateConditionHandler extends BaseConditionModuleHandler { // 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); @@ -207,7 +207,7 @@ public class ItemStateConditionHandler extends BaseConditionModuleHandler { 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; }