[pidcontroller] Improve logging (#11312)

Signed-off-by: Fabian Wolter <github@fabian-wolter.de>
This commit is contained in:
Fabian Wolter 2021-09-27 07:30:16 +02:00 committed by GitHub
parent 0d5ecd3417
commit 0363ba4588
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 5 deletions

View File

@ -72,10 +72,12 @@ public class PIDControllerTriggerHandler extends BaseTriggerModuleHandler implem
private @Nullable String iInspector;
private @Nullable String dInspector;
private @Nullable String eInspector;
private ItemRegistry itemRegistry;
public PIDControllerTriggerHandler(Trigger module, ItemRegistry itemRegistry, EventPublisher eventPublisher,
BundleContext bundleContext) {
super(module);
this.itemRegistry = itemRegistry;
this.eventPublisher = eventPublisher;
Configuration config = module.getConfiguration();
@ -154,14 +156,14 @@ public class PIDControllerTriggerHandler extends BaseTriggerModuleHandler implem
try {
input = getItemValueAsNumber(inputItem);
} catch (PIDException e) {
logger.warn("Input item: {}", e.getMessage());
logger.warn("Input item: {}: {}", inputItem.getName(), e.getMessage());
return;
}
try {
setpoint = getItemValueAsNumber(setpointItem);
} catch (PIDException e) {
logger.warn("Setpoint item: {}", e.getMessage());
logger.warn("Setpoint item: {}: {}", setpointItem.getName(), e.getMessage());
return;
}
@ -180,7 +182,12 @@ public class PIDControllerTriggerHandler extends BaseTriggerModuleHandler implem
private void updateItem(@Nullable String itemName, double value) {
if (itemName != null) {
try {
itemRegistry.getItem(itemName);
eventPublisher.post(ItemEventFactory.createCommandEvent(itemName, new DecimalType(value)));
} catch (ItemNotFoundException e) {
logger.warn("Item doesn't exist: {}", itemName);
}
}
}
@ -209,8 +216,7 @@ public class PIDControllerTriggerHandler extends BaseTriggerModuleHandler implem
// nothing
}
}
throw new PIDException(
"Item type is not a number: " + setpointState.getClass().getSimpleName() + ": " + setpointState);
throw new PIDException("Not a number: " + setpointState.getClass().getSimpleName() + ": " + setpointState);
}
@Override