From 96fb165348a894b92350f2561c4ecd6582e5920f Mon Sep 17 00:00:00 2001 From: Geert Meersman Date: Fri, 14 Apr 2023 23:59:31 +0200 Subject: [PATCH 1/2] Number of charges in graph period count --- custom_components/nexxtmove/client.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/custom_components/nexxtmove/client.py b/custom_components/nexxtmove/client.py index 9defbec..982d460 100644 --- a/custom_components/nexxtmove/client.py +++ b/custom_components/nexxtmove/client.py @@ -267,9 +267,8 @@ def fetch_data(self): 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 = {} @@ -290,6 +289,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) @@ -336,7 +340,7 @@ def fetch_data(self): device_key=device_key, device_name=device_name, device_model=device_model, - state=0, + state=period_charges, extra_attributes={"dates": monthly_date, "values": monthly_charges}, ) From 7d51bf225d3f948d7e64735d40263b5499b32740 Mon Sep 17 00:00:00 2001 From: Geert Meersman Date: Sat, 15 Apr 2023 00:03:17 +0200 Subject: [PATCH 2/2] Graph start & end date added to extra attributes --- custom_components/nexxtmove/client.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/custom_components/nexxtmove/client.py b/custom_components/nexxtmove/client.py index 982d460..967b893 100644 --- a/custom_components/nexxtmove/client.py +++ b/custom_components/nexxtmove/client.py @@ -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, @@ -262,6 +266,7 @@ 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 = [] @@ -311,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( @@ -326,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( @@ -341,7 +348,8 @@ def fetch_data(self): device_name=device_name, device_model=device_model, state=period_charges, - extra_attributes={"dates": monthly_date, "values": monthly_charges}, + extra_attributes=extra_attributes + | {"dates": monthly_date, "values": monthly_charges}, ) """