From 19bb0b43d9abc9eca7de1e4357c941962bbdc77f Mon Sep 17 00:00:00 2001 From: Geert Meersman Date: Thu, 24 Aug 2023 14:06:17 +0200 Subject: [PATCH] feat: non invoiced sensor added --- custom_components/nexxtmove/client.py | 20 ++++++++++++++++++++ custom_components/nexxtmove/sensor.py | 9 +++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/custom_components/nexxtmove/client.py b/custom_components/nexxtmove/client.py index e60203f..e620d62 100644 --- a/custom_components/nexxtmove/client.py +++ b/custom_components/nexxtmove/client.py @@ -190,6 +190,26 @@ def fetch_data(self): state=len(charge_latest.get("charges")), extra_attributes=charge_latest, ) + non_invoiced_charges = [] + non_invoiced_amount = 0 + for charge in charge_latest.get("charges"): + if charge.get("cleared") is False: + non_invoiced_charges.append(charge) + non_invoiced_amount += charge.get("costVat") + + key = format_entity_name(f"{self.username} non invoiced") + data[key] = NexxtmoveItem( + name="Non invoiced", + key=key, + type="euro", + sensor_type="sensor", + device_key=device_key, + device_name=device_name, + device_model=device_model, + state=non_invoiced_amount, + extra_attributes={"charges": non_invoiced_charges}, + ) + _LOGGER.critical(non_invoiced_charges) consumption = self.consumption() if consumption.get("consumptionInKwh") is not None: charges = self.charges() diff --git a/custom_components/nexxtmove/sensor.py b/custom_components/nexxtmove/sensor.py index 3f62b2a..c9deada 100644 --- a/custom_components/nexxtmove/sensor.py +++ b/custom_components/nexxtmove/sensor.py @@ -61,24 +61,25 @@ class NexxtmoveSensorDescription(SensorEntityDescription): ), NexxtmoveSensorDescription(key="counter", icon="mdi:counter"), NexxtmoveSensorDescription(key="charging_device", icon="mdi:ev-station"), - NexxtmoveSensorDescription(key="charging_point", icon="mdi:ev-plug-ccs2"), + NexxtmoveSensorDescription(key="charging_point", icon="mdi:ev-plug-type1"), NexxtmoveSensorDescription( key="charging_events", icon="mdi:calendar-multiple-check" ), NexxtmoveSensorDescription( - key="price", suggested_display_precision=1, icon="mdi:currency-eur" + key="price", suggested_display_precision=2, icon="mdi:currency-eur" ), NexxtmoveSensorDescription(key="charges", icon="mdi:currency-eur"), NexxtmoveSensorDescription( key="euro", icon="mdi:currency-eur", - suggested_display_precision=1, + suggested_display_precision=2, device_class=SensorDeviceClass.MONETARY, native_unit_of_measurement=CURRENCY_EURO, ), NexxtmoveSensorDescription( key="pricekwh", icon="mdi:currency-eur", + suggested_display_precision=2, device_class=SensorDeviceClass.MONETARY, ), NexxtmoveSensorDescription(key="residential_location", icon="mdi:home"), @@ -162,7 +163,7 @@ def extra_state_attributes(self): if not self.coordinator.data: return {} attributes = { - "last_nexxtmove_sync": self.last_synced, + "last_synced": self.last_synced, } if len(self.item.extra_attributes) > 0: for attr in self.item.extra_attributes: