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

update persistence, add more functions #213

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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 @@ -151,18 +151,19 @@ private void add(Method method, JRule jRule, boolean enableRule) {
logWarn("Skipping non-public method {} on class {}", method.getName(), jRule.getClass().getName());
return;
}
// Check if method is has none or a single parameter
// Check if method has none or a single parameter
if (method.getParameterCount() > 1) {
logWarn("Skipping method {} on class {}. Rule methods should have none or a single parameter",
method.getName(), jRule.getClass().getName());
return;
}

String jRuleName = Optional.ofNullable(method.getDeclaredAnnotation(JRuleName.class).value())
.filter(n -> !StringUtils.isBlank(n)).orElse(method.getName());
final String logName = Optional.ofNullable(method.getDeclaredAnnotation(JRuleLogName.class))
.map(JRuleLogName::value).orElse(method.getDeclaredAnnotation(JRuleName.class).value());
.map(JRuleLogName::value).filter(n -> !StringUtils.isBlank(n)).orElse(jRuleName);

JRuleBuilder jRuleBuilder = createJRuleBuilder(method.getDeclaredAnnotation(JRuleName.class).value(), jRule,
method).logName(logName);
JRuleBuilder jRuleBuilder = createJRuleBuilder(jRuleName, jRule, method).logName(logName);

ruleLoadingStatistics.addRuleMethod();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public class JRuleEventHandler {
stateMapping.put(JRuleStringListValue.class, StringListType.class);
}

public static Class<? extends State> mapJRuleToOhType(Class<? extends JRuleValue> type) {
return stateMapping.get(type);
}

private static final String LOG_NAME_EVENT = "JRuleEvent";

private static volatile JRuleEventHandler instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@
*/
package org.openhab.automation.jrule.internal.items;

import java.time.ZonedDateTime;
import java.util.List;
import java.util.Optional;

import org.openhab.automation.jrule.items.JRuleContactItem;
import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry;
import org.openhab.core.library.types.DecimalType;

/**
* The {@link JRuleInternalContactItem} Items
Expand All @@ -31,34 +28,4 @@ public JRuleInternalContactItem(String name, String label, String type, String i
JRuleMetadataRegistry metadataRegistry, List<String> tags) {
super(name, label, type, id, metadataRegistry, tags);
}

public Optional<Double> maximumSince(ZonedDateTime timestamp, String persistenceServiceId) {
return JRulePersistenceExtensions.maximumSince(name, timestamp, persistenceServiceId)
.map(DecimalType::doubleValue);
}

public Optional<Double> minimumSince(ZonedDateTime timestamp, String persistenceServiceId) {
return JRulePersistenceExtensions.minimumSince(name, timestamp, persistenceServiceId)
.map(DecimalType::doubleValue);
}

public Optional<Double> varianceSince(ZonedDateTime timestamp, String persistenceServiceId) {
return JRulePersistenceExtensions.varianceSince(name, timestamp, persistenceServiceId)
.map(state -> getNumericValue(state));
}

public Optional<Double> deviationSince(ZonedDateTime timestamp, String persistenceServiceId) {
return JRulePersistenceExtensions.deviationSince(name, timestamp, persistenceServiceId)
.map(state -> getNumericValue(state));
}

public Optional<Double> averageSince(ZonedDateTime timestamp, String persistenceServiceId) {
return JRulePersistenceExtensions.averageSince(name, timestamp, persistenceServiceId)
.map(state -> getNumericValue(state));
}

public Optional<Double> sumSince(ZonedDateTime timestamp, String persistenceServiceId) {
return JRulePersistenceExtensions.sumSince(name, timestamp, persistenceServiceId)
.map(state -> getNumericValue(state));
}
}
Loading
Loading