From b78edd9d80b59eab962808c4c70d4f645d1927f8 Mon Sep 17 00:00:00 2001 From: Elad Bar Date: Sun, 2 Jun 2024 11:09:56 +0300 Subject: [PATCH] bug fix state class for sensor --- CHANGELOG.md | 4 ++++ .../common/entity_descriptions.py | 18 +++++++++--------- .../citymind_water_meter/manifest.json | 2 +- .../citymind_water_meter/sensor.py | 1 + 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa16d96..06c2286 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v3.0.3 + +- Fix state class to total + ## v3.0.2 - Fix unload integration process diff --git a/custom_components/citymind_water_meter/common/entity_descriptions.py b/custom_components/citymind_water_meter/common/entity_descriptions.py index 4a340a1..a7bdf53 100644 --- a/custom_components/citymind_water_meter/common/entity_descriptions.py +++ b/custom_components/citymind_water_meter/common/entity_descriptions.py @@ -71,7 +71,7 @@ class IntegrationNumberEntityDescription( key=EntityKeys.LAST_READ, entity_type=EntityType.METER, device_class=SensorDeviceClass.WATER, - state_class=SensorStateClass.TOTAL_INCREASING, + state_class=SensorStateClass.TOTAL, native_unit_of_measurement=UnitOfVolume.CUBIC_METERS, reset_policy=ResetPolicy.MONTHLY, ), @@ -79,7 +79,7 @@ class IntegrationNumberEntityDescription( key=EntityKeys.MONTHLY_CONSUMPTION, entity_type=EntityType.METER, device_class=SensorDeviceClass.WATER, - state_class=SensorStateClass.TOTAL_INCREASING, + state_class=SensorStateClass.TOTAL, native_unit_of_measurement=UnitOfVolume.CUBIC_METERS, reset_policy=ResetPolicy.MONTHLY, ), @@ -87,7 +87,7 @@ class IntegrationNumberEntityDescription( key=EntityKeys.TODAYS_CONSUMPTION, entity_type=EntityType.METER, device_class=SensorDeviceClass.WATER, - state_class=SensorStateClass.TOTAL_INCREASING, + state_class=SensorStateClass.TOTAL, native_unit_of_measurement=UnitOfVolume.CUBIC_METERS, reset_policy=ResetPolicy.DAILY, ), @@ -95,7 +95,7 @@ class IntegrationNumberEntityDescription( key=EntityKeys.YESTERDAYS_CONSUMPTION, entity_type=EntityType.METER, device_class=SensorDeviceClass.WATER, - state_class=SensorStateClass.TOTAL_INCREASING, + state_class=SensorStateClass.TOTAL, native_unit_of_measurement=UnitOfVolume.CUBIC_METERS, reset_policy=ResetPolicy.DAILY, ), @@ -103,7 +103,7 @@ class IntegrationNumberEntityDescription( key=EntityKeys.HIGH_RATE_CONSUMPTION, entity_type=EntityType.METER, device_class=SensorDeviceClass.WATER, - state_class=SensorStateClass.TOTAL_INCREASING, + state_class=SensorStateClass.TOTAL, native_unit_of_measurement=UnitOfVolume.CUBIC_METERS, reset_policy=ResetPolicy.MONTHLY, ), @@ -111,7 +111,7 @@ class IntegrationNumberEntityDescription( key=EntityKeys.LOW_RATE_CONSUMPTION, entity_type=EntityType.METER, device_class=SensorDeviceClass.WATER, - state_class=SensorStateClass.TOTAL_INCREASING, + state_class=SensorStateClass.TOTAL, native_unit_of_measurement=UnitOfVolume.CUBIC_METERS, reset_policy=ResetPolicy.MONTHLY, ), @@ -119,7 +119,7 @@ class IntegrationNumberEntityDescription( key=EntityKeys.LOW_RATE_TOTAL_COST, entity_type=EntityType.METER, entity_category=EntityCategory.DIAGNOSTIC, - state_class=SensorStateClass.TOTAL_INCREASING, + state_class=SensorStateClass.TOTAL, native_unit_of_measurement=UNIT_COST, icon="mdi:currency-ils", reset_policy=ResetPolicy.MONTHLY, @@ -139,7 +139,7 @@ class IntegrationNumberEntityDescription( key=EntityKeys.HIGH_RATE_TOTAL_COST, entity_type=EntityType.METER, entity_category=EntityCategory.DIAGNOSTIC, - state_class=SensorStateClass.TOTAL_INCREASING, + state_class=SensorStateClass.TOTAL, native_unit_of_measurement=UNIT_COST, icon="mdi:currency-ils", reset_policy=ResetPolicy.MONTHLY, @@ -159,7 +159,7 @@ class IntegrationNumberEntityDescription( key=EntityKeys.SEWAGE_TOTAL_COST, entity_type=EntityType.METER, entity_category=EntityCategory.DIAGNOSTIC, - state_class=SensorStateClass.TOTAL_INCREASING, + state_class=SensorStateClass.TOTAL, native_unit_of_measurement=UNIT_COST, icon="mdi:currency-ils", reset_policy=ResetPolicy.MONTHLY, diff --git a/custom_components/citymind_water_meter/manifest.json b/custom_components/citymind_water_meter/manifest.json index db7f947..32645cb 100644 --- a/custom_components/citymind_water_meter/manifest.json +++ b/custom_components/citymind_water_meter/manifest.json @@ -8,5 +8,5 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/maorcc/citymind_water_meter/issues", "requirements": [], - "version": "3.0.2" + "version": "3.0.3" } diff --git a/custom_components/citymind_water_meter/sensor.py b/custom_components/citymind_water_meter/sensor.py index 9022978..09be88d 100644 --- a/custom_components/citymind_water_meter/sensor.py +++ b/custom_components/citymind_water_meter/sensor.py @@ -44,6 +44,7 @@ def __init__( entity_description.native_unit_of_measurement ) + self._attr_state_class = entity_description.state_class self._attr_last_reset = self._get_last_reset() def _get_last_reset(self) -> datetime | None: