Prefix service names with the accessory name - #98
Open
tillkruss wants to merge 1 commit into
Open
Conversation
HomeKit service names are currently hardcoded literals ('Temp',
'Humidity', 'Battery', ...), identical across every accessory this
plugin creates. Running two Airthings devices on one bridge therefore
produces services that are indistinguishable to downstream consumers.
Homebridge UI is affected: @homebridge/hap-client derives a service's
nameBasedUniqueId as
sha256([instance.name, instance.username, Manufacturer,
serviceName, uuid.slice(0, 8)].join('|'))
The serial number is not an input, so with two Airthings devices on the
same bridge all five components match and both devices' services hash
identically. The UI keys custom names on that hash, so renaming one
device's "Temp" tile silently renames the other's, and the two collapse
into a single tile. All seven services collide.
Prefixing with config.name — already used for the accessory's Name
characteristic — makes serviceName unique per accessory and resolves
all seven collisions. uniqueId is unaffected (it hashes aid/iid), so
existing Homebridge UI room layouts and HomeKit pairings are preserved.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the HomeKit service display names created by the Airthings Homebridge plugin so they’re unique per accessory instance, preventing Homebridge UI service collisions when multiple Airthings devices are bridged.
Changes:
- Prefixes each created service name with
config.name(the accessory name) for Battery, Air Quality, Temperature, Humidity, CO2, Air Pressure, and Radon services. - Keeps accessory identity stable (no changes to serial/UUID/subtype usage in the plugin code path shown).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every service this plugin creates is named with a hardcoded literal —
'Temp','Humidity','Battery','Air Quality','CO2','Air Pressure','Radon'— so two Airthings devices on the same bridge publish services with identical names.That makes them indistinguishable in Homebridge UI.
@homebridge/hap-clientderives each service'snameBasedUniqueIdas:The serial number isn't an input. With two Airthings devices on one bridge, all five components match, so both devices' services hash to the same value. Homebridge UI keys custom names on that hash, with two visible consequences:
All seven services collide. I hit this with a View Plus and a Wave Radon on one bridge — every rename applied to both devices, which looked like the UI was failing to save.
Fix
Prefix each service name with
config.name, which is already used for the accessory'sNamecharacteristic (line 100) and is therefore in scope and guaranteed set (the plugin defaults it upstream).Verification
Computing
nameBasedUniqueIdfor both of my devices, before and after:c5583c8a…vs636dfcea…19f83c0b…vs7c5b7ce1…763dc51f…vseef5d29e…c36e58e0…vs61324296…cb7e57d4…vs02aefa4e…74aae75b…vs5b1c6400…e88488f2…vsbf0604dc…7/7 collide before, 0/7 after.
npm run build(lint + tsc) passes clean.Compatibility
uniqueIdhashesusername + aid + iid + type, none of which change here, so existing Homebridge UI room layouts and HomeKit pairings are preserved. This is not a bridge-identity change.The user-visible effect is that service names in the Home app become e.g. "Blue Room View Plus Temp" instead of "Temp". Names users have set themselves in the Home app take precedence and are unaffected. If you'd rather not change this for existing single-device users, I'm happy to put it behind a config flag or apply the prefix only when more than one accessory is configured — just say which you'd prefer.
🤖 Generated with Claude Code
https://claude.ai/code/session_01SPgfBrVBq5w5useKSLXR14