Skip to content

Commit

Permalink
Number of charges in graph period count (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
geertmeersman authored Apr 14, 2023
2 parents aba406d + 7d51bf2 commit 1dc1472
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions custom_components/nexxtmove/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ def fetch_data(self):
extra_attributes=charging_device,
)

extra_attributes = {
"start_date": GRAPH_START_DATE,
"end_date": datetime.datetime.now().strftime("%Y%m%d"),
}
graph_data = self.charging_device_graph(
charging_device_id,
GRAPH_START_DATE,
Expand All @@ -262,14 +266,14 @@ def fetch_data(self):
device_name=device_name,
device_model=device_model,
state=graph_data.get("totals").get("totalReimbursed"),
extra_attributes=extra_attributes,
)
monthly_date = []
monthly_cost = []
monthly_energy = []
monthly_charges = []
period_energy = 0
period_charges = 0
for record in graph_data.get("records"):
period_energy += record.get("energyWh")
monthly_date.append(record.get("date"))
cost = {}
energy = {}
Expand All @@ -290,6 +294,11 @@ def fetch_data(self):
.get(category.upper())
.get("charges")
}
period_charges += (
record.get("detailsPerAccount")
.get(category.upper())
.get("charges")
)
monthly_cost.append(cost)
monthly_energy.append(energy)
monthly_charges.append(charges)
Expand All @@ -307,7 +316,8 @@ def fetch_data(self):
device_name=device_name,
device_model=device_model,
state=graph_data.get("totals").get("totalCost"),
extra_attributes={"dates": monthly_date, "values": monthly_cost},
extra_attributes=extra_attributes
| {"dates": monthly_date, "values": monthly_cost},
)
suffix = "period energy"
key = format_entity_name(
Expand All @@ -322,7 +332,8 @@ def fetch_data(self):
device_name=device_name,
device_model=device_model,
state=graph_data.get("totals").get("totalEnergyWh") / 1000,
extra_attributes={"dates": monthly_date, "values": monthly_energy},
extra_attributes=extra_attributes
| {"dates": monthly_date, "values": monthly_energy},
)
suffix = "period charges"
key = format_entity_name(
Expand All @@ -336,8 +347,9 @@ def fetch_data(self):
device_key=device_key,
device_name=device_name,
device_model=device_model,
state=0,
extra_attributes={"dates": monthly_date, "values": monthly_charges},
state=period_charges,
extra_attributes=extra_attributes
| {"dates": monthly_date, "values": monthly_charges},
)

"""
Expand Down

0 comments on commit 1dc1472

Please sign in to comment.