Skip to content

Commit

Permalink
add config to disable filter
Browse files Browse the repository at this point in the history
  • Loading branch information
zsco committed Nov 19, 2020
1 parent d108ffa commit 116422c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import uuid
from datetime import datetime

from senergy_local_analytics import App, Input, Output
from senergy_local_analytics import App, Input, Output, Config


class Adder:
Expand All @@ -25,20 +25,24 @@ def __init__(self):
self.sum_total = 0
self.message_no = 0

def process(self, inputs: typing.List[Input]):
def process(self, inputs: typing.List[Input], config: Config):
for inp in inputs:
if inp.current_value is not None:
self.values[inp.current_topic] = inp.current_value
self.message_no = self.message_no + 1
value_sum = sum(self.values.values())
if self.sum_total != value_sum:
self.sum_total = value_sum
return Output(True, {"sum": sum(self.values.values()), "message_no": self.message_no,
"message_id": str(uuid.uuid4()),
"timestamp": '{}Z'.format(datetime.utcnow().isoformat())})
if config.get_config_value("filter", "True") == "True":
if self.sum_total != value_sum:
self.sum_total = value_sum
return Output(True, {"sum": sum(self.values.values()), "message_no": self.message_no,
"message_id": str(uuid.uuid4()),
"timestamp": '{}Z'.format(datetime.utcnow().isoformat())})
else:
return Output(False, {"sum": sum(self.values.values()), "message_id": str(uuid.uuid4()),
"timestamp": '{}Z'.format(datetime.utcnow().isoformat())})
else:
return Output(False, {"sum": sum(self.values.values()), "message_id": str(uuid.uuid4()),
"timestamp": '{}Z'.format(datetime.utcnow().isoformat())})
return Output(True, {"sum": sum(self.values.values()), "message_id": str(uuid.uuid4()),
"timestamp": '{}Z'.format(datetime.utcnow().isoformat())})


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_process(self):
input2.current_topic = "test2"
output = adder.process([input1, input2])
self.assertTrue(output.send)
self.assertEqual({'sum', 'message_id', 'timestamp'}, output.values.keys())
self.assertEqual({'sum', 'message_no', 'message_id', 'timestamp'}, output.values.keys())
input1.current_value = 7
input1.current_topic = "test1"
input2.current_value = 4
Expand Down

0 comments on commit 116422c

Please sign in to comment.