Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add discovery schemas for Matter 1.3 power/energy sensors #125403

Merged
merged 4 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions homeassistant/components/matter/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def _update_from_device(self) -> None:
),
entity_class=MatterSensor,
required_attributes=(EveCluster.Attributes.Watt,),
absent_attributes=(clusters.ElectricalPowerMeasurement.Attributes.ActivePower,),
),
MatterDiscoverySchema(
platform=Platform.SENSOR,
Expand All @@ -188,6 +189,7 @@ def _update_from_device(self) -> None:
),
entity_class=MatterSensor,
required_attributes=(EveCluster.Attributes.Voltage,),
absent_attributes=(clusters.ElectricalPowerMeasurement.Attributes.Voltage,),
),
MatterDiscoverySchema(
platform=Platform.SENSOR,
Expand All @@ -201,6 +203,9 @@ def _update_from_device(self) -> None:
),
entity_class=MatterSensor,
required_attributes=(EveCluster.Attributes.WattAccumulated,),
absent_attributes=(
clusters.ElectricalEnergyMeasurement.Attributes.CumulativeEnergyImported,
),
),
MatterDiscoverySchema(
platform=Platform.SENSOR,
Expand All @@ -214,6 +219,9 @@ def _update_from_device(self) -> None:
),
entity_class=MatterSensor,
required_attributes=(EveCluster.Attributes.Current,),
absent_attributes=(
clusters.ElectricalPowerMeasurement.Attributes.ActiveCurrent,
),
),
MatterDiscoverySchema(
platform=Platform.SENSOR,
Expand Down Expand Up @@ -377,6 +385,7 @@ def _update_from_device(self) -> None:
required_attributes=(
ThirdRealityMeteringCluster.Attributes.InstantaneousDemand,
),
absent_attributes=(clusters.ElectricalPowerMeasurement.Attributes.ActivePower,),
),
MatterDiscoverySchema(
platform=Platform.SENSOR,
Expand All @@ -393,6 +402,9 @@ def _update_from_device(self) -> None:
required_attributes=(
ThirdRealityMeteringCluster.Attributes.CurrentSummationDelivered,
),
absent_attributes=(
clusters.ElectricalEnergyMeasurement.Attributes.CumulativeEnergyImported,
),
),
MatterDiscoverySchema(
platform=Platform.SENSOR,
Expand All @@ -407,6 +419,7 @@ def _update_from_device(self) -> None:
),
entity_class=MatterSensor,
required_attributes=(NeoCluster.Attributes.Watt,),
absent_attributes=(clusters.ElectricalPowerMeasurement.Attributes.ActivePower,),
),
MatterDiscoverySchema(
platform=Platform.SENSOR,
Expand All @@ -420,6 +433,9 @@ def _update_from_device(self) -> None:
),
entity_class=MatterSensor,
required_attributes=(NeoCluster.Attributes.WattAccumulated,),
absent_attributes=(
clusters.ElectricalEnergyMeasurement.Attributes.CumulativeEnergyImported,
),
),
MatterDiscoverySchema(
platform=Platform.SENSOR,
Expand All @@ -434,6 +450,7 @@ def _update_from_device(self) -> None:
),
entity_class=MatterSensor,
required_attributes=(NeoCluster.Attributes.Voltage,),
absent_attributes=(clusters.ElectricalPowerMeasurement.Attributes.Voltage,),
),
MatterDiscoverySchema(
platform=Platform.SENSOR,
Expand All @@ -447,6 +464,9 @@ def _update_from_device(self) -> None:
),
entity_class=MatterSensor,
required_attributes=(NeoCluster.Attributes.Current,),
absent_attributes=(
clusters.ElectricalPowerMeasurement.Attributes.ActiveCurrent,
),
),
MatterDiscoverySchema(
platform=Platform.SENSOR,
Expand All @@ -462,4 +482,67 @@ def _update_from_device(self) -> None:
required_attributes=(clusters.Switch.Attributes.CurrentPosition,),
allow_multi=True, # also used for event entity
),
MatterDiscoverySchema(
platform=Platform.SENSOR,
entity_description=MatterSensorEntityDescription(
key="ElectricalPowerMeasurementWatt",
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=(
clusters.ElectricalPowerMeasurement.Attributes.ActivePower,
),
),
MatterDiscoverySchema(
platform=Platform.SENSOR,
entity_description=MatterSensorEntityDescription(
key="ElectricalPowerMeasurementVoltage",
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 / 1000,
),
entity_class=MatterSensor,
required_attributes=(clusters.ElectricalPowerMeasurement.Attributes.Voltage,),
),
MatterDiscoverySchema(
platform=Platform.SENSOR,
entity_description=MatterSensorEntityDescription(
key="ElectricalPowerMeasurementActiveCurrent",
device_class=SensorDeviceClass.CURRENT,
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
suggested_display_precision=2,
state_class=SensorStateClass.MEASUREMENT,
measurement_to_ha=lambda x: x / 1000,
),
entity_class=MatterSensor,
required_attributes=(
clusters.ElectricalPowerMeasurement.Attributes.ActiveCurrent,
),
),
MatterDiscoverySchema(
platform=Platform.SENSOR,
entity_description=MatterSensorEntityDescription(
key="ElectricalEnergyMeasurementCumulativeEnergyImported",
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,
# id 0 of the EnergyMeasurementStruct is the cumulative energy (in mWh)
measurement_to_ha=lambda x: x.energy / 1000000,
),
entity_class=MatterSensor,
required_attributes=(
clusters.ElectricalEnergyMeasurement.Attributes.CumulativeEnergyImported,
),
),
]
Loading