Skip to content

Set volume_flow_rate device class for supported Metering demand units - #1009

Open
lboue wants to merge 1 commit into
zigpy:devfrom
lboue:volume-flow-rate-device-class
Open

lboue wants to merge 1 commit into
zigpy:devfrom
lboue:volume-flow-rate-device-class

Conversation

@lboue

@lboue lboue commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • The instantaneous_demand sensor on the Smart Energy Metering cluster never got a device_class for water/gas flow-rate units, leaving it without an icon in the Home Assistant UI (unlike the companion summation_delivered/consumption sensor, which does get device_class="volume").
  • Home Assistant has supported SensorDeviceClass.VOLUME_FLOW_RATE since 2023.1, covering all UnitOfVolumeFlowRate units. This PR assigns it for the metering device types that use a unit supported by that device class: m³/h (0x01, 0x03), ft³/min (0x02), gal/h (0x04) and L/h (0x07).
  • Also fixes the L/h unit string for unit_of_measure 0x07, which was previously built as lowercase "l/h" and did not match Home Assistant's UnitOfVolumeFlowRate.LITERS_PER_HOUR ("L/h").
  • Left untouched: imperial gallons/hour (0x05) and cubic-feet-per-hour (0x0A), since Home Assistant does not currently support those exact units for this device class.

Fixes #1008

Test plan

  • Added a parametrized regression test (test_smart_energy_metering_instantaneous_demand_device_class) covering all affected unit_of_measure values for a water metering device, asserting the resulting device_class and unit.
  • Regenerated the two device diagnostics fixtures whose instantaneous_demand entity changed (tools/regenerate_diagnostics.py).
  • pytest tests/ passes (1787 passed).
  • pre-commit run (ruff check/format, mypy, codespell) passes.

The instantaneous_demand sensor on the Smart Energy Metering cluster
never got a device_class for water/gas flow-rate units, leaving it
without an icon in the UI. Home Assistant has supported
SensorDeviceClass.VOLUME_FLOW_RATE since 2023.1 for all
UnitOfVolumeFlowRate units, so assign it for the metering device
types that use a supported unit (m³/h, ft³/min, gal/h, L/h).

Also fixes the L/h unit string, which was previously lowercase ("l/h")
and did not match Home Assistant's UnitOfVolumeFlowRate.LITERS_PER_HOUR.

Fixes zigpy#1008

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.48%. Comparing base (2da1a5b) to head (2b44480).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #1009   +/-   ##
=======================================
  Coverage   97.48%   97.48%           
=======================================
  Files          61       61           
  Lines       10870    10870           
=======================================
  Hits        10597    10597           
  Misses        273      273           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lboue

lboue commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Testing

Tested on a real Home Assistant OS instance against the actual device from #1008 (DIY Zigbee water pulse meter, metering_device_type = Water, unit_of_measure = 0x01). After installing this branch and restarting Core:

  • device_class attribute on sensor.*_demande_instantanee changed from unset to volume_flow_rate
  • The entity now shows the mdi:pipe-valve icon (Home Assistant's default icon for that device class) instead of the generic fallback icon, matching the sibling summation_delivered sensor's behavior.
image

@zigpy-review-bot zigpy-review-bot added the new feature Adds new feature label Nov 9, 2026
@TheJulianJES
TheJulianJES requested review from zigpy-review-bot and a balanced review from Copilot November 9, 2026 12:09

@zigpy-review-bot zigpy-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, no findings. The change is small and correct.

Verified (5 checks)
  • Every unit now given VOLUME_FLOW_RATE (m³/h, ft³/min, gal/h, L/h) is a member of UnitOfVolumeFlowRate in both zha/units.py and HA Core (SensorDeviceClass.VOLUME_FLOW_RATE: set(UnitOfVolumeFlowRate)), so none of them can trip HA's device-class/unit validation. The device class also allows measurement, which these entities use.
  • The L/h string fix is real: the old f"l/{UnitOfTime.HOURS}" produced l/h, which is not a valid UnitOfVolumeFlowRate value. The same applies to the old gal/h f-string, which is now the enum member.
  • Leaving 0x05 (imperial gal/h) and 0x0A unclassified is right, since neither has a matching HA unit.
  • The two regenerated fixtures show only the expected device_class and unit change on instantaneous_demand; unique IDs and the other fields are untouched.
  • tests/test_sensor.py passes in the PR worktree (114 passed), including the new parametrized test.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the flow-rate device-class and unit updates.

No open issues 🎉

What changed in this PR

Addresses #1008 by assigning the volume-flow-rate device class to supported Smart Energy Metering demand units, enabling default icons in Home Assistant.

Changes:

  • Assigns VOLUME_FLOW_RATE to supported units while leaving unsupported units unchanged.
  • Uses standard flow-rate constants, correcting "l/h" to "L/h".
  • Adds parametrized regression coverage and updates two device diagnostics fixtures.
File Description
zha/​application/​platforms/​sensor/​__init__.py Sets supported flow-rate device classes and standardizes units.
tests/​test_sensor.py Tests demand device classes and units for supported mappings.
tests/​data/​devices/​tze204-xlppj4f5-ts0601-0x0000004a.json Updates expected demand class and liter-per-hour unit.
tests/​data/​devices/​sinope-technologies-va4220zb.json Updates expected demand class and liter-per-hour unit.

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature Adds new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

instantaneous_demand sensor has no device_class (and thus no icon) for volume flow rate metering types

3 participants