Skip to content
Snippets Groups Projects
Commit e0e9ab2b authored by Manuel Krombholz's avatar Manuel Krombholz
Browse files

Added event processing frequency functionality

parent b1a24f79
No related branches found
No related tags found
2 merge requests!12Resolve "Cleanup parser",!11Resolve "Add processing frequency option for items"
Pipeline #9479 failed
......@@ -21,6 +21,8 @@ aspect ItemHandling {
eq ItemWithDoubleState.getStateAsString() = Double.toString(getState());
eq ItemWithStringState.getStateAsString() = getState();
syn StateData Item.getStateData() = new StateData();
//--- getStateAsDouble ---
syn double Item.getStateAsDouble();
// TupleHSB and String work like default
......@@ -292,17 +294,16 @@ aspect ItemHandling {
* @param shouldSendState whether to send the new state (currently affects MQTT and Influx)
*/
protected void Item.stateUpdated(boolean shouldSendState) {
this.getStateData().afterStateChangeApplied();
if (shouldSendState) {
try {
// sendState() refined in MQTT and Influx aspect
sendState();
} catch (Exception e) {
logger.catching(e);
}
}
if (hasItemObserver()) {
if (hasItemObserver() && this.getStateData().checkStateTransitionTime()) {
getItemObserver().apply();
}
}
......
aspect StateData {
public void StateData.afterStateChangeApplied() {
this.setLastChangeDate(Instant.now());
}
public boolean StateData.checkStateTransitionTime() {
if (this.getItemPerformance()==null) {
return true;
}
double frequency = this.getItemPerformance().getEventProcessingFrequency();
Instant lastStateChange = this.getLastChangeDate();
public void StateData.checkStateTransitionTime() {
return lastStateChange.toEpochMilli() + (1/frequency)*1000 < Instant.now().toEpochMilli();
}
}
\ No newline at end of file
......@@ -25,7 +25,7 @@ rel Channel.LinkedItem* <-> Item.Channel? ;
Parameter : DescribableModelElement ::= <Type:ParameterValueType> [DefaultValue:ParameterDefaultValue] <Context:String> <Required:boolean> ;
ParameterDefaultValue ::= <Value:String> ;
abstract Item : LabelledModelElement ::= <_fetched_data:boolean> MetaData:ItemMetaData* [ItemObserver] [StateData];
abstract Item : LabelledModelElement ::= <_fetched_data:boolean> MetaData:ItemMetaData* [ItemObserver] /StateData/;
rel Item.Category? -> ItemCategory ;
......@@ -50,7 +50,7 @@ ItemMetaData ::= <Key:String> <Value:String> ;
ItemCategory ::= <Name:String> ;
StateData ::= <lastChangeDate:Instant> ;
StateData ::= <LastChangeDate:Instant> ;
rel StateData.ItemPerformance -> ItemPerformance ;
Group : LabelledModelElement ::= Group* Item* [AggregationFunction:GroupAggregationFunction] ;
......
......@@ -116,8 +116,6 @@ public class EraserParserHelper {
}
private void setPerformanceOnItem(Item item, ItemPerformance itemPerformance) {
StateData stateData = item.getStateData();
ItemObserver itemObserver = item.getItemObserver();
item.getStateData().setItemPerformance(itemPerformance);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment