Add discovery schema for Matter CumulativeEnergyExported (#144061)

* Update sensor.py to add CumulativeEnergyExported attribute

* Report exported energy as positive value

* Add snapshot

* Add translation key
This commit is contained in:
Ludovic BOUÉ 2025-05-07 15:25:18 +02:00 committed by GitHub
parent 2f7fcb4f5e
commit c26b3f519a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 80 additions and 0 deletions

View File

@ -744,6 +744,25 @@ DISCOVERY_SCHEMAS = [
clusters.ElectricalEnergyMeasurement.Attributes.CumulativeEnergyImported,
),
),
MatterDiscoverySchema(
platform=Platform.SENSOR,
entity_description=MatterSensorEntityDescription(
key="ElectricalEnergyMeasurementCumulativeEnergyExported",
translation_key="energy_exported",
device_class=SensorDeviceClass.ENERGY,
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfEnergy.MILLIWATT_HOUR,
suggested_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,
),
entity_class=MatterSensor,
required_attributes=(
clusters.ElectricalEnergyMeasurement.Attributes.CumulativeEnergyExported,
),
),
MatterDiscoverySchema(
platform=Platform.SENSOR,
entity_description=MatterSensorEntityDescription(

View File

@ -303,6 +303,9 @@
"current_phase": {
"name": "Current phase"
},
"energy_exported": {
"name": "Energy exported"
},
"evse_fault_state": {
"name": "Fault state",
"state": {

View File

@ -4254,6 +4254,64 @@
'state': '-3.62',
})
# ---
# name: test_sensors[solar_power][sensor.solarpower_energy_exported-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.solarpower_energy_exported',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
'sensor': dict({
'suggested_display_precision': 3,
}),
'sensor.private': dict({
'suggested_unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
}),
}),
'original_device_class': <SensorDeviceClass.ENERGY: 'energy'>,
'original_icon': None,
'original_name': 'Energy exported',
'platform': 'matter',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'energy_exported',
'unique_id': '00000000000004D2-0000000000000001-MatterNodeDevice-1-ElectricalEnergyMeasurementCumulativeEnergyExported-145-2',
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
})
# ---
# name: test_sensors[solar_power][sensor.solarpower_energy_exported-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'energy',
'friendly_name': 'SolarPower Energy exported',
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
}),
'context': <ANY>,
'entity_id': 'sensor.solarpower_energy_exported',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '42.279',
})
# ---
# name: test_sensors[solar_power][sensor.solarpower_power-entry]
EntityRegistryEntrySnapshot({
'aliases': set({