Only persist MeterValues for ongoing transactions
All checks were successful
ci/woodpecker/push/docker Pipeline was successful

This commit is contained in:
Oliver Traber 2024-04-21 20:17:37 +02:00
parent f48a9d71ef
commit b6207a18c7
Signed by: Bluemedia
GPG key ID: C0674B105057136C

View file

@ -180,6 +180,8 @@ class ChargePoint(cp):
db.add(transaction) db.add(transaction)
elif event_type == str(TransactionEventType.updated): elif event_type == str(TransactionEventType.updated):
transaction = db.get(DbTransaction, transaction_info["transaction_id"]) transaction = db.get(DbTransaction, transaction_info["transaction_id"])
if transaction != None:
if transaction.status == TransactionStatus.ONGOING:
if "meter_value" in kwargs.keys(): if "meter_value" in kwargs.keys():
for meter_value_entry in kwargs['meter_value']: for meter_value_entry in kwargs['meter_value']:
timestamp = datetime.fromisoformat(meter_value_entry['timestamp']) timestamp = datetime.fromisoformat(meter_value_entry['timestamp'])
@ -205,6 +207,7 @@ class ChargePoint(cp):
transaction.user_id = token_owner_id transaction.user_id = token_owner_id
elif event_type == str(TransactionEventType.ended): elif event_type == str(TransactionEventType.ended):
transaction = db.get(DbTransaction, transaction_info["transaction_id"]) transaction = db.get(DbTransaction, transaction_info["transaction_id"])
if transaction != None:
transaction.status = TransactionStatus.ENDED transaction.status = TransactionStatus.ENDED
transaction.ended_at = datetime.fromisoformat(timestamp) transaction.ended_at = datetime.fromisoformat(timestamp)
transaction.end_reason = TransactionEventTriggerReason(trigger_reason) transaction.end_reason = TransactionEventTriggerReason(trigger_reason)