feature: restructured Datapoints

This commit is contained in:
Jan-Ole Hübner 2023-09-02 22:39:52 +02:00
parent db34941c30
commit dd9ee96396
2 changed files with 51 additions and 54 deletions

24
DataPoints.py Normal file
View file

@ -0,0 +1,24 @@
from influxdb_client import Point
class Pulse:
label = str(__name__).lower()
def __init__(self,data):
measurement = data['liveMeasurement']
timestamp = measurement['timestamp']
power = measurement['power']
cost = measurement.get('accumulatedCost',None)
lastMeterConsumption = measurement['lastMeterConsumption']
tags = {self.label: ""}
fields = {
"power": float(power),
"lastMeterConsumption": float(lastMeterConsumption)
}
if cost is not None:
fields.update({'accumulatedCost':cost})
self.datapoint = {"fields": fields,
"tags": tags,
"measurement": "pulse",
"time": timestamp
}
def get_datapoint(self):
return Point(measurement_name=str(self.label)).from_dict(self.datapoint)