macOS: USB UPS battery sensors get a new unique ID whenever the UPS name is read differently (no `Hardware Serial Number`; serial is in `Accessory Identifier`)

Abierto Apto para principiantes
#6,328 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
84/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
macos, swift
Área
backend, mobile

Línea de trabajo

Empieza por Sources/Shared/Environment/DeviceBattery.swift y sigue cómo DeviceBattery(powerSourceDescription:) construye el ID único del sensor de batería a partir de los campos de la fuente de alimentación. Usa el orden de alternativas sugerido en el issue: número de serie del hardware, después un identificador de accesorio recortado y no vacío, y luego el nombre. Revisa las pruebas de batería existentes o añade cobertura para los casos en que falte el número de serie del hardware y haya un identificador de accesorio; se considera terminado cuando los IDs se mantienen estables entre las variantes de nombre descritas en el issue y los dispositivos con números de serie del hardware conservan sus IDs actuales.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug mac
Does the issue also happen in Safari?

Not applicable (native app feature)

The problem

On macOS, a USB UPS (APC Back-UPS ES 600M1) gets a new …_level / …_state sensor pair every few boots. I now have 5 pairs for one UPS. Each new pair is created disabled, so automations reading the old pair silently stop getting updates.

Cause: DeviceBattery(powerSourceDescription:) builds uniqueID from kIOPSHardwareSerialNumberKey, falling back to kIOPSNameKey. For USB/HID UPS units, macOS never sets Hardware Serial Number. Apple's HID UPS plug-in (IOHIDFamily/IOHIDLib/IOHIDUPSClass.m) sets Name from the HID product string and puts the HID serial in "Accessory Identifier" (kIOPSAccessoryIdentifierKey, private IOPSKeysPrivate.h). So the ID comes from the name, and macOS sometimes reads the name cut short. My five unique IDs are all truncations of one string:

Back-UPS ES 600M1 FW:928.a11 .D USB FW:a10 
Back-UPS ES 600M1 FW:928.a11 .D USB FW:a
Back-UPS ES 600M1 FW:928.a11 .D USB F
Back-UPS ES 600M1 FW:928.a11 .D USB
Back-UPS ES 600M1 FW:928.a11 .D 

Accessory Identifier holds the same value (0B25XXXXXXXX ) on every variant. Live IOPSCopyPowerSourcesInfo output:

Name = "Back-UPS ES 600M1 FW:928.a11 .D USB FW:a10 "
Hardware Serial Number = (absent)
Accessory Identifier = "0B25XXXXXXXX  "
Power Source ID = 52625408   (changes every boot; not usable)
Type = "UPS"
Transport Type = "USB"
Vendor ID = 1309
Product ID = 2

Suggested fix: fall back to info["Accessory Identifier"] (trimmed, non-empty) before the name in Sources/Shared/Environment/DeviceBattery.swift. Devices that report a serial keep their current IDs. Affected users get one new pair once, then no more drift. #3120 covers the stale entities this leaves behind; this issue is about why they keep appearing.

Which platform has the issue?

macOS

Which device model are you using?

Mac mini (Mac16,10)

Which OS version is the device running?

macOS 27.2.1

What version of the app has the issue?

2026.10.3 (2026.3322)

What was the last working version of the app?

No response

What version of Home Assistant Core are you running?

core-2026.11.3

Steps to reproduce
  1. Connect a USB HID UPS that has no Hardware Serial Number (e.g. APC Back-UPS ES series) to a Mac running the companion app.
  2. Reboot the Mac several times, or unplug and replug the UPS USB cable.
  3. Check the device's sensors in HA: a new <name> Level / <name> State pair appears whenever the name is read differently.
Expected behavior

One stable sensor pair per physical UPS, keyed on its serial (Accessory Identifier), across reboots and USB reconnects.

Did you upload your companion app logs through the form above?

No

Lenguaje dominante
Swift
Estrellas
2.4k
Forks
583
Merge medio
1 d 10 h
PR fusionados (30 d)
82

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de home-assistant/iOS

Todos los issues de home-assistant/iOS

Issues similares

Más issues de Swift

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.