test for getting prices

This commit is contained in:
Jan-Ole Hübner 2023-09-09 03:00:56 +02:00
parent f07a6384cd
commit 0b995a9dae
4 changed files with 69 additions and 6 deletions

View file

@ -1,3 +1,4 @@
from datetime import datetime
from influxdb_client import Point
class Pulse:
label = str(__name__).lower()
@ -22,3 +23,22 @@ class Pulse:
def get_datapoint(self):
return Point(measurement_name=str(self.label)).from_dict(self.datapoint)
class Price:
label = str(__name__).lower()
def __init__(self,data):
measurement = data['data']['viewer']['homes'][0]['currentSubscription']['priceInfo']['current']
current_time_utc = datetime.utcnow()
timestamp = current_time_utc.isoformat()
total = measurement.get('total',0.34)
tags = {self.label: ""}
fields = {
"total": float(total),
}
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)