Skip to content
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 item name in warnings of ItemStateConditionHandler #2540

Merged
merged 1 commit into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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