Name devices by type alone, so entity_ids stay readable

Home Assistant mints an entity_id from the device name plus the entity
name, never from the unique_id, so the OCF device UUID the entries are now
keyed on (#381) was never at risk of reaching one. What did reach one is
the model: `device_display_name` folded modelNum into the device name, and
modelNum is a board string, so a fridge registered 46 entities along the
lines of `sensor.samsung_refrigerator_artik051_dongle_ref_energy`.

The name is now the appliance type alone -- `sensor.samsung_refrigerator_
energy`. The model is unchanged on DeviceInfo's own `model` field, where
the device page shows it and nothing derives an entity_id from it. Two
registry type names get an explicit display spelling, since they are
SmartThings/Samsung strings rather than English: 'airconditioner' and
'ehs'.

Subdevice devices (#177) had the same problem twice over, taking the
sibling's own board string ('Samsung Air Conditioner Tp2X Fac Bora Rac
21K'), so they are numbered by position instead: the master is unit 1 and
the first sibling is Unit 2.

Upgrading renames devices, which is display-only -- an entity_id is
assigned once, at first registration, so existing ids and the automations
referencing them are untouched. Only newly discovered entities get the
shorter form.

Three tests read entity_ids out of the registry after a real entry setup,
which is the only place the device name and the translated entity name are
combined: one pins the readable form, one asserts no id carries the device
key (or the literal 'None' HA appends when an entity has no name at all),
and one asserts the board string stays off.
This commit is contained in:
Marc Billow committed 2026-08-18 03:29:35 +00:00
1 parent 01c9dc9801
commit f2e0485b03
8 files changed
+130 -30

No files matched your search

+17
View File
@@ -2,6 +2,7 @@ import cbor2
from custom_components.localthings.registry.identity import (
DeviceIdentity,
device_display_name,
is_usable_device_id,
ocf_device_key,
read_identity,
@@ -252,3 +253,19 @@ def test_ocf_device_key_reports_absence_rather_than_collapsing_to_the_serial():
assert ocf_device_key(None) is None
assert ocf_device_key(_identity(serial="REAL-SERIAL")) is None
assert ocf_device_key(_identity(device_id="abc-123")) == "abc-123"
def test_the_device_name_is_the_device_type_alone():
"""The name is what HA slugifies into every entity_id on the device, so
the board string that modelNum reports stays out of it -- it is still
registered as the device's `model` (see coordinator.device_info)."""
assert device_display_name("refrigerator") == "Samsung Refrigerator"
assert device_display_name("range_hood") == "Samsung Range Hood"
assert device_display_name(None) == "Samsung Appliance"
def test_registry_type_names_that_dont_title_case_into_english():
"""Two registry names are SmartThings/Samsung spellings, not what the
appliance is called -- and this one is the user-visible half."""
assert device_display_name("airconditioner") == "Samsung Air Conditioner"
assert device_display_name("ehs") == "Samsung Heat Pump"