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`)

オープン 初心者向け
#6,328 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
84/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
macos, swift
領域
backend, mobile

調査の方向性

Sources/Shared/Environment/DeviceBattery.swift から始めて、DeviceBattery(powerSourceDescription:) が電源フィールドからバッテリーセンサーの一意な ID をどのように構築するかを追ってください。issue で提案されているフォールバック順序を使います。ハードウェアのシリアル番号、次に空白を除去した後に空でないアクセサリー識別子、最後に名前です。既存のバッテリーテストを確認するか、ハードウェアのシリアル番号がなくアクセサリー識別子がある場合のテストを追加してください。issue に記載された名前の各パターンで ID が安定し、ハードウェアのシリアル番号があるデバイスでは現在の ID が維持されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Swift
スター
2.4k
フォーク
583
平均マージ
1日 10時間
マージ済み PR(30日)
82

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

home-assistant/iOS のほかの issue

home-assistant/iOS の issue をすべて見る

似ている issue

Swift の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。