Repository navigation
Apply the metering unit scale and fix cubic-feet demand units - #1063
zigpy-review-bot wants to merge 1 commit into
Conversation
The Metering entity descriptions carry a `scale` (100 for ccf, 1000 for mcf) that converts the meter's unit to the cubic feet the entity shows. It was applied in Home Assistant's `native_value` before ZHA became a library, and was lost in the move, so ccf and mcf meters showed 100x and 1000x too little. Apply it again in both metering formatters, before the number formatting. Also label the demand of unit 0x02 (ft³/h per Smart Energy) and 0x03 (ccf/h, scaled to ft³/h) as ft³/h, like 0x0A already is, instead of ft³/min and m³/h.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #1063 +/- ##
=======================================
Coverage 97.48% 97.48%
=======================================
Files 61 61
Lines 10870 10874 +4
=======================================
+ Hits 10597 10601 +4
Misses 273 273 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
This PR now conflicts with dev: #1009 (merged in e13552b) changed the same two demand entries, 0x02 and 0x03, in What conflicts
You can't just take one side. Keeping dev's 0x03 entry with this PR's scale fix would show a ccf/h demand ×100 (that is, ft³/h) labelled Options
Option 1 keeps what #1009 added and still corrects the values, so I'd go with it. Whichever option you pick, I'll merge dev into this branch, resolve the conflict that way, update the tests from both PRs to match, and update the PR body. @TheJulianJES, which option should I use? |
Summary
Severity: medium (the audit's estimate)
Smart Energy meters that report in ccf (
unit_of_measure0x03) or mcf (0x0A) show their summation in cubic feet 100 or 1000 times too small (and the mcf demand in ft³/h 1000 times too small), because thescalethe metering entity descriptions carry for those units is never applied. Home Assistant applied it innative_valuebefore ZHA moved into this library; #6 dropped it. The demand units are also wrong: 0x02 (ft³/h per Smart Energy 1.4a, Table D-26) is labelled ft³/min, and 0x03 (ccf/h) shows the unconverted number as m³/h.Changes
SmartEnergyMeteringgets a_scaleproperty (the entity description'sscale, 1 when the unit has no description), and both metering formatters multiply by it after multiplier and divisor, before the number formatting.test_se_summation_uomnow expect cubic feet (23.4 and 23.6 instead of 0.23 and 0.24), an mcf case is added, and the newtest_se_demand_uomcovers the demand of 0x02, 0x03 and 0x0A.Breaking changes
For existing ccf and mcf meters the summation jumps once to the correct value (100 or 1000 times the old one); it is a total-increasing sensor, so the jump is recorded as consumption in the long-term statistics and the energy dashboard. The demand unit change on 0x02 and 0x03 makes Home Assistant ask to fix the statistics unit.
Open items
#1009 edits the same 0x02 and 0x03 demand entries (it adds the volume flow rate device class); whichever merges second needs a small rebase there, and the unit choice for those two entries should be settled with it.
Testing
test_se_summation_uom(three cases) andtest_se_demand_uom(three cases) fail at 2da1a5b and pass with the fix.tests/data/devices/use these units, so no snapshot changes.Opened by the scheduled code audit; not requested by a maintainer.
Fixes #1062