mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-11 05:41:52 +01:00
Log item name in warnings of ItemStateConditionHandler (#2540)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
parent
39dad81ebb
commit
f694535598
@ -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<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,
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public class ItemStateConditionHandler extends BaseConditionModuleHandler {
|
||||
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);
|
||||
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user