From 7a719754da4703b44c09ea2d03dea8ef322b3e90 Mon Sep 17 00:00:00 2001 From: marq24 Date: Tue, 18 Jun 2024 20:42:20 +0200 Subject: [PATCH] added unit to 'CHARGETOTALIMPORT' - solve issue #7 --- custom_components/evcc_intg/const.py | 7 ++++--- custom_components/evcc_intg/manifest.json | 2 +- custom_components/evcc_intg/sensor.py | 3 +++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/custom_components/evcc_intg/const.py b/custom_components/evcc_intg/const.py index 4f2f663..53403d2 100644 --- a/custom_components/evcc_intg/const.py +++ b/custom_components/evcc_intg/const.py @@ -538,9 +538,10 @@ class ExtSwitchEntityDescription(SwitchEntityDescription): ExtSensorEntityDescriptionStub( tag=Tag.CHARGETOTALIMPORT, icon="mdi:transmission-tower-export", - state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=None, - device_class=None + state_class=SensorStateClass.TOTAL_INCREASING, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, + device_class=SensorDeviceClass.ENERGY, + suggested_display_precision=2 ), ExtSensorEntityDescriptionStub( tag=Tag.CHARGEDENERGY, diff --git a/custom_components/evcc_intg/manifest.json b/custom_components/evcc_intg/manifest.json index 537e225..2f15e65 100644 --- a/custom_components/evcc_intg/manifest.json +++ b/custom_components/evcc_intg/manifest.json @@ -10,5 +10,5 @@ "iot_class": "local_polling", "issue_tracker": "https://github.com/marq24/ha-evcc/issues", "requirements": [], - "version": "2024.6.1" + "version": "2024.6.2" } diff --git a/custom_components/evcc_intg/sensor.py b/custom_components/evcc_intg/sensor.py index 8af67e9..cb077e2 100644 --- a/custom_components/evcc_intg/sensor.py +++ b/custom_components/evcc_intg/sensor.py @@ -89,6 +89,9 @@ def state(self): value = round(float(value)/self.entity_description.factor, 2) else: value = round(float(value)/self.entity_description.factor, self.entity_description.suggested_display_precision) + elif self.entity_description.suggested_display_precision is not None: + value = round(float(value), self.entity_description.suggested_display_precision) + except IndexError: value = "unknown"