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

Aperta Adatta ai principianti
#1,060 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@zigpy-review-bot ci sta già lavorando.

Dal 22/11/2026.

  • #1061 di @zigpy-review-bot — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
embedded-iot

Direzione di ricerca

Inizia da BACNET_UNITS_TO_HA_UNITS in zha/application/platforms/number/bacnet.py e correggi gli undici elementi elencati nella tabella, usando l'enum BacnetUnit nello stesso file per confermare ogni id. Esegui il test che fallisce e che associa un dispositivo ad uscita analogica a ciascun valore di engineering_units e verifica l'unità dell'entità; dovrebbe passare per tutti gli undici. Lascia invariati microsiemens (190) e millisiemens (202), come chiede la issue.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bot: code audit
Problem

Severity: low (the audit's estimate)

Analog output numbers, and analog input sensors without an application type, take their unit from the BACnet engineering_units attribute through BACNET_UNITS_TO_HA_UNITS in zha/application/platforms/number/bacnet.py. Eleven entries of that map name a different unit than the BACnet unit they stand for, so a device reporting one of these units has its value shown in Home Assistant with the wrong unit, and an analog input sensor's long-term statistics are recorded under that wrong unit. A water flow meter reporting liters per hour, for example, is shown in L/min, 60 times off.

BACnet unit (id) Shown as Should be
BTUs (20), energy BTU/h, power BTU
tons (41), mass st (stones) ton
degrees-angular (90) rpm °
BTUs-per-pound (117) cal BTU/lb
liters-per-hour (136) L/min L/h
kilowatt-hours-per-square-meter (137) km/kWh kWh/m²
kilowatt-hours-per-square-foot (138) mi/kWh kWh/ft²
millimeters-per-second (161) mm mm/s
decibels-millivolt (200) dBm dBmV
decibels-volt (201) dB dBV
ampere-square-hours (246) A·h A²·h

The ids and names are those of the BacnetUnit enum in the same file, taken from bacnet-stack's bacenum.h. The wrong entries came in with the map itself in zigpy/zha#197. For eight of them, the strings ZHA used before that named the right units ("Liters-per-hour", "Degrees-angular", …); ids 200, 201 and 246 had no unit before.

Evidence

BACNET_UNITS_TO_HA_UNITS is read by AnalogOutputNumber.recompute_capabilities() and, when the application type is missing, by AnalogInputSensor.recompute_capabilities().

A test that joins an analog output device with each of these engineering_units values and checks the entity's unit fails for all eleven at 2da1a5b5676158ac7b603ce6b9f42641cb90e7a0:

Failing test output
E       AssertionError: assert <UnitOfPower....HOUR: 'BTU/h'> == 'BTU'
E       AssertionError: assert <UnitOfMass.STONES: 'st'> == 'ton'
E       AssertionError: assert 'rpm' == '°'
E       AssertionError: assert <UnitOfEnergy.CALORIE: 'cal'> == 'BTU/lb'
E       AssertionError: assert <UnitOfVolume...NUTE: 'L/min'> == 'L/h'
E       AssertionError: assert <UnitOfEnergy...OUR: 'km/kWh'> == 'kWh/m²'
E       AssertionError: assert <UnitOfEnergy...OUR: 'mi/kWh'> == 'kWh/ft²'
E       AssertionError: assert <UnitOfLength...IMETERS: 'mm'> == 'mm/s'
E       AssertionError: assert 'dBm' == 'dBmV'
E       AssertionError: assert 'dB' == 'dBV'
E       AssertionError: assert 'A·h' == 'A²·h'
11 failed, 24 deselected
Proposed fix

Map each of the eleven units to the unit it names, as in the table: the existing UnitOfVolumeFlowRate.LITERS_PER_HOUR, UnitOfSpeed.MILLIMETERS_PER_SECOND and DEGREE constants, and plain strings for the rest, as the map already does for units Home Assistant has no constant for. The change, with the test above, is in zigpy/zha#1061.

Not changed: microsiemens (190) and millisiemens (202) name conductance but are shown as the conductivity units µS/cm and mS/cm. Changing them would take Home Assistant's conductivity units away from devices that may use these ids for conductivity readings (BACnet has no µS/cm), so that is left for a maintainer to decide. Likewise, with this fix tons (41) shows the same "ton" as tons-refrigeration (52), a power unit.

Lingua principale
Python
Stelle
96
Fork
84
Merge medio
3g 1h
PR unite (30g)
13

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di zigpy/zha

Tutte le issue di zigpy/zha

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.