Skip to content

Commit e0981dd

Browse files
committed
poller: retention
1 parent 11fa43b commit e0981dd

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/pylontech/pylontech.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(self, transport):
3131

3232
def poll_parameters(self, ids: range):
3333
while True:
34-
result = {"timestamp": datetime.datetime.now().isoformat(), "modules": []}
34+
result = {"timestamp": datetime.datetime.now(datetime.UTC), "modules": []}
3535
for idx in ids:
3636
vals = to_json_serializable(self.get_values_single(idx))
3737
result["modules"].append(vals)

src/pylontechpoller/poller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def minimize_module(m: json) -> json:
6363

6464
def mongo_cleanup(collection, retention_days):
6565
threshold = datetime.datetime.now() - datetime.timedelta(days=retention_days)
66-
collection.delete_many({"createdAt": {"$lt": threshold}})
66+
collection.delete_many({"ts": {"$lt": threshold}})
6767

6868
def run(argv: list[str]):
6969
parser = argparse.ArgumentParser(description="Pylontech RS485 poller")
@@ -99,7 +99,7 @@ def run(argv: list[str]):
9999
collection_meta = db[args.mongo_collection_meta]
100100

101101
collection_hist = db[args.mongo_collection_history]
102-
collection_hist.create_index("createdAt", expireAfterSeconds=3600*24*90)
102+
collection_hist.create_index("ts", expireAfterSeconds=3600*24*90)
103103

104104
logging.info("About to start polling...")
105105
bats = p.scan_for_batteries(2, 10)

0 commit comments

Comments
 (0)