Skip to content

Fix wrong units in the BACnet engineering units map - #1061

Open
zigpy-review-bot wants to merge 1 commit into
devfrom
zigpy-bot/audit/fix-bacnet-engineering-units-map
Open

zigpy-review-bot wants to merge 1 commit into
devfrom
zigpy-bot/audit/fix-bacnet-engineering-units-map

Conversation

@zigpy-review-bot

Copy link
Copy Markdown
Collaborator

Summary

Severity: low (the audit's estimate)

Eleven entries of BACNET_UNITS_TO_HA_UNITS named a different unit than the BACnet engineering unit they stand for, so analog output numbers, and analog input sensors without an application type, showed values from devices using these units with the wrong unit (liters per hour as L/min, tons as stones, BTUs as BTU/h, degrees-angular as rpm, …). This maps each of them to the unit it names.

Changes

zha/application/platforms/number/bacnet.py:

  • BTUs (20): BTU/h → "BTU"
  • tons (41): stones → "ton"
  • degrees-angular (90): rpm → DEGREE
  • BTUs-per-pound (117): cal → "BTU/lb"
  • liters-per-hour (136): L/min → UnitOfVolumeFlowRate.LITERS_PER_HOUR
  • kilowatt-hours-per-square-meter (137) and per-square-foot (138): km/kWh and mi/kWh → "kWh/m²" and "kWh/ft²"
  • millimeters-per-second (161): mm → UnitOfSpeed.MILLIMETERS_PER_SECOND
  • decibels-millivolt (200) and decibels-volt (201): dBm and dB → "dBmV" and "dBV"
  • ampere-square-hours (246): A·h → "A²·h"
  • The imports no longer used by the map are removed.

Microsiemens (190) and millisiemens (202), which name conductance, still map to the conductivity units µS/cm and mS/cm: devices may use these ids for conductivity readings (BACnet has no µS/cm), so that is left for a maintainer to decide. Tons (41) now shows the same ton as tons-refrigeration (52), a power unit; a maintainer may prefer a distinct string for one of them.

An existing analog input sensor on one of these units changes its unit with this fix. Except for L/min → L/h, which Home Assistant converts, its long-term statistics then get a "units changed" statistics issue once, as for any unit change of a sensor with a state class.

Testing

  • New test_number_engineering_units, parametrized over the eleven units, joins an analog output device with that engineering_units value and checks the entity's unit. All eleven cases fail at 2da1a5b and pass with the fix.
  • The full suite passes (1792 passed), the device snapshots unchanged. pre-commit (codespell, ruff, mypy) passes on the changed files.

Opened by the scheduled code audit; not requested by a maintainer.

Fixes #1060

Several BACnet engineering units were mapped to a different unit than
the one they name, so analog output numbers and analog input sensors
showed values from such devices with the wrong unit:

- BTUs (energy) as BTU/h (power)
- tons as stones
- degrees-angular as rpm
- BTUs-per-pound as calories
- liters-per-hour as L/min
- kilowatt-hours-per-square-meter/foot as km/kWh and mi/kWh
- millimeters-per-second as mm
- decibels-millivolt as dBm, decibels-volt as dB
- ampere-square-hours as A·h

Map each of them to the unit it names.
@zigpy-review-bot zigpy-review-bot added bot: code audit Found by the bot's scheduled code audit bot: unrequested PR PR: opened by the bot's issue triage, not requested by a maintainer bugfix This PR fixes a bug bot-watch: fix zigpy-review-bot follows this thread and also pushes fixes (review + fix) labels Nov 22, 2026
@codecov

codecov Bot commented Nov 22, 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 (f25bbad).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #1061   +/-   ##
=======================================
  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.

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

Labels

bot: code audit Found by the bot's scheduled code audit bot: unrequested PR PR: opened by the bot's issue triage, not requested by a maintainer bot-watch: fix zigpy-review-bot follows this thread and also pushes fixes (review + fix) bugfix This PR fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Analog output numbers and analog input sensors show eleven BACnet engineering units as a different unit

1 participant