From 85168239cdcfa8f3fcb04812f30e495c99ce3ff8 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Wed, 3 Jul 2024 17:16:51 +0200 Subject: [PATCH] Matter fix Energy sensor discovery schemas (#121080) --- homeassistant/components/matter/sensor.py | 98 +++++++++++++++++++++-- 1 file changed, 91 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/matter/sensor.py b/homeassistant/components/matter/sensor.py index d91d4d3347192..9c19be7ee08b9 100644 --- a/homeassistant/components/matter/sensor.py +++ b/homeassistant/components/matter/sensor.py @@ -6,7 +6,11 @@ from chip.clusters import Objects as clusters from chip.clusters.Types import Nullable, NullValue -from matter_server.common.custom_clusters import EveCluster +from matter_server.common.custom_clusters import ( + EveCluster, + NeoCluster, + ThirdRealityMeteringCluster, +) from homeassistant.components.sensor import ( SensorDeviceClass, @@ -171,9 +175,6 @@ def _update_from_device(self) -> None: ), entity_class=MatterSensor, required_attributes=(EveCluster.Attributes.Watt,), - # Add OnOff Attribute as optional attribute to poll - # the primary value when the relay is toggled - optional_attributes=(clusters.OnOff.Attributes.OnOff,), ), MatterDiscoverySchema( platform=Platform.SENSOR, @@ -213,9 +214,6 @@ def _update_from_device(self) -> None: ), entity_class=MatterSensor, required_attributes=(EveCluster.Attributes.Current,), - # Add OnOff Attribute as optional attribute to poll - # the primary value when the relay is toggled - optional_attributes=(clusters.OnOff.Attributes.OnOff,), ), MatterDiscoverySchema( platform=Platform.SENSOR, @@ -364,4 +362,90 @@ def _update_from_device(self) -> None: clusters.ActivatedCarbonFilterMonitoring.Attributes.Condition, ), ), + MatterDiscoverySchema( + platform=Platform.SENSOR, + entity_description=MatterSensorEntityDescription( + key="ThirdRealityEnergySensorWatt", + device_class=SensorDeviceClass.POWER, + entity_category=EntityCategory.DIAGNOSTIC, + native_unit_of_measurement=UnitOfPower.WATT, + suggested_display_precision=2, + state_class=SensorStateClass.MEASUREMENT, + measurement_to_ha=lambda x: x / 1000, + ), + entity_class=MatterSensor, + required_attributes=( + ThirdRealityMeteringCluster.Attributes.InstantaneousDemand, + ), + ), + MatterDiscoverySchema( + platform=Platform.SENSOR, + entity_description=MatterSensorEntityDescription( + key="ThirdRealityEnergySensorWattAccumulated", + device_class=SensorDeviceClass.ENERGY, + entity_category=EntityCategory.DIAGNOSTIC, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, + suggested_display_precision=3, + state_class=SensorStateClass.TOTAL_INCREASING, + measurement_to_ha=lambda x: x / 1000, + ), + entity_class=MatterSensor, + required_attributes=( + ThirdRealityMeteringCluster.Attributes.CurrentSummationDelivered, + ), + ), + MatterDiscoverySchema( + platform=Platform.SENSOR, + entity_description=MatterSensorEntityDescription( + key="NeoEnergySensorWatt", + device_class=SensorDeviceClass.POWER, + entity_category=EntityCategory.DIAGNOSTIC, + native_unit_of_measurement=UnitOfPower.WATT, + suggested_display_precision=2, + state_class=SensorStateClass.MEASUREMENT, + measurement_to_ha=lambda x: x / 10, + ), + entity_class=MatterSensor, + required_attributes=(NeoCluster.Attributes.Watt,), + ), + MatterDiscoverySchema( + platform=Platform.SENSOR, + entity_description=MatterSensorEntityDescription( + key="NeoEnergySensorWattAccumulated", + device_class=SensorDeviceClass.ENERGY, + entity_category=EntityCategory.DIAGNOSTIC, + native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, + suggested_display_precision=1, + state_class=SensorStateClass.TOTAL_INCREASING, + ), + entity_class=MatterSensor, + required_attributes=(NeoCluster.Attributes.WattAccumulated,), + ), + MatterDiscoverySchema( + platform=Platform.SENSOR, + entity_description=MatterSensorEntityDescription( + key="NeoEnergySensorVoltage", + device_class=SensorDeviceClass.VOLTAGE, + entity_category=EntityCategory.DIAGNOSTIC, + native_unit_of_measurement=UnitOfElectricPotential.VOLT, + suggested_display_precision=0, + state_class=SensorStateClass.MEASUREMENT, + measurement_to_ha=lambda x: x / 10, + ), + entity_class=MatterSensor, + required_attributes=(NeoCluster.Attributes.Voltage,), + ), + MatterDiscoverySchema( + platform=Platform.SENSOR, + entity_description=MatterSensorEntityDescription( + key="NeoEnergySensorWattCurrent", + device_class=SensorDeviceClass.CURRENT, + entity_category=EntityCategory.DIAGNOSTIC, + native_unit_of_measurement=UnitOfElectricCurrent.MILLIAMPERE, + suggested_display_precision=0, + state_class=SensorStateClass.MEASUREMENT, + ), + entity_class=MatterSensor, + required_attributes=(NeoCluster.Attributes.Current,), + ), ]