From a1ed5eff5acb7024aeb7e52daae2318da1160f7c Mon Sep 17 00:00:00 2001 From: Jakob Schlyter Date: Fri, 10 Jan 2025 21:31:39 +0100 Subject: [PATCH 1/2] Enable long-term statistics for odometers --- custom_components/polestar_api/sensor.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_components/polestar_api/sensor.py b/custom_components/polestar_api/sensor.py index a95fd3d..0b6af07 100644 --- a/custom_components/polestar_api/sensor.py +++ b/custom_components/polestar_api/sensor.py @@ -67,7 +67,7 @@ class PolestarSensorDescription(SensorEntityDescription): native_unit_of_measurement=UnitOfLength.METERS, suggested_unit_of_measurement=UnitOfLength.KILOMETERS, suggested_display_precision=0, - state_class=SensorStateClass.MEASUREMENT, + state_class=SensorStateClass.TOTAL_INCREASING, device_class=SensorDeviceClass.DISTANCE, ), PolestarSensorDescription( @@ -84,7 +84,7 @@ class PolestarSensorDescription(SensorEntityDescription): icon="mdi:map-marker-distance", native_unit_of_measurement=UnitOfLength.KILOMETERS, suggested_display_precision=1, - state_class=SensorStateClass.MEASUREMENT, + state_class=SensorStateClass.TOTAL_INCREASING, device_class=SensorDeviceClass.DISTANCE, ), PolestarSensorDescription( @@ -93,7 +93,7 @@ class PolestarSensorDescription(SensorEntityDescription): icon="mdi:map-marker-distance", native_unit_of_measurement=UnitOfLength.KILOMETERS, suggested_display_precision=1, - state_class=SensorStateClass.MEASUREMENT, + state_class=SensorStateClass.TOTAL_INCREASING, device_class=SensorDeviceClass.DISTANCE, ), PolestarSensorDescription( From 56d0fabd82da6211e2e0995da89df3d1d8520ed2 Mon Sep 17 00:00:00 2001 From: Jakob Schlyter Date: Sat, 11 Jan 2025 09:21:04 +0100 Subject: [PATCH 2/2] Use `SensorStateClass.TOTAL` for the odometer as it will never reset. Keep `SensorStateClass.TOTAL_INCREASING` for the trip meters as they may reset upon user request or start of new drive cycle. --- custom_components/polestar_api/sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/polestar_api/sensor.py b/custom_components/polestar_api/sensor.py index 0b6af07..27d7b87 100644 --- a/custom_components/polestar_api/sensor.py +++ b/custom_components/polestar_api/sensor.py @@ -67,7 +67,7 @@ class PolestarSensorDescription(SensorEntityDescription): native_unit_of_measurement=UnitOfLength.METERS, suggested_unit_of_measurement=UnitOfLength.KILOMETERS, suggested_display_precision=0, - state_class=SensorStateClass.TOTAL_INCREASING, + state_class=SensorStateClass.TOTAL, device_class=SensorDeviceClass.DISTANCE, ), PolestarSensorDescription(